1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2011 Novell Inc.
7 #include <linux/module.h>
9 #include <linux/slab.h>
10 #include <linux/file.h>
11 #include <linux/fileattr.h>
12 #include <linux/splice.h>
13 #include <linux/xattr.h>
14 #include <linux/security.h>
15 #include <linux/uaccess.h>
16 #include <linux/sched/signal.h>
17 #include <linux/cred.h>
18 #include <linux/namei.h>
19 #include <linux/fdtable.h>
20 #include <linux/ratelimit.h>
21 #include <linux/exportfs.h>
22 #include "overlayfs.h"
24 #define OVL_COPY_UP_CHUNK_SIZE (1 << 20)
26 static int ovl_ccup_set(const char *buf, const struct kernel_param *param)
28 pr_warn("\"check_copy_up\" module option is obsolete\n");
32 static int ovl_ccup_get(char *buf, const struct kernel_param *param)
34 return sprintf(buf, "N\n");
37 module_param_call(check_copy_up, ovl_ccup_set, ovl_ccup_get, NULL, 0644);
38 MODULE_PARM_DESC(check_copy_up, "Obsolete; does nothing");
40 static bool ovl_must_copy_xattr(const char *name)
42 return !strcmp(name, XATTR_POSIX_ACL_ACCESS) ||
43 !strcmp(name, XATTR_POSIX_ACL_DEFAULT) ||
44 !strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN);
47 int ovl_copy_xattr(struct super_block *sb, struct dentry *old,
50 ssize_t list_size, size, value_size = 0;
51 char *buf, *name, *value = NULL;
55 if (!(old->d_inode->i_opflags & IOP_XATTR) ||
56 !(new->d_inode->i_opflags & IOP_XATTR))
59 list_size = vfs_listxattr(old, NULL, 0);
61 if (list_size == -EOPNOTSUPP)
66 buf = kvzalloc(list_size, GFP_KERNEL);
70 list_size = vfs_listxattr(old, buf, list_size);
76 for (name = buf; list_size; name += slen) {
77 slen = strnlen(name, list_size) + 1;
79 /* underlying fs providing us with an broken xattr list? */
80 if (WARN_ON(slen > list_size)) {
86 if (ovl_is_private_xattr(sb, name))
89 error = security_inode_copy_up_xattr(name);
90 if (error < 0 && error != -EOPNOTSUPP)
94 continue; /* Discard */
97 size = vfs_getxattr(&init_user_ns, old, name, value, value_size);
99 size = vfs_getxattr(&init_user_ns, old, name, NULL, 0);
106 if (size > value_size) {
109 new = kvmalloc(size, GFP_KERNEL);
120 error = vfs_setxattr(&init_user_ns, new, name, value, size, 0);
122 if (error != -EOPNOTSUPP || ovl_must_copy_xattr(name))
125 /* Ignore failure to copy unknown xattrs */
135 static int ovl_copy_fileattr(struct inode *inode, struct path *old,
138 struct fileattr oldfa = { .flags_valid = true };
139 struct fileattr newfa = { .flags_valid = true };
142 err = ovl_real_fileattr_get(old, &oldfa);
146 err = ovl_real_fileattr_get(new, &newfa);
151 * We cannot set immutable and append-only flags on upper inode,
152 * because we would not be able to link upper inode to upper dir
153 * not set overlay private xattr on upper inode.
154 * Store these flags in overlay.protattr xattr instead.
156 if (oldfa.flags & OVL_PROT_FS_FLAGS_MASK) {
157 err = ovl_set_protattr(inode, new->dentry, &oldfa);
162 BUILD_BUG_ON(OVL_COPY_FS_FLAGS_MASK & ~FS_COMMON_FL);
163 newfa.flags &= ~OVL_COPY_FS_FLAGS_MASK;
164 newfa.flags |= (oldfa.flags & OVL_COPY_FS_FLAGS_MASK);
166 BUILD_BUG_ON(OVL_COPY_FSX_FLAGS_MASK & ~FS_XFLAG_COMMON);
167 newfa.fsx_xflags &= ~OVL_COPY_FSX_FLAGS_MASK;
168 newfa.fsx_xflags |= (oldfa.fsx_xflags & OVL_COPY_FSX_FLAGS_MASK);
170 return ovl_real_fileattr_set(new, &newfa);
173 static int ovl_copy_up_data(struct ovl_fs *ofs, struct path *old,
174 struct path *new, loff_t len)
176 struct file *old_file;
177 struct file *new_file;
181 loff_t data_pos = -1;
183 bool skip_hole = false;
189 old_file = ovl_path_open(old, O_LARGEFILE | O_RDONLY);
190 if (IS_ERR(old_file))
191 return PTR_ERR(old_file);
193 new_file = ovl_path_open(new, O_LARGEFILE | O_WRONLY);
194 if (IS_ERR(new_file)) {
195 error = PTR_ERR(new_file);
199 /* Try to use clone_file_range to clone up within the same fs */
200 cloned = do_clone_file_range(old_file, 0, new_file, 0, len, 0);
203 /* Couldn't clone, so now we try to copy the data */
205 /* Check if lower fs supports seek operation */
206 if (old_file->f_mode & FMODE_LSEEK &&
207 old_file->f_op->llseek)
211 size_t this_len = OVL_COPY_UP_CHUNK_SIZE;
217 if (signal_pending_state(TASK_KILLABLE, current)) {
223 * Fill zero for hole will cost unnecessary disk space
224 * and meanwhile slow down the copy-up speed, so we do
225 * an optimization for hole during copy-up, it relies
226 * on SEEK_DATA implementation in lower fs so if lower
227 * fs does not support it, copy-up will behave as before.
229 * Detail logic of hole detection as below:
230 * When we detect next data position is larger than current
231 * position we will skip that hole, otherwise we copy
232 * data in the size of OVL_COPY_UP_CHUNK_SIZE. Actually,
233 * it may not recognize all kind of holes and sometimes
234 * only skips partial of hole area. However, it will be
235 * enough for most of the use cases.
238 if (skip_hole && data_pos < old_pos) {
239 data_pos = vfs_llseek(old_file, old_pos, SEEK_DATA);
240 if (data_pos > old_pos) {
241 hole_len = data_pos - old_pos;
243 old_pos = new_pos = data_pos;
245 } else if (data_pos == -ENXIO) {
247 } else if (data_pos < 0) {
252 bytes = do_splice_direct(old_file, &old_pos,
254 this_len, SPLICE_F_MOVE);
259 WARN_ON(old_pos != new_pos);
264 if (!error && ovl_should_sync(ofs))
265 error = vfs_fsync(new_file, 0);
272 static int ovl_set_size(struct dentry *upperdentry, struct kstat *stat)
274 struct iattr attr = {
275 .ia_valid = ATTR_SIZE,
276 .ia_size = stat->size,
279 return notify_change(&init_user_ns, upperdentry, &attr, NULL);
282 static int ovl_set_timestamps(struct dentry *upperdentry, struct kstat *stat)
284 struct iattr attr = {
286 ATTR_ATIME | ATTR_MTIME | ATTR_ATIME_SET | ATTR_MTIME_SET,
287 .ia_atime = stat->atime,
288 .ia_mtime = stat->mtime,
291 return notify_change(&init_user_ns, upperdentry, &attr, NULL);
294 int ovl_set_attr(struct dentry *upperdentry, struct kstat *stat)
298 if (!S_ISLNK(stat->mode)) {
299 struct iattr attr = {
300 .ia_valid = ATTR_MODE,
301 .ia_mode = stat->mode,
303 err = notify_change(&init_user_ns, upperdentry, &attr, NULL);
306 struct iattr attr = {
307 .ia_valid = ATTR_UID | ATTR_GID,
311 err = notify_change(&init_user_ns, upperdentry, &attr, NULL);
314 ovl_set_timestamps(upperdentry, stat);
319 struct ovl_fh *ovl_encode_real_fh(struct ovl_fs *ofs, struct dentry *real,
324 int buflen = MAX_HANDLE_SZ;
325 uuid_t *uuid = &real->d_sb->s_uuid;
328 /* Make sure the real fid stays 32bit aligned */
329 BUILD_BUG_ON(OVL_FH_FID_OFFSET % 4);
330 BUILD_BUG_ON(MAX_HANDLE_SZ + OVL_FH_FID_OFFSET > 255);
332 fh = kzalloc(buflen + OVL_FH_FID_OFFSET, GFP_KERNEL);
334 return ERR_PTR(-ENOMEM);
337 * We encode a non-connectable file handle for non-dir, because we
338 * only need to find the lower inode number and we don't want to pay
339 * the price or reconnecting the dentry.
341 dwords = buflen >> 2;
342 fh_type = exportfs_encode_fh(real, (void *)fh->fb.fid, &dwords, 0);
343 buflen = (dwords << 2);
346 if (WARN_ON(fh_type < 0) ||
347 WARN_ON(buflen > MAX_HANDLE_SZ) ||
348 WARN_ON(fh_type == FILEID_INVALID))
351 fh->fb.version = OVL_FH_VERSION;
352 fh->fb.magic = OVL_FH_MAGIC;
353 fh->fb.type = fh_type;
354 fh->fb.flags = OVL_FH_FLAG_CPU_ENDIAN;
356 * When we will want to decode an overlay dentry from this handle
357 * and all layers are on the same fs, if we get a disconncted real
358 * dentry when we decode fid, the only way to tell if we should assign
359 * it to upperdentry or to lowerstack is by checking this flag.
362 fh->fb.flags |= OVL_FH_FLAG_PATH_UPPER;
363 fh->fb.len = sizeof(fh->fb) + buflen;
364 if (ofs->config.uuid)
374 int ovl_set_origin(struct ovl_fs *ofs, struct dentry *lower,
375 struct dentry *upper)
377 const struct ovl_fh *fh = NULL;
381 * When lower layer doesn't support export operations store a 'null' fh,
382 * so we can use the overlay.origin xattr to distignuish between a copy
383 * up and a pure upper inode.
385 if (ovl_can_decode_fh(lower->d_sb)) {
386 fh = ovl_encode_real_fh(ofs, lower, false);
392 * Do not fail when upper doesn't support xattrs.
394 err = ovl_check_setxattr(ofs, upper, OVL_XATTR_ORIGIN, fh->buf,
395 fh ? fh->fb.len : 0, 0);
398 /* Ignore -EPERM from setting "user.*" on symlink/special */
399 return err == -EPERM ? 0 : err;
402 /* Store file handle of @upper dir in @index dir entry */
403 static int ovl_set_upper_fh(struct ovl_fs *ofs, struct dentry *upper,
404 struct dentry *index)
406 const struct ovl_fh *fh;
409 fh = ovl_encode_real_fh(ofs, upper, true);
413 err = ovl_do_setxattr(ofs, index, OVL_XATTR_UPPER, fh->buf, fh->fb.len);
420 * Create and install index entry.
422 * Caller must hold i_mutex on indexdir.
424 static int ovl_create_index(struct dentry *dentry, struct dentry *origin,
425 struct dentry *upper)
427 struct ovl_fs *ofs = OVL_FS(dentry->d_sb);
428 struct dentry *indexdir = ovl_indexdir(dentry->d_sb);
429 struct inode *dir = d_inode(indexdir);
430 struct dentry *index = NULL;
431 struct dentry *temp = NULL;
432 struct qstr name = { };
436 * For now this is only used for creating index entry for directories,
437 * because non-dir are copied up directly to index and then hardlinked
440 * TODO: implement create index for non-dir, so we can call it when
441 * encoding file handle for non-dir in case index does not exist.
443 if (WARN_ON(!d_is_dir(dentry)))
446 /* Directory not expected to be indexed before copy up */
447 if (WARN_ON(ovl_test_flag(OVL_INDEX, d_inode(dentry))))
450 err = ovl_get_index_name(ofs, origin, &name);
454 temp = ovl_create_temp(indexdir, OVL_CATTR(S_IFDIR | 0));
459 err = ovl_set_upper_fh(ofs, upper, temp);
463 index = lookup_one_len(name.name, indexdir, name.len);
465 err = PTR_ERR(index);
467 err = ovl_do_rename(dir, temp, dir, index, 0);
472 ovl_cleanup(dir, temp);
479 struct ovl_copy_up_ctx {
480 struct dentry *parent;
481 struct dentry *dentry;
482 struct path lowerpath;
486 struct dentry *destdir;
487 struct qstr destname;
488 struct dentry *workdir;
494 static int ovl_link_up(struct ovl_copy_up_ctx *c)
497 struct dentry *upper;
498 struct dentry *upperdir = ovl_dentry_upper(c->parent);
499 struct inode *udir = d_inode(upperdir);
501 /* Mark parent "impure" because it may now contain non-pure upper */
502 err = ovl_set_impure(c->parent, upperdir);
506 err = ovl_set_nlink_lower(c->dentry);
510 inode_lock_nested(udir, I_MUTEX_PARENT);
511 upper = lookup_one_len(c->dentry->d_name.name, upperdir,
512 c->dentry->d_name.len);
513 err = PTR_ERR(upper);
514 if (!IS_ERR(upper)) {
515 err = ovl_do_link(ovl_dentry_upper(c->dentry), udir, upper);
519 /* Restore timestamps on parent (best effort) */
520 ovl_set_timestamps(upperdir, &c->pstat);
521 ovl_dentry_set_upper_alias(c->dentry);
528 err = ovl_set_nlink_upper(c->dentry);
533 static int ovl_copy_up_inode(struct ovl_copy_up_ctx *c, struct dentry *temp)
535 struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb);
536 struct inode *inode = d_inode(c->dentry);
537 struct path upperpath, datapath;
540 ovl_path_upper(c->dentry, &upperpath);
541 if (WARN_ON(upperpath.dentry != NULL))
544 upperpath.dentry = temp;
547 * Copy up data first and then xattrs. Writing data after
548 * xattrs will remove security.capability xattr automatically.
550 if (S_ISREG(c->stat.mode) && !c->metacopy) {
551 ovl_path_lowerdata(c->dentry, &datapath);
552 err = ovl_copy_up_data(ofs, &datapath, &upperpath,
558 err = ovl_copy_xattr(c->dentry->d_sb, c->lowerpath.dentry, temp);
562 if (inode->i_flags & OVL_COPY_I_FLAGS_MASK) {
564 * Copy the fileattr inode flags that are the source of already
567 err = ovl_copy_fileattr(inode, &c->lowerpath, &upperpath);
573 * Store identifier of lower inode in upper inode xattr to
574 * allow lookup of the copy up origin inode.
576 * Don't set origin when we are breaking the association with a lower
580 err = ovl_set_origin(ofs, c->lowerpath.dentry, temp);
586 err = ovl_check_setxattr(ofs, temp, OVL_XATTR_METACOPY,
587 NULL, 0, -EOPNOTSUPP);
592 inode_lock(temp->d_inode);
593 if (S_ISREG(c->stat.mode))
594 err = ovl_set_size(temp, &c->stat);
596 err = ovl_set_attr(temp, &c->stat);
597 inode_unlock(temp->d_inode);
602 struct ovl_cu_creds {
603 const struct cred *old;
607 static int ovl_prep_cu_creds(struct dentry *dentry, struct ovl_cu_creds *cc)
611 cc->old = cc->new = NULL;
612 err = security_inode_copy_up(dentry, &cc->new);
617 cc->old = override_creds(cc->new);
622 static void ovl_revert_cu_creds(struct ovl_cu_creds *cc)
625 revert_creds(cc->old);
631 * Copyup using workdir to prepare temp file. Used when copying up directories,
632 * special files or when upper fs doesn't support O_TMPFILE.
634 static int ovl_copy_up_workdir(struct ovl_copy_up_ctx *c)
637 struct inode *udir = d_inode(c->destdir), *wdir = d_inode(c->workdir);
638 struct dentry *temp, *upper;
639 struct ovl_cu_creds cc;
641 struct ovl_cattr cattr = {
642 /* Can't properly set mode on creation because of the umask */
643 .mode = c->stat.mode & S_IFMT,
644 .rdev = c->stat.rdev,
648 /* workdir and destdir could be the same when copying up to indexdir */
650 if (lock_rename(c->workdir, c->destdir) != NULL)
653 err = ovl_prep_cu_creds(c->dentry, &cc);
657 temp = ovl_create_temp(c->workdir, &cattr);
658 ovl_revert_cu_creds(&cc);
664 err = ovl_copy_up_inode(c, temp);
668 if (S_ISDIR(c->stat.mode) && c->indexed) {
669 err = ovl_create_index(c->dentry, c->lowerpath.dentry, temp);
674 upper = lookup_one_len(c->destname.name, c->destdir, c->destname.len);
675 err = PTR_ERR(upper);
679 err = ovl_do_rename(wdir, temp, udir, upper, 0);
685 ovl_set_upperdata(d_inode(c->dentry));
686 inode = d_inode(c->dentry);
687 ovl_inode_update(inode, temp);
688 if (S_ISDIR(inode->i_mode))
689 ovl_set_flag(OVL_WHITEOUTS, inode);
691 unlock_rename(c->workdir, c->destdir);
696 ovl_cleanup(wdir, temp);
701 /* Copyup using O_TMPFILE which does not require cross dir locking */
702 static int ovl_copy_up_tmpfile(struct ovl_copy_up_ctx *c)
704 struct inode *udir = d_inode(c->destdir);
705 struct dentry *temp, *upper;
706 struct ovl_cu_creds cc;
709 err = ovl_prep_cu_creds(c->dentry, &cc);
713 temp = ovl_do_tmpfile(c->workdir, c->stat.mode);
714 ovl_revert_cu_creds(&cc);
717 return PTR_ERR(temp);
719 err = ovl_copy_up_inode(c, temp);
723 inode_lock_nested(udir, I_MUTEX_PARENT);
725 upper = lookup_one_len(c->destname.name, c->destdir, c->destname.len);
726 err = PTR_ERR(upper);
727 if (!IS_ERR(upper)) {
728 err = ovl_do_link(temp, udir, upper);
737 ovl_set_upperdata(d_inode(c->dentry));
738 ovl_inode_update(d_inode(c->dentry), temp);
748 * Copy up a single dentry
750 * All renames start with copy up of source if necessary. The actual
751 * rename will only proceed once the copy up was successful. Copy up uses
752 * upper parent i_mutex for exclusion. Since rename can change d_parent it
753 * is possible that the copy up will lock the old parent. At that point
754 * the file will have already been copied up anyway.
756 static int ovl_do_copy_up(struct ovl_copy_up_ctx *c)
759 struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb);
760 bool to_index = false;
763 * Indexed non-dir is copied up directly to the index entry and then
764 * hardlinked to upper dir. Indexed dir is copied up to indexdir,
765 * then index entry is created and then copied up dir installed.
766 * Copying dir up to indexdir instead of workdir simplifies locking.
768 if (ovl_need_index(c->dentry)) {
770 if (S_ISDIR(c->stat.mode))
771 c->workdir = ovl_indexdir(c->dentry->d_sb);
776 if (S_ISDIR(c->stat.mode) || c->stat.nlink == 1 || to_index)
780 c->destdir = ovl_indexdir(c->dentry->d_sb);
781 err = ovl_get_index_name(ofs, c->lowerpath.dentry, &c->destname);
784 } else if (WARN_ON(!c->parent)) {
785 /* Disconnected dentry must be copied up to index dir */
789 * Mark parent "impure" because it may now contain non-pure
792 err = ovl_set_impure(c->parent, c->destdir);
797 /* Should we copyup with O_TMPFILE or with workdir? */
798 if (S_ISREG(c->stat.mode) && ofs->tmpfile)
799 err = ovl_copy_up_tmpfile(c);
801 err = ovl_copy_up_workdir(c);
806 ovl_set_flag(OVL_INDEX, d_inode(c->dentry));
809 /* Initialize nlink for copy up of disconnected dentry */
810 err = ovl_set_nlink_upper(c->dentry);
812 struct inode *udir = d_inode(c->destdir);
814 /* Restore timestamps on parent (best effort) */
816 ovl_set_timestamps(c->destdir, &c->pstat);
819 ovl_dentry_set_upper_alias(c->dentry);
824 kfree(c->destname.name);
828 static bool ovl_need_meta_copy_up(struct dentry *dentry, umode_t mode,
831 struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
833 if (!ofs->config.metacopy)
839 if (flags && ((OPEN_FMODE(flags) & FMODE_WRITE) || (flags & O_TRUNC)))
845 static ssize_t ovl_getxattr(struct dentry *dentry, char *name, char **value)
850 res = vfs_getxattr(&init_user_ns, dentry, name, NULL, 0);
851 if (res == -ENODATA || res == -EOPNOTSUPP)
855 buf = kzalloc(res, GFP_KERNEL);
859 res = vfs_getxattr(&init_user_ns, dentry, name, buf, res);
868 /* Copy up data of an inode which was copied up metadata only in the past. */
869 static int ovl_copy_up_meta_inode_data(struct ovl_copy_up_ctx *c)
871 struct ovl_fs *ofs = OVL_FS(c->dentry->d_sb);
872 struct path upperpath, datapath;
874 char *capability = NULL;
877 ovl_path_upper(c->dentry, &upperpath);
878 if (WARN_ON(upperpath.dentry == NULL))
881 ovl_path_lowerdata(c->dentry, &datapath);
882 if (WARN_ON(datapath.dentry == NULL))
886 err = cap_size = ovl_getxattr(upperpath.dentry, XATTR_NAME_CAPS,
892 err = ovl_copy_up_data(ofs, &datapath, &upperpath, c->stat.size);
897 * Writing to upper file will clear security.capability xattr. We
898 * don't want that to happen for normal copy-up operation.
901 err = vfs_setxattr(&init_user_ns, upperpath.dentry,
902 XATTR_NAME_CAPS, capability, cap_size, 0);
908 err = ovl_do_removexattr(ofs, upperpath.dentry, OVL_XATTR_METACOPY);
912 ovl_set_upperdata(d_inode(c->dentry));
919 static int ovl_copy_up_one(struct dentry *parent, struct dentry *dentry,
923 DEFINE_DELAYED_CALL(done);
924 struct path parentpath;
925 struct ovl_copy_up_ctx ctx = {
928 .workdir = ovl_workdir(dentry),
931 if (WARN_ON(!ctx.workdir))
934 ovl_path_lower(dentry, &ctx.lowerpath);
935 err = vfs_getattr(&ctx.lowerpath, &ctx.stat,
936 STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
940 ctx.metacopy = ovl_need_meta_copy_up(dentry, ctx.stat.mode, flags);
943 ovl_path_upper(parent, &parentpath);
944 ctx.destdir = parentpath.dentry;
945 ctx.destname = dentry->d_name;
947 err = vfs_getattr(&parentpath, &ctx.pstat,
948 STATX_ATIME | STATX_MTIME,
949 AT_STATX_SYNC_AS_STAT);
954 /* maybe truncate regular file. this has no effect on dirs */
958 if (S_ISLNK(ctx.stat.mode)) {
959 ctx.link = vfs_get_link(ctx.lowerpath.dentry, &done);
960 if (IS_ERR(ctx.link))
961 return PTR_ERR(ctx.link);
964 err = ovl_copy_up_start(dentry, flags);
965 /* err < 0: interrupted, err > 0: raced with another copy-up */
970 if (!ovl_dentry_upper(dentry))
971 err = ovl_do_copy_up(&ctx);
972 if (!err && parent && !ovl_dentry_has_upper_alias(dentry))
973 err = ovl_link_up(&ctx);
974 if (!err && ovl_dentry_needs_data_copy_up_locked(dentry, flags))
975 err = ovl_copy_up_meta_inode_data(&ctx);
976 ovl_copy_up_end(dentry);
978 do_delayed_call(&done);
983 static int ovl_copy_up_flags(struct dentry *dentry, int flags)
986 const struct cred *old_cred;
987 bool disconnected = (dentry->d_flags & DCACHE_DISCONNECTED);
990 * With NFS export, copy up can get called for a disconnected non-dir.
991 * In this case, we will copy up lower inode to index dir without
992 * linking it to upper dir.
994 if (WARN_ON(disconnected && d_is_dir(dentry)))
997 old_cred = ovl_override_creds(dentry->d_sb);
1000 struct dentry *parent = NULL;
1002 if (ovl_already_copied_up(dentry, flags))
1005 next = dget(dentry);
1006 /* find the topmost dentry not yet copied up */
1007 for (; !disconnected;) {
1008 parent = dget_parent(next);
1010 if (ovl_dentry_upper(parent))
1017 err = ovl_copy_up_one(parent, next, flags);
1022 revert_creds(old_cred);
1027 static bool ovl_open_need_copy_up(struct dentry *dentry, int flags)
1029 /* Copy up of disconnected dentry does not set upper alias */
1030 if (ovl_already_copied_up(dentry, flags))
1033 if (special_file(d_inode(dentry)->i_mode))
1036 if (!ovl_open_flags_need_copy_up(flags))
1042 int ovl_maybe_copy_up(struct dentry *dentry, int flags)
1046 if (ovl_open_need_copy_up(dentry, flags)) {
1047 err = ovl_want_write(dentry);
1049 err = ovl_copy_up_flags(dentry, flags);
1050 ovl_drop_write(dentry);
1057 int ovl_copy_up_with_data(struct dentry *dentry)
1059 return ovl_copy_up_flags(dentry, O_WRONLY);
1062 int ovl_copy_up(struct dentry *dentry)
1064 return ovl_copy_up_flags(dentry, 0);