From: "Marvin Häuser" <mhaeuser@posteo.de>
To: Pedro Falcato <pedro.falcato@gmail.com>
Cc: edk2-devel-groups-io <devel@edk2.groups.io>,
Savva Mitrofanov <savvamtr@gmail.com>
Subject: Re: [PATCH 1/3] Ext4Pkg: Fix out-of-bounds read in Ext4ReadDir
Date: Sat, 14 Jan 2023 17:05:57 +0000 [thread overview]
Message-ID: <7597DAF0-A613-4DA1-AC47-38C562425CE7@posteo.de> (raw)
In-Reply-To: <20230111235920.252317-3-pedro.falcato@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2060 bytes --]
Reviewed-by: Marvin Häuser <mhaeuser@posteo.de <mailto:mhaeuser@posteo.de>>
(Still two comments for next time)
> On 12. Jan 2023, at 00:59, Pedro Falcato <pedro.falcato@gmail.com> wrote:
>
> Fix an out-of-bounds read inside CompareMem() when
> checking for "." or ".." by explicitly bounding name_len
> to [0, 2] beforehand.
>
> Reported-by: Savva Mitrofanov <savvamtr@gmail.com>
> Fixes: 45e37d8533ca8 ("Ext4Pkg: Hide "." and ".." entries from Read() callers.")
> Cc: Marvin Häuser <mhaeuser@posteo.de>
> Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com>
> ---
> Features/Ext4Pkg/Ext4Dxe/Directory.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> diff --git a/Features/Ext4Pkg/Ext4Dxe/Directory.c b/Features/Ext4Pkg/Ext4Dxe/Directory.c
> index 4441e6d192b6..6ed664fc632f 100644
> --- a/Features/Ext4Pkg/Ext4Dxe/Directory.c
> +++ b/Features/Ext4Pkg/Ext4Dxe/Directory.c
> @@ -491,12 +491,14 @@ Ext4ReadDir (
> // or a checksum at the end of the directory block.
> // memcmp (and CompareMem) return 0 when the passed length is 0.
>
> - IsDotOrDotDot = Entry.name_len != 0 &&
> - (CompareMem (Entry.name, ".", Entry.name_len) == 0 ||
> - CompareMem (Entry.name, "..", Entry.name_len) == 0);
> + // We must bound name_len as > 0 and <= 2 to avoid any out-of-bounds accesses or bad detection of
"bad detection" = false positive?
> + // "." and "..".
> + IsDotOrDotDot = Entry.name_len > 0 && Entry.name_len <= 2 &&
> + CompareMem (Entry.name, "..", Entry.name_len) == 0;
>
> - // When inode = 0, it's unused.
> - ShouldSkip = Entry.inode == 0 || IsDotOrDotDot;
> + // When inode = 0, it's unused. When name_len == 0, it's a nameless entry
Inconsistency between "=" and "==".
> + // (which we should not expose to ReadDir).
> + ShouldSkip = Entry.inode == 0 || Entry.name_len == 0 || IsDotOrDotDot;
>
> if (ShouldSkip) {
> Offset += Entry.rec_len;
> --
> 2.39.0
>
[-- Attachment #2: Type: text/html, Size: 3162 bytes --]
next prev parent reply other threads:[~2023-01-14 17:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-11 23:59 [PATCH 0/3] Ext4Pkg: Small ext4 fixes and improvements Pedro Falcato
2023-01-11 23:59 ` [PATCH 1/2] Ext4Pkg: Add documentation surrounding ext4 directory entries Pedro Falcato
2023-01-11 23:59 ` [PATCH 1/3] Ext4Pkg: Fix out-of-bounds read in Ext4ReadDir Pedro Falcato
2023-01-14 17:05 ` Marvin Häuser [this message]
2023-01-11 23:59 ` [PATCH 2/3] Ext4Pkg: Add documentation surrounding ext4 directory entries Pedro Falcato
2023-01-14 17:10 ` Marvin Häuser
2023-01-11 23:59 ` [PATCH 2/2] Ext4Pkg: Fix and clarify handling regarding non-utf8 dir entries Pedro Falcato
2023-01-11 23:59 ` [PATCH 3/3] " Pedro Falcato
2023-01-14 17:13 ` Marvin Häuser
[not found] ` <1739669F06B92E95.23170@groups.io>
2023-01-12 0:04 ` [edk2-devel] [PATCH 2/3] Ext4Pkg: Add documentation surrounding ext4 directory entries Pedro Falcato
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-list 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=7597DAF0-A613-4DA1-AC47-38C562425CE7@posteo.de \
--to=devel@edk2.groups.io \
/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