msgrcv07: Check negative msg type filters
PATCH 1/2 msgrcv07: Check negative msg type filters
It should leave higher message types on the queue if they are above the specified type's magnitude.
Also check what happens when MSG_EXCEPT is passed with a negative msg type. This behavior is unspecified, but presently the kernel ignores the flag if the type is negative. The motivation to check this is long handling in 32bit compat mode. If the msg type is not sign extended then it will be treated as a large positive integer. In this case we should receive the remaining message.
On the current kernel under x86 the test passes because the system call has an explicit compat variant which performs the sign extension. Otherwise it would fail.
--- testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c | 7 +++++++ 1 file changed, 7 insertions(+)
testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c +7 -0
@@ -232,6 +232,13 @@ static void test_negative_msgtyp(void) "-msgtyp didn't get the first message in the queue with the lowest type"); } +TST_EXP_FAIL (msgrcv (queue_id, &rcv_buf,MSGSIZE , -MSGTYPE1 ,IPC_NOWAIT ), +ENOMSG , +"-msgtype didn't recv next lowest msg" ); +TST_EXP_FAIL (msgrcv (queue_id, &rcv_buf,MSGSIZE , -MSGTYPE1 ,MSG_EXCEPT |IPC_NOWAIT ), +ENOMSG , +"-msgtype (with except) didn't recv next lowest msg" ); + exit:SAFE_MSGCTL (queue_id,IPC_RMID ,NULL ); queue_id =-1 ;
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH 2/2 msgrcv07: Cleanup indentation
make make check happy.
--- testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c +2 -2
@@ -201,7 +201,7 @@ static void test_positive_msgtyp(void)if (strcmp (rcv_buf.mtext,MSG2 ) ==0 && rcv_buf.type ==MSGTYPE2 ) {tst_res (TPASS , -"msgtyp got the first message in the queue of type msgtyp" ); +"msgtyp got the first message in the queue of type msgtyp" ); }else {tst_res (TFAIL ,"msgtyp didn't get the first message in the queue of type msgtyp" );
@@ -226,7 +226,7 @@ static void test_negative_msgtyp(void)if (strcmp (rcv_buf.mtext,MSG1 ) ==0 && rcv_buf.type ==MSGTYPE1 ) {tst_res (TPASS , -"-msgtyp got the first message in the queue with the lowest type" ); +"-msgtyp got the first message in the queue with the lowest type" ); }else {tst_res (TFAIL ,"-msgtyp didn't get the first message in the queue with the lowest type" );
Signature · 5 lines
2.31.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH 2/2] msgrcv07: Cleanup indentation
Hi Richie,
Quoted 1 line
make make check happy.
thx!
Kind regards,
Petr
Quoted 27 lines
Signed-off-by Richard Palethorpe <[email protected]>--- testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c +2
-2@@ -201,7 +201,7 @@ static void test_positive_msgtyp(void)if (strcmp (rcv_buf.mtext,MSG2 ) ==0 && rcv_buf.type ==MSGTYPE2 ) {tst_res (TPASS , -"msgtyp got the first message in the queue of type msgtyp" ); +"msgtyp got the first message in the queue of type msgtyp" ); }else {tst_res (TFAIL ,"msgtyp didn't get the first message in the queue of type msgtyp" );@@ -226,7 +226,7 @@ static void test_negative_msgtyp(void)if (strcmp (rcv_buf.mtext,MSG1 ) ==0 && rcv_buf.type ==MSGTYPE1 ) {tst_res (TPASS , -"-msgtyp got the first message in the queue with the lowest type" ); +"-msgtyp got the first message in the queue with the lowest type" ); }else {tst_res (TFAIL ,"-msgtyp didn't get the first message in the queue with the lowest type" );
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Richie,
LGTM.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Richie,
...
testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c static void test_negative_msgtyp(void) · line 240
Quoted 11 lines
+++
b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.ctestcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c +6
-0@@ -232,6 +232,13 @@ static void test_negative_msgtyp(void) "-msgtyp didn't get the first message in the queue with the lowest type"); } +TST_EXP_FAIL (msgrcv (queue_id, &rcv_buf,MSGSIZE , -MSGTYPE1 ,IPC_NOWAIT ), +ENOMSG , +"-msgtype didn't recv next lowest msg" ); +TST_EXP_FAIL (msgrcv (queue_id, &rcv_buf,MSGSIZE , -MSGTYPE1 ,MSG_EXCEPT |IPC_NOWAIT ), +ENOMSG , +"-msgtype (with except) didn't recv next lowest msg" );
nit: I'd use msgtyp instead of msgtype (although it looks like typo, it's used without 'e' as a parametr name in man msgop(2) and also throughout this test (obviously can be changed during merge).
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hello Petr,
Quoted 8 lines · Petr Vorel
Hi Richie,
...
Quoted 4 lines
+++
b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.ctestcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c +0
-0@@ -232,6 +232,13 @@ static void test_negative_msgtyp(void) "-msgtyp didn't get the first message in the queue with the lowest type"); }
Quoted 9 lines
testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c static void test_negative_msgtyp(void) · line 240
Quoted 6 lines
testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c +6
-0+TST_EXP_FAIL (msgrcv (queue_id, &rcv_buf,MSGSIZE , -MSGTYPE1 ,IPC_NOWAIT ), +ENOMSG , +"-msgtype didn't recv next lowest msg" ); +TST_EXP_FAIL (msgrcv (queue_id, &rcv_buf,MSGSIZE , -MSGTYPE1 ,MSG_EXCEPT |IPC_NOWAIT ), +ENOMSG , +"-msgtype (with except) didn't recv next lowest msg" );nit: I'd use msgtyp instead of msgtype (although it looks like typo, it's used without 'e' as a parametr name in man msgop(2) and also throughout this test (obviously can be changed during merge).
Sure, sounds good.
Quoted 3 lines
Kind regards,
Petr
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
I guess that it would make more sense to add this to the msgrcv02.c as:
testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c +13 -7
@@ -21,6 +21,8 @@* msgflg and no message of the requested type existed on the message queue. */ +#define _GNU_SOURCE +#include <string.h> #include <sys/wait.h> #include <sys/msg.h>
@@ -35,10 +37,12 @@ static int queue_id = -1;static int bad_id =-1 ;struct passwd *pw; +#define MSGTYP 2 +static struct buf {long type;char mtext[MSGSIZE ]; -} rcv_buf, snd_buf = {MSGTYPE ,"hello" }; +} rcv_buf, snd_buf = {MSGTYP ,"hello" }; static struct tcase { int *id;
@@ -49,12 +53,14 @@ static struct tcase {int exp_user;int exp_err; } tcases[] = { - {&queue_id, &rcv_buf, 4, 1, 0, 0, E2BIG}, - {&queue_id, &rcv_buf, MSGSIZE, 1, 0, 1, EACCES}, - {&queue_id, NULL, MSGSIZE, 1, 0, 0, EFAULT}, - {&bad_id, &rcv_buf, MSGSIZE, 1, 0, 0, EINVAL}, - {&queue_id, &rcv_buf, -1, 1, 0, 0, EINVAL}, - {&queue_id, &rcv_buf, MSGSIZE, 2, IPC_NOWAIT, 0, ENOMSG}, + {&queue_id, &rcv_buf, 4, MSGTYP, 0, 0, E2BIG}, + {&queue_id, &rcv_buf, MSGSIZE, MSGTYP, 0, 1, EACCES}, + {&queue_id, NULL, MSGSIZE, MSGTYP, 0, 0, EFAULT}, + {&bad_id, &rcv_buf, MSGSIZE, MSGTYP, 0, 0, EINVAL}, + {&queue_id, &rcv_buf, -1, MSGTYP, 0, 0, EINVAL}, + {&queue_id, &rcv_buf, MSGSIZE, MSGTYP+1, IPC_NOWAIT, 0, ENOMSG}, + {&queue_id, &rcv_buf, MSGSIZE, -1, IPC_NOWAIT, 0, ENOMSG}, + {&queue_id, &rcv_buf, MSGSIZE, -1, IPC_NOWAIT | MSG_EXCEPT, 0, ENOMSG}, };
What do you think?
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hello,
Quoted 51 lines · Cyril Hrubis
Hi!
I guess that it would make more sense to add this to themsgrcv02.cas:testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c +13
-7@@ -21,6 +21,8 @@* msgflg and no message of the requested type existed on the message queue. */ +#define _GNU_SOURCE +#include <string.h> #include <sys/wait.h> #include <sys/msg.h> @@ -35,10 +37,12 @@ static int queue_id = -1;static int bad_id =-1 ;struct passwd *pw; +#define MSGTYP 2 +static struct buf {long type;char mtext[MSGSIZE ]; -} rcv_buf, snd_buf = {MSGTYPE ,"hello" }; +} rcv_buf, snd_buf = {MSGTYP ,"hello" }; static struct tcase { int *id;@@ -49,12 +53,14 @@ static struct tcase {int exp_user;int exp_err; } tcases[] = { - {&queue_id, &rcv_buf, 4, 1, 0, 0, E2BIG}, - {&queue_id, &rcv_buf, MSGSIZE, 1, 0, 1, EACCES}, - {&queue_id, NULL, MSGSIZE, 1, 0, 0, EFAULT}, - {&bad_id, &rcv_buf, MSGSIZE, 1, 0, 0, EINVAL}, - {&queue_id, &rcv_buf, -1, 1, 0, 0, EINVAL}, - {&queue_id, &rcv_buf, MSGSIZE, 2, IPC_NOWAIT, 0, ENOMSG}, + {&queue_id, &rcv_buf, 4, MSGTYP, 0, 0, E2BIG}, + {&queue_id, &rcv_buf, MSGSIZE, MSGTYP, 0, 1, EACCES}, + {&queue_id, NULL, MSGSIZE, MSGTYP, 0, 0, EFAULT}, + {&bad_id, &rcv_buf, MSGSIZE, MSGTYP, 0, 0, EINVAL}, + {&queue_id, &rcv_buf, -1, MSGTYP, 0, 0, EINVAL}, + {&queue_id, &rcv_buf, MSGSIZE, MSGTYP+1, IPC_NOWAIT, 0, ENOMSG}, + {&queue_id, &rcv_buf, MSGSIZE, -1, IPC_NOWAIT, 0, ENOMSG}, + {&queue_id, &rcv_buf, MSGSIZE, -1, IPC_NOWAIT | MSG_EXCEPT, 0, ENOMSG}, };
Quoted 1 line
What do you think?
I don't know, the functionality in each test seems arbitrary. I would be happy with either patch.
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 4 lines
Quoted 1 line
What do you think?
I don't know, the functionality in each test seems arbitrary. I would be happy with either patch.
I guess I slightly prefer having the negative tests in a single place...
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Richard
Quoted 24 lines
It should leave higher message types on the queue if they are above the specified type's magnitude.
Also check what happens when
MSG_EXCEPTis passed with a negative msg type. This behavior is unspecified, but presently the kernel ignores the flag if the type is negative. The motivation to check this is long handling in 32bit compat mode. If the msg type is not sign extended then it will be treated as a large positive integer. In this case we should receive the remaining message.On the current kernel under x86 the test passes because the system call has an explicit compat variant which performs the sign extension. Otherwise it would fail.
Signed-off-by Richard Palethorpe<[email protected]>--- testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c | 7 +++++++ 1 file changed, 7 insertions(+)testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c +0
-0
testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c static void test_negative_msgtyp(void) · line 241
Quoted 10 lines
testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c +7
-0@@ -232,6 +232,13 @@ static void test_negative_msgtyp(void) "-msgtyp didn't get the first message in the queue with the lowest type"); } +TST_EXP_FAIL (msgrcv (queue_id,&rcv_buf,MSGSIZE , -MSGTYPE1 ,IPC_NOWAIT ), +ENOMSG , +"-msgtype didn't recv next lowest msg" ); +TST_EXP_FAIL (msgrcv (queue_id,&rcv_buf,MSGSIZE , -MSGTYPE1 ,MSG_EXCEPT |IPC_NOWAIT ), +ENOMSG , +"-msgtype (with except) didn't recv next lowest msg" ); +
It should use TST_EXP_FAIL2 macro. Other than this, look good to me
Best Regards
Yang Xu
Quoted 3 lines
testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c +0
-0exit:SAFE_MSGCTL (queue_id,IPC_RMID ,NULL ); queue_id =-1 ;
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp