Skip to content

Commit eaf0e7a

Browse files
committed
lsm: handle the NULL buffer case in lsm_fill_user_ctx()
Passing a NULL buffer into the lsm_get_self_attr() syscall is a valid way to quickly determine the minimum size of the buffer needed to for the syscall to return all of the LSM attributes to the caller. Unfortunately we/I broke that behavior in commit d7cf341 ("lsm: consolidate buffer size handling into lsm_fill_user_ctx()") such that it returned an error to the caller; this patch restores the original desired behavior of using the NULL buffer as a quick way to correctly size the attribute buffer. Cc: [email protected] Fixes: d7cf341 ("lsm: consolidate buffer size handling into lsm_fill_user_ctx()") Signed-off-by: Paul Moore <[email protected]>
1 parent a5a858f commit eaf0e7a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

security/security.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,9 @@ static int lsm_superblock_alloc(struct super_block *sb)
780780
* @id: LSM id
781781
* @flags: LSM defined flags
782782
*
783-
* Fill all of the fields in a userspace lsm_ctx structure.
783+
* Fill all of the fields in a userspace lsm_ctx structure. If @uctx is NULL
784+
* simply calculate the required size to output via @utc_len and return
785+
* success.
784786
*
785787
* Returns 0 on success, -E2BIG if userspace buffer is not large enough,
786788
* -EFAULT on a copyout error, -ENOMEM if memory can't be allocated.
@@ -799,6 +801,10 @@ int lsm_fill_user_ctx(struct lsm_ctx __user *uctx, u32 *uctx_len,
799801
goto out;
800802
}
801803

804+
/* no buffer - return success/0 and set @uctx_len to the req size */
805+
if (!uctx)
806+
goto out;
807+
802808
nctx = kzalloc(nctx_len, GFP_KERNEL);
803809
if (nctx == NULL) {
804810
rc = -ENOMEM;

0 commit comments

Comments
 (0)