All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] proposed patch to fix sendmsg01 invalid flags set w/ control ; returned -1 (expected -1), errno 22 (expected 95)
@ 2015-02-03  9:06 snehalphule
  2015-02-03  9:37 ` Cyril Hrubis
  0 siblings, 1 reply; 3+ messages in thread
From: snehalphule @ 2015-02-03  9:06 UTC (permalink / raw)
  To: ltp-list


[-- Attachment #1.1: Type: text/plain, Size: 2368 bytes --]



*Description:*
For bug: https://bugs.launchpad.net/linaro-qa/+bug/1327251
Purpose of Change: Because of code changes in socket.c file for 
32bit-userspace, return value changed to EINVAL in case of 
32bit-userspace/64-bit-kernelspace.
Test changed to check if 32user/64kernel , then return value should be 
checked to EINVAL ,
for other systems return value should be EOPNOTSUPP


Kernel : 3.10.0-123.13.2
Signed-off-by: snehalphule <snehal@linux.vnet.ibm.com>

--- ltp-full-20140828/testcases/kernel/syscalls/sendmsg/sendmsg01.c.orig 
2015-01-23 00:54:22.804582530 -0600
+++ ltp-full-20140828/testcases/kernel/syscalls/sendmsg/sendmsg01.c 
2015-01-23 00:57:26.149032808 -0600
@@ -677,6 +677,38 @@ static void setup4(void)
      control->cmsg_type = SCM_RIGHTS;
      *(int *)CMSG_DATA(control) = tfd;
      controllen = control->cmsg_len;
+
+        // In case of Compact (32bit) user space and 64bit kernel 
space, return value is EINVAL
+        if (tdat[testno].flags == (unsigned)~MSG_CMSG_COMPAT)
+        {
+            char user_space_bit[BUFSIZ];
+            char kernel_arch[BUFSIZ];
+            int kernel_space_bit;
+
+            FILE *pipe = popen("getconf LONG_BIT", "r");
+            if (fgets(user_space_bit, BUFSIZ, pipe) != NULL)
+            {
+               pipe = popen("arch", "r");
+               if (fgets(kernel_arch, BUFSIZ, pipe) != NULL)
+               {
+                   // Remove carriage return from the buffer
+                   size_t len = strlen(user_space_bit);
+                   if (len > 0 && user_space_bit[len-1] == '\n') { 
user_space_bit[--len] = '\0';}
+                   len = strlen(kernel_arch);
+                   if (len > 0 && kernel_arch[len-1] == '\n') { 
kernel_arch[--len] = '\0';}
+
+                   // Check if Kernel used is 64 bit or 32 bit
+                   if (!strcmp(kernel_arch, "ppc64") || 
!strcmp(kernel_arch, "s390x") || !strcmp(kernel_arch, "x86_64"))
+                      kernel_space_bit = 64;
+                   else
+                      kernel_space_bit = 32;
+
+                   // Only if it is Compact user space (32bit), then 
return value is EINVAL
+                   if (atoi(user_space_bit) == 32  && kernel_space_bit 
== 64)
+                   tdat[testno].experrno = EINVAL;
+               }
+            }
+         }
  }

  static void cleanup4(void)




[-- Attachment #1.2: Type: text/html, Size: 4175 bytes --]

[-- Attachment #2: Type: text/plain, Size: 441 bytes --]

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/

[-- Attachment #3: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] proposed patch to fix sendmsg01 invalid flags set w/ control ; returned -1 (expected -1), errno 22 (expected 95)
  2015-02-03  9:06 [LTP] proposed patch to fix sendmsg01 invalid flags set w/ control ; returned -1 (expected -1), errno 22 (expected 95) snehalphule
@ 2015-02-03  9:37 ` Cyril Hrubis
       [not found]   ` <1501572527.5689680.1422957604905.JavaMail.zimbra@redhat.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Cyril Hrubis @ 2015-02-03  9:37 UTC (permalink / raw)
  To: snehalphule; +Cc: ltp-list, Chuck Ebbert

Hi!
> *Description:*
> For bug: https://bugs.launchpad.net/linaro-qa/+bug/1327251
> Purpose of Change: Because of code changes in socket.c file for 
> 32bit-userspace, return value changed to EINVAL in case of 
> 32bit-userspace/64-bit-kernelspace.
> Test changed to check if 32user/64kernel , then return value should be 
> checked to EINVAL ,
> for other systems return value should be EOPNOTSUPP
> 
> Kernel : 3.10.0-123.13.2
> Signed-off-by: snehalphule <snehal@linux.vnet.ibm.com>

I can see this exact failure when I compile the testsuite with -m32 on
64bit hardware as well. But the patch below is wrong on several levels.

My guess is that the root of the problem is similar to the problem fixed in:

commit 1153a8438fe45530eb480d902271476c2e330663
Author: Chuck Ebbert <cebbert.lkml@gmail.com>
Date:   Wed Oct 1 17:10:32 2014 -0500

    recvfrom01: fix test for invalid message flags


The test passes ~MSG_CMSG_COMPAT as flags and expect to hit particular safety
check. The difference may be that the order of checks is different for compat
syscalls, but that is just a guess. This would need more investigation to
figure out what is wrong.

> --- ltp-full-20140828/testcases/kernel/syscalls/sendmsg/sendmsg01.c.orig 
> 2015-01-23 00:54:22.804582530 -0600
> +++ ltp-full-20140828/testcases/kernel/syscalls/sendmsg/sendmsg01.c 
> 2015-01-23 00:57:26.149032808 -0600
> @@ -677,6 +677,38 @@ static void setup4(void)
>       control->cmsg_type = SCM_RIGHTS;
>       *(int *)CMSG_DATA(control) = tfd;
>       controllen = control->cmsg_len;
> +
> +        // In case of Compact (32bit) user space and 64bit kernel 
> space, return value is EINVAL
> +        if (tdat[testno].flags == (unsigned)~MSG_CMSG_COMPAT)
> +        {
> +            char user_space_bit[BUFSIZ];
> +            char kernel_arch[BUFSIZ];
> +            int kernel_space_bit;
> +
> +            FILE *pipe = popen("getconf LONG_BIT", "r");
> +            if (fgets(user_space_bit, BUFSIZ, pipe) != NULL)
> +            {
> +               pipe = popen("arch", "r");
> +               if (fgets(kernel_arch, BUFSIZ, pipe) != NULL)
> +               {
> +                   // Remove carriage return from the buffer
> +                   size_t len = strlen(user_space_bit);
> +                   if (len > 0 && user_space_bit[len-1] == '\n') { 
> user_space_bit[--len] = '\0';}
> +                   len = strlen(kernel_arch);
> +                   if (len > 0 && kernel_arch[len-1] == '\n') { 
> kernel_arch[--len] = '\0';}
> +
> +                   // Check if Kernel used is 64 bit or 32 bit
> +                   if (!strcmp(kernel_arch, "ppc64") || 
> !strcmp(kernel_arch, "s390x") || !strcmp(kernel_arch, "x86_64"))
> +                      kernel_space_bit = 64;
> +                   else
> +                      kernel_space_bit = 32;
> +
> +                   // Only if it is Compact user space (32bit), then 
> return value is EINVAL
> +                   if (atoi(user_space_bit) == 32  && kernel_space_bit 
> == 64)
> +                   tdat[testno].experrno = EINVAL;
> +               }
> +            }
> +         }
>   }
> 
>   static void cleanup4(void)
> 
> 
> 

> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming. The Go Parallel Website,
> sponsored by Intel and developed in partnership with Slashdot Media, is your
> hub for all things parallel software development, from weekly thought
> leadership blogs to news, videos, case studies, tutorials and more. Take a
> look and join the conversation now. http://goparallel.sourceforge.net/

> _______________________________________________
> Ltp-list mailing list
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list


-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] proposed patch to fix sendmsg01 invalid flags set w/ control ; returned -1 (expected -1), errno 22 (expected 95)
       [not found]     ` <2062151122.5724081.1422960324625.JavaMail.zimbra@redhat.com>
@ 2015-02-03 12:51       ` Cyril Hrubis
  0 siblings, 0 replies; 3+ messages in thread
From: Cyril Hrubis @ 2015-02-03 12:51 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp-list, Chuck Ebbert

Hi!
> > >     recvfrom01: fix test for invalid message flags
> > 
> > Agreed. We have seen in past, that this (.flags = ~MSG_CMSG_COMPAT)
> > leads to undefined behavior.
> 
> It appears the difference comes from LTP:
>   https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/utils/msg_common.h
> 
> The flags has 0 value when compiled with -m32, so we never make it pass
> this check:
>   if (flags & MSG_CMSG_COMPAT)
>       return -EINVAL;
> 
> but the kernel definition is rather based on config option:
>   #if defined(CONFIG_COMPAT)
>   #define MSG_CMSG_COMPAT 0x80000000      /* This message needs 32 bit fixups */
>   #else
>   #define MSG_CMSG_COMPAT 0               /* We never have 32 bit fixups */
>   #endif

Tricky.

But looking into the unix_dgram_sendmsg() which should be the one that
gets called in the particular case, the code realy just checks for the
MSG_OOB, just like the the recvmsg() case.

......

        err = -EOPNOTSUPP;
        if (msg->msg_flags&MSG_OOB)
                goto out;
......

So I guess that we should be safe with changing the test the same way as we did
with recvmsg().

> sendmsg01 seems to be the only place where this flag is used.

That is because it has been removed from the recvmsg01.c by the fix
mentioned in this thread. However the header in question stayed included
there...

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

end of thread, other threads:[~2015-02-03 12:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-03  9:06 [LTP] proposed patch to fix sendmsg01 invalid flags set w/ control ; returned -1 (expected -1), errno 22 (expected 95) snehalphule
2015-02-03  9:37 ` Cyril Hrubis
     [not found]   ` <1501572527.5689680.1422957604905.JavaMail.zimbra@redhat.com>
     [not found]     ` <2062151122.5724081.1422960324625.JavaMail.zimbra@redhat.com>
2015-02-03 12:51       ` Cyril Hrubis

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.