Skip to content

Commit ac13285

Browse files
Kumar Thangaveldavem330
authored andcommitted
net/ncsi : Add payload to be 32-bit aligned to fix dropped packets
Update NC-SI command handler (both standard and OEM) to take into account of payload paddings in allocating skb (in case of payload size is not 32-bit aligned). The checksum field follows payload field, without taking payload padding into account can cause checksum being truncated, leading to dropped packets. Fixes: fb4ee67 ("net/ncsi: Add NCSI OEM command support") Signed-off-by: Kumar Thangavel <[email protected]> Acked-by: Samuel Mendoza-Jonas <[email protected]> Reviewed-by: Paul Menzel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 619ca0d commit ac13285

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

net/ncsi/ncsi-cmd.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "internal.h"
1919
#include "ncsi-pkt.h"
2020

21+
static const int padding_bytes = 26;
22+
2123
u32 ncsi_calculate_checksum(unsigned char *data, int len)
2224
{
2325
u32 checksum = 0;
@@ -213,12 +215,17 @@ static int ncsi_cmd_handler_oem(struct sk_buff *skb,
213215
{
214216
struct ncsi_cmd_oem_pkt *cmd;
215217
unsigned int len;
218+
int payload;
219+
/* NC-SI spec DSP_0222_1.2.0, section 8.2.2.2
220+
* requires payload to be padded with 0 to
221+
* 32-bit boundary before the checksum field.
222+
* Ensure the padding bytes are accounted for in
223+
* skb allocation
224+
*/
216225

226+
payload = ALIGN(nca->payload, 4);
217227
len = sizeof(struct ncsi_cmd_pkt_hdr) + 4;
218-
if (nca->payload < 26)
219-
len += 26;
220-
else
221-
len += nca->payload;
228+
len += max(payload, padding_bytes);
222229

223230
cmd = skb_put_zero(skb, len);
224231
memcpy(&cmd->mfr_id, nca->data, nca->payload);
@@ -272,6 +279,7 @@ static struct ncsi_request *ncsi_alloc_command(struct ncsi_cmd_arg *nca)
272279
struct net_device *dev = nd->dev;
273280
int hlen = LL_RESERVED_SPACE(dev);
274281
int tlen = dev->needed_tailroom;
282+
int payload;
275283
int len = hlen + tlen;
276284
struct sk_buff *skb;
277285
struct ncsi_request *nr;
@@ -281,14 +289,14 @@ static struct ncsi_request *ncsi_alloc_command(struct ncsi_cmd_arg *nca)
281289
return NULL;
282290

283291
/* NCSI command packet has 16-bytes header, payload, 4 bytes checksum.
292+
* Payload needs padding so that the checksum field following payload is
293+
* aligned to 32-bit boundary.
284294
* The packet needs padding if its payload is less than 26 bytes to
285295
* meet 64 bytes minimal ethernet frame length.
286296
*/
287297
len += sizeof(struct ncsi_cmd_pkt_hdr) + 4;
288-
if (nca->payload < 26)
289-
len += 26;
290-
else
291-
len += nca->payload;
298+
payload = ALIGN(nca->payload, 4);
299+
len += max(payload, padding_bytes);
292300

293301
/* Allocate skb */
294302
skb = alloc_skb(len, GFP_ATOMIC);

0 commit comments

Comments
 (0)