linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-ext4@vger.kernel.org
Cc: linux-fscrypt@vger.kernel.org,
	Harshad Shirwadkar <harshadshirwadkar@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH 3/7] ext4: fix leaking uninitialized memory in fast-commit journal
Date: Sun,  6 Nov 2022 14:48:37 -0800	[thread overview]
Message-ID: <20221106224841.279231-4-ebiggers@kernel.org> (raw)
In-Reply-To: <20221106224841.279231-1-ebiggers@kernel.org>

From: Eric Biggers <ebiggers@google.com>

When space at the end of fast-commit journal blocks is unused, make sure
to zero it out so that uninitialized memory is not leaked to disk.

Fixes: aa75f4d3daae ("ext4: main fast-commit commit path")
Cc: <stable@vger.kernel.org> # v5.10+
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 fs/ext4/fast_commit.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
index da0c8228cf9c3..1e8be05542396 100644
--- a/fs/ext4/fast_commit.c
+++ b/fs/ext4/fast_commit.c
@@ -737,6 +737,9 @@ static u8 *ext4_fc_reserve_space(struct super_block *sb, int len, u32 *crc)
 		*crc = ext4_chksum(sbi, *crc, tl, EXT4_FC_TAG_BASE_LEN);
 	if (pad_len > 0)
 		ext4_fc_memzero(sb, tl + 1, pad_len, crc);
+	/* Don't leak uninitialized memory in the unused last byte. */
+	*((u8 *)(tl + 1) + pad_len) = 0;
+
 	ext4_fc_submit_bh(sb, false);
 
 	ret = jbd2_fc_get_buf(EXT4_SB(sb)->s_journal, &bh);
@@ -793,6 +796,8 @@ static int ext4_fc_write_tail(struct super_block *sb, u32 crc)
 	dst += sizeof(tail.fc_tid);
 	tail.fc_crc = cpu_to_le32(crc);
 	ext4_fc_memcpy(sb, dst, &tail.fc_crc, sizeof(tail.fc_crc), NULL);
+	dst += sizeof(tail.fc_crc);
+	memset(dst, 0, bsize - off); /* Don't leak uninitialized memory. */
 
 	ext4_fc_submit_bh(sb, true);
 
-- 
2.38.1


  parent reply	other threads:[~2022-11-06 22:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-06 22:48 [PATCH 0/7] ext4 fast-commit fixes Eric Biggers
2022-11-06 22:48 ` [PATCH 1/7] ext4: disable fast-commit of encrypted dir operations Eric Biggers
2022-11-06 22:48 ` [PATCH 2/7] ext4: don't set up encryption key during jbd2 transaction Eric Biggers
2022-11-06 22:48 ` Eric Biggers [this message]
2022-11-06 22:48 ` [PATCH 4/7] ext4: add missing validation of fast-commit record lengths Eric Biggers
2022-11-06 22:48 ` [PATCH 5/7] ext4: fix unaligned memory access in ext4_fc_reserve_space() Eric Biggers
2022-11-06 22:48 ` [PATCH 6/7] ext4: fix off-by-one errors in fast-commit block filling Eric Biggers
2022-11-06 22:48 ` [PATCH 7/7] ext4: simplify fast-commit CRC calculation Eric Biggers
2022-11-16  1:18 ` [PATCH 0/7] ext4 fast-commit fixes Eric Biggers
2022-11-28 19:03   ` Eric Biggers
2022-12-06 21:04 ` Theodore Ts'o
2022-12-09 16:12   ` harshad shirwadkar

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-all 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=20221106224841.279231-4-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --cc=harshadshirwadkar@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).