Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs/9p: v9fs_stat2inode should update suid/sgid bits.

Create a new helper that update the permission bits and use
that, instead of opencoding the logic.

Reported and bisected by: M. Mohan Kumar <mohan@in.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>

authored by

Aneesh Kumar K.V and committed by
Eric Van Hensbergen
df345c67 5d385153

+28 -12
+28 -12
fs/9p/vfs_inode.c
··· 95 95 } 96 96 97 97 /** 98 + * p9mode2perm- convert plan9 mode bits to unix permission bits 99 + * @v9ses: v9fs session information 100 + * @stat: p9_wstat from which mode need to be derived 101 + * 102 + */ 103 + static int p9mode2perm(struct v9fs_session_info *v9ses, 104 + struct p9_wstat *stat) 105 + { 106 + int res; 107 + int mode = stat->mode; 108 + 109 + res = mode & S_IALLUGO; 110 + if (v9fs_proto_dotu(v9ses)) { 111 + if ((mode & P9_DMSETUID) == P9_DMSETUID) 112 + res |= S_ISUID; 113 + 114 + if ((mode & P9_DMSETGID) == P9_DMSETGID) 115 + res |= S_ISGID; 116 + 117 + if ((mode & P9_DMSETVTX) == P9_DMSETVTX) 118 + res |= S_ISVTX; 119 + } 120 + return res; 121 + } 122 + 123 + /** 98 124 * p9mode2unixmode- convert plan9 mode bits to unix mode bits 99 125 * @v9ses: v9fs session information 100 126 * @stat: p9_wstat from which mode need to be derived ··· 133 107 int res; 134 108 int mode = stat->mode; 135 109 136 - res = mode & S_IALLUGO; 137 110 *rdev = 0; 111 + res = p9mode2perm(v9ses, stat); 138 112 139 113 if ((mode & P9_DMDIR) == P9_DMDIR) 140 114 res |= S_IFDIR; ··· 168 142 } else 169 143 res |= S_IFREG; 170 144 171 - if (v9fs_proto_dotu(v9ses)) { 172 - if ((mode & P9_DMSETUID) == P9_DMSETUID) 173 - res |= S_ISUID; 174 - 175 - if ((mode & P9_DMSETGID) == P9_DMSETGID) 176 - res |= S_ISGID; 177 - 178 - if ((mode & P9_DMSETVTX) == P9_DMSETVTX) 179 - res |= S_ISVTX; 180 - } 181 145 return res; 182 146 } 183 147 ··· 1184 1168 set_nlink(inode, i_nlink); 1185 1169 } 1186 1170 } 1187 - mode = stat->mode & S_IALLUGO; 1171 + mode = p9mode2perm(v9ses, stat); 1188 1172 mode |= inode->i_mode & ~S_IALLUGO; 1189 1173 inode->i_mode = mode; 1190 1174 i_size_write(inode, stat->length);