All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] A couple recent ext4 CVE fixes
@ 2018-10-06  0:55 Daniel Rosenberg
  2018-10-06  0:55 ` [PATCH 1/2] ext4: add corruption check in ext4_xattr_set_entry() Daniel Rosenberg
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Daniel Rosenberg @ 2018-10-06  0:55 UTC (permalink / raw)
  To: stable; +Cc: Daniel Rosenberg

A couple ext4-related CVE fixes were released to other kernels in
linux-stable, but didn't cleanly apply to 4.9.y. These are adjusted
cherry-picks of Ben Hutching's 3.16.y backports.

Theodore Ts'o (2):
  ext4: add corruption check in ext4_xattr_set_entry()
  ext4: always verify the magic number in xattr blocks

 fs/ext4/xattr.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

-- 
2.19.0.605.g01d371f741-goog

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

* [PATCH 1/2] ext4: add corruption check in ext4_xattr_set_entry()
  2018-10-06  0:55 [PATCH 0/2] A couple recent ext4 CVE fixes Daniel Rosenberg
@ 2018-10-06  0:55 ` Daniel Rosenberg
  2018-10-06  0:55 ` [PATCH 2/2] ext4: always verify the magic number in xattr blocks Daniel Rosenberg
  2018-10-11  9:19 ` [PATCH 0/2] A couple recent ext4 CVE fixes Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: Daniel Rosenberg @ 2018-10-06  0:55 UTC (permalink / raw)
  To: stable; +Cc: Theodore Ts'o, Ben Hutchings, Daniel Rosenberg

From: Theodore Ts'o <tytso@mit.edu>

commit 5369a762c882c0b6e9599e4ebbb3a9ba9eee7e2d upstream.

In theory this should have been caught earlier when the xattr list was
verified, but in case it got missed, it's simple enough to add check
to make sure we don't overrun the xattr buffer.

This addresses CVE-2018-10879.

