[SRU][Xenial][PATCH 2/4] commoncap: move assignment of fs_ns to avoid null pointer dereference

Seth Forshee seth.forshee at canonical.com
Fri Jun 22 21:43:57 UTC 2018


From: Colin Ian King <colin.king at canonical.com>

BugLink: http://bugs.launchpad.net/bugs/1778286

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")

Fixes: 8db6c34f1dbc ("Introduce v3 namespaced file capabilities")
Signed-off-by: Colin Ian King <colin.king at canonical.com>
Cc: stable at vger.kernel.org
Acked-by: Serge Hallyn <serge at hallyn.com>
Signed-off-by: James Morris <james.l.morris at oracle.com>
(backported from commit 76ba89c76f2c74e208d93a9e7c698e39eeb3b85c)
Signed-off-by: Seth Forshee <seth.forshee at canonical.com>
---
 security/commoncap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/security/commoncap.c b/security/commoncap.c
index c730ed00f427..6b4a8788c753 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -596,13 +596,14 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
 	struct 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 || !inode->i_op->getxattr)
 		return -ENODATA;
 
+	fs_ns = inode->i_sb->s_user_ns;
 	size = inode->i_op->getxattr((struct dentry *)dentry, XATTR_NAME_CAPS, &data,
 				   XATTR_CAPS_SZ);
 	if (size == -ENODATA || size == -EOPNOTSUPP)
-- 
2.17.0





More information about the kernel-team mailing list