Skip to contentSkip to conversation

shmctl: enable subtest SHM_LOCK SHM_UNLOCK only if kernel < 2.6.9

PATCH New Li Zhijian 2 participants 2 messages Oct 12, 2017

lore
Share & tools
lore

Li Zhijian

author
#0 lore raw

PATCH 1/1 shmctl: enable subtest SHM_LOCK SHM_UNLOCK only if kernel < 2.6.9

from man page, we can know that:
-----------------
EPERM IPC_SET or IPC_RMID is attempted, and the effective user ID of the calling process is not that of the creator (found in shm_perm.cuid), or the owner (found in shm_perm.uid), and the
process was not privileged (Linux: did not have the CAP_SYS_ADMIN capability).
Or (in kernels before 2.6.9), SHM_LOCK or SHM_UNLOCK was specified, but the process was not privileged (Linux: did not have the CAP_IPC_LOCK capability). (Since Linux 2.6.9, this error can also occur if the RLIMIT_MEMLOCK is 0 and the caller is not privileged.)
-----------------

---
 testcases/kernel/syscalls/ipc/shmctl/shmctl02.c | 3 +++
 1 file changed, 3 insertions(+)
testcases/kernel/syscalls/ipc/shmctl/shmctl02.c +3 -0
index 563f687..49bf846 100644
@@ -55,6 +55,7 @@
  *	none
  */
 
+#include <linux/version.h>
 #include "ipcshm.h"
 #include <pwd.h>
 
@@ -90,11 +91,13 @@ struct test_case_t {
 	{
 	&shm_id_2, -1, &buf, EINVAL},
 	    /* EPERM - the command is only valid for the super-user */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 9)
 	{
 	&shm_id_2, SHM_LOCK, &buf, EPERM},
 	    /* EPERM - the command is only valid for the super-user */
 	{
 	&shm_id_2, SHM_UNLOCK, &buf, EPERM}
+#endif
 };
 
 int TST_TOTAL = ARRAY_SIZE(TC);
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 shmctl: enable subtest SHM_LOCK SHM_UNLOCK only if kernel < 2.6.9

Hi!

Quoted 5 lines
testcases/kernel/syscalls/ipc/shmctl/shmctl02.c +1 -0
+#include <linux/version.h>
 #include "ipcshm.h"
 #include <pwd.h>

testcases/kernel/syscalls/ipc/shmctl/shmctl02.c struct test_case_t { · line 100

Quoted 10 lines
testcases/kernel/syscalls/ipc/shmctl/shmctl02.c +2 -0
@@ -90,11 +91,13 @@ struct test_case_t {
 	{
 	&shm_id_2, -1, &buf, EINVAL},
 	    /* EPERM - the command is only valid for the super-user */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 9)
 	{
 	&shm_id_2, SHM_LOCK, &buf, EPERM},
 	    /* EPERM - the command is only valid for the super-user */
 	{
 	&shm_id_2, SHM_UNLOCK, &buf, EPERM}
+#endif

First of all, this approach horribly broken. It assumes that the kernel we are running on has the same version as the kernel-headers package, which is almost never true.

Secondly the test issues TCONF in case that we don't get this error, so there is actually nothing to worry about.

What can be done for the test though is to temporary set RLIMIT_MEMLOCK to 0 in the test setup() so that the we can actually test that code path.

Signature · 2 lines
Cyril Hrubis
[email protected]