From: Michael Bommarito <michael.bommarito@gmail.com>
To: Samuel Mendoza-Jonas <sam@mendozajonas.com>,
Paul Fertser <fercerpav@gmail.com>,
netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
linux-kernel@vger.kernel.org,
Michael Bommarito <michael.bommarito@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH net 5/6] net/ncsi: validate AEN packet lengths against the skb
Date: Wed, 22 Apr 2026 12:03:41 -0400 [thread overview]
Message-ID: <20260422160342.1975093-6-michael.bommarito@gmail.com> (raw)
In-Reply-To: <20260422160342.1975093-1-michael.bommarito@gmail.com>
AEN packets are dispatched after only pulling the 16-byte common
header. ncsi_aen_handler() then reads the 20-byte AEN header to
select a per-type handler, and ncsi_validate_aen_pkt() walks
farther into the payload and checksum without first ensuring the
skb contains those bytes.
Pull the AEN-specific header before reading h->type, and pull the
full AEN header plus aligned payload before checksum validation.
That keeps short AEN packets from reading past the skb tail on the
AEN path.
Fixes: 2d283bdd079c ("net/ncsi: Resource management")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-4-7
Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com>
---
net/ncsi/ncsi-aen.c | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/net/ncsi/ncsi-aen.c b/net/ncsi/ncsi-aen.c
index 040a31557201..cd34ef144cf8 100644
--- a/net/ncsi/ncsi-aen.c
+++ b/net/ncsi/ncsi-aen.c
@@ -16,11 +16,19 @@
#include "internal.h"
#include "ncsi-pkt.h"
-static int ncsi_validate_aen_pkt(struct ncsi_aen_pkt_hdr *h,
+static int ncsi_validate_aen_pkt(struct sk_buff *skb,
const unsigned short payload)
{
+ struct ncsi_aen_pkt_hdr *h;
u32 checksum;
__be32 *pchecksum;
+ unsigned int len;
+
+ len = skb_network_offset(skb) + sizeof(*h) + ALIGN(payload, 4);
+ if (!pskb_may_pull(skb, len))
+ return -EINVAL;
+
+ h = (struct ncsi_aen_pkt_hdr *)skb_network_header(skb);
if (h->common.revision != NCSI_PKT_REVISION)
return -EINVAL;
@@ -31,7 +39,7 @@ static int ncsi_validate_aen_pkt(struct ncsi_aen_pkt_hdr *h,
* sender doesn't support checksum according to NCSI
* specification.
*/
- pchecksum = (__be32 *)((void *)(h + 1) + payload - 4);
+ pchecksum = (__be32 *)((void *)(h + 1) + ALIGN(payload, 4) - 4);
if (ntohl(*pchecksum) == 0)
return 0;
@@ -210,12 +218,19 @@ int ncsi_aen_handler(struct ncsi_dev_priv *ndp, struct sk_buff *skb)
{
struct ncsi_aen_pkt_hdr *h;
struct ncsi_aen_handler *nah = NULL;
+ unsigned char type;
int i, ret;
+ if (!pskb_may_pull(skb, skb_network_offset(skb) + sizeof(*h))) {
+ ret = -EINVAL;
+ goto out;
+ }
+
/* Find the handler */
h = (struct ncsi_aen_pkt_hdr *)skb_network_header(skb);
+ type = h->type;
for (i = 0; i < ARRAY_SIZE(ncsi_aen_handlers); i++) {
- if (ncsi_aen_handlers[i].type == h->type) {
+ if (ncsi_aen_handlers[i].type == type) {
nah = &ncsi_aen_handlers[i];
break;
}
@@ -223,24 +238,25 @@ int ncsi_aen_handler(struct ncsi_dev_priv *ndp, struct sk_buff *skb)
if (!nah) {
netdev_warn(ndp->ndev.dev, "Invalid AEN (0x%x) received\n",
- h->type);
+ type);
ret = -ENOENT;
goto out;
}
- ret = ncsi_validate_aen_pkt(h, nah->payload);
+ ret = ncsi_validate_aen_pkt(skb, nah->payload);
if (ret) {
netdev_warn(ndp->ndev.dev,
"NCSI: 'bad' packet ignored for AEN type 0x%x\n",
- h->type);
+ type);
goto out;
}
+ h = (struct ncsi_aen_pkt_hdr *)skb_network_header(skb);
ret = nah->handler(ndp, h);
if (ret)
netdev_err(ndp->ndev.dev,
"NCSI: Handler for AEN type 0x%x returned %d\n",
- h->type, ret);
+ type, ret);
out:
consume_skb(skb);
return ret;
--
2.53.0
next prev parent reply other threads:[~2026-04-22 16:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-22 16:03 [PATCH net 0/6] net/ncsi: harden packet parsing against malformed BMC replies Michael Bommarito
2026-04-22 16:03 ` [PATCH net 1/6] net/ncsi: validate response packet lengths against the skb Michael Bommarito
2026-04-22 16:03 ` [PATCH net 2/6] net/ncsi: bound filter table state to software limits Michael Bommarito
2026-04-22 16:03 ` [PATCH net 3/6] net/ncsi: validate GMCMA address counts against the payload Michael Bommarito
2026-04-22 16:03 ` [PATCH net 4/6] net/ncsi: validate OEM response payloads before parsing Michael Bommarito
2026-04-22 16:03 ` Michael Bommarito [this message]
2026-04-22 16:03 ` [PATCH net 6/6] net/ncsi: validate GP payload lengths " Michael Bommarito
2026-04-22 16:44 ` [PATCH net 0/6] net/ncsi: harden packet parsing against malformed BMC replies Paul Fertser
2026-04-22 17:06 ` Michael Bommarito
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=20260422160342.1975093-6-michael.bommarito@gmail.com \
--to=michael.bommarito@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=fercerpav@gmail.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sam@mendozajonas.com \
--cc=stable@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