[selftest/net/af_unix,1/1] Fix size of parameter to connect()

Message ID bd7ff00a-6892-fd56-b3ca-4b3feb6121d8@alu.unizg.hr
State New
Headers
Series [selftest/net/af_unix,1/1] Fix size of parameter to connect() |

Commit Message

Mirsad Todorovac Jan. 6, 2023, 5:18 p.m. UTC
  From: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>

Adjust size parameter in connect() to match the type of the parameter, to fix "No such file or directory"
error in selftests/net/af_unix/test_oob_unix.c:127.

The existing code happens to work provided that the autogenerated pathname is shorter than
sizeof (struct sockaddr), which is why it hasn't been noticed earlier.

Visible from the trace excerpt:

bind(3, {sa_family=AF_UNIX, sun_path="unix_oob_453059"}, 110) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fa6a6577a10) = 453060
[pid <child>] connect(6, {sa_family=AF_UNIX, sun_path="unix_oob_45305"}, 16) = -1 ENOENT (No such file or directory)

BUG: The filename is trimmed to sizeof (struct sockaddr).

The patch is generated against the "vanilla" torvalds mainline tree 6.2-rc2.

Thanks and regards,
Mirsad Todorovac

Reported-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
Cc: Florian Westphal <fw@strlen.de>
Reviewed-by: Florian Westphal <fw@strlen.de>

---
  tools/testing/selftests/net/af_unix/test_unix_oob.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)


--
Mirsad Goran Todorovac
Sistem inženjer
Grafički fakultet | Akademija likovnih umjetnosti
Sveučilište u Zagrebu
  

Comments

Kuniyuki Iwashima Jan. 6, 2023, 5:58 p.m. UTC | #1
Hi,

Thanks for the patch.

From:   Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>
Date:   Fri, 6 Jan 2023 18:18:58 +0100
> From: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>
> 
> Adjust size parameter in connect() to match the type of the parameter, to fix "No such file or directory"
> error in selftests/net/af_unix/test_oob_unix.c:127.

Could you wrap the changelog to 75 chars except for log (strace below) ?
checkpatch.pl will help.

  $ git show HEAD --format=email | ./scripts/checkpatch.pl


> 
> The existing code happens to work provided that the autogenerated pathname is shorter than
> sizeof (struct sockaddr), which is why it hasn't been noticed earlier.
> 
> Visible from the trace excerpt:
> 
> bind(3, {sa_family=AF_UNIX, sun_path="unix_oob_453059"}, 110) = 0
> clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fa6a6577a10) = 453060
> [pid <child>] connect(6, {sa_family=AF_UNIX, sun_path="unix_oob_45305"}, 16) = -1 ENOENT (No such file or directory)
> 
> BUG: The filename is trimmed to sizeof (struct sockaddr).
> 
> The patch is generated against the "vanilla" torvalds mainline tree 6.2-rc2.

Every patch that fixes networking code has to be applied cleanly on net.git.
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/

But the patch can not be applied to net.git.
Could you check this ?
https://patchwork.kernel.org/project/netdevbpf/patch/bd7ff00a-6892-fd56-b3ca-4b3feb6121d8@alu.unizg.hr/

Also, the mail title should be

  [PATCH Tree Version Nth/Total] subsystem: Description.

Next time, Tree is net and Version is v2, and we need not write 1/1, so the
subject should be

  [PATCH net v2] af_unix: selftest: Fix size of parameter to connect()

Please see here for details.
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/tree/Documentation/process/maintainer-netdev.rst


> 
> Thanks and regards,
> Mirsad Todorovac

You can remove these lines.


> 
> Reported-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>

In this case, you are the reporter and the author of the patch, so the
Reported-by tag is not needed.  Instead, you have to add your SOB tag.

  Signed-off-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>


> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: Shuah Khan <shuah@kernel.org>
> Cc: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
> Cc: Florian Westphal <fw@strlen.de>
> Reviewed-by: Florian Westphal <fw@strlen.de>

Please add Fixes tag as I said here.
https://lore.kernel.org/netdev/20230103111335.81600-1-kuniyu@amazon.com/#r

Thank you,
Kuniyuki


