* [PATCH] btrfs: Replace deprecated strncpy() with strscpy_pad()
@ 2025-02-25 9:29 Thorsten Blum
2025-02-25 12:28 ` David Sterba
0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Blum @ 2025-02-25 9:29 UTC (permalink / raw)
To: Chris Mason, Josef Bacik, David Sterba
Cc: Thorsten Blum, linux-hardening, linux-btrfs, linux-kernel
strncpy() is deprecated for NUL-terminated destination buffers. Use
strscpy_pad() instead and don't zero-initialize the param array.
Compile-tested only.
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
fs/btrfs/sysfs.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 53b846d99ece..b941fb37776d 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -1330,13 +1330,13 @@ MODULE_PARM_DESC(read_policy,
int btrfs_read_policy_to_enum(const char *str, s64 *value_ret)
{
- char param[32] = { 0 };
+ char param[32];
char __maybe_unused *value_str;
if (!str || strlen(str) == 0)
return 0;
- strncpy(param, str, sizeof(param) - 1);
+ strscpy_pad(param, str);
#ifdef CONFIG_BTRFS_EXPERIMENTAL
/* Separate value from input in policy:value format. */
--
2.48.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: Replace deprecated strncpy() with strscpy_pad()
2025-02-25 9:29 [PATCH] btrfs: Replace deprecated strncpy() with strscpy_pad() Thorsten Blum
@ 2025-02-25 12:28 ` David Sterba
2025-02-25 12:58 ` Thorsten Blum
0 siblings, 1 reply; 3+ messages in thread
From: David Sterba @ 2025-02-25 12:28 UTC (permalink / raw)
To: Thorsten Blum
Cc: Chris Mason, Josef Bacik, David Sterba, linux-hardening,
linux-btrfs, linux-kernel
On Tue, Feb 25, 2025 at 10:29:49AM +0100, Thorsten Blum wrote:
> strncpy() is deprecated for NUL-terminated destination buffers. Use
> strscpy_pad() instead and don't zero-initialize the param array.
>
> Compile-tested only.
>
> Link: https://github.com/KSPP/linux/issues/90
> Cc: linux-hardening@vger.kernel.org
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> fs/btrfs/sysfs.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> index 53b846d99ece..b941fb37776d 100644
> --- a/fs/btrfs/sysfs.c
> +++ b/fs/btrfs/sysfs.c
> @@ -1330,13 +1330,13 @@ MODULE_PARM_DESC(read_policy,
>
> int btrfs_read_policy_to_enum(const char *str, s64 *value_ret)
> {
> - char param[32] = { 0 };
> + char param[32];
> char __maybe_unused *value_str;
>
> if (!str || strlen(str) == 0)
> return 0;
>
> - strncpy(param, str, sizeof(param) - 1);
> + strscpy_pad(param, str);
I don't think we need the padding, so strscpy is probably ok. We copy
input string to a temporary modifiable buffer and then match it against
a table, so the NUL termination is ok.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: Replace deprecated strncpy() with strscpy_pad()
2025-02-25 12:28 ` David Sterba
@ 2025-02-25 12:58 ` Thorsten Blum
0 siblings, 0 replies; 3+ messages in thread
From: Thorsten Blum @ 2025-02-25 12:58 UTC (permalink / raw)
To: dsterba
Cc: Chris Mason, Josef Bacik, David Sterba, linux-hardening,
linux-btrfs, linux-kernel
On 25. Feb 2025, at 13:28, David Sterba wrote:
> On Tue, Feb 25, 2025 at 10:29:49AM +0100, Thorsten Blum wrote:
>> strncpy() is deprecated for NUL-terminated destination buffers. Use
>> strscpy_pad() instead and don't zero-initialize the param array.
>>
>> Compile-tested only.
>>
>> Link: https://github.com/KSPP/linux/issues/90
>> Cc: linux-hardening@vger.kernel.org
>> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
>> ---
>
> I don't think we need the padding, so strscpy is probably ok. We copy
> input string to a temporary modifiable buffer and then match it against
> a table, so the NUL termination is ok.
Ok thanks, I'll submit a v2 later today.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-25 12:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-25 9:29 [PATCH] btrfs: Replace deprecated strncpy() with strscpy_pad() Thorsten Blum
2025-02-25 12:28 ` David Sterba
2025-02-25 12:58 ` Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox