* [LTP] [PATCH] shmctl: enable subtest SHM_LOCK SHM_UNLOCK only if kernel < 2.6.9
@ 2017-10-12 10:36 Li Zhijian
2017-10-12 11:03 ` Cyril Hrubis
0 siblings, 1 reply; 3+ messages in thread
From: Li Zhijian @ 2017-10-12 10:36 UTC (permalink / raw)
To: ltp
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.)
-----------------
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
---
testcases/kernel/syscalls/ipc/shmctl/shmctl02.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl02.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl02.c
index 563f687..49bf846 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl02.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl02.c
@@ -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);
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread* [LTP] [PATCH] shmctl: enable subtest SHM_LOCK SHM_UNLOCK only if kernel < 2.6.9
2017-10-12 10:36 [LTP] [PATCH] shmctl: enable subtest SHM_LOCK SHM_UNLOCK only if kernel < 2.6.9 Li Zhijian
@ 2017-10-12 11:03 ` Cyril Hrubis
0 siblings, 0 replies; 3+ messages in thread
From: Cyril Hrubis @ 2017-10-12 11:03 UTC (permalink / raw)
To: ltp
Hi!
> +#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
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.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 3+ messages in thread
* [LTP] [PATCH] shmctl: enable subtest SHM_LOCK SHM_UNLOCK only if kernel < 2.6.9
@ 2017-10-12 10:55 Li Zhijian
0 siblings, 0 replies; 3+ messages in thread
From: Li Zhijian @ 2017-10-12 10:55 UTC (permalink / raw)
To: ltp
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.)
-----------------
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
---
testcases/kernel/syscalls/ipc/shmctl/shmctl02.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl02.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl02.c
index 563f687..49bf846 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl02.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl02.c
@@ -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);
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-10-12 11:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-12 10:36 [LTP] [PATCH] shmctl: enable subtest SHM_LOCK SHM_UNLOCK only if kernel < 2.6.9 Li Zhijian
2017-10-12 11:03 ` Cyril Hrubis
-- strict thread matches above, loose matches on Subject: below --
2017-10-12 10:55 Li Zhijian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox