[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzbTSAp6-2HZYuALuoF8bDeaJGtSyePe0DvmdRK29pN0aA@mail.gmail.com>
Date: Tue, 22 Apr 2025 08:48:39 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Mykyta Yatsenko <mykyta.yatsenko5@...il.com>
Cc: akpm@...ux-foundation.org, linux-mm@...ck.org, rostedt@...dmis.org,
mhiramat@...nel.org, andrii@...nel.org, kernel-team@...a.com,
linux-kernel@...r.kernel.org, Mykyta Yatsenko <yatsenko@...a.com>
Subject: Re: [PATCH v2] maccess: fix strncpy_from_user_nofault empty string handling
On Tue, Apr 22, 2025 at 6:15 AM Mykyta Yatsenko
<mykyta.yatsenko5@...il.com> wrote:
>
> From: Mykyta Yatsenko <yatsenko@...a.com>
>
> strncpy_from_user_nofault should return the length of the copied string
> including the trailing NUL, but if the argument unsafe_addr points to
> an empty string ({'\0'}), the return value is 0.
>
> This happens as strncpy_from_user copies terminal symbol into dst
> and returns 0 (as expected), but strncpy_from_user_nofault does not
> modify ret as it is not equal to count and not greater than 0, so 0 is
> returned, which contradicts the contract.
>
> Signed-off-by: Mykyta Yatsenko <yatsenko@...a.com>
> ---
> mm/maccess.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
Reviewed-by: Andrii Nakryiko <andrii@...nel.org>
> diff --git a/mm/maccess.c b/mm/maccess.c
> index 8f0906180a94..831b4dd7296c 100644
> --- a/mm/maccess.c
> +++ b/mm/maccess.c
> @@ -196,7 +196,7 @@ long strncpy_from_user_nofault(char *dst, const void __user *unsafe_addr,
> if (ret >= count) {
> ret = count;
> dst[ret - 1] = '\0';
> - } else if (ret > 0) {
> + } else if (ret >= 0) {
> ret++;
> }
>
> --
> 2.49.0
>
Powered by blists - more mailing lists