mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	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")
Fixes: 8db6c34f1d ("Introduce v3 namespaced file capabilities")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Cc: stable@vger.kernel.org
Acked-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: James Morris <james.l.morris@oracle.com>
			
			
This commit is contained in:
		
							parent
							
								
									494b9ae7ab
								
							
						
					
					
						commit
						76ba89c76f
					
				
					 1 changed files with 2 additions and 1 deletions
				
			
		| 
						 | 
					@ -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_ns_cap_data data, *nscaps = &data;
 | 
				
			||||||
	struct vfs_cap_data *caps = (struct vfs_cap_data *) &data;
 | 
						struct vfs_cap_data *caps = (struct vfs_cap_data *) &data;
 | 
				
			||||||
	kuid_t rootkuid;
 | 
						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));
 | 
						memset(cpu_caps, 0, sizeof(struct cpu_vfs_cap_data));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!inode)
 | 
						if (!inode)
 | 
				
			||||||
		return -ENODATA;
 | 
							return -ENODATA;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fs_ns = inode->i_sb->s_user_ns;
 | 
				
			||||||
	size = __vfs_getxattr((struct dentry *)dentry, inode,
 | 
						size = __vfs_getxattr((struct dentry *)dentry, inode,
 | 
				
			||||||
			      XATTR_NAME_CAPS, &data, XATTR_CAPS_SZ);
 | 
								      XATTR_NAME_CAPS, &data, XATTR_CAPS_SZ);
 | 
				
			||||||
	if (size == -ENODATA || size == -EOPNOTSUPP)
 | 
						if (size == -ENODATA || size == -EOPNOTSUPP)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue