public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Shengzhuo Wei" <me@cherr.cc>
To: "Richard Weinberger" <richard@nod.at>,
	 "Anton Ivanov" <anton.ivanov@cambridgegreys.com>,
	 "Johannes Berg" <johannes@sipsolutions.net>,
	 "Dan Carpenter" <error27@gmail.com>,
	 "Andrew Morton" <akpm@linux-foundation.org>,
	 "Jeff Dike" <jdike@addtoit.com>,
	 "David Laight" <david.laight.linux@gmail.com>
Cc: <linux-um@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
	 "Shengzhuo Wei" <me@cherr.cc>
Subject: Re: [PATCH] um: proc/exitcode: fix simple_strtol() out-of-bounds read
Date: Mon, 27 Apr 2026 21:36:13 +0800	[thread overview]
Message-ID: <ae9mTTqp0QgL6rcL@pve.cherr> (raw)
In-Reply-To: <20260423-fix_exitcode-v1-1-7e4508913d68@cherr.cc>

On 2026-04-23 01:39, Shengzhuo Wei wrote:
> write(2) should report the number of bytes consumed. Returning the original
> count would claim success even when the input was truncated, so userspace
> cannot detect it.
> 
> Clamp the copy length to sizeof(buf)-1, add a terminator, and return the
> consumed length.
> 
> Fixes: 201f99f170df ("uml: check length in exitcode_proc_write()")
> Fixes: e16f5350d4cf ("uml: get declaration of simple_strtoul")
> Signed-off-by: Shengzhuo Wei <me@cherr.cc>
> ---
>  arch/um/kernel/exitcode.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/um/kernel/exitcode.c b/arch/um/kernel/exitcode.c
> index 43edc2aa57e4fbd4a3d24f96878c76f9f8fd4eaa..8de404ff21a213918c5351bc20a6e047bf1b93f5 100644
> --- a/arch/um/kernel/exitcode.c
> +++ b/arch/um/kernel/exitcode.c
> @@ -43,16 +43,17 @@ static ssize_t exitcode_proc_write(struct file *file,
>  	size_t size;
>  	int tmp;
>  
> -	size = min(count, sizeof(buf));
> +	size = min(count, sizeof(buf) - 1);
>  	if (copy_from_user(buf, buffer, size))
>  		return -EFAULT;
> +	buf[size] = '\0';
>  
>  	tmp = simple_strtol(buf, &end, 0);
>  	if ((*end != '\0') && !isspace(*end))
>  		return -EINVAL;
>  
>  	uml_exitcode = tmp;
> -	return count;
> +	return size;

There is another problem that have been talked about in another patch.
Not consuming the whole string passed by user may (and will) break
some programs that want to ensure "FULL WRITE" that use some function
like "while (len > 0) { len -= write(); } ".

Should we just let the return count as-is and fix the OOB problem only?

Link: https://lore.kernel.org/all/20260424063531.d1508a3c79c4b7808ed04420@linux-foundation.org/t/#u
Link: https://lore.kernel.org/all/ef2301c4-bbc5-496e-b9d2-9adcff8b8d42@p183/

Regards,
Shengzhuo Wei

>  }
>  
>  static const struct proc_ops exitcode_proc_ops = {
> 
> ---

      parent reply	other threads:[~2026-04-27 13:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-22 17:39 [PATCH] um: proc/exitcode: fix simple_strtol() out-of-bounds read Shengzhuo Wei
2026-04-22 20:45 ` David Laight
2026-04-23  3:28   ` Shengzhuo Wei
2026-04-27 13:36 ` Shengzhuo Wei [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=ae9mTTqp0QgL6rcL@pve.cherr \
    --to=me@cherr.cc \
    --cc=akpm@linux-foundation.org \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=david.laight.linux@gmail.com \
    --cc=error27@gmail.com \
    --cc=jdike@addtoit.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-um@lists.infradead.org \
    --cc=richard@nod.at \
    /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