Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+3 -8
+3 -8
security/security.c
··· 4011 4011 if (size > PAGE_SIZE) 4012 4012 return -E2BIG; 4013 4013 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); 4022 4017 4023 4018 if (size < lctx->len || size < lctx->ctx_len + sizeof(*lctx) || 4024 4019 lctx->len < lctx->ctx_len + sizeof(*lctx)) {