Skip to content

Commit 03145be

Browse files
Dan Rosenbergtorvalds
authored andcommitted
ipc: initialize structure memory to zero for compat functions
This takes care of leaking uninitialized kernel stack memory to userspace from non-zeroed fields in structs in compat ipc functions. Signed-off-by: Dan Rosenberg <drosenberg@vsecurity.com> Cc: Manfred Spraul <manfred@colorfullife.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: <stable@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b795218 commit 03145be

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

‎ipc/compat.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ long compat_sys_semctl(int first, int second, int third, void __user *uptr)
241241
struct semid64_ds __user *up64;
242242
int version = compat_ipc_parse_version(&third);
243243

244+
memset(&s64, 0, sizeof(s64));
245+
244246
if (!uptr)
245247
return -EINVAL;
246248
if (get_user(pad, (u32 __user *) uptr))
@@ -421,6 +423,8 @@ long compat_sys_msgctl(int first, int second, void __user *uptr)
421423
int version = compat_ipc_parse_version(&second);
422424
void __user *p;
423425

426+
memset(&m64, 0, sizeof(m64));
427+
424428
switch (second & (~IPC_64)) {
425429
case IPC_INFO:
426430
case IPC_RMID:
@@ -594,6 +598,8 @@ long compat_sys_shmctl(int first, int second, void __user *uptr)
594598
int err, err2;
595599
int version = compat_ipc_parse_version(&second);
596600

601+
memset(&s64, 0, sizeof(s64));
602+
597603
switch (second & (~IPC_64)) {
598604
case IPC_RMID:
599605
case SHM_LOCK:

‎ipc/compat_mq.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ asmlinkage long compat_sys_mq_open(const char __user *u_name,
5353
void __user *p = NULL;
5454
if (u_attr && oflag & O_CREAT) {
5555
struct mq_attr attr;
56+
57+
memset(&attr, 0, sizeof(attr));
58+
5659
p = compat_alloc_user_space(sizeof(attr));
5760
if (get_compat_mq_attr(&attr, u_attr) ||
5861
copy_to_user(p, &attr, sizeof(attr)))
@@ -127,6 +130,8 @@ asmlinkage long compat_sys_mq_getsetattr(mqd_t mqdes,
127130
struct mq_attr __user *p = compat_alloc_user_space(2 * sizeof(*p));
128131
long ret;
129132

133+
memset(&mqstat, 0, sizeof(mqstat));
134+
130135
if (u_mqstat) {
131136
if (get_compat_mq_attr(&mqstat, u_mqstat) ||
132137
copy_to_user(p, &mqstat, sizeof(mqstat)))

0 commit comments

Comments
 (0)