From: "Gary Guo" <gary@garyguo.net>
To: "Andreas Hindborg" <a.hindborg@kernel.org>,
"Gary Guo" <gary@garyguo.net>,
"Priya Bala Govindasamy" <pgovind2@uci.edu>,
"Breno Leitao" <leitao@debian.org>
Cc: <boqun@kernel.org>, <bjorn3_gh@protonmail.com>,
<lossin@kernel.org>, <aliceryhl@google.com>, <tmgross@umich.edu>,
<dakr@kernel.org>, <daniel.almeida@collabora.com>,
<tamird@kernel.org>, <acourbot@nvidia.com>, <work@onurozkan.dev>,
<rust-for-linux@vger.kernel.org>, <ardalan@uci.edu>,
<zhiyunq@cs.ucr.edu>, <dzueck@uci.edu>, <ojeda@kernel.org>
Subject: Re: [PATCH 0/1] rust: configfs: Fix reference creation from uninitialized data in `Attribute::show`
Date: Fri, 09 Oct 2026 23:15:37 +0100 [thread overview]
Message-ID: <DM0NKMDE2IVW.18JVM92P0V6D7@garyguo.net> (raw)
In-Reply-To: <87mrsmd37t.fsf@kernel.org>
On Fri Oct 9, 2026 at 9:32 PM BST, Andreas Hindborg wrote:
> "Gary Guo" <gary@garyguo.net> writes:
>
>> On Fri Oct 9, 2026 at 1:49 PM BST, Andreas Hindborg wrote:
>>> Andreas Hindborg <a.hindborg@kernel.org> writes:
>>>
>>> Actually there may be a problem, but I think it may be in C configfs. If
>>> you take a look at the function that reads data from the iov_iter:
>>>
>>> static int fill_write_buffer(struct configfs_buffer *buffer,
>>> struct iov_iter *from)
>>> {
>>> int copied;
>>>
>>> if (!buffer->page)
>>> buffer->page = kmalloc(PAGE_SIZE, GFP_KERNEL); // <- HERE
>>> if (!buffer->page)
>>> return -ENOMEM;
>>>
>>> copied = copy_from_iter(buffer->page, SIMPLE_ATTR_SIZE - 1, from);
>>> buffer->needs_read_fill = 1;
>>> /* if buf is assumed to contain a string, terminate it by \0,
>>> * so e.g. sscanf() can scan the string easily */
>>> buffer->page[copied] = 0;
>>> return copied ? : -EFAULT;
>>> }
>>>
>>> This function does not zero the page that is written into. This,
>>> combined with the buffer being per file handle means that you can read
>>> the original data in the page. The `kmalloc` should be probably be
>>> replaced with a `kzalloc`. This should be a problem for C modules as
>>> well.
>>
>> Why is this an issue? The extra uninitialized bytes should not be used.
>
> I guess you are right. In C, a driver just promise to not read beyond
> the write count. At any rate, it is a cheap defensive mechanism to
> kzalloc this buffer. It would prevent leaking uninitialized data to user
> space under a wrong length returned by the `show` implementation after a
> `store` operation.
>
> In rust it is an issue because the *driver* _may_ read the uninitialized
> bytes.
Well, the driver shouldn't read the bytes at all. It is supposed to *write* to
the slice. We probably want something like
https://docs.rs/tokio/latest/tokio/io/struct.ReadBuf.html
instead of a raw slice.
(Also, the name "page" for variable name is a bad one, it leaks the
implementation detail of configfs. This is just a buffer to avoid having drivers
dealing with iov itself.)
>
> So we can fix it on the Rust side with this patch from Priya. Or we can
> initialize the buffer on allocation in C.
Not really, we can just "declare" all bytes allocated by kmalloc is initialized,
but to unpredictable values.
>
> For the record, I did not notice that the buffer is per file open, which
> is why the bug is here in the first place.
>
> @Breno, should we zero this buffer on initialization on the C side, or
> do we just zero the buffer before calling into Rust driver code?
Of course, leaking any bytes to userspace is bad because this is kernel memory.
So one can argue that zeroing it would be a good hardening measure.
Best,
Gary
next prev parent reply other threads:[~2026-10-09 22:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cUqSvTsTaMYu_TRrAABCYTNz0HZf5JeFdIq_Vv4e_-GFMgI5NwVfZJDcy8CTgc4fH_1OoiiMg2I2LIzQX1y3Rg==@protonmail.internalid>
2026-10-08 23:42 ` [PATCH 0/1] rust: configfs: Fix reference creation from uninitialized data in `Attribute::show` Priya Bala Govindasamy
2026-10-08 23:42 ` [PATCH] " Priya Bala Govindasamy
[not found] ` <87v77bcg0m.fsf@kernel.org>
2026-10-09 12:49 ` [PATCH 0/1] " Andreas Hindborg
2026-10-09 12:54 ` Gary Guo
[not found] ` <f-SD-RJDAM9vxqOj3MupDr-geggiu7qcKsYBwlTK02DS6siKkRU643dmvGb-ihkpH5LKF6zW1DH2KHAmzXjvNg==@protonmail.internalid>
[not found] ` <CAPPBnEZBeB2cZ7_2Syt_Vy0HcXWrRF6j-M1HmZQwKkwG=1nz-Q@mail.gmail.com>
2026-10-09 20:17 ` Andreas Hindborg
2026-10-09 20:32 ` Andreas Hindborg
2026-10-09 22:15 ` Gary Guo [this message]
2026-10-09 21:19 ` Priya Bala Govindasamy
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=DM0NKMDE2IVW.18JVM92P0V6D7@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=ardalan@uci.edu \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dzueck@uci.edu \
--cc=leitao@debian.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=pgovind2@uci.edu \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
--cc=zhiyunq@cs.ucr.edu \
/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