Skip to content

Commit b8ef920

Browse files
committed
Merge tag 'lsm-pr-20240215' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm
Pull lsm fix from Paul Moore: "One small LSM patch to fix a potential integer overflow in the newly added lsm_set_self_attr() syscall" * tag 'lsm-pr-20240215' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/lsm: lsm: fix integer overflow in lsm_set_self_attr() syscall
2 parents 4f5e509 + d8bdd79 commit b8ef920

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

security/security.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/backing-dev.h>
3030
#include <linux/string.h>
3131
#include <linux/msg.h>
32+
#include <linux/overflow.h>
3233
#include <net/flow.h>
3334

3435
/* How many LSMs were built into the kernel? */
@@ -4015,6 +4016,7 @@ int security_setselfattr(unsigned int attr, struct lsm_ctx __user *uctx,
40154016
struct security_hook_list *hp;
40164017
struct lsm_ctx *lctx;
40174018
int rc = LSM_RET_DEFAULT(setselfattr);
4019+
u64 required_len;
40184020

40194021
if (flags)
40204022
return -EINVAL;
@@ -4027,8 +4029,9 @@ int security_setselfattr(unsigned int attr, struct lsm_ctx __user *uctx,
40274029
if (IS_ERR(lctx))
40284030
return PTR_ERR(lctx);
40294031

4030-
if (size < lctx->len || size < lctx->ctx_len + sizeof(*lctx) ||
4031-
lctx->len < lctx->ctx_len + sizeof(*lctx)) {
4032+
if (size < lctx->len ||
4033+
check_add_overflow(sizeof(*lctx), lctx->ctx_len, &required_len) ||
4034+
lctx->len < required_len) {
40324035
rc = -EINVAL;
40334036
goto free_out;
40344037
}

0 commit comments

Comments
 (0)