Article View: linux.kernel.netdev
Article #10051Re: [PATCH net] nfc: s3fwrn5: validate the firmware image size against the firmware file
From: netdev-bot+sashiko
Date: Tue, 03 Nov 2026 03:02
Date: Tue, 03 Nov 2026 03:02
130 lines
12384 bytes
12384 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0 (1)
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 because the signature offsets and sizes in
the firmware header are still not checked.
Pre-existing issues:
- [Low] struct s3fwrn5_fw_cmd_get_bootinfo_rsp is 12 bytes
(hw_version[4], sector_size, page_size, frame_max_size,…
--
nfc: s3fwrn5: validate the firmware image size against the firmware file
This patch adds bounds checks to the s3fwrn5 firmware download path. It
checks the GET_BOOTINFO response length and rejects an image offset past
the end of the firmware file. It also checks that sector_size *
image_sectors, plus the 4 KiB sent per sector, fits in the firmware image
before the image is hashed and flashed.
> diff --git a/drivers/nfc/s3fwrn5/firmware.c b/drivers/nfc/s3fwrn5/firmware.c
> index 9145deec7f6c1..159afb8de7491 100644
> --- a/drivers/nfc/s3fwrn5/firmware.c
> +++ b/drivers/nfc/s3fwrn5/firmware.c
> @@ -93,7 +93,8 @@ static int s3fwrn5_fw_get_bootinfo(struct s3fwrn5_fw_info *fw_info,
> return ret;
>
> hdr = (struct s3fwrn5_fw_header *) rsp->data;
> - if (hdr->code != S3FWRN5_FW_RET_SUCCESS) {
> + if (hdr->code != S3FWRN5_FW_RET_SUCCESS ||
> + rsp->len < S3FWRN5_FW_HDR_SIZE + 10) {
[Severity: Low]
This is a pre-existing issue, but struct s3fwrn5_fw_cmd_get_bootinfo_rsp
is 12 bytes:
struct s3fwrn5_fw_cmd_get_bootinfo_rsp {
__u8 hw_version[4];
__u16 sector_size;
__u16 page_size;
__u16 frame_max_size;
__u16 hw_buffer_size;
};
The new length check and the existing memcpy() in
s3fwrn5_fw_get_bootinfo() both use the literal 10. That means
hw_buffer_size in the on-stack bootinfo in s3fwrn5_fw_setup() is never
filled in.
Nothing in drivers/nfc/s3fwrn5/ reads hw_buffer_size today, so this has
no functional effect.
Would it be cleaner to use sizeof(*bootinfo) here? Or a named constant
that documents a 10-byte wire format?
> ret = -EINVAL;
> goto out;
> }
[ ... ]
> @@ -307,6 +308,10 @@ int s3fwrn5_fw_request_firmware(struct s3fwrn5_fw_info *fw_info)
> memcpy(&fw->sig_size, fw->fw->data + 0x18, 4);
>
> memcpy(&image_off, fw->fw->data + 0x1C, 4);
> + if (image_off > fw->fw->size) {
> + release_firmware(fw->fw);
> + return -EINVAL;
> + }
> fw->image = fw->fw->data + image_off;
> memcpy(&fw->image_sectors, fw->fw->data + 0x20, 4);
>
[Severity: High]
image_off is now checked against fw->fw->size. The signature fields from
the same header are still used without any range check:
drivers/nfc/s3fwrn5/firmware.c:s3fwrn5_fw_request_firmware() {
...
memcpy(&sig_off, fw->fw->data + 0x14, 4);
fw->sig = fw->fw->data + sig_off;
memcpy(&fw->sig_size, fw->fw->data + 0x18, 4);
...
memcpy(&custom_sig_off, fw->fw->data + 0x24, 4);
fw->custom_sig = fw->fw->data + custom_sig_off;
memcpy(&fw->custom_sig_size, fw->fw->data + 0x28, 4);
...
}
s3fwrn5_fw_setup() then picks one of the two pairs based on
s3fwrn5_fw_is_custom(&bootinfo). That depends on hw_version[2], which the
controller reports in GET_BOOTINFO.
The chosen pointer and size (truncated to u16) are then sent to the
controller:
s3fwrn5_fw_download()
s3fwrn5_fw_enter_update_mode(fw_info, hash_data, SHA1_DIGEST_SIZE,
fw_info->sig, fw_info->sig_size)
s3fwrn5_fw_prep_msg(fw_info, &msg, S3FWRN5_FW_MSG_DATA, 0,
sig_data, sig_size)
skb_put_data(skb, data, len)
What happens if sig_off + sig_size, or custom_sig_off + custom_sig_size,
runs past fw->fw->size? Can skb_put_data() then read up to 64 KiB beyond
the firmware buffer?
Depending on how far the read goes, it would either oops on a guard page
or unmapped address, or copy nearby kernel memory into the DATA packet
sent to the controller.
The commit message says:
Check that everything that is hashed and sent lies within the image,
The signature is sent in the same update sequence. Should both signature
extents also be checked against fw->fw->size here, for example with
check_add_overflow()?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179332800288.52644.4206885352837613064%40gmail.com
Technical Details
Message-ID:
<179367496942.488856.4052477180493084885@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-355195-linux-kernel-netdev=dewy.ruReferences:
<179332800288.52644.4206885352837613064@gmail.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-355195-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] nfc: s3fwrn5: validate the firmware image size against the firmware file Date: Tue, 03 Nov 2026 03:02:49 +0000 Organization: Usenet Network Message-ID: <179367496942.488856.4052477180493084885@kernel.org> References: <179332800288.52644.4206885352837613064@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3086146"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:+/71qs3dNHJA/heF/RRYk+Z9n3w= sha256:n/jyeYvb6dQZJRJzkz6Or5iMFVNrcJEMWvL6N8yzOPo= sha1:I8gmUF6ohTkpHFBwxHm3/rAiMr0= sha256:7WRO4/BbgORrybiEKV/6FJGUNcy66p3OmxOMr86WlZU= 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 6696B112725; Tue, 3 Nov 2026 06:05:38 +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 BVlg7AoUfmNZ; Tue, 3 Nov 2026 06:05:35 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-355195-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 C7A7C11271D; Tue, 3 Nov 2026 06:05:24 +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 26FF82D0CB; Tue, 3 Nov 2026 03:02:54 +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=1793674973; b=lEmApWeqcPbldjAmH9qZ1S4EWLGYMt9tzlaxqiA5KvTRql77iEn3LfMAOgAw0WkS2u5F Ej8e+2bveRvPDur3ajc4MK2UNBgWlPdvFzSxJT+N7BNzjsZpPdyRur83BGgZYR25Yb5rb kRVqFFwK6jO2w8vYpXSzAKPsSfPIeeri51ylqpLpcxoT65nW0P2zNuRxv3qJjnqChu4Hl EtsHeEt9fJccjTCvMsswnSItVo3Fi9/ajE/5JhS8ctyt7+sluNzU0kAw9ooOjZ7ijd/qI UuuX6SXM2qgS/Pkz8PhIGQJPVzbjbrnSFDCw5jcsldt/lftovZ2GVufk08ViblK3RUw== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793674973; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=6uWrHIdQA4/I/nNEbaoqtIpWv2r/6R+u8p9kDzTlgDQ=; b=xAHEctN589yTtS0hGD91BZBIyQX8jc/BRUW+veNrUZ7WJYDAgKVRVlOd6a7GcCwi44e+ iHZSLeAfiavFVSBA4GyskaB9DBGbStN0WtMqWs1pAJdoko1x+lxdQmdi96lao50SmmPKX IDhKZnl0Knrd28UTxWG6oazgUlSO+To8ouwFzlRKu1NQ38tMW7Hj/bes59Tn8QUY4t9CY FHqWSUgU7JKQ5Lt4cA7OaZTOlud84EkJU0eXcS4UMKxrrZfLHoEhl7EwjMdDsDrLnw5PN Z+ZAZBzD9wrNed04H1NwXs0UpQue4WAVzPA3QXivfehteXjIIh9aRtT05F1KwxPnJcA== 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=oimnZTFG; 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 352B2606A339; Tue, 3 Nov 2026 03:02:53 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oimnZTFG 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=1793674971; b=W5e5dSwnIaxV4JJ7H5IR2WTjojS4te0Rtc9U74Yq6tnXaGnHzwvbmpI5mNjm3zBV+R7/ 6nX6MoQl6MdHDwjdB6CML+mcaZRnGn8NtGY07SwovcJd9wH6XQAKS4PfxwakP9hMgo2C6 FAOtG8XCdWOLbCnaEXHRtKHVd3wRjVb1OXlFxi7Llr/JEm4W/aYBLWTBGAQMdmjET+xiQ 6cdMpBVtZc4Dj0WDi68jLUviISsY+SqyKoQbGLk+07DEeOjAuFWRL0cxBDAqQDab8GYq7 jcWOCRITt0vDAcTjkDon7FnY6O11ag/U8YKRIwr4sm4o5QpVA73alinZpmv5YiNG7nQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793674971; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=6uWrHIdQA4/I/nNEbaoqtIpWv2r/6R+u8p9kDzTlgDQ=; b=AfT0QEri0aaZjuF73vr3f+K7DM0pcWdb4wFgUnxvSQOcXAKxIEw9JuGWSdAuvU/ckNLE D8/lg8Ly38WV0IRwrYpQAk0y+EQG6NoVO/PsyduWtEcSm4MVRRuHAVB0WAErjSjFIWMVr aQMhR0bbAuvDzoUYCgc+HWwixHO6y1zq6svptyHtjnguJG5R5BZZtmTybrqWe6QeuIOGZ MOwJowdl/cnUWKpIv1kfTj1nJA0rEs4aYLtf4TKiabb5L0HWNZt81BByQmePeo1biZf70 2g5/1shjnmIvHJ57v4Es7CS7b40RbL3WkjDTLhzHEbf5lqC32ei6w2pXGV/SSmIWu+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=oimnZTFG; 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 ABF25606A33B; Tue, 3 Nov 2026 03:02:50 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1AA61F00A18; Tue, 3 Nov 2026 03:02:49 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793674970; bh=6uWrHIdQA4/I/nNEbaoqtIpWv2r/6R+u8p9kDzTlgDQ=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=oimnZTFGTeJE43fq6q+zP9zhnnO569FfyCYBDdMi/QUj+r8PCev/2tGuRQVgJFyi1 zNn14mwrvWqixU2DGDV9iwX8h4ArR0F/sHQ55MnbFRBseHFWtbO8YSGCiLMK6F0kOT lsVgCgkYevp8m5X5EnIDj9/XrO3+ARFuwJqjhrTYoEvbzowm1UpQ5yNuZMuBw0FYHL Z8hN9XmbCKL7t/FEeqTeHmeoBQMTXdYcLspH2sCuPv0OnjVTFpPWNw4v2X7lQn6M+m SojdJtXleZQd0k3P6KPhdySSYA3MdqRCsKFQJ/3tYVfc1TeFXbM8p3cV/I6aUiYcnh xt65wV6HMoMjg== X-Cc: david@ixit.cz, krzk@kernel.org, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, oe-linux-nfc@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org X-In-Reply-To: <179332800288.52644.4206885352837613064@gmail.com> X-sashiko-severity: High 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