From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kumar Thangavel Date: Mon, 22 Nov 2021 22:08:18 +0530 Subject: [PATCH v8] net/ncsi : Add payload to be 32-bit aligned to fix dropped packets Message-ID: <20211122163818.GA11306@gmail.com> List-Id: To: linux-aspeed@lists.ozlabs.org MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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: fb4ee67529ff ("net/ncsi: Add NCSI OEM command support") Signed-off-by: Kumar Thangavel Acked-by: Samuel Mendoza-Jonas Reviewed-by: Paul Menzel --- v8: - Updated padding_bytes as static const int variable v7: - Updated padding_bytes as const static int variable v6: - Updated type of padding_bytes variable - Updated type of payload - Seperated variable declarations and code v5: - Added Fixes tag - Added const variable for padding_bytes v4: - Used existing macro for max function v3: - Added Macro for MAX - Fixed the missed semicolon v2: - Added NC-SI spec version and section - Removed blank line - corrected spellings v1: - Initial draft --- --- net/ncsi/ncsi-cmd.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c index ba9ae482141b..dda8b76b7798 100644 --- a/net/ncsi/ncsi-cmd.c +++ b/net/ncsi/ncsi-cmd.c @@ -18,6 +18,8 @@ #include "internal.h" #include "ncsi-pkt.h" +static const int padding_bytes = 26; + u32 ncsi_calculate_checksum(unsigned char *data, int len) { u32 checksum = 0; @@ -213,12 +215,17 @@ static int ncsi_cmd_handler_oem(struct sk_buff *skb, { struct ncsi_cmd_oem_pkt *cmd; unsigned int len; + int payload; + /* NC-SI spec DSP_0222_1.2.0, section 8.2.2.2 + * requires payload to be padded with 0 to + * 32-bit boundary before the checksum field. + * Ensure the padding bytes are accounted for in + * skb allocation + */ + payload = ALIGN(nca->payload, 4); len = sizeof(struct ncsi_cmd_pkt_hdr) + 4; - if (nca->payload < 26) - len += 26; - else - len += nca->payload; + len += max(payload, padding_bytes); cmd = skb_put_zero(skb, len); memcpy(&cmd->mfr_id, nca->data, nca->payload); @@ -272,6 +279,7 @@ static struct ncsi_request *ncsi_alloc_command(struct ncsi_cmd_arg *nca) struct net_device *dev = nd->dev; int hlen = LL_RESERVED_SPACE(dev); int tlen = dev->needed_tailroom; + int payload; int len = hlen + tlen; struct sk_buff *skb; struct ncsi_request *nr; @@ -281,14 +289,14 @@ static struct ncsi_request *ncsi_alloc_command(struct ncsi_cmd_arg *nca) return NULL; /* NCSI command packet has 16-bytes header, payload, 4 bytes checksum. + * Payload needs padding so that the checksum field following payload is + * aligned to 32-bit boundary. * The packet needs padding if its payload is less than 26 bytes to * meet 64 bytes minimal ethernet frame length. */ len += sizeof(struct ncsi_cmd_pkt_hdr) + 4; - if (nca->payload < 26) - len += 26; - else - len += nca->payload; + payload = ALIGN(nca->payload, 4); + len += max(payload, padding_bytes); /* Allocate skb */ skb = alloc_skb(len, GFP_ATOMIC); -- 2.17.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DCF7DC433EF for ; Mon, 22 Nov 2021 16:39:12 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HyXzM1WfMz305L for ; Tue, 23 Nov 2021 03:39:11 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=DTqBN1DB; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::429; helo=mail-pf1-x429.google.com; envelope-from=kumarthangavel.hcl@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=DTqBN1DB; dkim-atps=neutral Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4HyXyY5X9lz2xDH; Tue, 23 Nov 2021 03:38:28 +1100 (AEDT) Received: by mail-pf1-x429.google.com with SMTP id n85so16643553pfd.10; Mon, 22 Nov 2021 08:38:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:date:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=3T98/3whduiezAonMuPxJQbLzPy6xKkpapq3TTnGn3A=; b=DTqBN1DBvRcSPQY4uLvY4uTUvu28S0X3a0RZunwFl5MlX7cseoCA7weDmuwhy1XgNp vLUDwHMVXKz8JXjnV/RRqKyJB58qen9Vq2xs0J1sDgMg3xsqOBPMVMSHqoW4BC9SXf2w g0KXDmBvOvyKBrNp1BPfJhhc0Tio6RH1e7BOvXEBNgjSd1LfckCuC1KGKzqH2ez7RvKw STlaEnfykCrPIQzK8tN3gsBwppVDdnMbpDN+oEWoOFWQn/P6h1ajFLlNZQ6c4M0NCk4N BMRVfi8UXGxzvif4XfnpsyPP4i29L0uwcS+OQWl+e1QgisnpwYOi47kI0MtWq37pdFHE 7P4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=3T98/3whduiezAonMuPxJQbLzPy6xKkpapq3TTnGn3A=; b=mBAbcB0kgmtrdIRe+FeChajdMCSmQjmDS0gnAjszjKVybm3WzLJaZ2IOO1Ye3Mx4Cm qZYzRr70yLRGuc1CVzll7quPuOeip6WJgqZ9vKhnHDDDvMuVK7bHlzAh1zszbFMoaPqJ 1M/CBj5fatB5NdOkUHPPYXVg0i00T6m7+AfyWLlyty0/Ws0TdNqGy1kxeydf0whxWjFD ZS3UUzUdskc/SYGGTMTRSPfK3pLSbT3tkWD5Cbf9suTy4h2+4S1lq6eY5AnR+YQbKjbP 1y3re7B1brk6odIkmMiOyXz7JbKzlEMA3zz1SfR6zTHf7c6eRD3Ttlq6Rq+SHk6Q7ssL d1dw== X-Gm-Message-State: AOAM531UMVv+aoDwd/k85az+eJLruY99QoK1+dL8kPWwUPlZG/g+uPPa 8thEiNrek6Wmlqmk5KFCJas= X-Google-Smtp-Source: ABdhPJyV/5UP+Sjzqpc7BJDMQgu9hM1YcX9NW0+NbLC4BW7DL6VNt2cC7gIA0iFiooTxc4fjLcIMpQ== X-Received: by 2002:a63:f808:: with SMTP id n8mr15552616pgh.50.1637599105495; Mon, 22 Nov 2021 08:38:25 -0800 (PST) Received: from gmail.com ([122.178.80.201]) by smtp.gmail.com with ESMTPSA id p19sm10375718pfo.92.2021.11.22.08.38.22 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Nov 2021 08:38:25 -0800 (PST) From: Kumar Thangavel X-Google-Original-From: Kumar Thangavel Date: Mon, 22 Nov 2021 22:08:18 +0530 To: Samuel Mendoza-Jonas , "David S. Miller" , Jakub Kicinski Subject: [PATCH v8] net/ncsi : Add payload to be 32-bit aligned to fix dropped packets Message-ID: <20211122163818.GA11306@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-aspeed@lists.ozlabs.org, netdev@vger.kernel.org, openbmc@lists.ozlabs.org, Amithash Prasad , velumanit@hcl.com, patrickw3@fb.com Errors-To: openbmc-bounces+openbmc=archiver.kernel.org@lists.ozlabs.org Sender: "openbmc" 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: fb4ee67529ff ("net/ncsi: Add NCSI OEM command support") Signed-off-by: Kumar Thangavel Acked-by: Samuel Mendoza-Jonas Reviewed-by: Paul Menzel --- v8: - Updated padding_bytes as static const int variable v7: - Updated padding_bytes as const static int variable v6: - Updated type of padding_bytes variable - Updated type of payload - Seperated variable declarations and code v5: - Added Fixes tag - Added const variable for padding_bytes v4: - Used existing macro for max function v3: - Added Macro for MAX - Fixed the missed semicolon v2: - Added NC-SI spec version and section - Removed blank line - corrected spellings v1: - Initial draft --- --- net/ncsi/ncsi-cmd.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c index ba9ae482141b..dda8b76b7798 100644 --- a/net/ncsi/ncsi-cmd.c +++ b/net/ncsi/ncsi-cmd.c @@ -18,6 +18,8 @@ #include "internal.h" #include "ncsi-pkt.h" +static const int padding_bytes = 26; + u32 ncsi_calculate_checksum(unsigned char *data, int len) { u32 checksum = 0; @@ -213,12 +215,17 @@ static int ncsi_cmd_handler_oem(struct sk_buff *skb, { struct ncsi_cmd_oem_pkt *cmd; unsigned int len; + int payload; + /* NC-SI spec DSP_0222_1.2.0, section 8.2.2.2 + * requires payload to be padded with 0 to + * 32-bit boundary before the checksum field. + * Ensure the padding bytes are accounted for in + * skb allocation + */ + payload = ALIGN(nca->payload, 4); len = sizeof(struct ncsi_cmd_pkt_hdr) + 4; - if (nca->payload < 26) - len += 26; - else - len += nca->payload; + len += max(payload, padding_bytes); cmd = skb_put_zero(skb, len); memcpy(&cmd->mfr_id, nca->data, nca->payload); @@ -272,6 +279,7 @@ static struct ncsi_request *ncsi_alloc_command(struct ncsi_cmd_arg *nca) struct net_device *dev = nd->dev; int hlen = LL_RESERVED_SPACE(dev); int tlen = dev->needed_tailroom; + int payload; int len = hlen + tlen; struct sk_buff *skb; struct ncsi_request *nr; @@ -281,14 +289,14 @@ static struct ncsi_request *ncsi_alloc_command(struct ncsi_cmd_arg *nca) return NULL; /* NCSI command packet has 16-bytes header, payload, 4 bytes checksum. + * Payload needs padding so that the checksum field following payload is + * aligned to 32-bit boundary. * The packet needs padding if its payload is less than 26 bytes to * meet 64 bytes minimal ethernet frame length. */ len += sizeof(struct ncsi_cmd_pkt_hdr) + 4; - if (nca->payload < 26) - len += 26; - else - len += nca->payload; + payload = ALIGN(nca->payload, 4); + len += max(payload, padding_bytes); /* Allocate skb */ skb = alloc_skb(len, GFP_ATOMIC); -- 2.17.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8150AC433F5 for ; Mon, 22 Nov 2021 16:38:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240218AbhKVQle (ORCPT ); Mon, 22 Nov 2021 11:41:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240038AbhKVQld (ORCPT ); Mon, 22 Nov 2021 11:41:33 -0500 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC627C061574 for ; Mon, 22 Nov 2021 08:38:25 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id 8so16670033pfo.4 for ; Mon, 22 Nov 2021 08:38:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:date:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=3T98/3whduiezAonMuPxJQbLzPy6xKkpapq3TTnGn3A=; b=DTqBN1DBvRcSPQY4uLvY4uTUvu28S0X3a0RZunwFl5MlX7cseoCA7weDmuwhy1XgNp vLUDwHMVXKz8JXjnV/RRqKyJB58qen9Vq2xs0J1sDgMg3xsqOBPMVMSHqoW4BC9SXf2w g0KXDmBvOvyKBrNp1BPfJhhc0Tio6RH1e7BOvXEBNgjSd1LfckCuC1KGKzqH2ez7RvKw STlaEnfykCrPIQzK8tN3gsBwppVDdnMbpDN+oEWoOFWQn/P6h1ajFLlNZQ6c4M0NCk4N BMRVfi8UXGxzvif4XfnpsyPP4i29L0uwcS+OQWl+e1QgisnpwYOi47kI0MtWq37pdFHE 7P4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=3T98/3whduiezAonMuPxJQbLzPy6xKkpapq3TTnGn3A=; b=y4vkuYGhs23kWDUonpfYZF3NOf6zGu/pLboXaCT8i0ZSFkbu0ieoFZLn3j4NZaYxPr A46zL/eIOHzwFumo4AUDggBs8fyda7Or5EABuPC+PF2U/t/CTZTQrJI6E0C+gXlv0fPU 8oVM3vzPjOg1MaymnRbBNieexaHNyxTFgn3Rt3N6GMRF4k7jxXLOVfEY05xklwkdPwuQ rxtnTFSw+t00P3v2Q2HtsUMjScMXzOVn+mirS66him7MxWv2rSDUw/LMVm6PXQZ9UvAf O/+xtVi5NsHPp1SEI7PFE1bp9JsVIH09otPsADLhG0Fk8juHGxg8k5V7tBzGRM5KqSqu gTgw== X-Gm-Message-State: AOAM531twToPB2ti+zlTRXru9APXo6gkxeZf7UT/hV5J6C/S4hcgxJeZ NjL/9yr+q9VMh8n8M0nCw8U= X-Google-Smtp-Source: ABdhPJyV/5UP+Sjzqpc7BJDMQgu9hM1YcX9NW0+NbLC4BW7DL6VNt2cC7gIA0iFiooTxc4fjLcIMpQ== X-Received: by 2002:a63:f808:: with SMTP id n8mr15552616pgh.50.1637599105495; Mon, 22 Nov 2021 08:38:25 -0800 (PST) Received: from gmail.com ([122.178.80.201]) by smtp.gmail.com with ESMTPSA id p19sm10375718pfo.92.2021.11.22.08.38.22 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 22 Nov 2021 08:38:25 -0800 (PST) From: Kumar Thangavel X-Google-Original-From: Kumar Thangavel Date: Mon, 22 Nov 2021 22:08:18 +0530 To: Samuel Mendoza-Jonas , "David S. Miller" , Jakub Kicinski Cc: openbmc@lists.ozlabs.org, linux-aspeed@lists.ozlabs.org, netdev@vger.kernel.org, patrickw3@fb.com, Amithash Prasad , sdasari@fb.com, velumanit@hcl.com Subject: [PATCH v8] net/ncsi : Add payload to be 32-bit aligned to fix dropped packets Message-ID: <20211122163818.GA11306@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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: fb4ee67529ff ("net/ncsi: Add NCSI OEM command support") Signed-off-by: Kumar Thangavel Acked-by: Samuel Mendoza-Jonas Reviewed-by: Paul Menzel --- v8: - Updated padding_bytes as static const int variable v7: - Updated padding_bytes as const static int variable v6: - Updated type of padding_bytes variable - Updated type of payload - Seperated variable declarations and code v5: - Added Fixes tag - Added const variable for padding_bytes v4: - Used existing macro for max function v3: - Added Macro for MAX - Fixed the missed semicolon v2: - Added NC-SI spec version and section - Removed blank line - corrected spellings v1: - Initial draft --- --- net/ncsi/ncsi-cmd.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/net/ncsi/ncsi-cmd.c b/net/ncsi/ncsi-cmd.c index ba9ae482141b..dda8b76b7798 100644 --- a/net/ncsi/ncsi-cmd.c +++ b/net/ncsi/ncsi-cmd.c @@ -18,6 +18,8 @@ #include "internal.h" #include "ncsi-pkt.h" +static const int padding_bytes = 26; + u32 ncsi_calculate_checksum(unsigned char *data, int len) { u32 checksum = 0; @@ -213,12 +215,17 @@ static int ncsi_cmd_handler_oem(struct sk_buff *skb, { struct ncsi_cmd_oem_pkt *cmd; unsigned int len; + int payload; + /* NC-SI spec DSP_0222_1.2.0, section 8.2.2.2 + * requires payload to be padded with 0 to + * 32-bit boundary before the checksum field. + * Ensure the padding bytes are accounted for in + * skb allocation + */ + payload = ALIGN(nca->payload, 4); len = sizeof(struct ncsi_cmd_pkt_hdr) + 4; - if (nca->payload < 26) - len += 26; - else - len += nca->payload; + len += max(payload, padding_bytes); cmd = skb_put_zero(skb, len); memcpy(&cmd->mfr_id, nca->data, nca->payload); @@ -272,6 +279,7 @@ static struct ncsi_request *ncsi_alloc_command(struct ncsi_cmd_arg *nca) struct net_device *dev = nd->dev; int hlen = LL_RESERVED_SPACE(dev); int tlen = dev->needed_tailroom; + int payload; int len = hlen + tlen; struct sk_buff *skb; struct ncsi_request *nr; @@ -281,14 +289,14 @@ static struct ncsi_request *ncsi_alloc_command(struct ncsi_cmd_arg *nca) return NULL; /* NCSI command packet has 16-bytes header, payload, 4 bytes checksum. + * Payload needs padding so that the checksum field following payload is + * aligned to 32-bit boundary. * The packet needs padding if its payload is less than 26 bytes to * meet 64 bytes minimal ethernet frame length. */ len += sizeof(struct ncsi_cmd_pkt_hdr) + 4; - if (nca->payload < 26) - len += 26; - else - len += nca->payload; + payload = ALIGN(nca->payload, 4); + len += max(payload, padding_bytes); /* Allocate skb */ skb = alloc_skb(len, GFP_ATOMIC); -- 2.17.1