mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: Aamir Ahmed <elb12345@hotmail.co.uk>
Cc: Samuel Mendoza-Jonas <sam@mendozajonas.com>,
	Paul Fertser <fercerpav@gmail.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH 2/2] net: ncsi: validate MAC and VLAN counts in Get Parameters response
Date: Thu, 10 Sep 2026 11:14:31 +0100	[thread overview]
Message-ID: <20260910101431.GU40544@horms.kernel.org> (raw)
In-Reply-To: <AS8P251MB0001E99A1865DFEC3C3A16E7C8B32@AS8P251MB0001.EURP251.PROD.OUTLOOK.COM>

On Mon, Sep 07, 2026 at 12:37:52AM +0100, Aamir Ahmed wrote:
> The Get Parameters (GP) response handler iterates over MAC address
> and VLAN filter tables using counts (mac_cnt, vlan_cnt) taken directly
> from the response packet.  These counts are not validated against either
> the actual packet length or the filter arrays allocated by the earlier
> Get Capabilities response handler.
> 
> A malformed GP response can cause:
>  - out-of-bounds read past the packet data when iterating pdata
>  - out-of-bounds write to mac_filter.addrs[] when mac_cnt exceeds
>    the allocated filter size (n_uc + n_mc + n_mixed)
>  - out-of-bounds write to vlan_filter.vids[] when vlan_cnt exceeds
>    n_vids
>  - bitmap corruption via set_bit()/clear_bit() beyond u64 width
> 
> Add three validation checks before the filter table loops:
>  1. Packet is large enough for the claimed MAC and VLAN entries
>  2. mac_cnt does not exceed the allocated MAC filter capacity
>  3. vlan_cnt does not exceed the allocated VLAN filter capacity
> 
> Also check for NULL filter arrays in case Get Capabilities was not
> processed first.
> 
> Fixes: 0b49507fc090 ("net/ncsi: Resource management")
> Signed-off-by: Aamir Ahmed <elb12345@hotmail.co.uk>
> ---
>  net/ncsi/ncsi-rsp.c | 31 +++++++++++++++++++++++++++++--
>  1 file changed, 29 insertions(+), 2 deletions(-)
> 
> diff --git a/net/ncsi/ncsi-rsp.c b/net/ncsi/ncsi-rsp.c
> index 1401528dbd6c..88f3b8db0289 100644
> --- a/net/ncsi/ncsi-rsp.c
> +++ b/net/ncsi/ncsi-rsp.c
> @@ -884,10 +884,38 @@ static int ncsi_rsp_handler_gp(struct ncsi_request *nr)
>  	nc->modes[NCSI_MODE_AEN].enable = 1;
>  	nc->modes[NCSI_MODE_AEN].data[0] = ntohl(rsp->aen_mode);
>  
> +	/* Validate the response carries enough data for the MAC and VLAN
> +	 * tables it claims to contain.  The variable-length area begins
> +	 * at offset 48 (right after the fixed Get Parameters fields).
> +	 */
> +	if (nr->rsp->len < 48 + (unsigned int)rsp->mac_cnt * ETH_ALEN +
> +			    (unsigned int)rsp->vlan_cnt * sizeof(__be16)) {
> +		netdev_warn(ndp->ndev.dev,
> +			    "NCSI: GP response too short for %u MACs + %u VLANs\n",
> +			    rsp->mac_cnt, rsp->vlan_cnt);
> +		return -EINVAL;
> +	}

My concern with this patch is the same as for patch 1/2.

I'm not sure that there is any guarantee that nr->rsp is a linear skb
and if not then checking len is insufficient and I think the check
should be implemented using pskb_may_pull.

Not that any pointers referring to skb data may be invalidated
by that call, so, f.e. rsp should probably be set after the
call to pskb_may_pull().

...


As noted collectively by Greg and Paolo elsewhere:
1. Please include an Assisted-by tag
2. Please keep the number of patches in-flight to 15 or less

-- 
pw-bot: changes-requested

      reply	other threads:[~2026-09-10 10:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260906233752.87773-1-elb12345@hotmail.co.uk>
2026-09-06 23:37 ` Aamir Ahmed
2026-09-10 10:14   ` Simon Horman [this message]

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=20260910101431.GU40544@horms.kernel.org \
    --to=horms@kernel.org \
    --cc=elb12345@hotmail.co.uk \
    --cc=fercerpav@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®