64bit kernel/N32 userspace - shmctl corrupts userspace memory
If you're running a 64bit kernel with N32 userspace, shmctl will corrupt memory in userspace. When copy_shmid_to_user() is called, it copies the entire kernel shmid_ds into userspace. For a 64bit kernel, this is 88 bytes. In N32 userspace it is 76 bytes.
My hack to get around the problem is attached, but I expect someone here will be able to come up with a better fix. shmid_ds contains a lot of members that are marked unused. Are these really useless?
Chad
Index: linux/ipc/shm.c
===================================================================
RCS file: /repository/octsw/linux/kernel_2.6/linux/ipc/shm.c,v retrieving revision 1.1.1.6
retrieving revision 1.2
ipc/shm.c +5 -1
@@ -321,7 +321,11 @@ out.shm_lpid = in->shm_lpid; out.shm_nattch = in->shm_nattch; -return copy_to_user (buf, &out,sizeof (out)); +/* Use offsetof() instead of sizeof() since N32 userspace has a +different size including the unused fields. This just copies +what is used. The old method would corrupt data after the +structure */ +return copy_to_user (buf, &out, offsetof(struct shmid_ds , shm_unused2)); }default :return -EINVAL ;
Quoted 8 lines · Chad Reese
If you're running a 64bit kernel with N32 userspace, shmctl will corrupt memory in userspace. When
copy_shmid_to_user()is called, it copies the entire kernelshmid_dsinto userspace. For a 64bit kernel, this is 88 bytes. In N32 userspace it is 76 bytes.My hack to get around the problem is attached, but I expect someone here will be able to come up with a better fix.
shmid_dscontains a lot of members that are marked unused. Are these really useless?
Can you try below patch?
Ralf
arch/mips/kernel/scall64-n32.S +1 -1
@@ -150,7 +150,7 @@ EXPORT(sysn32_call_table) PTR sys_madvise PTR sys_shmget PTR sys32_shmat - PTR sys_shmctl /* 6030 */ + PTR compat_sys_shmctl /* 6030 */ PTR sys_dup PTR sys_dup2 PTR sys_pause
compat.c is only included if CONFIG_SYSVIPC_COMPAT is defined. This isn't anywhere in 2.6.16.26. Is this what you're refering to?
Chad
Quoted 31 lines · Ralf Baechle
Quoted 8 lines · Chad Reese
If you're running a 64bit kernel with N32 userspace, shmctl will corrupt memory in userspace. When
copy_shmid_to_user()is called, it copies the entire kernelshmid_dsinto userspace. For a 64bit kernel, this is 88 bytes. In N32 userspace it is 76 bytes.My hack to get around the problem is attached, but I expect someone here will be able to come up with a better fix.
shmid_dscontains a lot of members that are marked unused. Are these really useless?Can you try below patch?
Ralf
arch/mips/kernel/scall64-n32.S +1
-1@@ -150,7 +150,7 @@ EXPORT(sysn32_call_table) PTR sys_madvise PTR sys_shmget PTR sys32_shmat - PTR sys_shmctl /* 6030 */ + PTR compat_sys_shmctl /* 6030 */ PTR sys_dup PTR sys_dup2 PTR sys_pause
Signature · 4 lines
Chad Reese <[email protected]> Cavium Networks Phone: 650 - 623 - 7038 Cell: 321 - 438 - 7753
Quoted 2 lines · Chad Reese
compat.cis only included ifCONFIG_SYSVIPC_COMPATis defined. This isn't anywhere in 2.6.16.26. Is this what you're refering to?
You can add this to arch/mips/Kconfig:
config SYSVIPC_COMPAT
bool depends on COMPAT && SYSVIPC default y
BTW, it seems many SYSVIPC functions in arch/mips/kernel/linux32.c can be replaced by this common code.
---
Atsushi Nemoto
Quoted 8 lines · Chad Reese
If you're running a 64bit kernel with N32 userspace, shmctl will corrupt memory in userspace. When
copy_shmid_to_user()is called, it copies the entire kernelshmid_dsinto userspace. For a 64bit kernel, this is 88 bytes. In N32 userspace it is 76 bytes.My hack to get around the problem is attached, but I expect someone here will be able to come up with a better fix.
shmid_dscontains a lot of members that are marked unused. Are these really useless?
They need to be there for compatibility with older revisions of the structure - we can increase the size of the structure but not decrease.
Talking about compatibility, you change breaks N64 compatibility ...
Ralf