From: buermarc <buermarc@googlemail.com>
To: joel.granados@kernel.org
Cc: buermarc@googlemail.com, 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: Tue, 24 Mar 2026 23:36:40 +0100 [thread overview]
Message-ID: <20260324223640.807029-1-buermarc@googlemail.com> (raw)
In-Reply-To: <msjawemtxqykmbis625wctfjry7ycn77nxjjbibbck3m3atvsm@rfwow2ytmgtg>
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
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.
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.
> 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.
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.
Best Regards,
Marc
next prev parent reply other threads:[~2026-03-24 22:36 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 [this message]
2026-03-25 10:07 ` Joel Granados
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=20260324223640.807029-1-buermarc@googlemail.com \
--to=buermarc@googlemail.com \
--cc=davem@davemloft.net \
--cc=elias.rw2@gmail.com \
--cc=joel.granados@kernel.org \
--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