]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - fs/aufs/vfsub.c
UBUNTU: SAUCE: AUFS
[mirror_ubuntu-jammy-kernel.git] / fs / aufs / vfsub.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2005-2021 Junjiro R. Okajima
4 *
5 * This program, aufs is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /*
20 * sub-routines for VFS
21 */
22
23 #include <linux/mnt_namespace.h>
24 #include <linux/namei.h>
25 #include <linux/nsproxy.h>
26 #include <linux/security.h>
27 #include <linux/splice.h>
28 #include "aufs.h"
29
30 #ifdef CONFIG_AUFS_BR_FUSE
31 int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
32 {
33 if (!au_test_fuse(h_sb) || !au_userns)
34 return 0;
35
36 return is_current_mnt_ns(mnt) ? 0 : -EACCES;
37 }
38 #endif
39
40 int vfsub_sync_filesystem(struct super_block *h_sb, int wait)
41 {
42 int err;
43
44 lockdep_off();
45 down_read(&h_sb->s_umount);
46 err = __sync_filesystem(h_sb, wait);
47 up_read(&h_sb->s_umount);
48 lockdep_on();
49
50 return err;
51 }
52
53 /* ---------------------------------------------------------------------- */
54
55 int vfsub_update_h_iattr(struct path *h_path, int *did)
56 {
57 int err;
58 struct kstat st;
59 struct super_block *h_sb;
60
61 /*
62 * Always needs h_path->mnt for LSM or FUSE branch.
63 */
64 AuDebugOn(!h_path->mnt);
65
66 /* for remote fs, leave work for its getattr or d_revalidate */
67 /* for bad i_attr fs, handle them in aufs_getattr() */
68 /* still some fs may acquire i_mutex. we need to skip them */
69 err = 0;
70 if (!did)
71 did = &err;
72 h_sb = h_path->dentry->d_sb;
73 *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
74 if (*did)
75 err = vfsub_getattr(h_path, &st);
76
77 return err;
78 }
79
80 /* ---------------------------------------------------------------------- */
81
82 struct file *vfsub_dentry_open(struct path *path, int flags)
83 {
84 return dentry_open(path, flags /* | __FMODE_NONOTIFY */,
85 current_cred());
86 }
87
88 struct file *vfsub_filp_open(const char *path, int oflags, int mode)
89 {
90 struct file *file;
91
92 lockdep_off();
93 file = filp_open(path,
94 oflags /* | __FMODE_NONOTIFY */,
95 mode);
96 lockdep_on();
97 if (IS_ERR(file))
98 goto out;
99 vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
100
101 out:
102 return file;
103 }
104
105 /*
106 * Ideally this function should call VFS:do_last() in order to keep all its
107 * checkings. But it is very hard for aufs to regenerate several VFS internal
108 * structure such as nameidata. This is a second (or third) best approach.
109 * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
110 */
111 int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
112 struct vfsub_aopen_args *args)
113 {
114 int err;
115 struct au_branch *br = args->br;
116 struct file *file = args->file;
117 /* copied from linux/fs/namei.c:atomic_open() */
118 struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
119
120 IMustLock(dir);
121 AuDebugOn(!dir->i_op->atomic_open);
122
123 err = au_br_test_oflag(args->open_flag, br);
124 if (unlikely(err))
125 goto out;
126
127 au_lcnt_inc(&br->br_nfiles);
128 file->f_path.dentry = DENTRY_NOT_SET;
129 file->f_path.mnt = au_br_mnt(br);
130 AuDbg("%ps\n", dir->i_op->atomic_open);
131 err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
132 args->create_mode);
133 if (unlikely(err < 0)) {
134 au_lcnt_dec(&br->br_nfiles);
135 goto out;
136 }
137
138 /* temporary workaround for nfsv4 branch */
139 if (au_test_nfs(dir->i_sb))
140 nfs_mark_for_revalidate(dir);
141
142 if (file->f_mode & FMODE_CREATED)
143 fsnotify_create(dir, dentry);
144 if (!(file->f_mode & FMODE_OPENED)) {
145 au_lcnt_dec(&br->br_nfiles);
146 goto out;
147 }
148
149 /* todo: call VFS:may_open() here */
150 /* todo: ima_file_check() too? */
151 if (!err && (args->open_flag & __FMODE_EXEC))
152 err = deny_write_access(file);
153 if (!err)
154 fsnotify_open(file);
155 else
156 au_lcnt_dec(&br->br_nfiles);
157 /* note that the file is created and still opened */
158
159 out:
160 return err;
161 }
162
163 int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
164 {
165 int err;
166
167 err = kern_path(name, flags, path);
168 if (!err && d_is_positive(path->dentry))
169 vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
170 return err;
171 }
172
173 struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
174 struct path *ppath, int len)
175 {
176 struct path path;
177
178 path.dentry = lookup_one_len_unlocked(name, ppath->dentry, len);
179 if (IS_ERR(path.dentry))
180 goto out;
181 if (d_is_positive(path.dentry)) {
182 path.mnt = ppath->mnt;
183 vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
184 }
185
186 out:
187 AuTraceErrPtr(path.dentry);
188 return path.dentry;
189 }
190
191 struct dentry *vfsub_lookup_one_len(const char *name, struct path *ppath,
192 int len)
193 {
194 struct path path;
195
196 /* VFS checks it too, but by WARN_ON_ONCE() */
197 IMustLock(d_inode(ppath->dentry));
198
199 path.dentry = lookup_one_len(name, ppath->dentry, len);
200 if (IS_ERR(path.dentry))
201 goto out;
202 if (d_is_positive(path.dentry)) {
203 path.mnt = ppath->mnt;
204 vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
205 }
206
207 out:
208 AuTraceErrPtr(path.dentry);
209 return path.dentry;
210 }
211
212 void vfsub_call_lkup_one(void *args)
213 {
214 struct vfsub_lkup_one_args *a = args;
215 *a->errp = vfsub_lkup_one(a->name, a->ppath);
216 }
217
218 /* ---------------------------------------------------------------------- */
219
220 struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
221 struct dentry *d2, struct au_hinode *hdir2)
222 {
223 struct dentry *d;
224
225 lockdep_off();
226 d = lock_rename(d1, d2);
227 lockdep_on();
228 au_hn_suspend(hdir1);
229 if (hdir1 != hdir2)
230 au_hn_suspend(hdir2);
231
232 return d;
233 }
234
235 void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
236 struct dentry *d2, struct au_hinode *hdir2)
237 {
238 au_hn_resume(hdir1);
239 if (hdir1 != hdir2)
240 au_hn_resume(hdir2);
241 lockdep_off();
242 unlock_rename(d1, d2);
243 lockdep_on();
244 }
245
246 /* ---------------------------------------------------------------------- */
247
248 int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
249 {
250 int err;
251 struct dentry *d;
252 struct user_namespace *userns;
253
254 IMustLock(dir);
255
256 d = path->dentry;
257 path->dentry = d->d_parent;
258 err = security_path_mknod(path, d, mode, 0);
259 path->dentry = d;
260 if (unlikely(err))
261 goto out;
262 userns = mnt_user_ns(path->mnt);
263
264 lockdep_off();
265 err = vfs_create(userns, dir, path->dentry, mode, want_excl);
266 lockdep_on();
267 if (!err) {
268 struct path tmp = *path;
269 int did;
270
271 vfsub_update_h_iattr(&tmp, &did);
272 if (did) {
273 tmp.dentry = path->dentry->d_parent;
274 vfsub_update_h_iattr(&tmp, /*did*/NULL);
275 }
276 /*ignore*/
277 }
278
279 out:
280 return err;
281 }
282
283 int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
284 {
285 int err;
286 struct dentry *d;
287 struct user_namespace *userns;
288
289 IMustLock(dir);
290
291 d = path->dentry;
292 path->dentry = d->d_parent;
293 err = security_path_symlink(path, d, symname);
294 path->dentry = d;
295 if (unlikely(err))
296 goto out;
297 userns = mnt_user_ns(path->mnt);
298
299 lockdep_off();
300 err = vfs_symlink(userns, dir, path->dentry, symname);
301 lockdep_on();
302 if (!err) {
303 struct path tmp = *path;
304 int did;
305
306 vfsub_update_h_iattr(&tmp, &did);
307 if (did) {
308 tmp.dentry = path->dentry->d_parent;
309 vfsub_update_h_iattr(&tmp, /*did*/NULL);
310 }
311 /*ignore*/
312 }
313
314 out:
315 return err;
316 }
317
318 int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
319 {
320 int err;
321 struct dentry *d;
322 struct user_namespace *userns;
323
324 IMustLock(dir);
325
326 d = path->dentry;
327 path->dentry = d->d_parent;
328 err = security_path_mknod(path, d, mode, new_encode_dev(dev));
329 path->dentry = d;
330 if (unlikely(err))
331 goto out;
332 userns = mnt_user_ns(path->mnt);
333
334 lockdep_off();
335 err = vfs_mknod(userns, dir, path->dentry, mode, dev);
336 lockdep_on();
337 if (!err) {
338 struct path tmp = *path;
339 int did;
340
341 vfsub_update_h_iattr(&tmp, &did);
342 if (did) {
343 tmp.dentry = path->dentry->d_parent;
344 vfsub_update_h_iattr(&tmp, /*did*/NULL);
345 }
346 /*ignore*/
347 }
348
349 out:
350 return err;
351 }
352
353 static int au_test_nlink(struct inode *inode)
354 {
355 const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
356
357 if (!au_test_fs_no_limit_nlink(inode->i_sb)
358 || inode->i_nlink < link_max)
359 return 0;
360 return -EMLINK;
361 }
362
363 int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
364 struct inode **delegated_inode)
365 {
366 int err;
367 struct dentry *d;
368 struct user_namespace *userns;
369
370 IMustLock(dir);
371
372 err = au_test_nlink(d_inode(src_dentry));
373 if (unlikely(err))
374 return err;
375
376 /* we don't call may_linkat() */
377 d = path->dentry;
378 path->dentry = d->d_parent;
379 err = security_path_link(src_dentry, path, d);
380 path->dentry = d;
381 if (unlikely(err))
382 goto out;
383 userns = mnt_user_ns(path->mnt);
384
385 lockdep_off();
386 err = vfs_link(src_dentry, userns, dir, path->dentry, delegated_inode);
387 lockdep_on();
388 if (!err) {
389 struct path tmp = *path;
390 int did;
391
392 /* fuse has different memory inode for the same inumber */
393 vfsub_update_h_iattr(&tmp, &did);
394 if (did) {
395 tmp.dentry = path->dentry->d_parent;
396 vfsub_update_h_iattr(&tmp, /*did*/NULL);
397 tmp.dentry = src_dentry;
398 vfsub_update_h_iattr(&tmp, /*did*/NULL);
399 }
400 /*ignore*/
401 }
402
403 out:
404 return err;
405 }
406
407 int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
408 struct inode *dir, struct path *path,
409 struct inode **delegated_inode, unsigned int flags)
410 {
411 int err;
412 struct renamedata rd;
413 struct path tmp = {
414 .mnt = path->mnt
415 };
416 struct dentry *d;
417
418 IMustLock(dir);
419 IMustLock(src_dir);
420
421 d = path->dentry;
422 path->dentry = d->d_parent;
423 tmp.dentry = src_dentry->d_parent;
424 err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
425 path->dentry = d;
426 if (unlikely(err))
427 goto out;
428
429 rd.old_mnt_userns = mnt_user_ns(path->mnt);
430 rd.old_dir = src_dir;
431 rd.old_dentry = src_dentry;
432 rd.new_mnt_userns = rd.old_mnt_userns;
433 rd.new_dir = dir;
434 rd.new_dentry = path->dentry;
435 rd.delegated_inode = delegated_inode;
436 rd.flags = flags;
437 lockdep_off();
438 err = vfs_rename(&rd);
439 lockdep_on();
440 if (!err) {
441 int did;
442
443 tmp.dentry = d->d_parent;
444 vfsub_update_h_iattr(&tmp, &did);
445 if (did) {
446 tmp.dentry = src_dentry;
447 vfsub_update_h_iattr(&tmp, /*did*/NULL);
448 tmp.dentry = src_dentry->d_parent;
449 vfsub_update_h_iattr(&tmp, /*did*/NULL);
450 }
451 /*ignore*/
452 }
453
454 out:
455 return err;
456 }
457
458 int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
459 {
460 int err;
461 struct dentry *d;
462 struct user_namespace *userns;
463
464 IMustLock(dir);
465
466 d = path->dentry;
467 path->dentry = d->d_parent;
468 err = security_path_mkdir(path, d, mode);
469 path->dentry = d;
470 if (unlikely(err))
471 goto out;
472 userns = mnt_user_ns(path->mnt);
473
474 lockdep_off();
475 err = vfs_mkdir(userns, dir, path->dentry, mode);
476 lockdep_on();
477 if (!err) {
478 struct path tmp = *path;
479 int did;
480
481 vfsub_update_h_iattr(&tmp, &did);
482 if (did) {
483 tmp.dentry = path->dentry->d_parent;
484 vfsub_update_h_iattr(&tmp, /*did*/NULL);
485 }
486 /*ignore*/
487 }
488
489 out:
490 return err;
491 }
492
493 int vfsub_rmdir(struct inode *dir, struct path *path)
494 {
495 int err;
496 struct dentry *d;
497 struct user_namespace *userns;
498
499 IMustLock(dir);
500
501 d = path->dentry;
502 path->dentry = d->d_parent;
503 err = security_path_rmdir(path, d);
504 path->dentry = d;
505 if (unlikely(err))
506 goto out;
507 userns = mnt_user_ns(path->mnt);
508
509 lockdep_off();
510 err = vfs_rmdir(userns, dir, path->dentry);
511 lockdep_on();
512 if (!err) {
513 struct path tmp = {
514 .dentry = path->dentry->d_parent,
515 .mnt = path->mnt
516 };
517
518 vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
519 }
520
521 out:
522 return err;
523 }
524
525 /* ---------------------------------------------------------------------- */
526
527 /* todo: support mmap_sem? */
528 ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
529 loff_t *ppos)
530 {
531 ssize_t err;
532
533 lockdep_off();
534 err = vfs_read(file, ubuf, count, ppos);
535 lockdep_on();
536 if (err >= 0)
537 vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
538 return err;
539 }
540
541 ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
542 loff_t *ppos)
543 {
544 ssize_t err;
545
546 lockdep_off();
547 err = kernel_read(file, kbuf, count, ppos);
548 lockdep_on();
549 AuTraceErr(err);
550 if (err >= 0)
551 vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
552 return err;
553 }
554
555 ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
556 loff_t *ppos)
557 {
558 ssize_t err;
559
560 lockdep_off();
561 err = vfs_write(file, ubuf, count, ppos);
562 lockdep_on();
563 if (err >= 0)
564 vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
565 return err;
566 }
567
568 ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
569 {
570 ssize_t err;
571
572 lockdep_off();
573 err = kernel_write(file, kbuf, count, ppos);
574 lockdep_on();
575 if (err >= 0)
576 vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
577 return err;
578 }
579
580 int vfsub_flush(struct file *file, fl_owner_t id)
581 {
582 int err;
583
584 err = 0;
585 if (file->f_op->flush) {
586 if (!au_test_nfs(file->f_path.dentry->d_sb))
587 err = file->f_op->flush(file, id);
588 else {
589 lockdep_off();
590 err = file->f_op->flush(file, id);
591 lockdep_on();
592 }
593 if (!err)
594 vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
595 /*ignore*/
596 }
597 return err;
598 }
599
600 int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
601 {
602 int err;
603
604 AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos);
605
606 lockdep_off();
607 err = iterate_dir(file, ctx);
608 lockdep_on();
609 if (err >= 0)
610 vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
611
612 return err;
613 }
614
615 long vfsub_splice_to(struct file *in, loff_t *ppos,
616 struct pipe_inode_info *pipe, size_t len,
617 unsigned int flags)
618 {
619 long err;
620
621 lockdep_off();
622 err = do_splice_to(in, ppos, pipe, len, flags);
623 lockdep_on();
624 file_accessed(in);
625 if (err >= 0)
626 vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
627 return err;
628 }
629
630 long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
631 loff_t *ppos, size_t len, unsigned int flags)
632 {
633 long err;
634
635 lockdep_off();
636 err = do_splice_from(pipe, out, ppos, len, flags);
637 lockdep_on();
638 if (err >= 0)
639 vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
640 return err;
641 }
642
643 int vfsub_fsync(struct file *file, struct path *path, int datasync)
644 {
645 int err;
646
647 /* file can be NULL */
648 lockdep_off();
649 err = vfs_fsync(file, datasync);
650 lockdep_on();
651 if (!err) {
652 if (!path) {
653 AuDebugOn(!file);
654 path = &file->f_path;
655 }
656 vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
657 }
658 return err;
659 }
660
661 /* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
662 int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
663 struct file *h_file)
664 {
665 int err;
666 struct inode *h_inode;
667 struct super_block *h_sb;
668 struct user_namespace *h_userns;
669
670 if (!h_file) {
671 err = vfsub_truncate(h_path, length);
672 goto out;
673 }
674
675 h_inode = d_inode(h_path->dentry);
676 h_sb = h_inode->i_sb;
677 lockdep_off();
678 sb_start_write(h_sb);
679 lockdep_on();
680 err = security_path_truncate(h_path);
681 if (!err) {
682 h_userns = mnt_user_ns(h_path->mnt);
683 lockdep_off();
684 err = do_truncate(h_userns, h_path->dentry, length, attr,
685 h_file);
686 lockdep_on();
687 }
688 lockdep_off();
689 sb_end_write(h_sb);
690 lockdep_on();
691
692 out:
693 return err;
694 }
695
696 /* ---------------------------------------------------------------------- */
697
698 struct au_vfsub_mkdir_args {
699 int *errp;
700 struct inode *dir;
701 struct path *path;
702 int mode;
703 };
704
705 static void au_call_vfsub_mkdir(void *args)
706 {
707 struct au_vfsub_mkdir_args *a = args;
708 *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
709 }
710
711 int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
712 {
713 int err, do_sio, wkq_err;
714 struct user_namespace *userns;
715
716 userns = mnt_user_ns(path->mnt);
717 do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
718 if (!do_sio) {
719 lockdep_off();
720 err = vfsub_mkdir(dir, path, mode);
721 lockdep_on();
722 } else {
723 struct au_vfsub_mkdir_args args = {
724 .errp = &err,
725 .dir = dir,
726 .path = path,
727 .mode = mode
728 };
729 wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
730 if (unlikely(wkq_err))
731 err = wkq_err;
732 }
733
734 return err;
735 }
736
737 struct au_vfsub_rmdir_args {
738 int *errp;
739 struct inode *dir;
740 struct path *path;
741 };
742
743 static void au_call_vfsub_rmdir(void *args)
744 {
745 struct au_vfsub_rmdir_args *a = args;
746 *a->errp = vfsub_rmdir(a->dir, a->path);
747 }
748
749 int vfsub_sio_rmdir(struct inode *dir, struct path *path)
750 {
751 int err, do_sio, wkq_err;
752 struct user_namespace *userns;
753
754 userns = mnt_user_ns(path->mnt);
755 do_sio = au_test_h_perm_sio(userns, dir, MAY_EXEC | MAY_WRITE);
756 if (!do_sio) {
757 lockdep_off();
758 err = vfsub_rmdir(dir, path);
759 lockdep_on();
760 } else {
761 struct au_vfsub_rmdir_args args = {
762 .errp = &err,
763 .dir = dir,
764 .path = path
765 };
766 wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
767 if (unlikely(wkq_err))
768 err = wkq_err;
769 }
770
771 return err;
772 }
773
774 /* ---------------------------------------------------------------------- */
775
776 struct notify_change_args {
777 int *errp;
778 struct path *path;
779 struct iattr *ia;
780 struct inode **delegated_inode;
781 };
782
783 static void call_notify_change(void *args)
784 {
785 struct notify_change_args *a = args;
786 struct inode *h_inode;
787 struct user_namespace *userns;
788
789 h_inode = d_inode(a->path->dentry);
790 IMustLock(h_inode);
791
792 *a->errp = -EPERM;
793 if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
794 userns = mnt_user_ns(a->path->mnt);
795 lockdep_off();
796 *a->errp = notify_change(userns, a->path->dentry, a->ia,
797 a->delegated_inode);
798 lockdep_on();
799 if (!*a->errp)
800 vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
801 }
802 AuTraceErr(*a->errp);
803 }
804
805 int vfsub_notify_change(struct path *path, struct iattr *ia,
806 struct inode **delegated_inode)
807 {
808 int err;
809 struct notify_change_args args = {
810 .errp = &err,
811 .path = path,
812 .ia = ia,
813 .delegated_inode = delegated_inode
814 };
815
816 call_notify_change(&args);
817
818 return err;
819 }
820
821 int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
822 struct inode **delegated_inode)
823 {
824 int err, wkq_err;
825 struct notify_change_args args = {
826 .errp = &err,
827 .path = path,
828 .ia = ia,
829 .delegated_inode = delegated_inode
830 };
831
832 wkq_err = au_wkq_wait(call_notify_change, &args);
833 if (unlikely(wkq_err))
834 err = wkq_err;
835
836 return err;
837 }
838
839 /* ---------------------------------------------------------------------- */
840
841 struct unlink_args {
842 int *errp;
843 struct inode *dir;
844 struct path *path;
845 struct inode **delegated_inode;
846 };
847
848 static void call_unlink(void *args)
849 {
850 struct unlink_args *a = args;
851 struct dentry *d = a->path->dentry;
852 struct inode *h_inode;
853 struct user_namespace *userns;
854 const int stop_sillyrename = (au_test_nfs(d->d_sb)
855 && au_dcount(d) == 1);
856
857 IMustLock(a->dir);
858
859 a->path->dentry = d->d_parent;
860 *a->errp = security_path_unlink(a->path, d);
861 a->path->dentry = d;
862 if (unlikely(*a->errp))
863 return;
864
865 if (!stop_sillyrename)
866 dget(d);
867 h_inode = NULL;
868 if (d_is_positive(d)) {
869 h_inode = d_inode(d);
870 ihold(h_inode);
871 }
872
873 userns = mnt_user_ns(a->path->mnt);
874 lockdep_off();
875 *a->errp = vfs_unlink(userns, a->dir, d, a->delegated_inode);
876 lockdep_on();
877 if (!*a->errp) {
878 struct path tmp = {
879 .dentry = d->d_parent,
880 .mnt = a->path->mnt
881 };
882 vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
883 }
884
885 if (!stop_sillyrename)
886 dput(d);
887 if (h_inode)
888 iput(h_inode);
889
890 AuTraceErr(*a->errp);
891 }
892
893 /*
894 * @dir: must be locked.
895 * @dentry: target dentry.
896 */
897 int vfsub_unlink(struct inode *dir, struct path *path,
898 struct inode **delegated_inode, int force)
899 {
900 int err;
901 struct unlink_args args = {
902 .errp = &err,
903 .dir = dir,
904 .path = path,
905 .delegated_inode = delegated_inode
906 };
907
908 if (!force)
909 call_unlink(&args);
910 else {
911 int wkq_err;
912
913 wkq_err = au_wkq_wait(call_unlink, &args);
914 if (unlikely(wkq_err))
915 err = wkq_err;
916 }
917
918 return err;
919 }