Skip to content

Commit 3cb6ee9

Browse files
Christian Braunermartinetd
authored andcommitted
9p: only copy valid iattrs in 9P2000.L setattr implementation
The 9P2000.L setattr method v9fs_vfs_setattr_dotl() copies struct iattr values without checking whether they are valid causing unitialized values to be copied. The 9P2000 setattr method v9fs_vfs_setattr() method gets this right. Check whether struct iattr fields are valid first before copying in v9fs_vfs_setattr_dotl() too and make sure that all other fields are set to 0 apart from {g,u}id which should be set to INVALID_{G,U}ID. This ensure that they can be safely sent over the wire or printed for debugging later on. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/000000000000a0d53f05d1c72a4c%40google.com Cc: Eric Van Hensbergen <[email protected]> Cc: Latchesar Ionkov <[email protected]> Cc: Dominique Martinet <[email protected]> Cc: [email protected] Cc: [email protected] Reported-by: [email protected] Signed-off-by: Christian Brauner <[email protected]> [Dominique: do not set a/mtime with just ATTR_A/MTIME as discussed] Signed-off-by: Dominique Martinet <[email protected]>
1 parent a7a427d commit 3cb6ee9

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

fs/9p/vfs_inode_dotl.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,10 @@ int v9fs_vfs_setattr_dotl(struct user_namespace *mnt_userns,
551551
{
552552
int retval, use_dentry = 0;
553553
struct p9_fid *fid = NULL;
554-
struct p9_iattr_dotl p9attr;
554+
struct p9_iattr_dotl p9attr = {
555+
.uid = INVALID_UID,
556+
.gid = INVALID_GID,
557+
};
555558
struct inode *inode = d_inode(dentry);
556559

557560
p9_debug(P9_DEBUG_VFS, "\n");
@@ -561,14 +564,22 @@ int v9fs_vfs_setattr_dotl(struct user_namespace *mnt_userns,
561564
return retval;
562565

563566
p9attr.valid = v9fs_mapped_iattr_valid(iattr->ia_valid);
564-
p9attr.mode = iattr->ia_mode;
565-
p9attr.uid = iattr->ia_uid;
566-
p9attr.gid = iattr->ia_gid;
567-
p9attr.size = iattr->ia_size;
568-
p9attr.atime_sec = iattr->ia_atime.tv_sec;
569-
p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
570-
p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
571-
p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
567+
if (iattr->ia_valid & ATTR_MODE)
568+
p9attr.mode = iattr->ia_mode;
569+
if (iattr->ia_valid & ATTR_UID)
570+
p9attr.uid = iattr->ia_uid;
571+
if (iattr->ia_valid & ATTR_GID)
572+
p9attr.gid = iattr->ia_gid;
573+
if (iattr->ia_valid & ATTR_SIZE)
574+
p9attr.size = iattr->ia_size;
575+
if (iattr->ia_valid & ATTR_ATIME_SET) {
576+
p9attr.atime_sec = iattr->ia_atime.tv_sec;
577+
p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
578+
}
579+
if (iattr->ia_valid & ATTR_MTIME_SET) {
580+
p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
581+
p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
582+
}
572583

573584
if (iattr->ia_valid & ATTR_FILE) {
574585
fid = iattr->ia_file->private_data;

0 commit comments

Comments
 (0)