<div dir="ltr"><div dir="ltr"></div>Thanks for your review. Please find my response below.<div><br></div><div>Fixed all the comments. I will update the next patchset. </div><div><br></div><div>Thanks,</div><div>Kumar.<br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 13, 2021 at 8:16 AM Samuel Mendoza-Jonas <<a href="mailto:sam@mendozajonas.com" target="_blank">sam@mendozajonas.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, 2021-10-12 at 22:44 +0000, Joel Stanley wrote:<br>
> On Tue, 12 Oct 2021 at 06:23, Kumar Thangavel<br>
> <<a href="mailto:kumarthangavel.hcl@gmail.com" target="_blank">kumarthangavel.hcl@gmail.com</a>> wrote:<br>
> > <br>
> > Update NC-SI command handler (both standard and OEM) to take into<br>
> > account of payload paddings in allocating skb (in case of payload<br>
> > size is not 32-bit aligned).<br>
> > <br>
> > The checksum field follows payload field, without taking payload<br>
> > padding into account can cause checksum being truncated, leading to<br>
> > dropped packets.<br>
> <br>
> Can you help us review this by pointing out where this is described in<br>
> the NCSI spec?<br>
> <br>
> We've been running this code for a number of years now and I wonder<br>
> why this hasn't been a problem so far.<br>
<br>
I'm assuming this is referencing section <a href="http://8.2.2.2" rel="noreferrer" target="_blank">8.2.2.2</a>:<br>
If the payload is present and does not end on a 32-bit boundary, one to<br>
three padding bytes equal to 0x00 shall be present to align the<br>
checksum field to a 32-bit boundary.<br></blockquote><div><br>Kumar : Yes. In the NC-SI spec, section 8.2.2.2 represents a 32-bit boundary.<br>              If it does not end on a 32-bit boundary, padding bytes can be added.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
But I'm also surprised this hasn't caused issues so far if we've been<br>
getting it wrong. Is there an example that reproduces the issue?<br></blockquote><div><br>Kumar :  We have a use case of NIC firmware update in our system which is pldm based and the transport layer is NC-SI based on RBT.<br>               Sending some pldm based commands to NIC. In that, some of the commands failed because of a payload size less than 32.</div><div>               So, Added padding bytes to align the 32-bit boundary and issues got resolved.</div><div>               </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Cheers,<br>
Sam<br>
<br>
> <br>
> Cheers,<br>
> <br>
> Joel<br>
> <br>
> > <br>
> > Signed-off-by: Kumar Thangavel <<a href="mailto:thangavel.k@hcl.com" target="_blank">thangavel.k@hcl.com</a>><br>
> > <br>
> > ---<br>
> >  net/ncsi/ncsi-cmd.c | 21 +++++++++++++++++----<br>
> >  1 file changed, 17 insertions(+), 4 deletions(-)<br>
> > <br>
> > diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c<br>
> > index ba9ae482141b..4625fc935603 100644<br>
> > --- a/net/ncsi/ncsi-cmd.c<br>
> > +++ b/net/ncsi/ncsi-cmd.c<br>
> > @@ -214,11 +214,19 @@ static int ncsi_cmd_handler_oem(struct sk_buff<br>
> > *skb,<br>
> >         struct ncsi_cmd_oem_pkt *cmd;<br>
> >         unsigned int len;<br>
> > <br>
> > +       /* NC-SI spec requires payload to be padded with 0<br>
> > +        * to 32-bit boundary before the checksum field.<br>
> > +        * Ensure the padding bytes are accounted for in<br>
> > +        * skb allocation<br>
> > +        */<br>
> > +<br>
> > +       unsigned short payload = ALIGN(nca->payload, 4);<br>
> > +<br>
> >         len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;<br>
> > -       if (nca->payload < 26)<br>
> > +       if (payload < 26)<br>
> >                 len += 26;<br>
> >         else<br>
> > -               len += nca->payload;<br>
> > +               len += payload;<br>
> > <br>
> >         cmd = skb_put_zero(skb, len);<br>
> >         memcpy(&cmd->mfr_id, nca->data, nca->payload);<br>
> > @@ -272,6 +280,7 @@ static struct ncsi_request<br>
> > *ncsi_alloc_command(struct ncsi_cmd_arg *nca)<br>
> >         struct net_device *dev = nd->dev;<br>
> >         int hlen = LL_RESERVED_SPACE(dev);<br>
> >         int tlen = dev->needed_tailroom;<br>
> > +       int payload;<br>
> >         int len = hlen + tlen;<br>
> >         struct sk_buff *skb;<br>
> >         struct ncsi_request *nr;<br>
> > @@ -281,14 +290,18 @@ static struct ncsi_request<br>
> > *ncsi_alloc_command(struct ncsi_cmd_arg *nca)<br>
> >                 return NULL;<br>
> > <br>
> >         /* NCSI command packet has 16-bytes header, payload, 4 bytes<br>
> > checksum.<br>
> > +        * Payload needs padding so that the checksum field follwoing<br>
> > payload is<br>
> > +        * aligned to 32bit boundary.<br>
> >          * The packet needs padding if its payload is less than 26<br>
> > bytes to<br>
> >          * meet 64 bytes minimal ethernet frame length.<br>
> >          */<br>
> >         len += sizeof(struct ncsi_cmd_pkt_hdr) + 4;<br>
> > -       if (nca->payload < 26)<br>
> > +<br>
> > +       payload = ALIGN(nca->payload, 4);<br>
> > +       if (payload < 26)<br>
> >                 len += 26;<br>
> >         else<br>
> > -               len += nca->payload;<br>
> > +               len += payload;<br>
> > <br>
> >         /* Allocate skb */<br>
> >         skb = alloc_skb(len, GFP_ATOMIC);<br>
> > --<br>
> > 2.17.1<br>
> > <br>
<br>
<br>
</blockquote></div></div></div>