🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #1952

Re: [PATCH net] net: sparx5: free the matchall entry on destroy

#1952
From: netdev-bot+sashiko
Date: Sun, 11 Oct 2026 15:19
145 lines
10513 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 1 (1) · Medium: 0 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The fix is incomplete: `struct sparx5_mall_entry` still leaks on
  every error return in `sparx5_tc_matchall_replace()`.

Pre-existing issues:
- [High] `sparx5_tc_matchall_parse_mirror_action()` sets
  `entry->mirror.port = netdev_priv(action->dev)` without checking that…

--

net: sparx5: free the matchall entry on destroy

This patch adds a kfree() of the struct sparx5_mall_entry in
sparx5_tc_matchall_destroy(), after the entry is removed from
sparx5->mall_entries. Without it, every deleted mirror and goto matchall
filter leaked its entry.

> diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c
> index 702257979462d..146d7f28e8f3d 100644
> --- a/drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c
> +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c
> @@ -160,6 +160,7 @@ static int sparx5_tc_matchall_destroy(struct net_device *ndev,
>  	}
>  
>  	list_del(&entry->list);
> +	kfree(entry);
>  
>  	return err;
>  }

[Severity: High]
Does sparx5_tc_matchall_replace() still leak mall_entry on its error
paths?

The entry is allocated before the action is checked or the hardware is
programmed. It is only added to the list at the very end:

sparx5_tc_matchall_replace() {
    ...
	mall_entry = kzalloc_obj(*mall_entry);
	if (!mall_entry)
		return -ENOMEM;
    ...
	list_add_tail(&mall_entry->list, &sparx5->mall_entries);

	return 0;
}

Each return between those two points loses the only pointer to the entry
without freeing it:

- the sparx5_mirror_add() failure in the FLOW_ACTION_MIRRED case, which
  returns err (-EEXIST, -EINVAL, -ENOENT)

- the four vcap_enable_lookups() failure returns in the FLOW_ACTION_GOTO
  case (-EFAULT, -EADDRINUSE, -EADDRNOTAVAIL, and other errors)

- the default case:

	default:
		NL_SET_ERR_MSG_MOD(tmo->common.extack, "Unsupported action");
		return -EOPNOTSUPP;

These entries never reach sparx5->mall_entries. That means
sparx5_tc_matchall_destroy() can never find them, and the new kfree()
does not cover them.

A failed offload is easy to repeat. Examples are a matchall filter with
an action like drop, which hits the default case, a second mirror on a
port that is already mirrored, or a goto to an unsupported chain.
Without skip_sw the software filter is still installed, so this can run
in a loop.

Since this is the same object the commit message says is leaked, could
the fix also free mall_entry on these paths? A shared error label in
sparx5_tc_matchall_replace() would work, or the action could be checked
before the allocation.

[Severity: High]
This is a pre-existing issue and was not introduced by this patch. Is
the mirred target device checked before it is used as a sparx5 port?

sparx5_tc_matchall_parse_mirror_action() {
	entry->mirror.port = netdev_priv(action->dev);
}

Nothing checks that action->dev is a sparx5 port, or even that it is
non-NULL. The driver already has a helper that checks both:

sparx5_netdevice_check() {
	return dev && (dev->netdev_ops == &sparx5_port_netdev_ops);
}

The lan966x driver does a similar check in lan966x_mirror_port_add().

If the mirred target is a foreign netdev such as dummy, veth or a
bridge, sparx5_mirror_add() reads mport->portno from that driver's
private area. It then writes the value to hardware:

sparx5_mirror_add() {
    ...
	if (sport->portno == mport->portno)
		return -EINVAL;
    ...
	sparx5_mirror_monitor_set(sparx5, mirror_idx, mport->portno);
    ...
}

As a result, mirrored traffic could be sent to an arbitrary switch port.

action->dev can also be NULL. In net/sched/act_mirred.c,
tcf_offload_mirred_get_dev() leaves entry->dev NULL when the action has
no device:

tcf_offload_mirred_get_dev() {
	entry->dev = act->ops->get_dev(act, &entry->destructor);
	if (!entry->dev)
		return;
    ...
}

This happens with mirred blockid actions, where tcf_mirred_init() calls
tcf_mirred_replace_dev(m, NULL). It also happens when the target device
has been unregistered. In both cases entry->id is still set to
FLOW_ACTION_MIRRED.

netdev_priv(NULL) then returns a small non-NULL pointer, and the
mport->portno read in sparx5_mirror_add() would oops.

Would calling sparx5_netdevice_check() on action->dev before it is
used fix both cases?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261007-sparx5-matchall-kfree-net-v1-1-c8918685b337%40microchip.com
Technical Details
Message-ID: <179173197837.434549.9373931425008737442@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-344528-linux-kernel-netdev=dewy.ru
References: <20261007-sparx5-matchall-kfree-net-v1-1-c8918685b337@microchip.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-344528-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net: sparx5: free the matchall entry on destroy
Date: Sun, 11 Oct 2026 15:19:38 +0000
Organization: Usenet Network
Message-ID: <179173197837.434549.9373931425008737442@kernel.org>
References: <20261007-sparx5-matchall-kfree-net-v1-1-c8918685b337@microchip.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1565572"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:OkknF8sDDn0l6wy1kvbpfOuAx8s= sha256:9SqdahDe56a1macr8w6AK7p+UORWNpfLvjVYslWFASM=
	sha1:U0xkiCfeb7BIenNsNPjcV2eIGAw= sha256:JApseIVk4dY5cnDYKv/84ByB27zMu4fkHXmWqdqKmqM=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id F2E0D10FA1E; Sun, 11 Oct 2026 18:19:57 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.34
X-Spam-Status: No, score=-1.34 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.241, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id TFS87-fdqjRe;
	Sun, 11 Oct 2026 18:19:54 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-344528-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 92C3810F7EE; Sun, 11 Oct 2026 18:19:49 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by sin.lore.kernel.org (Postfix) with ESMTP id D949724358; Sun, 11 Oct 2026 15:19:41 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 1BF0F28B4E2;
	Sun, 11 Oct 2026 15:19:41 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AL4bhu1L"
X-Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id E38AA405F7;
	Sun, 11 Oct 2026 15:19:39 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1791731981; cv=none; b=WNPkOS9Ix3ODiL5JGkRChUOelb6nVCSTspWOVph9MANKBoICaVvy+TEEx3eqpWO4M6tfdiB7Lhm9wVJ22erEvsfMiCyenr02OwqUCpgzNaG414/oOKGozC/rVoCCJDEEDn0GYL57NgQwBkkBVG4jOkAZELWXsgBf/bKhNPYyXzk=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1791731981; c=relaxed/simple;
	bh=LtCyh9nnBrjqkIbbIwLiupRPV+TFwFkyJ6gs9wxDGhU=;
	h=Subject:From:To:Cc:Date:Message-ID:In-Reply-To:References:
	 Content-Type:MIME-Version; b=IHHohwGy3nqZXKaz34FL4XV3cZnu9Gm4i1+k3X0PQkUgiIu3zVJSS81tDa3DkECGdgKufj5ESdCGRo4NKPAu8fPvVII5yc8t/4N9YwLrq4i/g+OKlqH+Br3WgvKomhvIyno/SoJ37vsafQ6E0XzNvYk+crEYQwzgZPX7vKjRR6Q=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AL4bhu1L; arc=none smtp.client-ip=100.103.45.18
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB3081F0089B;
	Sun, 11 Oct 2026 15:19:38 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1791731979;
	bh=mUCf4nSzDUXsV7PZq3Gz76x5gHcSeE+bODEKH+oBdV0=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=AL4bhu1LyToQDNaPaazv5jrGEIREIo2aa5pzBLdnLCPz1NP1mapNZ/IzhX9iYkBVw
	 MjrKMbTn65jjC6IqVQ1bi0rpFEgHeFXOWoiciouJ3cVF8XMWXSXlp+uajgixtRNRFh
	 3m4dHhHjRXIjcl+JUCRKNY2NkyywRddYkUiOi4g0mv5cqp3xJbUKFGq7WOAuqDo9yY
	 YmwigJbGiZQO8oWGfy6g5CEC8jDz3Q8AzYYeUTZk7mwhJZ+vKxdMGKUtugf7TjJ87O
	 3T7HyDXoEhh1fXPzXWy81oFpCJwUhdWBL6PuhNWhB6U+DVdHyqfpXT6v8YsErfUsde
	 tQT2Xo1ZLsZNw==
X-Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
 kuba@kernel.org, pabeni@redhat.com, Steen.Hegelund@microchip.com,
 UNGLinuxDriver@microchip.com, netdev@vger.kernel.org,
 linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org,
 kees@kernel.org
X-In-Reply-To:  <20261007-sparx5-matchall-kfree-net-v1-1-c8918685b337@microchip.com>
X-sashiko-severity: High
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>