Skip to content

Commit 161e43a

Browse files
Christian Braunergregkh
authored andcommitted
9p: only copy valid iattrs in 9P2000.L setattr implementation
commit 3cb6ee9 upstream. 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/20211129114434.3637938-1-brauner@kernel.org Link: https://lkml.kernel.org/r/000000000000a0d53f05d1c72a4c%40google.com Cc: Eric Van Hensbergen <ericvh@gmail.com> Cc: Latchesar Ionkov <lucho@ionkov.net> Cc: Dominique Martinet <asmadeus@codewreck.org> Cc: stable@kernel.org Cc: v9fs-developer@lists.sourceforge.net Reported-by: syzbot+dfac92a50024b54acaa4@syzkaller.appspotmail.com Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com> [Dominique: do not set a/mtime with just ATTR_A/MTIME as discussed] Signed-off-by: Dominique Martinet <asmadeus@codewreck.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0e6c0f3 commit 161e43a

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

fs/9p/vfs_inode_dotl.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,10 @@ int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
541541
{
542542
int retval;
543543
struct p9_fid *fid = NULL;
544-
struct p9_iattr_dotl p9attr;
544+
struct p9_iattr_dotl p9attr = {
545+
.uid = INVALID_UID,
546+
.gid = INVALID_GID,
547+
};
545548
struct inode *inode = d_inode(dentry);
546549

547550
p9_debug(P9_DEBUG_VFS, "\n");
@@ -551,14 +554,22 @@ int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
551554
return retval;
552555

553556
p9attr.valid = v9fs_mapped_iattr_valid(iattr->ia_valid);
554-
p9attr.mode = iattr->ia_mode;
555-
p9attr.uid = iattr->ia_uid;
556-
p9attr.gid = iattr->ia_gid;
557-
p9attr.size = iattr->ia_size;
558-
p9attr.atime_sec = iattr->ia_atime.tv_sec;
559-
p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
560-
p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
561-
p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
557+
if (iattr->ia_valid & ATTR_MODE)
558+
p9attr.mode = iattr->ia_mode;
559+
if (iattr->ia_valid & ATTR_UID)
560+
p9attr.uid = iattr->ia_uid;
561+
if (iattr->ia_valid & ATTR_GID)
562+
p9attr.gid = iattr->ia_gid;
563+
if (iattr->ia_valid & ATTR_SIZE)
564+
p9attr.size = iattr->ia_size;
565+
if (iattr->ia_valid & ATTR_ATIME_SET) {
566+
p9attr.atime_sec = iattr->ia_atime.tv_sec;
567+
p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
568+
}
569+
if (iattr->ia_valid & ATTR_MTIME_SET) {
570+
p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
571+
p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
572+
}
562573

563574
if (iattr->ia_valid & ATTR_FILE) {
564575
fid = iattr->ia_file->private_data;

0 commit comments

Comments
 (0)