diff mbox series

[v3,1/2] Fix net.c warning on GCC 11

Message ID dcb4bfa3fe810236475b338f2f6401ec3d1a1c57.1610607906.git.mrezanin@redhat.com (mailing list archive)
State New, archived
Headers show
Series Fixing several GCC 11 warnings | expand

Commit Message

Miroslav Rezanina Jan. 14, 2021, 7:07 a.m. UTC
When building qemu with GCC 11, compiling eth.c file produce following warning:

   warning: array subscript 'struct ip6_ext_hdr_routing[0]' is partly outside array bounds of 'struct ip6_ext_hdr[1]' [-Warray-bounds]

This is caused by retyping from ip6_ext_hdr to ip6_ext_hdr_routing that has more
attributes.

As this usage is expected, suppress the warning temporarily through the function
using this retyping.

Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
---
 net/eth.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Philippe Mathieu-Daudé Jan. 14, 2021, 1:15 p.m. UTC | #1
+Jason +Dmitry

On 1/14/21 8:07 AM, Miroslav Rezanina wrote:
> When building qemu with GCC 11, compiling eth.c file produce following warning:
> 
>    warning: array subscript 'struct ip6_ext_hdr_routing[0]' is partly outside array bounds of 'struct ip6_ext_hdr[1]' [-Warray-bounds]
> 
> This is caused by retyping from ip6_ext_hdr to ip6_ext_hdr_routing that has more
> attributes.
> 
> As this usage is expected, suppress the warning temporarily through the function
> using this retyping.

This is not expected, this is a bug...

