All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] msgrcv07: Check negative msg type filters
@ 2021-09-24  9:21 Richard Palethorpe via ltp
  2021-09-24  9:21 ` [LTP] [PATCH 2/2] msgrcv07: Cleanup indentation Richard Palethorpe via ltp
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Richard Palethorpe via ltp @ 2021-09-24  9:21 UTC (permalink / raw)
  To: ltp; +Cc: Richard Palethorpe

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.

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
 testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
index 2c687c5c8..8635ef7a4 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
@@ -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;
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [LTP] [PATCH 2/2] msgrcv07: Cleanup indentation
  2021-09-24  9:21 [LTP] [PATCH 1/2] msgrcv07: Check negative msg type filters Richard Palethorpe via ltp
@ 2021-09-24  9:21 ` Richard Palethorpe via ltp
  2021-09-24 10:22   ` Petr Vorel
  2021-09-24 10:21 ` [LTP] [PATCH 1/2] msgrcv07: Check negative msg type filters Petr Vorel
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Richard Palethorpe via ltp @ 2021-09-24  9:21 UTC (permalink / raw)
  To: ltp; +Cc: Richard Palethorpe

make make check happy.

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
 testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
index 8635ef7a4..4528f69b2 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
@@ -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");
-- 
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH 1/2] msgrcv07: Check negative msg type filters
  2021-09-24  9:21 [LTP] [PATCH 1/2] msgrcv07: Check negative msg type filters Richard Palethorpe via ltp
  2021-09-24  9:21 ` [LTP] [PATCH 2/2] msgrcv07: Cleanup indentation Richard Palethorpe via ltp
@ 2021-09-24 10:21 ` Petr Vorel
  2021-09-24 10:26 ` Petr Vorel
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Petr Vorel @ 2021-09-24 10:21 UTC (permalink / raw)
  To: Richard Palethorpe; +Cc: ltp

Hi Richie,

LGTM.
Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH 2/2] msgrcv07: Cleanup indentation
  2021-09-24  9:21 ` [LTP] [PATCH 2/2] msgrcv07: Cleanup indentation Richard Palethorpe via ltp
@ 2021-09-24 10:22   ` Petr Vorel
  0 siblings, 0 replies; 10+ messages in thread
From: Petr Vorel @ 2021-09-24 10:22 UTC (permalink / raw)
  To: Richard Palethorpe; +Cc: ltp

Hi Richie,

> make make check happy.
thx!
Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

> Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
> ---
>  testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

> diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
> index 8635ef7a4..4528f69b2 100644
> --- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
> +++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
> @@ -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");

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH 1/2] msgrcv07: Check negative msg type filters
  2021-09-24  9:21 [LTP] [PATCH 1/2] msgrcv07: Check negative msg type filters Richard Palethorpe via ltp
  2021-09-24  9:21 ` [LTP] [PATCH 2/2] msgrcv07: Cleanup indentation Richard Palethorpe via ltp
  2021-09-24 10:21 ` [LTP] [PATCH 1/2] msgrcv07: Check negative msg type filters Petr Vorel
@ 2021-09-24 10:26 ` Petr Vorel
  2021-09-24 10:30   ` Richard Palethorpe
  2021-10-08 14:14 ` Cyril Hrubis
  2021-10-13  6:56 ` xuyang2018.jy
  4 siblings, 1 reply; 10+ messages in thread
From: Petr Vorel @ 2021-09-24 10:26 UTC (permalink / raw)
  To: Richard Palethorpe; +Cc: ltp

Hi Richie,

...
> +++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
> @@ -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

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH 1/2] msgrcv07: Check negative msg type filters
  2021-09-24 10:26 ` Petr Vorel
