[PATCH 2/5] firmware: arm_scmi: imx: Add i.MX95 CPU Protocol
Cristian Marussi
cristian.marussi at arm.com
Wed Jan 22 04:55:45 PST 2025
On Wed, Jan 22, 2025 at 03:41:41PM +0300, Dan Carpenter wrote:
> On Wed, Jan 22, 2025 at 12:22:18PM +0000, Cristian Marussi wrote:
> > > > +struct scmi_msg_imx_cpu_attributes_out {
> > > > + __le32 attributes;
> > > > +#define CPU_MAX_NAME 16
> > > > + u8 name[CPU_MAX_NAME];
> > >
> > > char is always unsigned in the kernel these days but strings should
> > > still always be char. Same thing in patch 1, there were a couple u8
> > > names.
> > >
> >
Hi Dan,
> > While it is certainly true that char is the way to go for strings and, as
> > such, it is used elsewhere to hold the resource names across all SCMI
> > protocols, in this context it is a field of structure representing
> > exactly the layout of message reply coming from the server, and defined
> > in the SCMI spec as a uint8 array, so, we have generally preferred to
> > used u8 to represent such fixed size array all across the SCMI stack
> > protocols implementation....
> >
> > .... not saying that it is necessarily completelt right, but that is the
> > reason we are guilty :D
>
> Fine. I don't have intense emotions about this.
>
> It does slightly bother me when we assume that the SCMI server NUL
> terminates these when we do things like:
>
> dev_info(ph->dev, "i.MX CPU: name: %s\n", out->name);
>
Hang on...I have not really done a proper review still on this series...
...and this printout above straight out of the message payload seems very
wrong to me too..
> But from a practical perspective we have to trust the SCMI server.
>
....nope we should NEVER trust the server...and instead assume it can
kill us (kernel) all the time :P
...despite what the spec says, we tend to assume tha the server can be
maliciously wrong (or just crappy), so in other protocols where we do used
an u8[] to describe the resource name field in a message, we have also always
(hopefully :D) taken care to use it ONLY after having processed that field like...
strscpy(dom_info->name, attr->name, SCMI_SHORT_NAME_MAX_SIZE);
...to remove any possible bad outcome from a misbehaving SCMI fw server.
Thanks,
Cristian
More information about the linux-arm-kernel
mailing list