lsm: correct error codes in security_getselfattr()
authorPaul Moore <paul@paul-moore.com>
Tue, 24 Oct 2023 16:42:38 +0000 (12:42 -0400)
committerPaul Moore <paul@paul-moore.com>
Mon, 13 Nov 2023 03:54:42 +0000 (22:54 -0500)
We should return -EINVAL if the user specifies LSM_FLAG_SINGLE without
supplying a valid lsm_ctx struct buffer.

Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Reviewed-by: Mickaël Salaün <mic@digikod.net>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/security.c

index 74ff9a48bd66d636c8789b8352aded4c9a164971..78e7ffcc9f6cd3aa63e8056e531efd60fc4f9fed 100644 (file)
@@ -3922,9 +3922,9 @@ int security_getselfattr(unsigned int attr, struct lsm_ctx __user *uctx,
                /*
                 * Only flag supported is LSM_FLAG_SINGLE
                 */
-               if (flags != LSM_FLAG_SINGLE)
+               if (flags != LSM_FLAG_SINGLE || !uctx)
                        return -EINVAL;
-               if (uctx && copy_from_user(&lctx, uctx, sizeof(lctx)))
+               if (copy_from_user(&lctx, uctx, sizeof(lctx)))
                        return -EFAULT;
                /*
                 * If the LSM ID isn't specified it is an error.