linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>
Cc: linux-mm@kvack.org, rostedt@goodmis.org, mhiramat@kernel.org,
	andrii@kernel.org, kernel-team@meta.com,
	linux-kernel@vger.kernel.org, Mykyta Yatsenko <yatsenko@meta.com>
Subject: Re: [PATCH mm] maccess: fix strncpy_from_user_nofault empty string handling
Date: Thu, 17 Apr 2025 13:40:06 -0700	[thread overview]
Message-ID: <20250417134006.60e0d6b3fc963bcbec1255b0@linux-foundation.org> (raw)
In-Reply-To: <20250417152808.722409-1-mykyta.yatsenko5@gmail.com>

On Thu, 17 Apr 2025 16:28:08 +0100 Mykyta Yatsenko <mykyta.yatsenko5@gmail.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?


  reply	other threads:[~2025-04-17 20:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-17 15:28 Mykyta Yatsenko
2025-04-17 20:40 ` Andrew Morton [this message]
2025-04-17 21:07   ` Andrii Nakryiko
2025-04-17 20:44 ` Andrii Nakryiko
2025-04-17 20:47   ` Andrii Nakryiko
2025-04-17 22:10   ` Steven Rostedt

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=20250417134006.60e0d6b3fc963bcbec1255b0@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhiramat@kernel.org \
    --cc=mykyta.yatsenko5@gmail.com \
    --cc=rostedt@goodmis.org \
    --cc=yatsenko@meta.com \
    /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