From: Jakub Kicinski <jakub.kicinski@netronome.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, Jakub Kicinski <jakub.kicinski@netronome.com>
Subject: [PATCHv3 net 4/5] nfp: fix RX buffer length validation
Date: Thu, 18 Feb 2016 20:38:12 +0000 [thread overview]
Message-ID: <1455827893-26366-5-git-send-email-jakub.kicinski@netronome.com> (raw)
In-Reply-To: <1455827893-26366-1-git-send-email-jakub.kicinski@netronome.com>
Meaning of data_len and meta_len RX WB descriptor fields depend
slightly on whether rx_offset is dynamic or not. For dynamic
offsets data_len includes meta_len. This makes the code harder
to follow, in fact our RX buffer length check is incorrect -
we are comparing allocation length to data_len while we should
also account for meta_len.
Let's adjust the values of data_len and meta_len to their natural
meaning and simplify the logic.
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Rolf Neugebauer <rolf.neugebauer@netronome.com>
---
drivers/net/ethernet/netronome/nfp/nfp_net_common.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
index 553ae64e2f7f..070645f9bc21 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
@@ -1259,22 +1259,19 @@ static int nfp_net_rx(struct nfp_net_rx_ring *rx_ring, int budget)
meta_len = rxd->rxd.meta_len_dd & PCIE_DESC_RX_META_LEN_MASK;
data_len = le16_to_cpu(rxd->rxd.data_len);
+ /* For dynamic offset data_len includes meta_len, adjust */
+ if (nn->rx_offset == NFP_NET_CFG_RX_OFFSET_DYNAMIC)
+ data_len -= meta_len;
+ else
+ meta_len = nn->rx_offset;
- if (WARN_ON_ONCE(data_len > nn->fl_bufsz)) {
+ if (WARN_ON_ONCE(meta_len + data_len > nn->fl_bufsz)) {
dev_kfree_skb_any(skb);
continue;
}
- if (nn->rx_offset == NFP_NET_CFG_RX_OFFSET_DYNAMIC) {
- /* The packet data starts after the metadata */
- skb_reserve(skb, meta_len);
- } else {
- /* The packet data starts at a fixed offset */
- skb_reserve(skb, nn->rx_offset);
- }
-
- /* Adjust the SKB for the dynamic meta data pre-pended */
- skb_put(skb, data_len - meta_len);
+ skb_reserve(skb, meta_len);
+ skb_put(skb, data_len);
nfp_net_set_hash(nn->netdev, skb, rxd);
--
1.9.1
next prev parent reply other threads:[~2016-02-18 20:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-18 20:38 [PATCHv3 net 0/5] nfp: MTU fixes for net Jakub Kicinski
2016-02-18 20:38 ` [PATCHv3 net 1/5] nfp: return error if MTU change fails Jakub Kicinski
2016-02-18 20:38 ` [PATCHv3 net 2/5] nfp: free buffers before changing MTU Jakub Kicinski
2016-02-18 20:38 ` [PATCHv3 net 3/5] nfp: correct RX buffer length calculation Jakub Kicinski
2016-02-18 20:38 ` Jakub Kicinski [this message]
2016-02-18 20:38 ` [PATCHv3 net 5/5] nfp: don't trust netif_running() in debug code Jakub Kicinski
2016-02-20 5:01 ` David Miller
2016-02-20 10:51 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1455827893-26366-5-git-send-email-jakub.kicinski@netronome.com \
--to=jakub.kicinski@netronome.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).