Article View: linux.kernel.netdev
Article #12694[PATCH v2] net: mscc: ocelot: release the mirror reference on policer failure
From: Wentao Liang
Date: Sun, 08 Nov 2026 11:01
Date: Sun, 08 Nov 2026 11:01
62 lines
10447 bytes
10447 bytes
ocelot_vcap_filter_add_aux_resources() takes a reference on the mirror
before setting up the policer. If ocelot_vcap_policer_add() fails, the
function returns without dropping that reference. The filter is not
added to the block, so the deletion path never releases it.
Release the mirror reference on this error path. Use a goto-based
unwind ladder so that a failure added to this function later does not
have to repeat the cleanup.
The issue was found by a static analysis tool; the candidate was then
audited and the fix was prepared with the help of DeepSeek and
GPT-6.1 Sol. It was identified by code inspection only and was not
triggered; this patch was compile-tested, not tested on hardware.
Fixes: f2a0e216bee5 ("net: mscc: ocelot: offload per-flow mirroring using tc-mirred and VCAP IS2")
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
Changes in v2:
- Sorry for the very late follow-up to the review.
- Use a goto-based unwind ladder, as suggested by Simon Horman,
instead of an inline ocelot_mirror_put() call.
- Describe how the issue was found and how it was tested, as
requested by netdev-bot.
- Drop Cc: stable@vger.kernel.org: the leak is only reachable when
the policer allocation fails.
drivers/net/ethernet/mscc/ocelot_vcap.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/mscc/ocelot_vcap.c b/drivers/net/ethernet/mscc/ocelot_vcap.c
index 25e533e91d71..ce4a3da38c58 100644
--- a/drivers/net/ethernet/mscc/ocelot_vcap.c
+++ b/drivers/net/ethernet/mscc/ocelot_vcap.c
@@ -957,7 +957,7 @@ ocelot_vcap_filter_add_aux_resources(struct ocelot *ocelot,
struct ocelot_vcap_filter *filter,
struct netlink_ext_ack *extack)
{
- struct ocelot_mirror *m;
+ struct ocelot_mirror *m = NULL;
int ret;
if (filter->block_id == VCAP_IS2 && filter->action.mirror_ena) {
@@ -971,10 +971,15 @@ ocelot_vcap_filter_add_aux_resources(struct ocelot *ocelot,
ret = ocelot_vcap_policer_add(ocelot, filter->action.pol_ix,
&filter->action.pol);
if (ret)
- return ret;
+ goto err_mirror_put;
}
return 0;
+
+err_mirror_put:
+ if (m)
+ ocelot_mirror_put(ocelot);
+ return ret;
}
static void
--
2.34.1
Technical Details
Message-ID:
<20261108110138.315003-1-vulab@iscas.ac.cn>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358679-linux-kernel-netdev=dewy.ruShow 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-358679-linux-kernel-netdev=dewy.ru From: vulab@iscas.ac.cn (Wentao Liang) Newsgroups: linux.kernel.netdev Subject: [PATCH v2] net: mscc: ocelot: release the mirror reference on policer failure Date: Sun, 08 Nov 2026 11:01:38 +0000 Organization: Usenet Network Message-ID: <20261108110138.315003-1-vulab@iscas.ac.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="109965"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:h0uDAZlj8SL2nRlxRaOEqTGf1K4= sha256:NGTkaxldSKpK6RYbc7kUZN3AVL+gXW14WEtr6GzYS4s= sha1:pd8dBHwOxkJUIhv16k5mIG6LBng= sha256:H0GuoAitamf2+/n7bfe9x0egWbGt6spXVMULFDnL1hU= 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 A08A6113551; Sun, 8 Nov 2026 14:01:13 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.051 X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31 tests=[HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no 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 QBz_5K9x4GSo; Sun, 8 Nov 2026 14:01:09 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-358679-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=iscas.ac.cn X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id 8B00311353C; Sun, 8 Nov 2026 14:01:02 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 7A064609AAD; Sun, 8 Nov 2026 11:00:46 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1794135641; b=O9GSNedjwf+8ZHowc4IOFWODdLIdtPUAwiGikeK57jPkL64zwLDOKxMzCLWEQXsezKlO t2/mvT1TfxBcQGcF+xZ7jWk07Iel/i0YVF+U/o5HzHugPi5RkqNjHdUOG3qM7nAJ9aimu I25jRLh3pEBhm+q4d0kzKCNlKUa2HdMxYl90rSu7yDbkLkpgsC8lgxuCllJnm8nBl39t4 nGGlFyXaBE5OIB4lfMo0NNOB1EEYkfCiPJ4TfwfxqO8LXR+C2lXvDBSxdngWcIFCAExLV 5PD3zSXqg6NymhPWaErfMHnId9f0DfPaHSIJewzR5RIfPE1eMD/Lb4euA4Pcbqk6KCA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794135641; h=X-Original-To:Received:DMARC-Filter:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type: Content-Transfer-Encoding:X-CM-TRANSID:X-Coremail-Antispam: X-CM-SenderInfo; bh=Ttz1b1xvGOZQ5uY4SvW+d2KsWCJGIzO1EwdoPlIKTCA=; b=RecF2gZlUE39ztQbr9c5+Y2H234VNxaHEvV2hlEPKeoHTUh1xi2762I2c8D+kDn1rFZr nsvssLTVBtP2HwpXidhD1V1Ch4FSUg11zbgFYB9EXrZXX8tkbimN+DPwpFHHEDE3vQZTG XKWFWgjNfdDDzXgshG7JLRD1dtA5QNCV6tQtxy+ThiQa4RVxTR6yqkO0om22izKOZPm/c 6TuBgYBtT46WrNdiOaHtLFuD2YKY9w3viPXGHb37G44cqX6wP2JJLvlH0EVmlPGj4Q5BL t2YpNLPm9b4fR8BuV78bQZygbk6yuOaU8WBSblstKQN7kf2LFS9Zfcsa6i+Si9vn9pg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none header.from=iscas.ac.cn; spf=pass smtp.mailfrom=iscas.ac.cn; arc=fail smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2667F606A326; Sun, 8 Nov 2026 11:00:41 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=159.226.251.25 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794135635; b=yFpyur7LdZYTP+xV6egCeE1m5l2swca9AtCeZS5WNhRZkW1Al1JMZADAizmPhrGWqe5s 9kf0cDsAO/UiZKmYnTYaqOyg4MIzRv3v72P7FSl7CmxgJD+gSMj8h1UaR6uO9gCd2Q7Rb HVOF6pPiJozuUbKHmzvgjxSazQcwJJwGJ9HyLPeZsBzFF1wdzV3naXAazdjJa2T1u8grp FOK1NjUsUMTG+y+WRb/HXdaI0lMX1Uj3pxT19FClAgsqfzOLA+QEtabehdD29kC2bpT7p uPGxcvN42GD0yNTlx56KYtGHpF3qgBuENLqut6u/2zvTYn8FNBqcymLmoD3tgLt6bLw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794135635; h=DMARC-Filter:Received:From:To:Cc:Subject:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding:X-CM-TRANSID: X-Coremail-Antispam:X-Originating-IP:X-CM-SenderInfo; bh=Ttz1b1xvGOZQ5uY4SvW+d2KsWCJGIzO1EwdoPlIKTCA=; b=ki1uOYlffsrH0vJ14tu7DotoE4XMU+llaC+Tp/y5zEluhc3FZCX0p9Bm2fiTkh1N+NjD 8/bX6IRHOcbUIDXuSK8tqyVgsb4j/cOrJYqDCMRt43gk/84NIoDJlEZF8x/3MRD+Sxsu2 ohkqwjY6ENnd1mHu3HLCY2RCGjQYxzdnweXKVhVB7JHC91YUR7sEiEOYaP75SwQqa6Mpl 0L+xsX7KOpgoa5kgBOauGDeH2JZkM0vnO0sCC4aZhW/jYTPpGTDml7Fe+h05ovFsG8RRL u0oT7JfllxMnJa7v4tj2OD1NTDoerOaWsV7y4xHW48zcoBvytATwhDU0QV1PVfu0cwQ== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=iscas.ac.cn; spf=pass smtp.mailfrom=iscas.ac.cn; arc=none smtp.remote-ip=159.226.251.25 X-Received: from cstnet.cn (smtp25.cstnet.cn [159.226.251.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ABD83606A321; Sun, 8 Nov 2026 11:00:33 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ABD83606A321 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iscas.ac.cn X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iscas.ac.cn X-Received: from [172.100.0.8] (unknown [36.110.52.2]) by APP-05 (Coremail) with SMTP id zQCowABH4LVIVvBqgvOZAA--.18736S2; Sun, 08 Nov 2026 19:00:24 +0800 (CST) X-Cc: Andrew Lunn <andrew+netdev@lunn.ch>, "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, vulab@iscas.ac.cn X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-CM-TRANSID: zQCowABH4LVIVvBqgvOZAA--.18736S2 X-Coremail-Antispam: 1UD129KBjvJXoW7tFWxCw47AFWftFykWFyrXrb_yoW8tF4kpF 4UKa9rGr4qqF4fuw17Zr4vv3s0yFW7KFZ09ry8uws3uwn8Jr98GFsrtFWj9ryDCFWFyr92 vF4qyw4UA3WDAw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9G1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AE w4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2 IY67AKxVWUCVW8JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJw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