linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] e2fsck: Fix access after free for dx_db structure
@ 2017-10-30 13:32 Artem Blagodarenko
  2017-11-03 20:00 ` Andreas Dilger
  0 siblings, 1 reply; 2+ messages in thread
From: Artem Blagodarenko @ 2017-10-30 13:32 UTC (permalink / raw)
  To: linux-ext4; +Cc: adilger.kernel

dx_db structure is freed after fixing of PR_2_HTREE_BAD_ROOT
problem. Next code block use this structure to unerstand if leaf
is beeng processed.

If dx_db is freed, then root block is being processed and if_leaf
need to be set to 0.

Signed-off-by: Artem Blagodarenko <artem.blagodarenko@gmail.com>
---
 e2fsck/pass2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c
index 09c16179..7bda37a7 100644
--- a/e2fsck/pass2.c
+++ b/e2fsck/pass2.c
@@ -1109,7 +1109,7 @@ inline_read_fail:
 			    ((fs->blocksize - (8 + dx_csum_size)) /
 			     sizeof(struct ext2_dx_entry))))
 			dx_db->type = DX_DIRBLOCK_NODE;
-		is_leaf = (dx_db->type == DX_DIRBLOCK_LEAF);
+		is_leaf = dx_db ? (dx_db->type == DX_DIRBLOCK_LEAF) : 0;
 	}
 out_htree:
 
-- 
2.13.5 (Apple Git-94)

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

* Re: [PATCH] e2fsck: Fix access after free for dx_db structure
  2017-10-30 13:32 [PATCH] e2fsck: Fix access after free for dx_db structure Artem Blagodarenko
@ 2017-11-03 20:00 ` Andreas Dilger
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Dilger @ 2017-11-03 20:00 UTC (permalink / raw)
  To: Artem Blagodarenko; +Cc: linux-ext4, adilger.kernel

[-- Attachment #1: Type: text/plain, Size: 1533 bytes --]


> On Oct 30, 2017, at 7:32 AM, Artem Blagodarenko <artem.blagodarenko@gmail.com> wrote:
> 
> dx_db structure is freed after fixing of PR_2_HTREE_BAD_ROOT
> problem. Next code block use this structure to unerstand if leaf
> is beeng processed.
> 
> If dx_db is freed, then root block is being processed and if_leaf
> need to be set to 0.
> 
> Signed-off-by: Artem Blagodarenko <artem.blagodarenko@gmail.com>
> ---
> e2fsck/pass2.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c
> index 09c16179..7bda37a7 100644
> --- a/e2fsck/pass2.c
> +++ b/e2fsck/pass2.c
> @@ -1109,7 +1109,7 @@ inline_read_fail:
> 			    ((fs->blocksize - (8 + dx_csum_size)) /
> 			     sizeof(struct ext2_dx_entry))))
> 			dx_db->type = DX_DIRBLOCK_NODE;
> -		is_leaf = (dx_db->type == DX_DIRBLOCK_LEAF);
> +		is_leaf = dx_db ? (dx_db->type == DX_DIRBLOCK_LEAF) : 0;

Ah, this code is a bit confusing.  From looking at this patch, and even
looking at the code directly, I thought "the previous line is also
accessing dx_db, so what is the problem?"  However, there really IS a
problem, because the previous line is part of a different if/else block.

It would be good to add braces around the "else" part of the condition
to make it clear that this is a separate block of code, which is why we
typically ask for matching braces for both legs of an if/else block.  It
would also be good to set "dx_db = NULL" instead of setting it to "0".

Cheers, Andreas






[-- Attachment #2: Message signed with OpenPGP --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

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

end of thread, other threads:[~2017-11-03 20:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-30 13:32 [PATCH] e2fsck: Fix access after free for dx_db structure Artem Blagodarenko
2017-11-03 20:00 ` Andreas Dilger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).