> 
> Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
> ---
>  net/eth.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/net/eth.c b/net/eth.c
> index 1e0821c5f8..b9bdd0435c 100644
> --- a/net/eth.c
> +++ b/net/eth.c
> @@ -405,6 +405,8 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags,
>                          struct ip6_ext_hdr *ext_hdr,
>                          struct in6_address *dst_addr)
>  {
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Warray-bounds"
>      struct ip6_ext_hdr_routing *rthdr = (struct ip6_ext_hdr_routing *) ext_hdr;

eth_parse_ipv6_hdr() called iov_to_buf() to fill the 2 bytes of ext_hdr.

>      if ((rthdr->rtype == 2) &&

Here we access after the 2 bytes filled... rthdr->rtype is somewhere on
eth_parse_ipv6_hdr's stack, its content is unknown.

> @@ -426,6 +428,7 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags,
>      }
>  
>      return false;
> +#pragma GCC diagnostic pop

Nacked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Alexander Bulekov Jan. 14, 2021, 2:19 p.m. UTC | #2
On 210114 1415, Philippe Mathieu-Daudé wrote:
> +Jason +Dmitry
> 
> On 1/14/21 8:07 AM, Miroslav Rezanina wrote:
> > When building qemu with GCC 11, compiling eth.c file produce following warning:
> > 
> >    warning: array subscript 'struct ip6_ext_hdr_routing[0]' is partly outside array bounds of 'struct ip6_ext_hdr[1]' [-Warray-bounds]
> > 
> > This is caused by retyping from ip6_ext_hdr to ip6_ext_hdr_routing that has more
> > attributes.
> > 
> > As this usage is expected, suppress the warning temporarily through the function
> > using this retyping.
> 
> This is not expected, this is a bug...
> 

Seems related: https://bugs.launchpad.net/qemu/+bug/1879531
-Alex

> > 
> > Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
> > ---
> >  net/eth.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/net/eth.c b/net/eth.c
> > index 1e0821c5f8..b9bdd0435c 100644
> > --- a/net/eth.c
> > +++ b/net/eth.c
> > @@ -405,6 +405,8 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags,
> >                          struct ip6_ext_hdr *ext_hdr,
> >                          struct in6_address *dst_addr)
> >  {
> > +#pragma GCC diagnostic push
> > +#pragma GCC diagnostic ignored "-Warray-bounds"
> >      struct ip6_ext_hdr_routing *rthdr = (struct ip6_ext_hdr_routing *) ext_hdr;
> 
> eth_parse_ipv6_hdr() called iov_to_buf() to fill the 2 bytes of ext_hdr.
> 
> >      if ((rthdr->rtype == 2) &&
> 
> Here we access after the 2 bytes filled... rthdr->rtype is somewhere on
> eth_parse_ipv6_hdr's stack, its content is unknown.
> 
> > @@ -426,6 +428,7 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags,
> >      }
> >  
> >      return false;
> > +#pragma GCC diagnostic pop
> 
> Nacked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> 
>
Philippe Mathieu-Daudé Jan. 14, 2021, 2:35 p.m. UTC | #3
On 1/14/21 3:19 PM, Alexander Bulekov wrote:
> On 210114 1415, Philippe Mathieu-Daudé wrote:
>> +Jason +Dmitry
>>
>> On 1/14/21 8:07 AM, Miroslav Rezanina wrote:
>>> When building qemu with GCC 11, compiling eth.c file produce following warning:
>>>
>>>    warning: array subscript 'struct ip6_ext_hdr_routing[0]' is partly outside array bounds of 'struct ip6_ext_hdr[1]' [-Warray-bounds]
>>>
>>> This is caused by retyping from ip6_ext_hdr to ip6_ext_hdr_routing that has more
>>> attributes.
>>>
>>> As this usage is expected, suppress the warning temporarily through the function
>>> using this retyping.
>>
>> This is not expected, this is a bug...
>>
> 
> Seems related: https://bugs.launchpad.net/qemu/+bug/1879531

Yes!
Miroslav Rezanina Jan. 14, 2021, 2:36 p.m. UTC | #4
On Thu, Jan 14, 2021 at 02:15:59PM +0100, Philippe Mathieu-Daudé wrote:
> +Jason +Dmitry
> 
> On 1/14/21 8:07 AM, Miroslav Rezanina wrote:
> > When building qemu with GCC 11, compiling eth.c file produce following warning:
> > 
> >    warning: array subscript 'struct ip6_ext_hdr_routing[0]' is partly outside array bounds of 'struct ip6_ext_hdr[1]' [-Warray-bounds]
> > 
> > This is caused by retyping from ip6_ext_hdr to ip6_ext_hdr_routing that has more
> > attributes.
> > 
> > As this usage is expected, suppress the warning temporarily through the function
> > using this retyping.
> 
> This is not expected, this is a bug...

Thanks for confirmation, my initial idea was the same but then I got
impression (do not remember where) that ip6_ext_hdr is not type where
data are initially written to so the overflow here is expected.

Mirek

> 
> > 
> > Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
> > ---
> >  net/eth.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/net/eth.c b/net/eth.c
> > index 1e0821c5f8..b9bdd0435c 100644
> > --- a/net/eth.c
> > +++ b/net/eth.c
> > @@ -405,6 +405,8 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags,
> >                          struct ip6_ext_hdr *ext_hdr,
> >                          struct in6_address *dst_addr)
> >  {
> > +#pragma GCC diagnostic push
> > +#pragma GCC diagnostic ignored "-Warray-bounds"
> >      struct ip6_ext_hdr_routing *rthdr = (struct ip6_ext_hdr_routing *) ext_hdr;
> 
> eth_parse_ipv6_hdr() called iov_to_buf() to fill the 2 bytes of ext_hdr.
> 
> >      if ((rthdr->rtype == 2) &&
> 
> Here we access after the 2 bytes filled... rthdr->rtype is somewhere on
> eth_parse_ipv6_hdr's stack, its content is unknown.
> 
> > @@ -426,6 +428,7 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags,
> >      }
> >  
> >      return false;
> > +#pragma GCC diagnostic pop
> 
> Nacked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> 
>
Miroslav Rezanina Jan. 14, 2021, 2:38 p.m. UTC | #5
On Thu, Jan 14, 2021 at 09:19:20AM -0500, Alexander Bulekov wrote:
> On 210114 1415, Philippe Mathieu-Daudé wrote:
> > +Jason +Dmitry
> > 
> > On 1/14/21 8:07 AM, Miroslav Rezanina wrote:
> > > When building qemu with GCC 11, compiling eth.c file produce following warning:
> > > 
> > >    warning: array subscript 'struct ip6_ext_hdr_routing[0]' is partly outside array bounds of 'struct ip6_ext_hdr[1]' [-Warray-bounds]
> > > 
> > > This is caused by retyping from ip6_ext_hdr to ip6_ext_hdr_routing that has more
> > > attributes.
> > > 
> > > As this usage is expected, suppress the warning temporarily through the function
> > > using this retyping.
> > 
> > This is not expected, this is a bug...
> > 
> 
> Seems related: https://bugs.launchpad.net/qemu/+bug/1879531
> -Alex
>

Yes, it is caused by the issue triggering the warning. Do you know
whether the patch mentioned in bug was already sent?

Mirek
> > > 
> > > Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
> > > ---
> > >  net/eth.c | 3 +++
> > >  1 file changed, 3 insertions(+)
> > > 
> > > diff --git a/net/eth.c b/net/eth.c
> > > index 1e0821c5f8..b9bdd0435c 100644
> > > --- a/net/eth.c
> > > +++ b/net/eth.c
> > > @@ -405,6 +405,8 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags,
> > >                          struct ip6_ext_hdr *ext_hdr,
> > >                          struct in6_address *dst_addr)
> > >  {
> > > +#pragma GCC diagnostic push
> > > +#pragma GCC diagnostic ignored "-Warray-bounds"
> > >      struct ip6_ext_hdr_routing *rthdr = (struct ip6_ext_hdr_routing *) ext_hdr;
> > 
> > eth_parse_ipv6_hdr() called iov_to_buf() to fill the 2 bytes of ext_hdr.
> > 
> > >      if ((rthdr->rtype == 2) &&
> > 
> > Here we access after the 2 bytes filled... rthdr->rtype is somewhere on
> > eth_parse_ipv6_hdr's stack, its content is unknown.
> > 
> > > @@ -426,6 +428,7 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags,
> > >      }
> > >  
> > >      return false;
> > > +#pragma GCC diagnostic pop
> > 
> > Nacked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> > 
> > 
>
Alexander Bulekov Jan. 14, 2021, 2:42 p.m. UTC | #6
On 210114 1538, Miroslav Rezanina wrote:
> On Thu, Jan 14, 2021 at 09:19:20AM -0500, Alexander Bulekov wrote:
> > On 210114 1415, Philippe Mathieu-Daudé wrote:
> > > +Jason +Dmitry
> > > 
> > > On 1/14/21 8:07 AM, Miroslav Rezanina wrote:
> > > > When building qemu with GCC 11, compiling eth.c file produce following warning:
> > > > 
> > > >    warning: array subscript 'struct ip6_ext_hdr_routing[0]' is partly outside array bounds of 'struct ip6_ext_hdr[1]' [-Warray-bounds]
> > > > 
> > > > This is caused by retyping from ip6_ext_hdr to ip6_ext_hdr_routing that has more
> > > > attributes.
> > > > 
> > > > As this usage is expected, suppress the warning temporarily through the function
> > > > using this retyping.
> > > 
> > > This is not expected, this is a bug...
> > > 
> > 
> > Seems related: https://bugs.launchpad.net/qemu/+bug/1879531
> > -Alex
> >
> 
> Yes, it is caused by the issue triggering the warning. Do you know
> whether the patch mentioned in bug was already sent?
> 
> Mirek

I don't think so..
-Alex


> > > > 
> > > > Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
> > > > ---
> > > >  net/eth.c | 3 +++
> > > >  1 file changed, 3 insertions(+)
> > > > 
> > > > diff --git a/net/eth.c b/net/eth.c
> > > > index 1e0821c5f8..b9bdd0435c 100644
> > > > --- a/net/eth.c
> > > > +++ b/net/eth.c
> > > > @@ -405,6 +405,8 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags,
> > > >                          struct ip6_ext_hdr *ext_hdr,
> > > >                          struct in6_address *dst_addr)
> > > >  {
> > > > +#pragma GCC diagnostic push
> > > > +#pragma GCC diagnostic ignored "-Warray-bounds"
> > > >      struct ip6_ext_hdr_routing *rthdr = (struct ip6_ext_hdr_routing *) ext_hdr;
> > > 
> > > eth_parse_ipv6_hdr() called iov_to_buf() to fill the 2 bytes of ext_hdr.
> > > 
> > > >      if ((rthdr->rtype == 2) &&
> > > 
> > > Here we access after the 2 bytes filled... rthdr->rtype is somewhere on
> > > eth_parse_ipv6_hdr's stack, its content is unknown.
> > > 
> > > > @@ -426,6 +428,7 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags,
> > > >      }
> > > >  
> > > >      return false;
> > > > +#pragma GCC diagnostic pop
> > > 
> > > Nacked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> > > 
> > > 
> > 
>
Philippe Mathieu-Daudé Jan. 14, 2021, 3:09 p.m. UTC | #7
On 1/14/21 3:42 PM, Alexander Bulekov wrote:
> On 210114 1538, Miroslav Rezanina wrote:
>> On Thu, Jan 14, 2021 at 09:19:20AM -0500, Alexander Bulekov wrote:
>>> On 210114 1415, Philippe Mathieu-Daudé wrote:
>>>> +Jason +Dmitry
>>>>
>>>> On 1/14/21 8:07 AM, Miroslav Rezanina wrote:
>>>>> When building qemu with GCC 11, compiling eth.c file produce following warning:
>>>>>
>>>>>    warning: array subscript 'struct ip6_ext_hdr_routing[0]' is partly outside array bounds of 'struct ip6_ext_hdr[1]' [-Warray-bounds]
>>>>>
>>>>> This is caused by retyping from ip6_ext_hdr to ip6_ext_hdr_routing that has more
>>>>> attributes.
>>>>>
>>>>> As this usage is expected, suppress the warning temporarily through the function
>>>>> using this retyping.
>>>>
>>>> This is not expected, this is a bug...
>>>>
>>>
>>> Seems related: https://bugs.launchpad.net/qemu/+bug/1879531
>>> -Alex
>>>
>>
>> Yes, it is caused by the issue triggering the warning. Do you know
>> whether the patch mentioned in bug was already sent?
>>
>> Mirek
> 
> I don't think so..

Just sent one:

https://lists.gnu.org/archive/html/qemu-devel/2021-01/msg03205.html
diff mbox series

Patch

diff --git a/net/eth.c b/net/eth.c
index 1e0821c5f8..b9bdd0435c 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -405,6 +405,8 @@  _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags,
                         struct ip6_ext_hdr *ext_hdr,
                         struct in6_address *dst_addr)
 {
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Warray-bounds"
     struct ip6_ext_hdr_routing *rthdr = (struct ip6_ext_hdr_routing *) ext_hdr;
 
     if ((rthdr->rtype == 2) &&
@@ -426,6 +428,7 @@  _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags,
     }
 
     return false;
+#pragma GCC diagnostic pop
 }
 
 static bool