@ 2021-09-24 10:30   ` Richard Palethorpe
  0 siblings, 0 replies; 10+ messages in thread
From: Richard Palethorpe @ 2021-09-24 10:30 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

Hello Petr,

Petr Vorel <pvorel@suse.cz> writes:

> Hi Richie,
>
> ...
>> +++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
>> @@ -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).

Sure, sounds good.

>
> Kind regards,
> Petr


-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH 1/2] msgrcv07: Check negative msg type filters
  2021-09-24  9:21 [LTP] [PATCH 1/2] msgrcv07: Check negative msg type filters Richard Palethorpe via ltp
                   ` (2 preceding siblings ...)
  2021-09-24 10:26 ` Petr Vorel
@ 2021-10-08 14:14 ` Cyril Hrubis
  2021-10-11  8:46   ` Richard Palethorpe
  2021-10-13  6:56 ` xuyang2018.jy
  4 siblings, 1 reply; 10+ messages in thread
From: Cyril Hrubis @ 2021-10-08 14:14 UTC (permalink / raw)
  To: Richard Palethorpe; +Cc: ltp

Hi!
I guess that it would make more sense to add this to the msgrcv02.c as:

diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
index cfb7d7446..b305d1f92 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
@@ -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?

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH 1/2] msgrcv07: Check negative msg type filters
  2021-10-08 14:14 ` Cyril Hrubis
@ 2021-10-11  8:46   ` Richard Palethorpe
  2021-10-11 12:57     ` Cyril Hrubis
  0 siblings, 1 reply; 10+ messages in thread
From: Richard Palethorpe @ 2021-10-11  8:46 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp

Hello,

Cyril Hrubis <chrubis@suse.cz> writes:

> Hi!
> I guess that it would make more sense to add this to the msgrcv02.c as:
>
> diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
> index cfb7d7446..b305d1f92 100644
> --- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
> +++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
> @@ -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?

I don't know, the functionality in each test seems arbitrary. I would be
happy with either patch.

-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH 1/2] msgrcv07: Check negative msg type filters
  2021-10-11  8:46   ` Richard Palethorpe
@ 2021-10-11 12:57     ` Cyril Hrubis
  0 siblings, 0 replies; 10+ messages in thread
From: Cyril Hrubis @ 2021-10-11 12:57 UTC (permalink / raw)
  To: Richard Palethorpe; +Cc: ltp

Hi!
> > 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...

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [LTP] [PATCH 1/2] msgrcv07: Check negative msg type filters
  2021-09-24  9:21 [LTP] [PATCH 1/2] msgrcv07: Check negative msg type filters Richard Palethorpe via ltp
                   ` (3 preceding siblings ...)
  2021-10-08 14:14 ` Cyril Hrubis
@ 2021-10-13  6:56 ` xuyang2018.jy
  4 siblings, 0 replies; 10+ messages in thread
From: xuyang2018.jy @ 2021-10-13  6:56 UTC (permalink / raw)
  To: Richard Palethorpe; +Cc: Richard Palethorpe via ltp

Hi Richard
> 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.
>
> Signed-off-by: Richard Palethorpe<rpalethorpe@suse.com>
> ---
>   testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c | 7 +++++++
>   1 file changed, 7 insertions(+)
>
> diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
> index 2c687c5c8..8635ef7a4 100644
> --- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
> +++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
> @@ -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
Reviewed-by: Yang Xu <xuyang2018.jy@fujitsu.com>

Best Regards
Yang Xu
>   exit:
>   	SAFE_MSGCTL(queue_id, IPC_RMID, NULL);
>   	queue_id = -1;

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-10-13  6:56 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-24  9:21 [LTP] [PATCH 1/2] msgrcv07: Check negative msg type filters Richard Palethorpe via ltp
2021-09-24  9:21 ` [LTP] [PATCH 2/2] msgrcv07: Cleanup indentation Richard Palethorpe via ltp
2021-09-24 10:22   ` Petr Vorel
2021-09-24 10:21 ` [LTP] [PATCH 1/2] msgrcv07: Check negative msg type filters Petr Vorel
2021-09-24 10:26 ` Petr Vorel
2021-09-24 10:30   ` Richard Palethorpe
2021-10-08 14:14 ` Cyril Hrubis
2021-10-11  8:46   ` Richard Palethorpe
2021-10-11 12:57     ` Cyril Hrubis
2021-10-13  6:56 ` xuyang2018.jy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.