public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib/ext2fs: Validity checks for ext2fs_inode_scan_goto_blockgroup()
@ 2023-12-01  0:01 Brian Norris
  2023-12-01 16:24 ` Darrick J. Wong
  0 siblings, 1 reply; 4+ messages in thread
From: Brian Norris @ 2023-12-01  0:01 UTC (permalink / raw)
  To: Theodore Ts'o; +Cc: linux-ext4, Brian Norris

We don't validate the 'group' argument, so it's easy to get underflows
or crashes here.

This resolves issues seen in ureadahead, when it uses an old packfile
(with mismatching group indices) with a new filesystem.

Signed-off-by: Brian Norris <briannorris@chromium.org>
---

 lib/ext2fs/inode.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/ext2fs/inode.c b/lib/ext2fs/inode.c
index 957d5aa9f9d6..96d854b5fb69 100644
--- a/lib/ext2fs/inode.c
+++ b/lib/ext2fs/inode.c
@@ -313,6 +313,9 @@ static errcode_t get_next_blockgroup(ext2_inode_scan scan)
 errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
 					    int	group)
 {
+	if (group <= 0 || group >= scan->fs->group_desc_count)
+		return EXT2_ET_INVALID_ARGUMENT;
+
 	scan->current_group = group - 1;
 	scan->groups_left = scan->fs->group_desc_count - group;
 	scan->bad_block_ptr = 0;
-- 
2.43.0.rc2.451.g8631bc7472-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] lib/ext2fs: Validity checks for ext2fs_inode_scan_goto_blockgroup()
  2023-12-01  0:01 [PATCH] lib/ext2fs: Validity checks for ext2fs_inode_scan_goto_blockgroup() Brian Norris
@ 2023-12-01 16:24 ` Darrick J. Wong
  2023-12-01 17:30   ` Brian Norris
  0 siblings, 1 reply; 4+ messages in thread
From: Darrick J. Wong @ 2023-12-01 16:24 UTC (permalink / raw)
  To: Brian Norris; +Cc: Theodore Ts'o, linux-ext4

On Thu, Nov 30, 2023 at 04:01:18PM -0800, Brian Norris wrote:
> We don't validate the 'group' argument, so it's easy to get underflows
> or crashes here.
> 
> This resolves issues seen in ureadahead, when it uses an old packfile
> (with mismatching group indices) with a new filesystem.

Say what now?  The boot time pre-caching thing Ubuntu used to have?
https://manpages.ubuntu.com/manpages/trusty/man8/ureadahead.8.html

--D

> Signed-off-by: Brian Norris <briannorris@chromium.org>
> ---
> 
>  lib/ext2fs/inode.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/ext2fs/inode.c b/lib/ext2fs/inode.c
> index 957d5aa9f9d6..96d854b5fb69 100644
> --- a/lib/ext2fs/inode.c
> +++ b/lib/ext2fs/inode.c
> @@ -313,6 +313,9 @@ static errcode_t get_next_blockgroup(ext2_inode_scan scan)
>  errcode_t ext2fs_inode_scan_goto_blockgroup(ext2_inode_scan scan,
>  					    int	group)
>  {
> +	if (group <= 0 || group >= scan->fs->group_desc_count)
> +		return EXT2_ET_INVALID_ARGUMENT;
> +
>  	scan->current_group = group - 1;
>  	scan->groups_left = scan->fs->group_desc_count - group;
>  	scan->bad_block_ptr = 0;
> -- 
> 2.43.0.rc2.451.g8631bc7472-goog
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] lib/ext2fs: Validity checks for ext2fs_inode_scan_goto_blockgroup()
  2023-12-01 16:24 ` Darrick J. Wong
@ 2023-12-01 17:30   ` Brian Norris
  2023-12-02 17:10     ` Darrick J. Wong
  0 siblings, 1 reply; 4+ messages in thread
From: Brian Norris @ 2023-12-01 17:30 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: Theodore Ts'o, linux-ext4

On Fri, Dec 1, 2023 at 8:24 AM Darrick J. Wong <djwong@kernel.org> wrote:
> On Thu, Nov 30, 2023 at 04:01:18PM -0800, Brian Norris wrote:
> > This resolves issues seen in ureadahead, when it uses an old packfile
> > (with mismatching group indices) with a new filesystem.
>
> Say what now?  The boot time pre-caching thing Ubuntu used to have?
> https://manpages.ubuntu.com/manpages/trusty/man8/ureadahead.8.html

Sure. ChromeOS still uses it. Steven Rostedt even bothered to do a
talk about it recently:
https://eoss2023.sched.com/event/1LcMw/the-resurrection-of-ureadahead-and-speeding-up-the-boot-process-and-preloading-applications-steven-rostedt-google

Brian

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] lib/ext2fs: Validity checks for ext2fs_inode_scan_goto_blockgroup()
  2023-12-01 17:30   ` Brian Norris
@ 2023-12-02 17:10     ` Darrick J. Wong
  0 siblings, 0 replies; 4+ messages in thread
From: Darrick J. Wong @ 2023-12-02 17:10 UTC (permalink / raw)
  To: Brian Norris; +Cc: Theodore Ts'o, linux-ext4

On Fri, Dec 01, 2023 at 09:30:38AM -0800, Brian Norris wrote:
> On Fri, Dec 1, 2023 at 8:24 AM Darrick J. Wong <djwong@kernel.org> wrote:
> > On Thu, Nov 30, 2023 at 04:01:18PM -0800, Brian Norris wrote:
> > > This resolves issues seen in ureadahead, when it uses an old packfile
> > > (with mismatching group indices) with a new filesystem.
> >
> > Say what now?  The boot time pre-caching thing Ubuntu used to have?
> > https://manpages.ubuntu.com/manpages/trusty/man8/ureadahead.8.html
> 
> Sure. ChromeOS still uses it. Steven Rostedt even bothered to do a
> talk about it recently:
> https://eoss2023.sched.com/event/1LcMw/the-resurrection-of-ureadahead-and-speeding-up-the-boot-process-and-preloading-applications-steven-rostedt-google

Wow.  I had no idea that ureadahead reads the inode blocks of a mounted
ext* filesystem into the page cache.  Welp, it's a good thing those are
part of the static layout.

Anyway, this fix looks correct to me, so I don't see any reason to hold
this up...
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> 
> Brian
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-02 17:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-01  0:01 [PATCH] lib/ext2fs: Validity checks for ext2fs_inode_scan_goto_blockgroup() Brian Norris
2023-12-01 16:24 ` Darrick J. Wong
2023-12-01 17:30   ` Brian Norris
2023-12-02 17:10     ` Darrick J. Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox