🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #15885

Re: [PATCH v2] nfc: pn533: bounds-check the ATR_RES response before parsing it

#15885
From: Simon Horman
Date: Fri, 13 Nov 2026 17:31
37 lines
9469 bytes
On Mon, Nov 09, 2026 at 08:00:16PM +0900, hyunjungg wrote:
> From: Hyunjung Ko <hj351016@gmail.com>
> 
> pn533_poll_dep_complete(), pn533_in_dep_link_up_complete() and
> pn533_activate_target_nfcdep() cast resp->data to the fixed ATR_RES
> header (struct pn533_cmd_jump_dep_response / pn533_cmd_activate_response)
> and, on a successful response, read nfcid3t[] and compute the general-
> bytes length as resp->len - sizeof(header). A short response leaves that
> read past the end of the skb data, an out-of-bounds read; the copied
> nfcid3t reaches userspace via nfc_targets_found() and netlink.
> 
> Only the success path needs the full fixed header: a no-peer/failure
> reply is just the status byte, and the existing failure handling (turn
> the radio off and re-arm polling, or print the error) must keep running
> for it. So validate resp->len >= sizeof(*rsp) after the status check, on
> the success path, in all three handlers, before nfcid3t and the general
> bytes are read.
> 
> Found by code review; not reproduced.
> 
> Fixes: 361f3cb7f9cf ("NFC: DEP link hook implementation for pn533")
> Fixes: 673088fb42d0 ("NFC: pn533: Send ATR_REQ directly for active device detection")
> Cc: stable@vger.kernel.org
> Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
> ---
> Changes in v2 (thanks to the Sashiko AI review):
>  - move the length check to the SUCCESS path (after the status check), so
>    a no-peer/timeout reply (resp->len == 1) still takes the existing
>    "turn radio off, re-arm polling" / error path instead of returning
>    -EINVAL and stalling the poll loop
>  - also guard pn533_activate_target_nfcdep(), the third ATR_RES parser
>  - add Fixes: tags for the two commits that introduced the parsing
>  - drop the inaccurate claim that the other handlers already length-check
>    resp->len (only pn533_init_target_complete() does)

Reviewed-by: Simon Horman <horms@kernel.org>
Technical Details
Message-ID: <20261113173111.GX18859@horms.kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-362813-linux-kernel-netdev=dewy.ru
References: <20261109110016.1511307-1-hj351016@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-362813-linux-kernel-netdev=dewy.ru
From: horms@kernel.org (Simon Horman)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v2] nfc: pn533: bounds-check the ATR_RES response before
 parsing it
Date: Fri, 13 Nov 2026 17:31:11 +0000
Organization: Usenet Network
Message-ID: <20261113173111.GX18859@horms.kernel.org>
References: <20261109110016.1511307-1-hj351016@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="1406165"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:5/zqsh3hwrc1DBlSBV0eZJTkMFA= sha256:pv7xAhoIsIXNzi/hZzZrNODfRzBUxjyYYuz39Zk+/xw=
	sha1:thQVXvaCDv8fML35/jKQGFRmVvs= sha256:Aj/IxKkmhgPeZne9Kl4ue+9/UV50xi6QGdM3pXbpENk=
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 342DE1145F2; Fri, 13 Nov 2026 21:29:25 +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 Wz9xAJ_zRfuT;
	Fri, 13 Nov 2026 21:29:22 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-362813-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 AE2CA1145EC; Fri, 13 Nov 2026 21:29:13 +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 B86A0490EB; Fri, 13 Nov 2026 17:42:40 +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=1794591081;
	b=MPNRRsiyWy7YrB471o8mpl/VGc0Ooe/1/NQ31dFaAPWmNjM9bG+noxqOIHh6tnE2Nc1w
	 KsLw+8u+tNc3kJ4KmIhvohMUl6VtZwESNds5SCF+GNlwtMK9DUVgE4zO8Pi0xtdeu89A4
	 yRm7Yvgfp9rAi7LyZgbNOeCCbCqawniJWHIrNdNKADw9brQNmlJNSkWy0mTO18q3vNEwA
	 HM4BgqASA4PzKVhsrfwQttrIRWjEqd8AXXndam/6ikwNh+9LCyk68wMAlt7HO/GteOudv
	 8eJi+V3fwvGtEe33KkwcudDgNw4XmeVDEgxTkMUCH57D8crrQywcVX5qKDnEvMRJzoA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794591081;
	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=fax9dsDLfWgV2bx85EWAVzVfZQhzYfTnApIR7+ezcww=;
	b=2tI84l+6USuG6tYjdLbLa3zuWuogwfjOTMo7yxO++0UWZrZCyCzjSEI7LR6hn4vdVATk
	 OBA86IWr9jFCSp5Wqo517vgY32mzzHroP9IMfdxyc77OcaFYu8QGpgdi/MPObPTFOPer1
	 JNqxsBWctAzOEBqPlOfdcOiqyPafYT3v0DewV4G3zfOXO7jH+ijRHWWYUrlgSbjbejSzm
	 rtef8tCg9/8dUuOK5eh25kCD+uf5QtPDsh/rIqs/PjxFkPIhD9rwJ5fp1ktF4/7vset6w
	 lS4/IWR3N5Yj8HHRqu8iNrtOSMkQnBiOjTmNxGzmiG/+pZVDq26BotQJL3CPT8itQfQ==
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=JY+usgkm;
	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 341C16073215;
	Fri, 13 Nov 2026 17:31:21 +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=JY+usgkm
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=1794591075;
	b=ltltu65wGnv3kWYdhOvBR38YiJs1VWibQjJO1HBzlo/7Q+RPckXrJcrJ4C22xwPI3n5e
	 qlIj6/X7T2eh9PfWACZucL3hDdtjHD3arVf+cl6dz6eEry1Y1kgDW6w0KgsG51WWVlIQD
	 FGzSu5qHUENOETz7vfoKmx3XTPx2y2SXsjwV9o/mPx2kcEwsZ7U4lY52Ex8aswQJHU76G
	 g3EmQBQBtxIdGV2IQ7twwkym747GcoT3W4a8K865CsoS9150m2w5ZjCTAlZJg8HXJsFcC
	 ck9ujzMMRcmdrWgJ84WOZ9yEJyF9oFPAlvnQjQwDpRRPUa4WfN+2QIfYcttK0mfQpAw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794591075;
	h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=fax9dsDLfWgV2bx85EWAVzVfZQhzYfTnApIR7+ezcww=;
	b=0nG5Q54WBhPf4+O5fJnalW98q9vAnGbRja5ALz9kIO2Ckevy+ICD38O3X4YKzZ5+O9Ya
	 0kvou0VtRO7jZHzNn01TkG1ZOP/SU/kASnFWPt90S9ycY+6e2QKnBSeLEFp2j9qAB0d0E
	 /BD9Vv7pknsjJ0z1dGnZq4qQBqlChOpws8hrEkHwq9iuTJkWYEa7jfapaFdOesxBbH1P5
	 N9/Qo3YnuuuZ6QNNriIgizdAUJyj5JsQHKYNd4oApbdh+FMuoNo+9KDYUPvNkFxxPqtEA
	 rvxIP9ivDyomS3vHv/O5xS8SoGqoiWfxw2uJSgfrR931Ah41SUllubQKh/BzDyRQ1wA==
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=JY+usgkm;
	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 522E6606B35A;
	Fri, 13 Nov 2026 17:31:15 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id EBA921F000C8;
	Fri, 13 Nov 2026 17:31:13 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794591075;
	bh=fax9dsDLfWgV2bx85EWAVzVfZQhzYfTnApIR7+ezcww=;
	h=Date:From:To:Cc:Subject:References:In-Reply-To;
	b=JY+usgkmSJ0sLJLH9HT2wyqRGflYj1R+RXQP5D3LzHR+jL9CcljUGgCkmpaTx3moa
	 HBDKUOmI4viDo9VqgC1+9+1Ry1uXMTgorwmLISYIV6HZ0lPlHvU8di+kpWxmH/IbQy
	 1nuFj6FvQpSJlB8CMrPhgYyTc02FWQGXGylQrs01iTTyyOwOV4ya4t4BfN473YJtDD
	 HcKtuWZaXuLRDbWW+c7qbTf+jy1Wd/wArGqm4uX5Y2298Q7Vv2kVmFuQQ2umv7++LG
	 vOlLLMnNP9vJ9yrwNHLAum3yhv3JZ0rTRPtRoK3y9rOfJZ2y9p4WHTS45jARWBwrDL
	 XmO2ZvHEio1/A==
X-Cc: David Heidelberg <david@ixit.cz>, oe-linux-nfc@lists.linux.dev,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
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: <20261109110016.1511307-1-hj351016@gmail.com>