[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <fd74de9a-4deb-4fb7-9461-65c38ff1443c@nvidia.com>
Date: Mon, 6 May 2024 11:50:40 -0700
From: John Hubbard <jhubbard@...dia.com>
To: Willem de Bruijn <willemdebruijn.kernel@...il.com>,
Shuah Khan <shuah@...nel.org>, richardbgobert@...il.com
Cc: "David S . Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Steffen Klassert <steffen.klassert@...unet.com>,
Herbert Xu <herbert@...dor.apana.org.au>, Andreas Färber
<afaerber@...e.de>, Manivannan Sadhasivam
<manivannan.sadhasivam@...aro.org>, Matthieu Baerts <matttbe@...nel.org>,
Mat Martineau <martineau@...nel.org>, Geliang Tang <geliang@...nel.org>,
Pravin B Shelar <pshelar@....org>,
Alexander Mikhalitsyn <alexander@...alicyn.com>,
zhujun2 <zhujun2@...s.chinamobile.com>, Petr Machata <petrm@...dia.com>,
Ido Schimmel <idosch@...dia.com>, Hangbin Liu <liuhangbin@...il.com>,
Nikolay Aleksandrov <razor@...ckwall.org>,
Benjamin Poirier <bpoirier@...dia.com>,
Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
Dmitry Safonov <0x7f454c46@...il.com>, netdev@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, linux-actions@...ts.infradead.org,
mptcp@...ts.linux.dev, dev@...nvswitch.org,
Valentin Obst <kernel@...entinobst.de>, linux-kselftest@...r.kernel.org,
LKML <linux-kernel@...r.kernel.org>, llvm@...ts.linux.dev
Subject: Re: [PATCH 2/2] selftests/net: fix uninitialized variables
On 5/6/24 11:00 AM, Willem de Bruijn wrote:
> John Hubbard wrote:
...
>> diff --git a/tools/testing/selftests/net/gro.c b/tools/testing/selftests/net/gro.c
>> index 353e1e867fbb..0eb61edaad83 100644
>> --- a/tools/testing/selftests/net/gro.c
>> +++ b/tools/testing/selftests/net/gro.c
>> @@ -110,7 +110,8 @@ static void setup_sock_filter(int fd)
>> const int dport_off = tcp_offset + offsetof(struct tcphdr, dest);
>> const int ethproto_off = offsetof(struct ethhdr, h_proto);
>> int optlen = 0;
>> - int ipproto_off, opt_ipproto_off;
>> + int ipproto_off;
>> + int opt_ipproto_off = 0;
>
> This is only intended to be used in the case where the IP proto is not TCP:
>
> BPF_STMT(BPF_LD + BPF_B + BPF_ABS, ipproto_off),
> + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_TCP, 2, 0),
> + BPF_STMT(BPF_LD + BPF_B + BPF_ABS, opt_ipproto_off),
> BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_TCP, 0, 5),
>
> In that case the test tries again at a different offset that accounts
> for optional IPv6 extension headers.
>
> This is indeed buggy, in that it might accidentally accept packets
> that should be dropped.
>
> Initializing to 0 compares against against the first byte of the
> Ethernet header. Which is an external argument to the test. So
> safest is to initialize opt_ipproto_off to ipproto_off and just
> repeat the previous check. Perhaps:
>
> @@ -118,6 +118,7 @@ static void setup_sock_filter(int fd)
> else
> next_off = offsetof(struct ipv6hdr, nexthdr);
> ipproto_off = ETH_HLEN + next_off;
> + opt_ipproto_off = ipproto_off; /* overridden later if may have exthdrs */
OK, thanks for pointing out the right fix, I'll send a v2 that does that.
thanks,
--
John Hubbard
NVIDIA
Powered by blists - more mailing lists