FAILED: patch "[PATCH] commoncap: move assignment of fs_ns to avoid null pointer" failed to apply to 4.13-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 4.13-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 ------------------
Quoted 1 line
From
76ba89c76f2c74e208d93a9e7c698e39eeb3b85cMon Sep 17 00:00:00 2001
From: Colin Ian King <[email protected]>
Date: Mon, 4 Sep 2017 18:50:05 +0100
Subject: [PATCH] commoncap: move assignment of fs_ns to avoid null pointer
dereference
The pointer fs_ns is assigned from inode->i_ib->s_user_ns before a null pointer check on inode, hence if inode is actually null we will get a null pointer dereference on this assignment. Fix this by only dereferencing inode after the null pointer check on inode.
Detected by CoverityScan CID#1455328 ("Dereference before null check")
security/commoncap.c +2 -1
@@ -585,13 +585,14 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_datastruct vfs_ns_cap_data data, *nscaps = &data;struct vfs_cap_data *caps = (struct vfs_cap_data *) &data;kuid_t rootkuid; -struct user_namespace *fs_ns = inode->i_sb->s_user_ns; +struct user_namespace *fs_ns;memset (cpu_caps,0 ,sizeof (struct cpu_vfs_cap_data ));if (!inode)return -ENODATA ; + fs_ns = inode->i_sb->s_user_ns; size =__vfs_getxattr ((struct dentry *)dentry, inode,XATTR_NAME_CAPS , &data,XATTR_CAPS_SZ );if (size == -ENODATA || size == -EOPNOTSUPP )