From: Thorsten Blum <thorsten.blum@linux.dev>
To: David Laight <david.laight.linux@gmail.com>,
Krzysztof Kozlowski <krzk@kernel.org>,
Huisong Li <lihuisong@huawei.com>,
Akira Shimahara <akira215corp@gmail.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: stable@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] w1: therm: Fix off-by-one buffer overflow in alarms_store
Date: Wed, 29 Oct 2025 16:25:59 +0100 [thread overview]
Message-ID: <DB14BF54-DA19-408C-8D0E-65279AF19282@linux.dev> (raw)
In-Reply-To: <20251029130045.70127-2-thorsten.blum@linux.dev>
On 29. Oct 2025, at 14:00, Thorsten Blum wrote:
> The sysfs buffer passed to alarms_store() is allocated with 'size + 1'
> bytes and a NUL terminator is appended. However, the 'size' argument
> does not account for this extra byte. The original code then allocated
> 'size' bytes and used strcpy() to copy 'buf', which always writes one
> byte past the allocated buffer since strcpy() copies until the NUL
> terminator at index 'size'.
>
> Fix this by parsing the 'buf' parameter directly using simple_strtol()
> without allocating any intermediate memory or string copying. This
> removes the overflow while simplifying the code.
>
> Cc: stable@vger.kernel.org
> Fixes: e2c94d6f5720 ("w1_therm: adding alarm sysfs entry")
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
I should still add overflow detection to simple_strtol() to match the
behavior of kstrtoint(), but please let me know what you think of the
current version first.
Thanks,
Thorsten
prev parent reply other threads:[~2025-10-29 15:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-29 13:00 [PATCH v2] w1: therm: Fix off-by-one buffer overflow in alarms_store Thorsten Blum
2025-10-29 15:25 ` Thorsten Blum [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DB14BF54-DA19-408C-8D0E-65279AF19282@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=akira215corp@gmail.com \
--cc=david.laight.linux@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=krzk@kernel.org \
--cc=lihuisong@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox