lsm: convert security_setselfattr() to use memdup_user()
Paul Moore
maintainerPATCH 1/1 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 <[email protected]>
Signed-off-by Paul Moore <[email protected]>
--- security/security.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
security/security.c +3 -8
@@ -4011,14 +4011,9 @@ int security_setselfattr(unsigned int attr, struct lsm_ctx __user *uctx,if (size >PAGE_SIZE )return -E2BIG ; - lctx =kmalloc (size,GFP_KERNEL ); -if (lctx ==NULL ) -return -ENOMEM ; - -if (copy_from_user (lctx, uctx, size)) { - rc = -EFAULT ; - goto free_out; - } + lctx =memdup_user (uctx, size); +if (IS_ERR (lctx)) +return PTR_ERR (lctx);if (size < lctx->len || size < lctx->ctx_len +sizeof (*lctx) || lctx->len < lctx->ctx_len +sizeof (*lctx)) {
Signature · 1 line
2.42.0
Quoted 6 lines · Paul Moore
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 <[email protected]>Signed-off-by Paul Moore <[email protected]>
Acked-by Casey Schaufler <[email protected]>
Quoted 26 lines
--- security/security.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)security/security.c +3
-8@@ -4011,14 +4011,9 @@ int security_setselfattr(unsigned int attr, struct lsm_ctx __user *uctx,if (size >PAGE_SIZE )return -E2BIG ; - lctx =kmalloc (size,GFP_KERNEL ); -if (lctx ==NULL ) -return -ENOMEM ; - -if (copy_from_user (lctx, uctx, size)) { - rc = -EFAULT ; - goto free_out; - } + lctx =memdup_user (uctx, size); +if (IS_ERR (lctx)) +return PTR_ERR (lctx);if (size < lctx->len || size < lctx->ctx_len +sizeof (*lctx) || lctx->len < lctx->ctx_len +sizeof (*lctx)) {
Quoted 10 lines · Paul Moore
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 <[email protected]>Signed-off-by Paul Moore <[email protected]>--- security/security.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
Merged into lsm/dev-staging.
Signature · 1 line
paul-moore.com
Quoted 10 lines · Paul Moore
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 <[email protected]>Signed-off-by Paul Moore <[email protected]>--- security/security.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
Merged into lsm/dev.
Signature · 1 line
paul-moore.com