From: <rongqing.li@windriver.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH] btrfs: fix a overflowing boundary writing in csum_tree_block
Date: Tue, 9 Sep 2014 17:19:36 +0800 [thread overview]
Message-ID: <1410254376-6357-1-git-send-email-rongqing.li@windriver.com> (raw)
From: Li RongQing <roy.qing.li@gmail.com>
It is impossible that csum_size is larger than sizeof(long), but the codes
still add the handler for this condition, like allocate new memory, for
extension. If it becomes true someday, copying csum_size size memory to local
32bit variable found and val will overflow these two variables.
Fix it by returning the max 4 byte checksum.
Signed-off-by: Li RongQing <roy.qing.li@gmail.com>
---
fs/btrfs/disk-io.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index ce8b8b6..cfa2953 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -296,6 +296,8 @@ static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf,
if (memcmp_extent_buffer(buf, result, 0, csum_size)) {
u32 val;
u32 found = 0;
+
+ csum_size = min_t(u16, csum_size, sizeof(u32));
memcpy(&found, result, csum_size);
read_extent_buffer(buf, &val, 0, csum_size);
--
1.7.10.4
next reply other threads:[~2014-09-09 9:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-09 9:19 rongqing.li [this message]
2014-09-11 14:02 ` [PATCH] btrfs: fix a overflowing boundary writing in csum_tree_block Chris Mason
2014-09-12 1:50 ` Li RongQing
2014-09-29 15:55 ` David Sterba
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=1410254376-6357-1-git-send-email-rongqing.li@windriver.com \
--to=rongqing.li@windriver.com \
--cc=linux-btrfs@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).