https://bugzilla.kernel.org/show_bug.cgi?id=200001

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
[bwh: Backported to 3.16:
 - Add inode parameter to ext4_xattr_set_entry() and update callers
 - Return -EIO instead of -EFSCORRUPTED on error
 - Adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
[adjusted context for 4.9]
Signed-off-by: Daniel Rosenberg <drosen@google.com>
---
 fs/ext4/xattr.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index c19c96840480a..2888fc6527908 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -645,14 +645,20 @@ static size_t ext4_xattr_free_space(struct ext4_xattr_entry *last,
 }
 
 static int
-ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s)
+ext4_xattr_set_entry(struct ext4_xattr_info *i, struct ext4_xattr_search *s,
+		     struct inode *inode)
 {
-	struct ext4_xattr_entry *last;
+	struct ext4_xattr_entry *last, *next;
 	size_t free, min_offs = s->end - s->base, name_len = strlen(i->name);
 
 	/* Compute min_offs and last. */
 	last = s->first;
-	for (; !IS_LAST_ENTRY(last); last = EXT4_XATTR_NEXT(last)) {
+	for (; !IS_LAST_ENTRY(last); last = next) {
+		next = EXT4_XATTR_NEXT(last);
+		if ((void *)next >= s->end) {
+			EXT4_ERROR_INODE(inode, "corrupted xattr entries");
+			return -EIO;
+		}
 		if (last->e_value_size) {
 			size_t offs = le16_to_cpu(last->e_value_offs);
 			if (offs < min_offs)
@@ -834,7 +840,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
 			mb_cache_entry_delete_block(ext4_mb_cache, hash,
 						    bs->bh->b_blocknr);
 			ea_bdebug(bs->bh, "modifying in-place");
-			error = ext4_xattr_set_entry(i, s);
+			error = ext4_xattr_set_entry(i, s, inode);
 			if (!error) {
 				if (!IS_LAST_ENTRY(s->first))
 					ext4_xattr_rehash(header(s->base),
@@ -881,7 +887,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
 		s->end = s->base + sb->s_blocksize;
 	}
 
-	error = ext4_xattr_set_entry(i, s);
+	error = ext4_xattr_set_entry(i, s, inode);
 	if (error == -EFSCORRUPTED)
 		goto bad_block;
 	if (error)
@@ -1079,7 +1085,7 @@ int ext4_xattr_ibody_inline_set(handle_t *handle, struct inode *inode,
 
 	if (EXT4_I(inode)->i_extra_isize == 0)
 		return -ENOSPC;
-	error = ext4_xattr_set_entry(i, s);
+	error = ext4_xattr_set_entry(i, s, inode);
 	if (error) {
 		if (error == -ENOSPC &&
 		    ext4_has_inline_data(inode)) {
@@ -1091,7 +1097,7 @@ int ext4_xattr_ibody_inline_set(handle_t *handle, struct inode *inode,
 			error = ext4_xattr_ibody_find(inode, i, is);
 			if (error)
 				return error;
-			error = ext4_xattr_set_entry(i, s);
+			error = ext4_xattr_set_entry(i, s, inode);
 		}
 		if (error)
 			return error;
@@ -1117,7 +1123,7 @@ static int ext4_xattr_ibody_set(handle_t *handle, struct inode *inode,
 
 	if (EXT4_I(inode)->i_extra_isize == 0)
 		return -ENOSPC;
-	error = ext4_xattr_set_entry(i, s);
+	error = ext4_xattr_set_entry(i, s, inode);
 	if (error)
 		return error;
 	header = IHDR(inode, ext4_raw_inode(&is->iloc));
-- 
2.19.0.605.g01d371f741-goog

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

* [PATCH 2/2] ext4: always verify the magic number in xattr blocks
  2018-10-06  0:55 [PATCH 0/2] A couple recent ext4 CVE fixes Daniel Rosenberg
  2018-10-06  0:55 ` [PATCH 1/2] ext4: add corruption check in ext4_xattr_set_entry() Daniel Rosenberg
@ 2018-10-06  0:55 ` Daniel Rosenberg
  2018-10-11  9:19 ` [PATCH 0/2] A couple recent ext4 CVE fixes Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: Daniel Rosenberg @ 2018-10-06  0:55 UTC (permalink / raw)
  To: stable; +Cc: Theodore Ts'o, Daniel Rosenberg

From: Theodore Ts'o <tytso@mit.edu>

commit 513f86d73855ce556ea9522b6bfd79f87356dc3a upstream.

If there an inode points to a block which is also some other type of
metadata block (such as a block allocation bitmap), the
buffer_verified flag can be set when it was validated as that other
metadata block type; however, it would make a really terrible external
attribute block.  The reason why we use the verified flag is to avoid
constantly reverifying the block.  However, it doesn't take much
overhead to make sure the magic number of the xattr block is correct,
and this will avoid potential crashes.

This addresses CVE-2018-10879.

https://bugzilla.kernel.org/show_bug.cgi?id=200001

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
[Backported to 4.9: adjust context]
Signed-off-by: Daniel Rosenberg <drosen@google.com>
---
 fs/ext4/xattr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 2888fc6527908..c10180d0b0189 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -209,12 +209,12 @@ ext4_xattr_check_block(struct inode *inode, struct buffer_head *bh)
 {
 	int error;
 
-	if (buffer_verified(bh))
-		return 0;
-
 	if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) ||
 	    BHDR(bh)->h_blocks != cpu_to_le32(1))
 		return -EFSCORRUPTED;
+	if (buffer_verified(bh))
+		return 0;
+
 	if (!ext4_xattr_block_csum_verify(inode, bh))
 		return -EFSBADCRC;
 	error = ext4_xattr_check_names(BFIRST(bh), bh->b_data + bh->b_size,
-- 
2.19.0.605.g01d371f741-goog

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

* Re: [PATCH 0/2] A couple recent ext4 CVE fixes
  2018-10-06  0:55 [PATCH 0/2] A couple recent ext4 CVE fixes Daniel Rosenberg
  2018-10-06  0:55 ` [PATCH 1/2] ext4: add corruption check in ext4_xattr_set_entry() Daniel Rosenberg
  2018-10-06  0:55 ` [PATCH 2/2] ext4: always verify the magic number in xattr blocks Daniel Rosenberg
@ 2018-10-11  9:19 ` Greg KH
  2 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2018-10-11  9:19 UTC (permalink / raw)
  To: Daniel Rosenberg; +Cc: stable

On Fri, Oct 05, 2018 at 05:55:52PM -0700, Daniel Rosenberg wrote:
> A couple ext4-related CVE fixes were released to other kernels in
> linux-stable, but didn't cleanly apply to 4.9.y. These are adjusted
> cherry-picks of Ben Hutching's 3.16.y backports.

Now applied, thanks.

greg k-h

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

* [PATCH 2/2] ext4: always verify the magic number in xattr blocks
  2018-10-06  0:51 Daniel Rosenberg
@ 2018-10-06  0:51 ` Daniel Rosenberg
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Rosenberg @ 2018-10-06  0:51 UTC (permalink / raw)
  To: stable; +Cc: Theodore Ts'o, Daniel Rosenberg

From: Theodore Ts'o <tytso@mit.edu>

commit 513f86d73855ce556ea9522b6bfd79f87356dc3a upstream.

If there an inode points to a block which is also some other type of
metadata block (such as a block allocation bitmap), the
buffer_verified flag can be set when it was validated as that other
metadata block type; however, it would make a really terrible external
attribute block.  The reason why we use the verified flag is to avoid
constantly reverifying the block.  However, it doesn't take much
overhead to make sure the magic number of the xattr block is correct,
and this will avoid potential crashes.

This addresses CVE-2018-10879.

https://bugzilla.kernel.org/show_bug.cgi?id=200001

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
[Backported to 4.4: adjust context]
Signed-off-by: Daniel Rosenberg <drosen@google.com>
---
 fs/ext4/xattr.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index b1a2d1cd23e55..ba2a12b34ff16 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -220,12 +220,12 @@ ext4_xattr_check_block(struct inode *inode, struct buffer_head *bh)
 {
 	int error;
 
-	if (buffer_verified(bh))
-		return 0;
-
 	if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) ||
 	    BHDR(bh)->h_blocks != cpu_to_le32(1))
 		return -EFSCORRUPTED;
+	if (buffer_verified(bh))
+		return 0;
+
 	if (!ext4_xattr_block_csum_verify(inode, bh->b_blocknr, BHDR(bh)))
 		return -EFSBADCRC;
 	error = ext4_xattr_check_names(BFIRST(bh), bh->b_data + bh->b_size,
-- 
2.19.0.605.g01d371f741-goog

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

end of thread, other threads:[~2018-10-11 16:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-06  0:55 [PATCH 0/2] A couple recent ext4 CVE fixes Daniel Rosenberg
2018-10-06  0:55 ` [PATCH 1/2] ext4: add corruption check in ext4_xattr_set_entry() Daniel Rosenberg
2018-10-06  0:55 ` [PATCH 2/2] ext4: always verify the magic number in xattr blocks Daniel Rosenberg
2018-10-11  9:19 ` [PATCH 0/2] A couple recent ext4 CVE fixes Greg KH
  -- strict thread matches above, loose matches on Subject: below --
2018-10-06  0:51 Daniel Rosenberg
2018-10-06  0:51 ` [PATCH 2/2] ext4: always verify the magic number in xattr blocks Daniel Rosenberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.