netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf v2] libbpf: fix passing uninitialized bytes to setsockopt
@ 2019-10-09 16:49 Ilya Maximets
  2019-10-09 16:54 ` Andrii Nakryiko
  2019-10-09 22:49 ` Alexei Starovoitov
  0 siblings, 2 replies; 5+ messages in thread
From: Ilya Maximets @ 2019-10-09 16:49 UTC (permalink / raw)
  To: netdev
  Cc: bpf, linux-kernel, Alexei Starovoitov, Daniel Borkmann,
	David S . Miller, Jonathan Lemon, Andrii Nakryiko, Ilya Maximets

'struct xdp_umem_reg' has 4 bytes of padding at the end that makes
valgrind complain about passing uninitialized stack memory to the
syscall:

  Syscall param socketcall.setsockopt() points to uninitialised byte(s)
    at 0x4E7AB7E: setsockopt (in /usr/lib64/libc-2.29.so)
    by 0x4BDE035: xsk_umem__create@@LIBBPF_0.0.4 (xsk.c:172)
  Uninitialised value was created by a stack allocation
    at 0x4BDDEBA: xsk_umem__create@@LIBBPF_0.0.4 (xsk.c:140)

Padding bytes appeared after introducing of a new 'flags' field.
memset() is required to clear them.

Fixes: 10d30e301732 ("libbpf: add flags to umem config")
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
---

Version 2:
  * Struct initializer replaced with explicit memset(). [Andrii]

 tools/lib/bpf/xsk.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