> 
> ---
>   tools/testing/selftests/net/af_unix/test_unix_oob.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/net/af_unix/test_unix_oob.c b/tools/testing/selftests/net/af_unix/test_unix_oob.c
> index b57e91e1c3f2..532459a15067 100644
> --- a/tools/testing/selftests/net/af_unix/test_unix_oob.c
> +++ b/tools/testing/selftests/net/af_unix/test_unix_oob.c
> @@ -124,7 +124,7 @@ void producer(struct sockaddr_un *consumer_addr)
> 
>          wait_for_signal(pipefd[0]);
>          if (connect(cfd, (struct sockaddr *)consumer_addr,
> -                    sizeof(struct sockaddr)) != 0) {
> +                    sizeof(*consumer_addr)) != 0) {
>                  perror("Connect failed");
>                  kill(0, SIGTERM);
>                  exit(1);
> 
> --
> Mirsad Goran Todorovac
> Sistem inženjer
> Grafički fakultet | Akademija likovnih umjetnosti
> Sveučilište u Zagrebu
> -- 
> System engineer
> Faculty of Graphic Arts | Academy of Fine Arts
> University of Zagreb, Republic of Croatia
> The European Union
  
Mirsad Todorovac Jan. 6, 2023, 7:19 p.m. UTC | #2
Hi,

On 06. 01. 2023. 18:58, Kuniyuki Iwashima wrote:
> Hi,
> 
> Thanks for the patch.

Thank you for your quick review. I had to do the homework before replying.

> From:   Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>
> Date:   Fri, 6 Jan 2023 18:18:58 +0100
>> From: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>
>>
>> Adjust size parameter in connect() to match the type of the parameter, to fix "No such file or directory"
>> error in selftests/net/af_unix/test_oob_unix.c:127.
> 
> Could you wrap the changelog to 75 chars except for log (strace below) ?
> checkpatch.pl will help.
> 
>    $ git show HEAD --format=email | ./scripts/checkpatch.pl

The complete result according to the guidelines will be in the followup email.

>> The existing code happens to work provided that the autogenerated pathname is shorter than
>> sizeof (struct sockaddr), which is why it hasn't been noticed earlier.
>>
>> Visible from the trace excerpt:
>>
>> bind(3, {sa_family=AF_UNIX, sun_path="unix_oob_453059"}, 110) = 0
>> clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7fa6a6577a10) = 453060
>> [pid <child>] connect(6, {sa_family=AF_UNIX, sun_path="unix_oob_45305"}, 16) = -1 ENOENT (No such file or directory)
>>
>> BUG: The filename is trimmed to sizeof (struct sockaddr).
>>
>> The patch is generated against the "vanilla" torvalds mainline tree 6.2-rc2.
> 
> Every patch that fixes networking code has to be applied cleanly on net.git.
> https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/
> 
> But the patch can not be applied to net.git.

I have tested the patch against net.git, and it is a verbatim copy (tested by diff).

> Could you check this ?
> https://patchwork.kernel.org/project/netdevbpf/patch/bd7ff00a-6892-fd56-b3ca-4b3feb6121d8@alu.unizg.hr/
> 
> Also, the mail title should be
> 
>    [PATCH Tree Version Nth/Total] subsystem: Description.
> 
> Next time, Tree is net and Version is v2, and we need not write 1/1, so the
> subject should be
> 
>    [PATCH net v2] af_unix: selftest: Fix size of parameter to connect()

Got it. Will do in the followup email.

> Please see here for details.
> https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/tree/Documentation/process/maintainer-netdev.rst
> 
> 
>>
>> Thanks and regards,
>> Mirsad Todorovac
> 
> You can remove these lines.

Sure.

>> Reported-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>
> 
> In this case, you are the reporter and the author of the patch, so the
> Reported-by tag is not needed.  Instead, you have to add your SOB tag.
> 
>    Signed-off-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>

OK.

>> Cc: "David S. Miller" <davem@davemloft.net>
>> Cc: Eric Dumazet <edumazet@google.com>
>> Cc: Jakub Kicinski <kuba@kernel.org>
>> Cc: Paolo Abeni <pabeni@redhat.com>
>> Cc: Shuah Khan <shuah@kernel.org>
>> Cc: Kuniyuki Iwashima <kuniyu@amazon.co.jp>
>> Cc: Florian Westphal <fw@strlen.de>
>> Reviewed-by: Florian Westphal <fw@strlen.de>
> 
> Please add Fixes tag as I said here.
> https://lore.kernel.org/netdev/20230103111335.81600-1-kuniyu@amazon.com/#r
> 
> Thank you,
> Kuniyuki
> 
> 
>>
>> ---
>>    tools/testing/selftests/net/af_unix/test_unix_oob.c | 2 +-
>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tools/testing/selftests/net/af_unix/test_unix_oob.c b/tools/testing/selftests/net/af_unix/test_unix_oob.c
>> index b57e91e1c3f2..532459a15067 100644
>> --- a/tools/testing/selftests/net/af_unix/test_unix_oob.c
>> +++ b/tools/testing/selftests/net/af_unix/test_unix_oob.c
>> @@ -124,7 +124,7 @@ void producer(struct sockaddr_un *consumer_addr)
>>
>>           wait_for_signal(pipefd[0]);
>>           if (connect(cfd, (struct sockaddr *)consumer_addr,
>> -                    sizeof(struct sockaddr)) != 0) {
>> +                    sizeof(*consumer_addr)) != 0) {
>>                   perror("Connect failed");
>>                   kill(0, SIGTERM);
>>                   exit(1);
>>

--
Mirsad Goran Todorovac
Sistem inženjer
Grafički fakultet | Akademija likovnih umjetnosti
Sveučilište u Zagrebu
  

Patch

diff --git a/tools/testing/selftests/net/af_unix/test_unix_oob.c b/tools/testing/selftests/net/af_unix/test_unix_oob.c
index b57e91e1c3f2..532459a15067 100644
--- a/tools/testing/selftests/net/af_unix/test_unix_oob.c
+++ b/tools/testing/selftests/net/af_unix/test_unix_oob.c
@@ -124,7 +124,7 @@  void producer(struct sockaddr_un *consumer_addr)

         wait_for_signal(pipefd[0]);
         if (connect(cfd, (struct sockaddr *)consumer_addr,
-                    sizeof(struct sockaddr)) != 0) {
+                    sizeof(*consumer_addr)) != 0) {
                 perror("Connect failed");
                 kill(0, SIGTERM);
                 exit(1);