Skip to content

Commit 9ba8802

Browse files
committed
lsm: convert security_setselfattr() to use memdup_user()
As suggested by the kernel test robot, memdup_user() is a better option than the combo of kmalloc()/copy_from_user(). Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202310270805.2ArE52i5-lkp@intel.com/ Acked-by: Casey Schaufler <casey@schaufler-ca.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 4179320 commit 9ba8802

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

security/security.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4011,14 +4011,9 @@ int security_setselfattr(unsigned int attr, struct lsm_ctx __user *uctx,
40114011
if (size > PAGE_SIZE)
40124012
return -E2BIG;
40134013

4014-
lctx = kmalloc(size, GFP_KERNEL);
4015-
if (lctx == NULL)
4016-
return -ENOMEM;
4017-
4018-
if (copy_from_user(lctx, uctx, size)) {
4019-
rc = -EFAULT;
4020-
goto free_out;
4021-
}
4014+
lctx = memdup_user(uctx, size);
4015+
if (IS_ERR(lctx))
4016+
return PTR_ERR(lctx);
40224017

40234018
if (size < lctx->len || size < lctx->ctx_len + sizeof(*lctx) ||
40244019
lctx->len < lctx->ctx_len + sizeof(*lctx)) {

0 commit comments

Comments
 (0)