public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joel Granados <joel.granados@kernel.org>
To: buermarc <buermarc@googlemail.com>
Cc: davem@davemloft.net, elias.rw2@gmail.com, kees@kernel.org,
	 linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	opurdila@ixiacom.com,  ps.report@gmx.net
Subject: Re: [PATCH v3] sysctl: fix check against uninitialized variable in proc_do_large_bitmap
Date: Wed, 25 Mar 2026 11:07:23 +0100	[thread overview]
Message-ID: <kqjjzsarsqgwtzrrih5hvmbeyrhsbkobvcjaznnxh7oegyin7w@p3u3jenw4h2r> (raw)
In-Reply-To: <20260324223640.807029-1-buermarc@googlemail.com>

[-- Attachment #1: Type: text/plain, Size: 2792 bytes --]

On Tue, Mar 24, 2026 at 11:36:40PM +0100, buermarc wrote:
> From: Marc Buerg <buermarc@googlemail.com>
> 
> Hi,
> 
> On Tue, 24 Mar 2026 08:44:13 +0100 Joel Granados, wrote:
> 
> > 1. len is calculated by doing len = p - tmp
> > 2. tmp is the beginning of the buffer
> > 3. p is the first character that is not a digit.
> >
> > There will always be at least one ('\0') character that is not a digit.
> 
> Yes.
> 
> > So len will be less than size at least by one (could be more if the
> > string contains non digit chars). When it is parsed to the end,
> > len will be less than size by one.
> 
> I don't think this is the case. See below.
> 
> > TL;DR
> 
> I'll try to make it shorter. size is the length of the user buffer, even
> after the copy to the kernel buffer. The added '\0' does not increment
> size in proc_sys_call_handler(). Following the example for
> write(fd,"123",3). In the beginning of proc_get_long():
> 
> size = 3
> 
> @:012 3
> -------
>  "123\0"
>   |
>  tmp=@0
>   |
>   p=@0
> 
> After strtoul_lenient():
> 
> @:012 3
> -------
>  "123\0"
>   |   |
>  tmp=@0
>       |
>       p=@3
> 
> @3 - @0 = 3
> len = 3
> 
> (len < size) => (3 < 3) => false

I see it now! I needed to pass '-n' to echo. I was testing with
write(fd, "123\n" 4) instead of write(fd, "123", 3)

> 
> And size must be 3, proc_sys_call_handler() does not increment it. If we
> provide something like write(fd,"123\0",4) size will be 4, but now we will
> return -EINVAL.
Agreed.

> 
> If len < size is true, we call memchk(). memchk will not find a trailing
> character as p points to '\0'. This means in this case we would return
> -EINVAL for the first proc_get_long() call in the while loop. Reason is
> '\0' is not in tr_a and therefore not a valid delimiter for the first
> proc_get_long() call.
> 
> I hope this get's my point across.
It does. Thx for insisting :)

> 
> > All this holds unless the trailing '\0' is modified in some way in that
> > BPF call.
> 
> To my knowledge there was no bpf tracing enabled on the affected host at
> the time that the behavior was observed.
Indeed. I can reproduce without BPF

> 
> Finally: the fix which adds a check for left introduces a regression.
> "123-" is wrongly accepted. Not sure if you saw my other message. It
> should not be used.
I saw that, thx.

I think the correct fix is your original version. Init 'c' to zero only.
Please resend it without the '---' so I can pull your trailers properly.

We don't check 'left' in the c == '-' condition because it will
incorrectly accept strings that end in '-' (e.g. "123-"). In other
words, we need to enter that branch to fail as expected.

> 
> Best Regards,
> Marc

Thx

-- 

Joel Granados

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

  reply	other threads:[~2026-03-25 10:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-19 22:50 [PATCH v3] sysctl: fix check against uninitialized variable in proc_do_large_bitmap Marc Buerg
2026-03-20 18:30 ` Kees Cook
2026-03-21 12:05   ` Peter Seiderer
2026-03-22 10:13     ` Marc Buerg
2026-03-23 13:53 ` Joel Granados
2026-03-23 23:46   ` buermarc
2026-03-24  7:44     ` Joel Granados
2026-03-24 22:36       ` buermarc
2026-03-25 10:07         ` Joel Granados [this message]
2026-03-25 20:48           ` Marc Buerg

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=kqjjzsarsqgwtzrrih5hvmbeyrhsbkobvcjaznnxh7oegyin7w@p3u3jenw4h2r \
    --to=joel.granados@kernel.org \
    --cc=buermarc@googlemail.com \
    --cc=davem@davemloft.net \
    --cc=elias.rw2@gmail.com \
    --cc=kees@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=opurdila@ixiacom.com \
    --cc=ps.report@gmx.net \
    /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