[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YpX9K3x2zoToVy+3@e120937-lin>
Date: Tue, 31 May 2022 12:36:07 +0100
From: Cristian Marussi <cristian.marussi@....com>
To: Robin Murphy <robin.murphy@....com>
Cc: linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
Sudeep Holla <sudeep.holla@....com>
Subject: Re: [PATCH 2/2] firmware: arm_scmi: Fix pointers arithmetic in Base
protocol
On Tue, May 31, 2022 at 12:02:53PM +0100, Robin Murphy wrote:
> On 2022-05-30 12:52, Cristian Marussi wrote:
> > Fix a possible undefined behaviour involving pointer arithmetic in Base
> > protocol scmi_base_implementation_list_get().
> >
> > cppcheck complains with:
> >
> > drivers/firmware/arm_scmi/base.c:190:19: warning: 't->rx.buf' is of type 'void *'. When using void pointers in calculations, the behaviour is undefined. [arithOperationsOnVoidPointer]
> > list = t->rx.buf + sizeof(*num_ret);
>
> Except we use GNU C, where it is well-defined[1]. We use void pointer
> arithmetic *all over* Linux, so there really isn't any valid argument that
> it could be problematic. If this was a common SCMI library intended to be
> portable then the patch would seem more reasonable, but in Linux-specific
> driver code it's just pointless churn.
>
Hi Robin,
thanks for the correction, I'll drop this.
Thanks,
Cristian
> Cheers,
> Robin.
>
> [1] https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html
>
> > Fixes: b6f20ff8bd94 ("firmware: arm_scmi: add common infrastructure and support for base protocol")
> > Cc: Sudeep Holla <sudeep.holla@....com>
> > Signed-off-by: Cristian Marussi <cristian.marussi@....com>
> > ---
> > drivers/firmware/arm_scmi/base.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/firmware/arm_scmi/base.c b/drivers/firmware/arm_scmi/base.c
> > index 20fba7370f4e..6d6214d9e68c 100644
> > --- a/drivers/firmware/arm_scmi/base.c
> > +++ b/drivers/firmware/arm_scmi/base.c
> > @@ -187,7 +187,7 @@ scmi_base_implementation_list_get(const struct scmi_protocol_handle *ph,
> > num_skip = t->tx.buf;
> > num_ret = t->rx.buf;
> > - list = t->rx.buf + sizeof(*num_ret);
> > + list = ((u8 *)t->rx.buf) + sizeof(*num_ret);
> > do {
> > size_t real_list_sz;
Powered by blists - more mailing lists