Skip to content

Commit

Permalink
main: Do not set -1 for owner overriding xattrs
Browse files Browse the repository at this point in the history
ovl_setattr () used to pass -1 as uid or gid when either of them
is not changed for do_fchown () / do_chown (), but if these functions
use overriding xattrs instead of real fchown () or chown (), it causes
-1 to be written in owner overriding xattrs and break them.

Replace -1 with the current uid or gid before calling do_fchown () /
do_chown ().

Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
  • Loading branch information
akihikodaki committed Jun 17, 2024
1 parent c41076f commit a09f4b8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4158,6 +4158,24 @@ ovl_setattr (fuse_req_t req, fuse_ino_t ino, struct stat *attr, int to_set, stru

if (uid != -1 || gid != -1)
{
struct stat st;

if (do_stat (node, fd, NULL, &st) < 0)
{
fuse_reply_err (req, errno);
return;
}

if (uid == -1)
{
uid = st.st_uid;
}

if (gid == -1)
{
gid = st.st_gid;
}

if (fd >= 0)
ret = do_fchown (lo, fd, uid, gid, node->ino->mode);
else
Expand Down
18 changes: 18 additions & 0 deletions tests/unpriv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,21 @@ else
fi

fusermount -u merged || [ $? -eq "${EXPECT_UMOUNT_STATUS:-0}" ]

# xattr_permissions=2
rm -rf lower upper workdir merged
mkdir lower upper workdir merged

touch upper/file

fuse-overlayfs -o lowerdir=lower,upperdir=upper,workdir=workdir,xattr_permissions=2 merged

# Ensure UID is preserved with chgrp.
unshare --map-auto -r chgrp 1 merged/file
test $(unshare --map-auto -r stat -c %u:%g merged/file) = 0:1

# Ensure UID and GID are preserved with chmod.
chmod 600 merged/file
test $(unshare --map-auto -r stat -c %u:%g merged/file) = 0:1

fusermount -u merged || [ $? -eq "${EXPECT_UMOUNT_STATUS:-0}" ]

0 comments on commit a09f4b8

Please sign in to comment.