Article View: linux.kernel.netdev
Article #15693Re: [PATCH net-next] NFC: digital: fix target leak after Type 1 Tag discovery
From: Simon Horman
Date: Fri, 13 Nov 2026 10:34
Date: Fri, 13 Nov 2026 10:34
96 lines
11322 bytes
11322 bytes
On Fri, Nov 13, 2026 at 10:00:07AM +0000, Simon Horman wrote:
> On Mon, Nov 09, 2026 at 03:18:32AM +0000, Xia Yan wrote:
> > digital_in_recv_sens_res() allocates a target for an NFC-A response.
> > For a Type 1 Tag, it calls digital_target_found() synchronously.
> > nfc_targets_found() copies the target into dev->targets.
> >
> > On success, rc is zero and the callback skips kfree(target).
> > The original allocation is lost when the callback returns.
> > Each completed Type 1 Tag discovery leaks one struct nfc_target.
> >
> > Free the target after digital_target_found() returns. Clear the pointer
> > to avoid freeing it again on the error path. Keep the target for other
> > tag types, whose discovery continues asynchronously.
> >
> > Found during a code review of NFC-A target ownership.
> >
> > Fixes: 2c66daecc409 ("NFC Digital: Add NFC-A technology support")
> > Signed-off-by: Xia Yan <yanxia@cmss.chinamobile.com>
> > ---
> > net/nfc/digital_technology.c | 7 +++++--
> > 1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/net/nfc/digital_technology.c b/net/nfc/digital_technology.c
> > index ae6487c10a25..2d52e390cc67 100644
> > --- a/net/nfc/digital_technology.c
> > +++ b/net/nfc/digital_technology.c
> > @@ -510,10 +510,13 @@ static void digital_in_recv_sens_res(struct nfc_digital_dev *ddev, void *arg,
> > goto exit;
> > }
> >
> > - if (DIGITAL_SENS_RES_IS_T1T(target->sens_res))
> > + if (DIGITAL_SENS_RES_IS_T1T(target->sens_res)) {
> > rc = digital_target_found(ddev, target, NFC_PROTO_JEWEL);
> > - else
> > + kfree(target);
> > + target = NULL;
> > + } else {
> > rc = digital_in_send_sdd_req(ddev, target);
> > + }
> >
> > exit:
> > dev_kfree_skb(resp);
>
> Thanks Yan,
>
> I agree this is a bug and that you patch correctly addresses it.
> However, I wonder if it would be cleaner to confine cleanup to
> the exit path, centralising the kfree logic.
>
> Something like this (compile tested only!):
>
> diff --git a/net/nfc/digital_technology.c b/net/nfc/digital_technology.c
> index ae6487c10a25..94880172f016 100644
> --- a/net/nfc/digital_technology.c
> +++ b/net/nfc/digital_technology.c
> @@ -483,6 +483,7 @@ static void digital_in_recv_sens_res(struct nfc_digital_dev *ddev, void *arg,
> struct sk_buff *resp)
> {
> struct nfc_target *target = NULL;
> + bool res_is_t1t = false;
> int rc;
>
> if (IS_ERR(resp)) {
> @@ -510,7 +511,8 @@ static void digital_in_recv_sens_res(struct nfc_digital_dev *ddev, void *arg,
> goto exit;
> }
>
> - if (DIGITAL_SENS_RES_IS_T1T(target->sens_res))
> + res_is_t1t = DIGITAL_SENS_RES_IS_T1T(target->sens_res);
> + if (res_is_t1t)
> rc = digital_target_found(ddev, target, NFC_PROTO_JEWEL);
> else
> rc = digital_in_send_sdd_req(ddev, target);
> @@ -518,10 +520,11 @@ static void digital_in_recv_sens_res(struct nfc_digital_dev *ddev, void *arg,
> exit:
> dev_kfree_skb(resp);
>
> - if (rc) {
Probably a comment is warranted here. Something like this:
/* Release target on error.
* digital_target_found() does not take ownership of target,
* so also release target if res_is_t1t is true.
*/
> + if (rc || res_is_t1t)
> kfree(target);
> +
> + if (rc)
> digital_poll_next_tech(ddev);
> - }
> }
>
> int digital_in_send_sens_req(struct nfc_digital_dev *ddev, u8 rf_tech)
Technical Details
Message-ID:
<20261113103426.GK18859@horms.kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-362566-linux-kernel-netdev=dewy.ruReferences:
<20261109031832.37642-1-yanxia@cmss.chinamobile.com> <20261113100007.GI18859@horms.kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-362566-linux-kernel-netdev=dewy.ru From: horms@kernel.org (Simon Horman) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net-next] NFC: digital: fix target leak after Type 1 Tag discovery Date: Fri, 13 Nov 2026 10:34:26 +0000 Organization: Usenet Network Message-ID: <20261113103426.GK18859@horms.kernel.org> References: <20261109031832.37642-1-yanxia@cmss.chinamobile.com> <20261113100007.GI18859@horms.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: usenet.network; logging-data="1330558"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:LxAdl+AHpSMel7bcu9ZQqHkb2Ao= sha256:8AjONkRfhdGYp7VUL3t6HDJ9gmTI3OjlW1e09WtWGwI= sha1:8xnMGrh0r7Mt02vSCwsTjujDRQI= sha256:0sUfTXRQPN8k1jO2P/vY0QWN3E7SThJSLS8o2nWaaaQ= Content-Disposition: inline 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 7614D114509; Fri, 13 Nov 2026 14:56:13 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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-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 ia2Dasr50DEg; Fri, 13 Nov 2026 14:56:08 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-362566-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id DEF5F114502; Fri, 13 Nov 2026 14:55:58 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 0FF931A0C96; Fri, 13 Nov 2026 10:34:44 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794566077; b=Vh0vpGxdy86TxHpvPfgPUWb6HQEwVd6SkZM2YodW6uXvW+8zGbSRy09+HISMwzldc276 PP+4zP5HwVjfFKJUP75t8RIRd8aZZET76ksczOqSkFZ4nxBWC+BVkRQ2JT8ITTDAjXl5M QOMMdIN3C0bcZkkBDb5ZHwirYpHZCoeZUtyFFcLsTTZ9P1IykB6LoXLR+f1uBl+kRB96L evl8fOtlk4pMmJ1uz3q/Q3xCo9vmWMFBU4O20K5cSO1pCkT8SUzw3ydz7MRtOckA70O0H /+WP9329ol+a7t964in6pdFuZ0XK/ENDSzBoVutVPz76JnFZQdxFPP95GP8RUq3obQA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794566077; h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc: Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=/YmEl9MFZJXUpvQcOVvvVL0ExNudpMN/SkBtuR3ZO8M=; b=MBz0wiF9z9npiLsMOwDsnaQ7MTqiteBf4m8TAa4nNXBcBvDh2DOPM0YpXhyMZwgbDqnr GGZQS8PACdoxyxp2ZMHAdhHZQLbJi0sSMcLrqg6vSDQztkltS2erQndUYY3j7UVlxkqWu gvqw7fpv0XM4ws9GbFh/QbdJaQ6oxwTSP34tl16mpEtOeCq5azvJyJWXmoagnfpgdO9+O 1Q7FfwdrFpzRTDhVvCiamyQcYwYros0awAaqQx8+ThASG6Js4pG9JZFXCHO0glQRNVt2V /beLyd03JSLQ17mJjSoyT4N549jGlx1GOroeALWzyqC4lrdbPpxHMx7rF/oJgX5MFQQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dYzvZ9Vu; arc=pass header.oldest-pass=0 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 62BB2606A332; Fri, 13 Nov 2026 10:34:37 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dYzvZ9Vu X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794566071; b=ploeMM3uggvycWCUHTVfiAvwcbdt6PDr6Zx5VuwZF6zmA+3GghK2OtmdM/a4ptNxT/KF C3ft0lveqwi5Bt+NGsX74s+1mQKJQnnrbeFS8spD9fuVLQnpTOjmeGi3m0w5tZzouqSR5 ui9PkC4FJBtUFIjHiiPRnIiNId86kzE5jIEh/ppe7JVvFMXc5aRRe89pjcAB1MO0lr5T5 /Ro1C6y39Y1ZnF9yuRYzMh2fCVbv3oWIryTAE5T+9655j0HUFvDdT8T0Eo3rBOGGM7KZN 0g2r7DQJnzuEIGceXfCMc3luAYV/pY6yeMg/x/UENIDOZQT16Y86nPbiiwObLPCIwpA== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794566071; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=/YmEl9MFZJXUpvQcOVvvVL0ExNudpMN/SkBtuR3ZO8M=; b=BYPCOuHBbyqAjahJbepk7Ke9uEzt/6KZkvjwLBICtoUNhXtmNETc1VzP9CN/aaotnj3n Vh7NrLjVbtp0LOMBXiPMjX87pIo938COHoc0Z+03oWLxvsqY/zsXjoJubTrZRoA0B4pbV fJ/lR7bJzWWF1qqIlGTdT4cyhc/H3bWyxyhMY7F9YvhcEoiGLm+29NlU2wjDQWxSnpwUy 2mQCsFJnL0VBEavWtb/KiDNC2xPLSIYyHNVr8ded6twgCsIo1pnXkoqA/59ME2U9M+C33 gh4KTll6gJSnyVWvTNg8y8r7HoC6hcg3kgeVfSBAMVyMMN6jJlYN9jX9LMeHLMlsd/A== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dYzvZ9Vu; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B0CA606A31C; Fri, 13 Nov 2026 10:34:31 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6C621F000C4; Fri, 13 Nov 2026 10:34:28 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794566071; bh=/YmEl9MFZJXUpvQcOVvvVL0ExNudpMN/SkBtuR3ZO8M=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=dYzvZ9VuqN0iwIV1Ntjt6pLlZGQ2VfvGi1FQqbo+ihEW+xZEUfxZy+H9+P3yObpGy 0f2LFRss025GXIfk/hZaHQpfPOg5T3Kf43WZpPfXhSvrs+DzqOLV8oCqyLm3P9hF1F JfxAcP/aBjt2aNTbsvlUJksV9ED0PLbF5mtTU+76dxAiXln5RipbQEjP8ir0htc0+O GhZWg9p8mD2smMhKo/FaTvcMJyMhHf5LhMSNVA8LYCkPao7yi4Q85f/Deyr2Bfis9j 1dN3BmStapfIYy8XmRI/YGCq0WXpXJnAiGGfm0zFeBG3jFkwIoro3/ZY7PZPOzpVjb VVHsgM4PmZeTw== X-Cc: netdev@vger.kernel.org, oe-linux-nfc@lists.linux.dev, David Heidelberg <david@ixit.cz>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Thierry Escande <thierry.escande@linux.intel.com>, Samuel Ortiz <sameo@linux.intel.com>, Samuel Ortiz <sameo@rivosinc.com>, linux-kernel@vger.kernel.org, yana06070@163.com 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-In-Reply-To: <20261113100007.GI18859@horms.kernel.org>