[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250417134006.60e0d6b3fc963bcbec1255b0@linux-foundation.org>
Date: Thu, 17 Apr 2025 13:40:06 -0700
From: Andrew Morton <akpm@...ux-foundation.org>
To: Mykyta Yatsenko <mykyta.yatsenko5@...il.com>
Cc: 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 mm] maccess: fix strncpy_from_user_nofault empty string
handling
On Thu, 17 Apr 2025 16:28:08 +0100 Mykyta Yatsenko <mykyta.yatsenko5@...il.com> wrote:
> 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.
Looks right, I think.
But why do strncpy_from_user() and strncpy_from_user_nofault() have
different interfaces?
/**
* strncpy_from_user: - Copy a NUL terminated string from userspace.
* ...
* On success, returns the length of the string (not including the trailing
* NUL).
/**
* strncpy_from_user_nofault: - Copy a NUL terminated string from unsafe user
* address.
* ...
* On success, returns the length of the string INCLUDING the trailing NUL.
This is surprising and I'm wondering what led us to do this?
Powered by blists - more mailing lists