Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1726216 > unrolled thread

[PATCH][capabilities-next] commoncap: move assignment of fs_ns to avoid null pointer dereference

Started byColin King <colin.king@canonical.com>
First post2017-09-04 20:00 +0200
Last post2017-09-04 21:00 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH][capabilities-next] commoncap: move assignment of fs_ns to avoid null pointer dereference Colin King <colin.king@canonical.com> - 2017-09-04 20:00 +0200
    Re: [PATCH][capabilities-next] commoncap: move assignment of fs_ns  to avoid null pointer dereference "Serge E. Hallyn" <serge@hallyn.com> - 2017-09-04 21:00 +0200

#1726216 — [PATCH][capabilities-next] commoncap: move assignment of fs_ns to avoid null pointer dereference

FromColin King <colin.king@canonical.com>
Date2017-09-04 20:00 +0200
Subject[PATCH][capabilities-next] commoncap: move assignment of fs_ns to avoid null pointer dereference
Message-ID<um3Pc-58-13@gated-at.bofh.it>
From: Colin Ian King <colin.king@canonical.com>

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@canonical.com>
---
 security/commoncap.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/security/commoncap.c b/security/commoncap.c
index c25e0d27537f..fc46f5b85251 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -585,13 +585,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)
 		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)
-- 
2.14.1

[toc] | [next] | [standalone]


#1726224 — Re: [PATCH][capabilities-next] commoncap: move assignment of fs_ns to avoid null pointer dereference

From"Serge E. Hallyn" <serge@hallyn.com>
Date2017-09-04 21:00 +0200
SubjectRe: [PATCH][capabilities-next] commoncap: move assignment of fs_ns to avoid null pointer dereference
Message-ID<um4Lf-Dl-11@gated-at.bofh.it>
In reply to#1726216
On Mon, Sep 04, 2017 at 06:50:05PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> 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@canonical.com>

thanks!

Acked-by: Serge Hallyn <serge@hallyn.com>

> ---
>  security/commoncap.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/security/commoncap.c b/security/commoncap.c
> index c25e0d27537f..fc46f5b85251 100644
> --- a/security/commoncap.c
> +++ b/security/commoncap.c
> @@ -585,13 +585,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)
>  		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)
> -- 
> 2.14.1

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web