From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [PATCH] resize.f2fs: fix access out-of memory boundary
Date: Fri, 23 Mar 2018 09:32:31 -0700 [thread overview]
Message-ID: <20180323163231.40244-1-jaegeuk@kernel.org> (raw)
This fixes out-of memory boundary on nat_bitmap, when resizing small to
large partition.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fsck/f2fs.h | 1 +
fsck/mount.c | 13 +++++++++----
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/fsck/f2fs.h b/fsck/f2fs.h
index 8a5ce36..d0e08aa 100644
--- a/fsck/f2fs.h
+++ b/fsck/f2fs.h
@@ -50,6 +50,7 @@ struct node_info {
struct f2fs_nm_info {
block_t nat_blkaddr;
+ block_t nat_blocks;
nid_t max_nid;
nid_t init_scan_nid;
nid_t next_scan_nid;
diff --git a/fsck/mount.c b/fsck/mount.c
index 545f862..a925bb9 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -998,7 +998,12 @@ void write_nat_bits(struct f2fs_sb_info *sbi,
(seg_off << get_sb(log_blocks_per_seg) << 1) +
(i & ((1 << get_sb(log_blocks_per_seg)) - 1)));
- if (f2fs_test_bit(i, nm_i->nat_bitmap))
+ /*
+ * Should consider new nat_blocks is larger than old
+ * nm_i->nat_blocks, since nm_i->nat_bitmap is based on
+ * old one.
+ */
+ if (i < nm_i->nat_blocks && f2fs_test_bit(i, nm_i->nat_bitmap))
blkaddr += (1 << get_sb(log_blocks_per_seg));
ret = dev_read_block(nat_block, blkaddr);
@@ -1037,14 +1042,14 @@ int init_node_manager(struct f2fs_sb_info *sbi)
struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
struct f2fs_nm_info *nm_i = NM_I(sbi);
unsigned char *version_bitmap;
- unsigned int nat_segs, nat_blocks;
+ unsigned int nat_segs;
nm_i->nat_blkaddr = get_sb(nat_blkaddr);
/* segment_count_nat includes pair segment so divide to 2. */
nat_segs = get_sb(segment_count_nat) >> 1;
- nat_blocks = nat_segs << get_sb(log_blocks_per_seg);
- nm_i->max_nid = NAT_ENTRY_PER_BLOCK * nat_blocks;
+ nm_i->nat_blocks = nat_segs << get_sb(log_blocks_per_seg);
+ nm_i->max_nid = NAT_ENTRY_PER_BLOCK * nm_i->nat_blocks;
nm_i->fcnt = 0;
nm_i->nat_cnt = 0;
nm_i->init_scan_nid = get_cp(next_free_nid);
--
2.15.0.531.g2ccb3012c9-goog
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
next reply other threads:[~2018-03-23 16:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-23 16:32 Jaegeuk Kim [this message]
2018-03-28 3:01 ` [PATCH] resize.f2fs: fix access out-of memory boundary Chao Yu
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=20180323163231.40244-1-jaegeuk@kernel.org \
--to=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
/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).