public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: Jan Henrik Weinstock <jan@mwa.re>
Cc: adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org,
	linux-kernel@vger.kernel.org, lukas@mwa.re, simon@mwa.re
Subject: Re: [PATCH] ext4: fix kernel segfault after iterator overflow
Date: Thu, 27 Jun 2024 09:27:27 -0400	[thread overview]
Message-ID: <20240627132727.GB412555@mit.edu> (raw)
In-Reply-To: <20240627085601.24321-1-jan@mwa.re>

On Thu, Jun 27, 2024 at 10:56:01AM +0200, Jan Henrik Weinstock wrote:
> When search_buf gets placed at the end of the virtual address space
>         de = (struct ext4_dir_entry_2 *) ((char *) de + de_len);
> might overflow to zero and a subsequent loop iteration will crash.
> 
> Observed on a simulated riscv32 system using 2GB of memory and a rootfs
> on MMC.
> 
> Signed-off-by: Jan Henrik Weinstock <jan@mwa.re>

This is discussed earlier and the conclusion that it is a bug that on
RiscV architectures the kernel can hand out the last 4k page in the 
address space.  As Al Viro pointed out on this thread[1]:

>On Sat, Apr 13, 2024 at 07:46:03PM -0600, Andreas Dilger wrote:
>>
>> As to whether the 0xfffff000 address itself is valid for riscv32 is
>> outside my realm, but given that RAM is cheap it doesn't seem unlikely
>> to have 4GB+ of RAM and want to use it all.  The riscv32 might consider
>> reserving this page address from allocation to avoid similar issues in
>> other parts of the code, as is done with the NULL/0 page address.
>
>Not a chance.  *Any* page mapped there is a serious bug on any 32bit
>box.  Recall what ERR_PTR() is...
>
>On any architecture the virtual addresses in range (unsigned long)-512..
>(unsigned long)-1 must never resolve to valid kernel objects.
>In other words, any kind of wraparound here is asking for an oops on
>attempts to access the elements of buffer - kernel dereference of
>(char *)0xfffff000 on a 32bit box is already a bug.

[1] https://lore.kernel.org/all/878r1ibpdn.fsf@all.your.base.are.belong.to.us/

In any case, if on the RiscV platform the mm layer hands out a page at
the very end of the address space, there will be **all** sorts of
failures, not just in this particular ext4 codepath.  So this needs to
be fixed for RiscV in the mm layer.

Cheers,

					- Ted

      reply	other threads:[~2024-06-27 13:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-27  8:56 [PATCH] ext4: fix kernel segfault after iterator overflow Jan Henrik Weinstock
2024-06-27 13:27 ` Theodore Ts'o [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=20240627132727.GB412555@mit.edu \
    --to=tytso@mit.edu \
    --cc=adilger.kernel@dilger.ca \
    --cc=jan@mwa.re \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas@mwa.re \
    --cc=simon@mwa.re \
    /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