linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] e2fsck: do not read EA header beyond the end of an inode
@ 2015-11-26 19:24 Artemiy Volkov
  2015-11-26 20:23 ` [PATCH v2] " Artemiy Volkov
  0 siblings, 1 reply; 5+ messages in thread
From: Artemiy Volkov @ 2015-11-26 19:24 UTC (permalink / raw)
  To: linux-ext4; +Cc: Artemiy Volkov

In check_inode_extra_space(), if we attempt to read an EA header at
the end of the extra space, in a corrupted filesystem it may result in
a read beyond the bounds of the inode. Add a check to prevent this.

Reproduced by running ./test_one --valgrind f_write_ea_toobig_extra_isize.

Signed-off-by: Artemiy Volkov <artemiyv@acm.org>
---
 e2fsck/pass1.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c
index 0a8e23e..f1c99ea 100644
--- a/e2fsck/pass1.c
+++ b/e2fsck/pass1.c
@@ -482,6 +482,10 @@ static void check_inode_extra_space(e2fsck_t ctx, struct problem_context *pctx)
                return;
        }

+        /* check if there is no place for an EA header */
+        if (inode->i_extra_isize >= max - sizeof(__u32))
+                return;
+
        eamagic = (__u32 *) (((char *) inode) + EXT2_GOOD_OLD_INODE_SIZE +
                        inode->i_extra_isize);
        if (*eamagic == EXT2_EXT_ATTR_MAGIC) {
-- 
2.6.2

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

* [PATCH v2] e2fsck: do not read EA header beyond the end of an inode
  2015-11-26 19:24 [PATCH] e2fsck: do not read EA header beyond the end of an inode Artemiy Volkov
@ 2015-11-26 20:23 ` Artemiy Volkov
  2015-11-26 20:59   ` [PATCH v3] " Artemiy Volkov
  0 siblings, 1 reply; 5+ messages in thread
From: Artemiy Volkov @ 2015-11-26 20:23 UTC (permalink / raw)
  To: linux-ext4; +Cc: Artemiy Volkov

In check_inode_extra_space(), if we attempt to read an EA header at
the end of the extra space, in a corrupted filesystem it may result in
a read beyond the bounds of the inode. Add a check to prevent this.

Reproduced by running ./test_one --valgrind f_write_ea_toobig_extra_isize.

Signed-off-by: Artemiy Volkov <artemiyv@acm.org>
---

A quick fix to v1 which wrongly uses spaces instead of tabs.

 e2fsck/pass1.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c
index 0a8e23e..71ea943 100644
--- a/e2fsck/pass1.c
+++ b/e2fsck/pass1.c
@@ -482,6 +482,10 @@ static void check_inode_extra_space(e2fsck_t ctx, struct problem_context *pctx)
 		return;
 	}
 
+	/* check if there is no place for an EA header */
+	if (inode->i_extra_size >= max - sizeof(__u32))
+		return;
+
 	eamagic = (__u32 *) (((char *) inode) + EXT2_GOOD_OLD_INODE_SIZE +
 			inode->i_extra_isize);
 	if (*eamagic == EXT2_EXT_ATTR_MAGIC) {
-- 
1.7.10.4


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

* [PATCH v3] e2fsck: do not read EA header beyond the end of an inode
  2015-11-26 20:23 ` [PATCH v2] " Artemiy Volkov
@ 2015-11-26 20:59   ` Artemiy Volkov
  2015-11-28 21:54     ` Darrick J. Wong
  2015-11-30 17:06     ` Theodore Ts'o
  0 siblings, 2 replies; 5+ messages in thread
From: Artemiy Volkov @ 2015-11-26 20:59 UTC (permalink / raw)
  To: linux-ext4; +Cc: Artemiy Volkov

In check_inode_extra_space(), if we attempt to read an EA header at
the end of the extra space, in a corrupted filesystem it may result in
a read beyond the bounds of the inode. Add a check to prevent this.

Reproduced by running ./test_one --valgrind f_write_ea_toobig_extra_isize.

Signed-off-by: Artemiy Volkov <artemiyv@acm.org>
---

A quick fix to v1 which wrongly uses spaces instead of tabs.
Correct a nonexistent struct ext2_inode_large field name used in v2.

 e2fsck/pass1.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c
index 0a8e23e..71ea943 100644
--- a/e2fsck/pass1.c
+++ b/e2fsck/pass1.c
@@ -482,6 +482,10 @@ static void check_inode_extra_space(e2fsck_t ctx, struct problem_context *pctx)
 		return;
 	}
 
+	/* check if there is no place for an EA header */
+	if (inode->i_extra_isize >= max - sizeof(__u32))
+		return;
+
 	eamagic = (__u32 *) (((char *) inode) + EXT2_GOOD_OLD_INODE_SIZE +
 			inode->i_extra_isize);
 	if (*eamagic == EXT2_EXT_ATTR_MAGIC) {
-- 
1.7.10.4


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

* Re: [PATCH v3] e2fsck: do not read EA header beyond the end of an inode
  2015-11-26 20:59   ` [PATCH v3] " Artemiy Volkov
@ 2015-11-28 21:54     ` Darrick J. Wong
  2015-11-30 17:06     ` Theodore Ts'o
  1 sibling, 0 replies; 5+ messages in thread
From: Darrick J. Wong @ 2015-11-28 21:54 UTC (permalink / raw)
  To: Artemiy Volkov; +Cc: linux-ext4

On Thu, Nov 26, 2015 at 08:59:54PM +0000, Artemiy Volkov wrote:
> In check_inode_extra_space(), if we attempt to read an EA header at
> the end of the extra space, in a corrupted filesystem it may result in
> a read beyond the bounds of the inode. Add a check to prevent this.
> 
> Reproduced by running ./test_one --valgrind f_write_ea_toobig_extra_isize.
> 
> Signed-off-by: Artemiy Volkov <artemiyv@acm.org>
> ---
> 
> A quick fix to v1 which wrongly uses spaces instead of tabs.
> Correct a nonexistent struct ext2_inode_large field name used in v2.
> 
>  e2fsck/pass1.c |    4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c
> index 0a8e23e..71ea943 100644
> --- a/e2fsck/pass1.c
> +++ b/e2fsck/pass1.c
> @@ -482,6 +482,10 @@ static void check_inode_extra_space(e2fsck_t ctx, struct problem_context *pctx)
>  		return;
>  	}
>  
> +	/* check if there is no place for an EA header */
> +	if (inode->i_extra_isize >= max - sizeof(__u32))
> +		return;
> +

Looks reasonable enough.
Acked-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

>  	eamagic = (__u32 *) (((char *) inode) + EXT2_GOOD_OLD_INODE_SIZE +
>  			inode->i_extra_isize);
>  	if (*eamagic == EXT2_EXT_ATTR_MAGIC) {
> -- 
> 1.7.10.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH v3] e2fsck: do not read EA header beyond the end of an inode
  2015-11-26 20:59   ` [PATCH v3] " Artemiy Volkov
  2015-11-28 21:54     ` Darrick J. Wong
@ 2015-11-30 17:06     ` Theodore Ts'o
  1 sibling, 0 replies; 5+ messages in thread
From: Theodore Ts'o @ 2015-11-30 17:06 UTC (permalink / raw)
  To: Artemiy Volkov; +Cc: linux-ext4

On Thu, Nov 26, 2015 at 08:59:54PM +0000, Artemiy Volkov wrote:
> In check_inode_extra_space(), if we attempt to read an EA header at
> the end of the extra space, in a corrupted filesystem it may result in
> a read beyond the bounds of the inode. Add a check to prevent this.
> 
> Reproduced by running ./test_one --valgrind f_write_ea_toobig_extra_isize.
> 
> Signed-off-by: Artemiy Volkov <artemiyv@acm.org>

Applied, thanks.

					- Ted

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

end of thread, other threads:[~2015-11-30 17:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-26 19:24 [PATCH] e2fsck: do not read EA header beyond the end of an inode Artemiy Volkov
2015-11-26 20:23 ` [PATCH v2] " Artemiy Volkov
2015-11-26 20:59   ` [PATCH v3] " Artemiy Volkov
2015-11-28 21:54     ` Darrick J. Wong
2015-11-30 17:06     ` Theodore Ts'o

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).