* [PATCH] hw/scsi/mptsas: Avoid silent integer truncation in MPI_FUNC_IOC_INIT
@ 2025-08-11 9:55 Philippe Mathieu-Daudé
2025-09-01 11:43 ` Philippe Mathieu-Daudé
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-08-11 9:55 UTC (permalink / raw)
To: qemu-devel
Cc: Don Slutz, Fam Zheng, Peter Maydell, Paolo Bonzini,
Philippe Mathieu-Daudé
For the MaxDevices 8-bit field of the request / response structures
of the MPI_FUNCTION_IOC_INIT command, the 0x00 value means "max 256
devices". This is not a problem because when max_devices=256, its
value (0x100), being casted to a uint8_t, is truncated to 0x00.
However Coverity complains for an "Overflowed constant". Fix by
re-using the request fields in the response, since they are not
modified and use the same types.
Fix: Coverity 1547736 (Overflowed constant)
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/scsi/mptsas.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/hw/scsi/mptsas.c b/hw/scsi/mptsas.c
index 1ebe0b82a79..4ada35b7ec8 100644
--- a/hw/scsi/mptsas.c
+++ b/hw/scsi/mptsas.c
@@ -579,11 +579,11 @@ static void mptsas_process_ioc_init(MPTSASState *s, MPIMsgIOCInit *req)
}
memset(&reply, 0, sizeof(reply));
- reply.WhoInit = s->who_init;
+ reply.WhoInit = req->WhoInit;
reply.MsgLength = sizeof(reply) / 4;
reply.Function = req->Function;
- reply.MaxDevices = s->max_devices;
- reply.MaxBuses = s->max_buses;
+ reply.MaxDevices = req->MaxDevices;
+ reply.MaxBuses = req->MaxBuses;
reply.MsgContext = req->MsgContext;
mptsas_fix_ioc_init_reply_endianness(&reply);
--
2.49.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hw/scsi/mptsas: Avoid silent integer truncation in MPI_FUNC_IOC_INIT
2025-08-11 9:55 [PATCH] hw/scsi/mptsas: Avoid silent integer truncation in MPI_FUNC_IOC_INIT Philippe Mathieu-Daudé
@ 2025-09-01 11:43 ` Philippe Mathieu-Daudé
2025-09-01 12:11 ` Peter Maydell
2025-09-01 20:59 ` Philippe Mathieu-Daudé
2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-09-01 11:43 UTC (permalink / raw)
To: qemu-devel
Cc: Don Slutz, Fam Zheng, Peter Maydell, Paolo Bonzini,
Michael Tokarev
ping?
On 11/8/25 11:55, Philippe Mathieu-Daudé wrote:
> For the MaxDevices 8-bit field of the request / response structures
> of the MPI_FUNCTION_IOC_INIT command, the 0x00 value means "max 256
> devices". This is not a problem because when max_devices=256, its
> value (0x100), being casted to a uint8_t, is truncated to 0x00.
> However Coverity complains for an "Overflowed constant". Fix by
> re-using the request fields in the response, since they are not
> modified and use the same types.
>
> Fix: Coverity 1547736 (Overflowed constant)
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> hw/scsi/mptsas.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/hw/scsi/mptsas.c b/hw/scsi/mptsas.c
> index 1ebe0b82a79..4ada35b7ec8 100644
> --- a/hw/scsi/mptsas.c
> +++ b/hw/scsi/mptsas.c
> @@ -579,11 +579,11 @@ static void mptsas_process_ioc_init(MPTSASState *s, MPIMsgIOCInit *req)
> }
>
> memset(&reply, 0, sizeof(reply));
> - reply.WhoInit = s->who_init;
> + reply.WhoInit = req->WhoInit;
> reply.MsgLength = sizeof(reply) / 4;
> reply.Function = req->Function;
> - reply.MaxDevices = s->max_devices;
> - reply.MaxBuses = s->max_buses;
> + reply.MaxDevices = req->MaxDevices;
> + reply.MaxBuses = req->MaxBuses;
> reply.MsgContext = req->MsgContext;
>
> mptsas_fix_ioc_init_reply_endianness(&reply);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] hw/scsi/mptsas: Avoid silent integer truncation in MPI_FUNC_IOC_INIT
2025-08-11 9:55 [PATCH] hw/scsi/mptsas: Avoid silent integer truncation in MPI_FUNC_IOC_INIT Philippe Mathieu-Daudé
2025-09-01 11:43 ` Philippe Mathieu-Daudé
@ 2025-09-01 12:11 ` Peter Maydell
2025-09-01 20:59 ` Philippe Mathieu-Daudé
2 siblings, 0 replies; 4+ messages in thread
From: Peter Maydell @ 2025-09-01 12:11 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: qemu-devel, Don Slutz, Fam Zheng, Paolo Bonzini
On Mon, 11 Aug 2025 at 10:55, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> For the MaxDevices 8-bit field of the request / response structures
> of the MPI_FUNCTION_IOC_INIT command, the 0x00 value means "max 256
> devices". This is not a problem because when max_devices=256, its
> value (0x100), being casted to a uint8_t, is truncated to 0x00.
> However Coverity complains for an "Overflowed constant". Fix by
> re-using the request fields in the response, since they are not
> modified and use the same types.
>
> Fix: Coverity 1547736 (Overflowed constant)
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> hw/scsi/mptsas.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/hw/scsi/mptsas.c b/hw/scsi/mptsas.c
> index 1ebe0b82a79..4ada35b7ec8 100644
> --- a/hw/scsi/mptsas.c
> +++ b/hw/scsi/mptsas.c
> @@ -579,11 +579,11 @@ static void mptsas_process_ioc_init(MPTSASState *s, MPIMsgIOCInit *req)
> }
>
> memset(&reply, 0, sizeof(reply));
> - reply.WhoInit = s->who_init;
> + reply.WhoInit = req->WhoInit;
> reply.MsgLength = sizeof(reply) / 4;
> reply.Function = req->Function;
> - reply.MaxDevices = s->max_devices;
> - reply.MaxBuses = s->max_buses;
> + reply.MaxDevices = req->MaxDevices;
> + reply.MaxBuses = req->MaxBuses;
> reply.MsgContext = req->MsgContext;
>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] hw/scsi/mptsas: Avoid silent integer truncation in MPI_FUNC_IOC_INIT
2025-08-11 9:55 [PATCH] hw/scsi/mptsas: Avoid silent integer truncation in MPI_FUNC_IOC_INIT Philippe Mathieu-Daudé
2025-09-01 11:43 ` Philippe Mathieu-Daudé
2025-09-01 12:11 ` Peter Maydell
@ 2025-09-01 20:59 ` Philippe Mathieu-Daudé
2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-09-01 20:59 UTC (permalink / raw)
To: qemu-devel; +Cc: Don Slutz, Fam Zheng, Peter Maydell, Paolo Bonzini
On 11/8/25 11:55, Philippe Mathieu-Daudé wrote:
> For the MaxDevices 8-bit field of the request / response structures
> of the MPI_FUNCTION_IOC_INIT command, the 0x00 value means "max 256
> devices". This is not a problem because when max_devices=256, its
> value (0x100), being casted to a uint8_t, is truncated to 0x00.
> However Coverity complains for an "Overflowed constant". Fix by
> re-using the request fields in the response, since they are not
> modified and use the same types.
>
> Fix: Coverity 1547736 (Overflowed constant)
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> hw/scsi/mptsas.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
Patch queued, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-01 21:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11 9:55 [PATCH] hw/scsi/mptsas: Avoid silent integer truncation in MPI_FUNC_IOC_INIT Philippe Mathieu-Daudé
2025-09-01 11:43 ` Philippe Mathieu-Daudé
2025-09-01 12:11 ` Peter Maydell
2025-09-01 20:59 ` Philippe Mathieu-Daudé
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).