index a902838f9fcc..9d5348086203 100644
--- a/tools/lib/bpf/xsk.c
+++ b/tools/lib/bpf/xsk.c
@@ -163,6 +163,7 @@ int xsk_umem__create_v0_0_4(struct xsk_umem **umem_ptr, void *umem_area,
 	umem->umem_area = umem_area;
 	xsk_set_umem_config(&umem->config, usr_config);
 
+	memset(&mr, 0, sizeof(mr));
 	mr.addr = (uintptr_t)umem_area;
 	mr.len = size;
 	mr.chunk_size = umem->config.frame_size;
-- 
2.17.1


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

* Re: [PATCH bpf v2] libbpf: fix passing uninitialized bytes to setsockopt
  2019-10-09 16:49 [PATCH bpf v2] libbpf: fix passing uninitialized bytes to setsockopt Ilya Maximets
@ 2019-10-09 16:54 ` Andrii Nakryiko
  2019-10-09 22:49 ` Alexei Starovoitov
  1 sibling, 0 replies; 5+ messages in thread
From: Andrii Nakryiko @ 2019-10-09 16:54 UTC (permalink / raw)
  To: Ilya Maximets
  Cc: Networking, bpf, open list, Alexei Starovoitov, Daniel Borkmann,
	David S . Miller, Jonathan Lemon

On Wed, Oct 9, 2019 at 9:49 AM Ilya Maximets <i.maximets@ovn.org> wrote:
>
> 'struct xdp_umem_reg' has 4 bytes of padding at the end that makes
> valgrind complain about passing uninitialized stack memory to the
> syscall:
>
>   Syscall param socketcall.setsockopt() points to uninitialised byte(s)
>     at 0x4E7AB7E: setsockopt (in /usr/lib64/libc-2.29.so)
>     by 0x4BDE035: xsk_umem__create@@LIBBPF_0.0.4 (xsk.c:172)
>   Uninitialised value was created by a stack allocation
>     at 0x4BDDEBA: xsk_umem__create@@LIBBPF_0.0.4 (xsk.c:140)
>
> Padding bytes appeared after introducing of a new 'flags' field.
> memset() is required to clear them.
>
> Fixes: 10d30e301732 ("libbpf: add flags to umem config")
> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
> ---
>

Thanks!

Acked-by: Andrii Nakryiko <andriin@fb.com>

> Version 2:
>   * Struct initializer replaced with explicit memset(). [Andrii]
>
>  tools/lib/bpf/xsk.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
> index a902838f9fcc..9d5348086203 100644
> --- a/tools/lib/bpf/xsk.c
> +++ b/tools/lib/bpf/xsk.c
> @@ -163,6 +163,7 @@ int xsk_umem__create_v0_0_4(struct xsk_umem **umem_ptr, void *umem_area,
>         umem->umem_area = umem_area;
>         xsk_set_umem_config(&umem->config, usr_config);
>
> +       memset(&mr, 0, sizeof(mr));
>         mr.addr = (uintptr_t)umem_area;
>         mr.len = size;
>         mr.chunk_size = umem->config.frame_size;
> --
> 2.17.1
>

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

* Re: [PATCH bpf v2] libbpf: fix passing uninitialized bytes to setsockopt
  2019-10-09 16:49 [PATCH bpf v2] libbpf: fix passing uninitialized bytes to setsockopt Ilya Maximets
  2019-10-09 16:54 ` Andrii Nakryiko
@ 2019-10-09 22:49 ` Alexei Starovoitov
  1 sibling, 0 replies; 5+ messages in thread
From: Alexei Starovoitov @ 2019-10-09 22:49 UTC (permalink / raw)
  To: Ilya Maximets
  Cc: Network Development, bpf, LKML, Alexei Starovoitov,
	Daniel Borkmann, David S . Miller, Jonathan Lemon,
	Andrii Nakryiko

On Wed, Oct 9, 2019 at 9:49 AM Ilya Maximets <i.maximets@ovn.org> wrote:
>
> 'struct xdp_umem_reg' has 4 bytes of padding at the end that makes
> valgrind complain about passing uninitialized stack memory to the
> syscall:
>
>   Syscall param socketcall.setsockopt() points to uninitialised byte(s)
>     at 0x4E7AB7E: setsockopt (in /usr/lib64/libc-2.29.so)
>     by 0x4BDE035: xsk_umem__create@@LIBBPF_0.0.4 (xsk.c:172)
>   Uninitialised value was created by a stack allocation
>     at 0x4BDDEBA: xsk_umem__create@@LIBBPF_0.0.4 (xsk.c:140)
>
> Padding bytes appeared after introducing of a new 'flags' field.
> memset() is required to clear them.
>
> Fixes: 10d30e301732 ("libbpf: add flags to umem config")
> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>

Applied. Thanks

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

* Re: [PATCH bpf v2] libbpf: fix passing uninitialized bytes to setsockopt
  2019-10-12 23:24 ` Alexei Starovoitov
@ 2019-10-13 10:17   ` Ilya Maximets
  0 siblings, 0 replies; 5+ messages in thread
From: Ilya Maximets @ 2019-10-13 10:17 UTC (permalink / raw)
  To: Alexei Starovoitov, Ilya Maximets
  Cc: netdev, bpf, linux-kernel, Alexei Starovoitov, Daniel Borkmann,
	David S . Miller, Jonathan Lemon, Andrii Nakryiko

On 13.10.2019 1:24, Alexei Starovoitov wrote:
> On Wed, Oct 09, 2019 at 06:49:29PM +0200, Ilya Maximets wrote:
>> 'struct xdp_umem_reg' has 4 bytes of padding at the end that makes
>> valgrind complain about passing uninitialized stack memory to the
>> syscall:
>>
>>    Syscall param socketcall.setsockopt() points to uninitialised byte(s)
>>      at 0x4E7AB7E: setsockopt (in /usr/lib64/libc-2.29.so)
>>      by 0x4BDE035: xsk_umem__create@@LIBBPF_0.0.4 (xsk.c:172)
>>    Uninitialised value was created by a stack allocation
>>      at 0x4BDDEBA: xsk_umem__create@@LIBBPF_0.0.4 (xsk.c:140)
>>
>> Padding bytes appeared after introducing of a new 'flags' field.
>> memset() is required to clear them.
>>
>> Fixes: 10d30e301732 ("libbpf: add flags to umem config")
>> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
>> ---
>>
>> Version 2:
>>    * Struct initializer replaced with explicit memset(). [Andrii]
>>
>>   tools/lib/bpf/xsk.c | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
>> index a902838f9fcc..9d5348086203 100644
>> --- a/tools/lib/bpf/xsk.c
>> +++ b/tools/lib/bpf/xsk.c
>> @@ -163,6 +163,7 @@ int xsk_umem__create_v0_0_4(struct xsk_umem **umem_ptr, void *umem_area,
>>   	umem->umem_area = umem_area;
>>   	xsk_set_umem_config(&umem->config, usr_config);
>>   
>> +	memset(&mr, 0, sizeof(mr));
>>   	mr.addr = (uintptr_t)umem_area;
>>   	mr.len = size;
>>   	mr.chunk_size = umem->config.frame_size;
> 
> This was already applied. Why did you resend?
> 

Sorry, it wasn't me.  Looking at the mail delivery chain:

Received: from listssympa-test.colorado.edu (listssympa-test.colorado.edu [128.138.129.156])
	by spool.mail.gandi.net (Postfix) with ESMTPS id 66E2F780445
	for <i.maximets@ovn.org>; Sun, 13 Oct 2019 04:52:14 +0000 (UTC)
Received: from listssympa-test.colorado.edu (localhost [127.0.0.1])
	by listssympa-test.colorado.edu (8.15.2/8.15.2/MJC-8.0/sympa) with ESMTPS id x9D4pvsL015926
	(version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO);
	Sat, 12 Oct 2019 22:51:57 -0600
Received: (from root@localhost)
	by listssympa-test.colorado.edu (8.15.2/8.15.2/MJC-8.0/submit) id x9D4pujl015885;
	Sat, 12 Oct 2019 22:51:56 -0600
Received: from DM5PR03MB3273.namprd03.prod.outlook.com (2603:10b6:a03:54::17) by
  BYAPR03MB4376.namprd03.prod.outlook.com with HTTPS via
  BYAPR02CA0040.NAMPRD02.PROD.OUTLOOK.COM; Wed, 9 Oct 2019 22:04:15 +0000
Received: from BN6PR03CA0057.namprd03.prod.outlook.com (2603:10b6:404:4c::19) by
  DM5PR03MB3273.namprd03.prod.outlook.com (2603:10b6:4:42::32) with Microsoft
  SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
  id 15.20.2347.16; Wed, 9 Oct 2019 17:44:13 +0000

There is some strange server listssympa-test.colorado.edu.
Looks like someone in colorado.edu is testing stuff on production server.

The simplified delivery chain looks like this:

Me -> relay6-d.mail.gandi.net -> vger.kernel.org -> mx.colorado.edu ->
mail.protection.outlook.com -> namprd03.prod.outlook.com ->
listssympa-test.colorado.edu -> spool.mail.gandi.net -> Me again!

Best regards, Ilya Maximets.

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

* Re: [PATCH bpf v2] libbpf: fix passing uninitialized bytes to setsockopt
       [not found] <5da24d48.1c69fb81.a3069.c817SMTPIN_ADDED_BROKEN@mx.google.com>
@ 2019-10-12 23:24 ` Alexei Starovoitov
  2019-10-13 10:17   ` Ilya Maximets
  0 siblings, 1 reply; 5+ messages in thread
From: Alexei Starovoitov @ 2019-10-12 23:24 UTC (permalink / raw)
  To: Ilya Maximets
  Cc: netdev, bpf, linux-kernel, Alexei Starovoitov, Daniel Borkmann,
	David S . Miller, Jonathan Lemon, Andrii Nakryiko

On Wed, Oct 09, 2019 at 06:49:29PM +0200, Ilya Maximets wrote:
> 'struct xdp_umem_reg' has 4 bytes of padding at the end that makes
> valgrind complain about passing uninitialized stack memory to the
> syscall:
> 
>   Syscall param socketcall.setsockopt() points to uninitialised byte(s)
>     at 0x4E7AB7E: setsockopt (in /usr/lib64/libc-2.29.so)
>     by 0x4BDE035: xsk_umem__create@@LIBBPF_0.0.4 (xsk.c:172)
>   Uninitialised value was created by a stack allocation
>     at 0x4BDDEBA: xsk_umem__create@@LIBBPF_0.0.4 (xsk.c:140)
> 
> Padding bytes appeared after introducing of a new 'flags' field.
> memset() is required to clear them.
> 
> Fixes: 10d30e301732 ("libbpf: add flags to umem config")
> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
> ---
> 
> Version 2:
>   * Struct initializer replaced with explicit memset(). [Andrii]
> 
>  tools/lib/bpf/xsk.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/lib/bpf/xsk.c b/tools/lib/bpf/xsk.c
> index a902838f9fcc..9d5348086203 100644
> --- a/tools/lib/bpf/xsk.c
> +++ b/tools/lib/bpf/xsk.c
> @@ -163,6 +163,7 @@ int xsk_umem__create_v0_0_4(struct xsk_umem **umem_ptr, void *umem_area,
>  	umem->umem_area = umem_area;
>  	xsk_set_umem_config(&umem->config, usr_config);
>  
> +	memset(&mr, 0, sizeof(mr));
>  	mr.addr = (uintptr_t)umem_area;
>  	mr.len = size;
>  	mr.chunk_size = umem->config.frame_size;

This was already applied. Why did you resend?


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

end of thread, other threads:[~2019-10-13 10:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-09 16:49 [PATCH bpf v2] libbpf: fix passing uninitialized bytes to setsockopt Ilya Maximets
2019-10-09 16:54 ` Andrii Nakryiko
2019-10-09 22:49 ` Alexei Starovoitov
     [not found] <5da24d48.1c69fb81.a3069.c817SMTPIN_ADDED_BROKEN@mx.google.com>
2019-10-12 23:24 ` Alexei Starovoitov
2019-10-13 10:17   ` Ilya Maximets

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).