Skip to contentSkip to conversation

security: cap_inode_getsecctx returning garbage

PATCH In review J. Bruce Fields 3 participants 6 messages May 9, 2013 – May 12, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 security: cap_inode_getsecctx returning garbage

From: "J. Bruce Fields" <[email protected]>

We shouldn't be returning success from this function without also filling in the return values ctx and ctxlen.

Note currently this doesn't appear to cause bugs since the only inode_getsecctx caller I can find is fs/sysfs/inode.c, which only calls this if security_inode_setsecurity succeeds. Assuming security_inode_setsecurity is set to cap_inode_setsecurity whenever inode_getsecctx is set to cap_inode_getsecctx, this function can never actually called.

So I noticed this only because the server labeled NFS patches add a real caller.

---
 security/capability.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Also, assuming this is correct, would you be willing to apply it for 3.10?

If you'd prefer it wait till the next merge window: could you ACK it, and let me merge it through the nfsd tree? (It's a prerequisite for the labeled NFS patches that I hope to merge for 3.11.)

security/capability.c +1 -1
index d32e16e..32b5157 100644
@@ -858,7 +858,7 @@ static int cap_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
 
 static int cap_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
 {
-	return 0;
+	return -EOPNOTSUPP;
 }
 #ifdef CONFIG_KEYS
 static int cap_key_alloc(struct key *key, const struct cred *cred,
Signature · 1 line
1.7.9.5
Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · J. Bruce Fields

From: "J. Bruce Fields" <[email protected]>

We shouldn't be returning success from this function without also filling in the return values ctx and ctxlen.

Note currently this doesn't appear to cause bugs since the only inode_getsecctx caller I can find is fs/sysfs/inode.c, which only calls this if security_inode_setsecurity succeeds. Assuming security_inode_setsecurity is set to cap_inode_setsecurity whenever inode_getsecctx is set to cap_inode_getsecctx, this function can never actually called.

Quoted 4 lines

So I noticed this only because the server labeled NFS patches add a real caller.

Thanks, the comment in include/linux/security.h doesn't mention the return value at all, but based on the other implementations this looks right.

Quoted 27 lines
---
 security/capability.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Also, assuming this is correct, would you be willing to apply it for 3.10?

If you'd prefer it wait till the next merge window: could you ACK it, and let me merge it through the nfsd tree? (It's a prerequisite for the labeled NFS patches that I hope to merge for 3.11.)

security/capability.c +1 -1
index d32e16e..32b5157 100644
@@ -858,7 +858,7 @@ static int cap_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
 
 static int cap_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
 {
-	return 0;
+	return -EOPNOTSUPP;
 }
 #ifdef CONFIG_KEYS
 static int cap_key_alloc(struct key *key, const struct cred *cred,
Signature · 1 line
1.7.9.5
#2 lore raw
Quoted 16 lines · Serge Hallyn
Quoted 15 lines · J. Bruce Fields

From: "J. Bruce Fields" <[email protected]>

We shouldn't be returning success from this function without also filling in the return values ctx and ctxlen.

Note currently this doesn't appear to cause bugs since the only inode_getsecctx caller I can find is fs/sysfs/inode.c, which only calls this if security_inode_setsecurity succeeds. Assuming security_inode_setsecurity is set to cap_inode_setsecurity whenever inode_getsecctx is set to cap_inode_getsecctx, this function can never actually called.

So I noticed this only because the server labeled NFS patches add a real caller.

Quoted 7 lines
Quoted 1 line

Thanks, the comment in include/linux/security.h doesn't mention the return value at all, but based on the other implementations this looks right.

Thanks! Hm, would something like this help clarify?:

@@ -1412,7 +1412,8 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
* @ctxlen contains the length of @ctx.
*
* @inode_getsecctx:
- * Returns a string containing all relevant security context information
+ * On success, fills out @ctx and @ctxlen with the security context
+ * for the given @inode.
*
* @inode we wish to get the security context of.
* @ctx is a pointer in which to place the allocated security context.

--b.

Acked-by
#3 lore raw
Quoted 28 lines · J. Bruce Fields
Quoted 16 lines · Serge Hallyn
Quoted 15 lines · J. Bruce Fields

From: "J. Bruce Fields" <[email protected]>

We shouldn't be returning success from this function without also filling in the return values ctx and ctxlen.

Note currently this doesn't appear to cause bugs since the only inode_getsecctx caller I can find is fs/sysfs/inode.c, which only calls this if security_inode_setsecurity succeeds. Assuming security_inode_setsecurity is set to cap_inode_setsecurity whenever inode_getsecctx is set to cap_inode_getsecctx, this function can never actually called.

So I noticed this only because the server labeled NFS patches add a real caller.

Quoted 7 lines
Quoted 1 line

Thanks, the comment in include/linux/security.h doesn't mention the return value at all, but based on the other implementations this looks right.

Thanks! Hm, would something like this help clarify?:

Review static inline void security_free_mnt_opts(struct security_mnt_opts *opts) · line 1416

Quoted 6 lines
(quoted diff) +2 -1
@@ -1412,7 +1412,8 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  * 	@ctxlen contains the length of @ctx.
  *
  * @inode_getsecctx:
- *	Returns a string containing all relevant security context information
+ *	On success, fills out @ctx and @ctxlen with the security context
+ *	for the given @inode.

... and returns 0.

That would be great, thanks!

Quoted 5 lines
(quoted diff) +0 -1
  *
  * 	@inode we wish to get the security context of.
  *	@ctx is a pointer in which to place the allocated security context.
 
--b.
#4 lore raw

PATCH 1/1 security: clarify cap_inode_getsecctx description

From: "J. Bruce Fields" <[email protected]>

Make it clear that cap_inode_getsecctx shouldn't return success without filling in the context data.

---
 include/linux/security.h |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/security.h +2 -1
index 4686491..40560f4 100644
@@ -1392,7 +1392,8 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  * 	@ctxlen contains the length of @ctx.
  *
  * @inode_getsecctx:
- *	Returns a string containing all relevant security context information
+ *	On success, returns 0 and fills out @ctx and @ctxlen with the security
+ *	context for the given @inode.
  *
  * 	@inode we wish to get the security context of.
  *	@ctx is a pointer in which to place the allocated security context.
Signature · 1 line
1.7.9.5
maintainer
#5 lore raw

Re: [PATCH] security: clarify cap_inode_getsecctx description

Quoted 7 lines · J. Bruce Fields

From: "J. Bruce Fields" <[email protected]>

Make it clear that cap_inode_getsecctx shouldn't return success without filling in the context data.

Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security.git next

Signature · 2 lines
James Morris
<[email protected]>