FAILED: patch "[PATCH] 9p: only copy valid iattrs in 9P2000.L setattr implementation" failed to apply to 4.4-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 4.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 3cb6ee991496b67ee284c6895a0ba007e2d7bac3 Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Mon, 29 Nov 2021 12:44:34 +0100
Subject: [PATCH] 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.
fs/9p/vfs_inode_dotl.c +20 -9
@@ -551,7 +551,10 @@ int v9fs_vfs_setattr_dotl(struct user_namespace *mnt_userns, {int retval, use_dentry =0 ;struct p9_fid *fid =NULL ; -struct p9_iattr_dotl p9attr; +struct p9_iattr_dotl p9attr = { + .uid =INVALID_UID , + .gid =INVALID_GID , + };struct inode *inode =d_inode (dentry);p9_debug (P9_DEBUG_VFS ,"\n" );
@@ -561,14 +564,22 @@ int v9fs_vfs_setattr_dotl(struct user_namespace *mnt_userns,return retval; p9attr.valid =v9fs_mapped_iattr_valid (iattr->ia_valid); - p9attr.mode = iattr->ia_mode; - p9attr.uid = iattr->ia_uid; - p9attr.gid = iattr->ia_gid; - p9attr.size = iattr->ia_size; - p9attr.atime_sec = iattr->ia_atime.tv_sec; - p9attr.atime_nsec = iattr->ia_atime.tv_nsec; - p9attr.mtime_sec = iattr->ia_mtime.tv_sec; - p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec; +if (iattr->ia_valid &ATTR_MODE ) + p9attr.mode = iattr->ia_mode; +if (iattr->ia_valid &ATTR_UID ) + p9attr.uid = iattr->ia_uid; +if (iattr->ia_valid &ATTR_GID ) + p9attr.gid = iattr->ia_gid; +if (iattr->ia_valid &ATTR_SIZE ) + p9attr.size = iattr->ia_size; +if (iattr->ia_valid &ATTR_ATIME_SET ) { + p9attr.atime_sec = iattr->ia_atime.tv_sec; + p9attr.atime_nsec = iattr->ia_atime.tv_nsec; + } +if (iattr->ia_valid &ATTR_MTIME_SET ) { + p9attr.mtime_sec = iattr->ia_mtime.tv_sec; + p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec; + }if (iattr->ia_valid &ATTR_FILE ) { fid = iattr->ia_file->private_data;