* [PATCH] hw/net/rocker: Avoid undefined shifts with more than 31 ports
@ 2022-07-29 15:59 Peter Maydell
2022-08-04 10:45 ` Peter Maydell
0 siblings, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2022-07-29 15:59 UTC (permalink / raw)
To: qemu-devel; +Cc: Jiri Pirko, Jason Wang
In rocker_port_phys_link_status() and rocker_port_phys_enable_read()
we construct a 64-bit value with one bit per front-panel port.
However we accidentally do the shift as 32-bit arithmetic, which
means that if there are more than 31 front-panel ports this is
undefined behaviour.
Fix the problem by ensuring we use 64-bit arithmetic for the whole
calculation. (We won't ever shift off the 64-bit value because
ROCKER_FP_PORTS_MAX is 62.)
Resolves: Coverity CID 1487121, 1487160
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/net/rocker/rocker.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c
index 31f2340fb91..d8f3f16fe87 100644
--- a/hw/net/rocker/rocker.c
+++ b/hw/net/rocker/rocker.c
@@ -1010,7 +1010,7 @@ static uint64_t rocker_port_phys_link_status(Rocker *r)
FpPort *port = r->fp_port[i];
if (fp_port_get_link_up(port)) {
- status |= 1 << (i + 1);
+ status |= 1ULL << (i + 1);
}
}
return status;
@@ -1025,7 +1025,7 @@ static uint64_t rocker_port_phys_enable_read(Rocker *r)
FpPort *port = r->fp_port[i];
if (fp_port_enabled(port)) {
- ret |= 1 << (i + 1);
+ ret |= 1ULL << (i + 1);
}
}
return ret;
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hw/net/rocker: Avoid undefined shifts with more than 31 ports
2022-07-29 15:59 [PATCH] hw/net/rocker: Avoid undefined shifts with more than 31 ports Peter Maydell
@ 2022-08-04 10:45 ` Peter Maydell
2022-08-04 15:27 ` Richard Henderson
0 siblings, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2022-08-04 10:45 UTC (permalink / raw)
To: qemu-devel; +Cc: Jiri Pirko, Jason Wang
Ping?
thanks
-- PMM
On Fri, 29 Jul 2022 at 16:59, Peter Maydell <peter.maydell@linaro.org> wrote:
>
> In rocker_port_phys_link_status() and rocker_port_phys_enable_read()
> we construct a 64-bit value with one bit per front-panel port.
> However we accidentally do the shift as 32-bit arithmetic, which
> means that if there are more than 31 front-panel ports this is
> undefined behaviour.
>
> Fix the problem by ensuring we use 64-bit arithmetic for the whole
> calculation. (We won't ever shift off the 64-bit value because
> ROCKER_FP_PORTS_MAX is 62.)
>
> Resolves: Coverity CID 1487121, 1487160
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> hw/net/rocker/rocker.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c
> index 31f2340fb91..d8f3f16fe87 100644
> --- a/hw/net/rocker/rocker.c
> +++ b/hw/net/rocker/rocker.c
> @@ -1010,7 +1010,7 @@ static uint64_t rocker_port_phys_link_status(Rocker *r)
> FpPort *port = r->fp_port[i];
>
> if (fp_port_get_link_up(port)) {
> - status |= 1 << (i + 1);
> + status |= 1ULL << (i + 1);
> }
> }
> return status;
> @@ -1025,7 +1025,7 @@ static uint64_t rocker_port_phys_enable_read(Rocker *r)
> FpPort *port = r->fp_port[i];
>
> if (fp_port_enabled(port)) {
> - ret |= 1 << (i + 1);
> + ret |= 1ULL << (i + 1);
> }
> }
> return ret;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] hw/net/rocker: Avoid undefined shifts with more than 31 ports
2022-08-04 10:45 ` Peter Maydell
@ 2022-08-04 15:27 ` Richard Henderson
2022-08-05 3:43 ` Jason Wang
0 siblings, 1 reply; 4+ messages in thread
From: Richard Henderson @ 2022-08-04 15:27 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: Jiri Pirko, Jason Wang
On 8/4/22 03:45, Peter Maydell wrote:
> Ping?
>
> thanks
> -- PMM
>
> On Fri, 29 Jul 2022 at 16:59, Peter Maydell <peter.maydell@linaro.org> wrote:
>>
>> In rocker_port_phys_link_status() and rocker_port_phys_enable_read()
>> we construct a 64-bit value with one bit per front-panel port.
>> However we accidentally do the shift as 32-bit arithmetic, which
>> means that if there are more than 31 front-panel ports this is
>> undefined behaviour.
>>
>> Fix the problem by ensuring we use 64-bit arithmetic for the whole
>> calculation. (We won't ever shift off the 64-bit value because
>> ROCKER_FP_PORTS_MAX is 62.)
>>
>> Resolves: Coverity CID 1487121, 1487160
>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
>> ---
>> hw/net/rocker/rocker.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c
>> index 31f2340fb91..d8f3f16fe87 100644
>> --- a/hw/net/rocker/rocker.c
>> +++ b/hw/net/rocker/rocker.c
>> @@ -1010,7 +1010,7 @@ static uint64_t rocker_port_phys_link_status(Rocker *r)
>> FpPort *port = r->fp_port[i];
>>
>> if (fp_port_get_link_up(port)) {
>> - status |= 1 << (i + 1);
>> + status |= 1ULL << (i + 1);
>> }
>> }
>> return status;
>> @@ -1025,7 +1025,7 @@ static uint64_t rocker_port_phys_enable_read(Rocker *r)
>> FpPort *port = r->fp_port[i];
>>
>> if (fp_port_enabled(port)) {
>> - ret |= 1 << (i + 1);
>> + ret |= 1ULL << (i + 1);
>> }
>> }
>> return ret;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] hw/net/rocker: Avoid undefined shifts with more than 31 ports
2022-08-04 15:27 ` Richard Henderson
@ 2022-08-05 3:43 ` Jason Wang
0 siblings, 0 replies; 4+ messages in thread
From: Jason Wang @ 2022-08-05 3:43 UTC (permalink / raw)
To: Richard Henderson; +Cc: Peter Maydell, qemu-devel, Jiri Pirko
On Thu, Aug 4, 2022 at 11:27 PM Richard Henderson
<richard.henderson@linaro.org> wrote:
>
> On 8/4/22 03:45, Peter Maydell wrote:
> > Ping?
> >
> > thanks
> > -- PMM
> >
> > On Fri, 29 Jul 2022 at 16:59, Peter Maydell <peter.maydell@linaro.org> wrote:
> >>
> >> In rocker_port_phys_link_status() and rocker_port_phys_enable_read()
> >> we construct a 64-bit value with one bit per front-panel port.
> >> However we accidentally do the shift as 32-bit arithmetic, which
> >> means that if there are more than 31 front-panel ports this is
> >> undefined behaviour.
> >>
> >> Fix the problem by ensuring we use 64-bit arithmetic for the whole
> >> calculation. (We won't ever shift off the 64-bit value because
> >> ROCKER_FP_PORTS_MAX is 62.)
> >>
> >> Resolves: Coverity CID 1487121, 1487160
> >> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Queued.
Thanks
>
>
> r~
>
> >> ---
> >> hw/net/rocker/rocker.c | 4 ++--
> >> 1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c
> >> index 31f2340fb91..d8f3f16fe87 100644
> >> --- a/hw/net/rocker/rocker.c
> >> +++ b/hw/net/rocker/rocker.c
> >> @@ -1010,7 +1010,7 @@ static uint64_t rocker_port_phys_link_status(Rocker *r)
> >> FpPort *port = r->fp_port[i];
> >>
> >> if (fp_port_get_link_up(port)) {
> >> - status |= 1 << (i + 1);
> >> + status |= 1ULL << (i + 1);
> >> }
> >> }
> >> return status;
> >> @@ -1025,7 +1025,7 @@ static uint64_t rocker_port_phys_enable_read(Rocker *r)
> >> FpPort *port = r->fp_port[i];
> >>
> >> if (fp_port_enabled(port)) {
> >> - ret |= 1 << (i + 1);
> >> + ret |= 1ULL << (i + 1);
> >> }
> >> }
> >> return ret;
> >
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-08-05 3:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-29 15:59 [PATCH] hw/net/rocker: Avoid undefined shifts with more than 31 ports Peter Maydell
2022-08-04 10:45 ` Peter Maydell
2022-08-04 15:27 ` Richard Henderson
2022-08-05 3:43 ` Jason Wang
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.