Skip to content

Commit 0d28544

Browse files
committed
Merge tag 'f2fs-for-v5.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs
Pull f2fs updates from Jaegeuk Kim: "Another round of various bug fixes came in. Damien improved SMR drive support a bit, and Chao replaced BUG_ON() with reporting errors to user since we've not hit from users but did hit from crafted images. We've found a disk layout bug in large_nat_bits feature which supports very large NAT entries enabled at mkfs. If the feature is enabled, it will give a notice to run fsck to correct the on-disk layout. Enhancements: - reduce memory consumption for SMR drive - better discard handling for multiple partitions - tracepoints for f2fs_file_write_iter/f2fs_filemap_fault - allow to change CP_CHKSUM_OFFSET - detect wrong layout of large_nat_bitmap feature - enhance checking valid data indices Bug fixes: - Multiple partition support for SMR drive - deadlock problem in f2fs_balance_fs_bg - add boundary checks to fix abnormal behaviors on fuzzed images - inline_xattr space calculations - replace f2fs_bug_on with errors In addition, this series contains various memory boundary check and sanity check of on-disk consistency" * tag 'f2fs-for-v5.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (40 commits) f2fs: fix to avoid accessing xattr across the boundary f2fs: fix to avoid potential race on sbi->unusable_block_count access/update f2fs: add tracepoint for f2fs_filemap_fault() f2fs: introduce DATA_GENERIC_ENHANCE f2fs: fix to handle error in f2fs_disable_checkpoint() f2fs: remove redundant check in f2fs_file_write_iter() f2fs: fix to be aware of readonly device in write_checkpoint() f2fs: fix to skip recovery on readonly device f2fs: fix to consider multiple device for readonly check f2fs: relocate chksum_offset for large_nat_bitmap feature f2fs: allow unfixed f2fs_checkpoint.checksum_offset f2fs: Replace spaces with tab f2fs: insert space before the open parenthesis '(' f2fs: allow address pointer number of dnode aligning to specified size f2fs: introduce f2fs_read_single_page() for cleanup f2fs: mark is_extension_exist() inline f2fs: fix to set FI_UPDATE_WRITE correctly f2fs: fix to avoid panic in f2fs_inplace_write_data() f2fs: fix to do sanity check on valid block count of segment f2fs: fix to do sanity check on valid node/block count ...
2 parents fa4bff1 + 2777e65 commit 0d28544

18 files changed

Lines changed: 688 additions & 302 deletions

File tree

‎fs/f2fs/acl.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static int f2fs_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
285285
/* assert(atomic_read(acl->a_refcount) == 1); */
286286

287287
FOREACH_ACL_ENTRY(pa, acl, pe) {
288-
switch(pa->e_tag) {
288+
switch (pa->e_tag) {
289289
case ACL_USER_OBJ:
290290
pa->e_perm &= (mode >> 6) | ~S_IRWXO;
291291
mode &= (pa->e_perm << 6) | ~S_IRWXU;
@@ -326,7 +326,7 @@ static int f2fs_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
326326
}
327327

328328
*mode_p = (*mode_p & ~S_IRWXUGO) | mode;
329-
return not_equiv;
329+
return not_equiv;
330330
}
331331

332332
static int f2fs_acl_create(struct inode *dir, umode_t *mode,

‎fs/f2fs/checkpoint.c‎

Lines changed: 86 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static struct page *__get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index,
6666
.old_blkaddr = index,
6767
.new_blkaddr = index,
6868
.encrypted_page = NULL,
69-
.is_meta = is_meta,
69+
.is_por = !is_meta,
7070
};
7171
int err;
7272

@@ -130,6 +130,30 @@ struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index)
130130
return __get_meta_page(sbi, index, false);
131131
}
132132

133+
static bool __is_bitmap_valid(struct f2fs_sb_info *sbi, block_t blkaddr,
134+
int type)
135+
{
136+
struct seg_entry *se;
137+
unsigned int segno, offset;
138+
bool exist;
139+
140+
if (type != DATA_GENERIC_ENHANCE && type != DATA_GENERIC_ENHANCE_READ)
141+
return true;
142+
143+
segno = GET_SEGNO(sbi, blkaddr);
144+
offset = GET_BLKOFF_FROM_SEG0(sbi, blkaddr);
145+
se = get_seg_entry(sbi, segno);
146+
147+
exist = f2fs_test_bit(offset, se->cur_valid_map);
148+
if (!exist && type == DATA_GENERIC_ENHANCE) {
149+
f2fs_msg(sbi->sb, KERN_ERR, "Inconsistent error "
150+
"blkaddr:%u, sit bitmap:%d", blkaddr, exist);
151+
set_sbi_flag(sbi, SBI_NEED_FSCK);
152+
WARN_ON(1);
153+
}
154+
return exist;
155+
}
156+
133157
bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
134158
block_t blkaddr, int type)
135159
{
@@ -151,15 +175,22 @@ bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
151175
return false;
152176
break;
153177
case META_POR:
178+
if (unlikely(blkaddr >= MAX_BLKADDR(sbi) ||
179+
blkaddr < MAIN_BLKADDR(sbi)))
180+
return false;
181+
break;
154182
case DATA_GENERIC:
183+
case DATA_GENERIC_ENHANCE:
184+
case DATA_GENERIC_ENHANCE_READ:
155185
if (unlikely(blkaddr >= MAX_BLKADDR(sbi) ||
156-
blkaddr < MAIN_BLKADDR(sbi))) {
157-
if (type == DATA_GENERIC) {
158-
f2fs_msg(sbi->sb, KERN_WARNING,
159-
"access invalid blkaddr:%u", blkaddr);
160-
WARN_ON(1);
161-
}
186+
blkaddr < MAIN_BLKADDR(sbi))) {
187+
f2fs_msg(sbi->sb, KERN_WARNING,
188+
"access invalid blkaddr:%u", blkaddr);
189+
set_sbi_flag(sbi, SBI_NEED_FSCK);
190+
WARN_ON(1);
162191
return false;
192+
} else {
193+
return __is_bitmap_valid(sbi, blkaddr, type);
163194
}
164195
break;
165196
case META_GENERIC:
@@ -189,7 +220,7 @@ int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
189220
.op_flags = sync ? (REQ_META | REQ_PRIO) : REQ_RAHEAD,
190221
.encrypted_page = NULL,
191222
.in_list = false,
192-
.is_meta = (type != META_POR),
223+
.is_por = (type == META_POR),
193224
};
194225
struct blk_plug plug;
195226

@@ -644,6 +675,12 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *sbi)
644675
if (!is_set_ckpt_flags(sbi, CP_ORPHAN_PRESENT_FLAG))
645676
return 0;
646677

678+
if (bdev_read_only(sbi->sb->s_bdev)) {
679+
f2fs_msg(sbi->sb, KERN_INFO, "write access "
680+
"unavailable, skipping orphan cleanup");
681+
return 0;
682+
}
683+
647684
if (s_flags & SB_RDONLY) {
648685
f2fs_msg(sbi->sb, KERN_INFO, "orphan cleanup on readonly fs");
649686
sbi->sb->s_flags &= ~SB_RDONLY;
@@ -758,13 +795,27 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk)
758795
}
759796
}
760797

798+
static __u32 f2fs_checkpoint_chksum(struct f2fs_sb_info *sbi,
799+
struct f2fs_checkpoint *ckpt)
800+
{
801+
unsigned int chksum_ofs = le32_to_cpu(ckpt->checksum_offset);
802+
__u32 chksum;
803+
804+
chksum = f2fs_crc32(sbi, ckpt, chksum_ofs);
805+
if (chksum_ofs < CP_CHKSUM_OFFSET) {
806+
chksum_ofs += sizeof(chksum);
807+
chksum = f2fs_chksum(sbi, chksum, (__u8 *)ckpt + chksum_ofs,
808+
F2FS_BLKSIZE - chksum_ofs);
809+
}
810+
return chksum;
811+
}
812+
761813
static int get_checkpoint_version(struct f2fs_sb_info *sbi, block_t cp_addr,
762814
struct f2fs_checkpoint **cp_block, struct page **cp_page,
763815
unsigned long long *version)
764816
{
765-
unsigned long blk_size = sbi->blocksize;
766817
size_t crc_offset = 0;
767-
__u32 crc = 0;
818+
__u32 crc;
768819

769820
*cp_page = f2fs_get_meta_page(sbi, cp_addr);
770821
if (IS_ERR(*cp_page))
@@ -773,15 +824,27 @@ static int get_checkpoint_version(struct f2fs_sb_info *sbi, block_t cp_addr,
773824
*cp_block = (struct f2fs_checkpoint *)page_address(*cp_page);
774825

775826
crc_offset = le32_to_cpu((*cp_block)->checksum_offset);
776-
if (crc_offset > (blk_size - sizeof(__le32))) {
827+
if (crc_offset < CP_MIN_CHKSUM_OFFSET ||
828+
crc_offset > CP_CHKSUM_OFFSET) {
777829
f2fs_put_page(*cp_page, 1);
778830
f2fs_msg(sbi->sb, KERN_WARNING,
779831
"invalid crc_offset: %zu", crc_offset);
780832
return -EINVAL;
781833
}
782834

783-
crc = cur_cp_crc(*cp_block);
784-
if (!f2fs_crc_valid(sbi, crc, *cp_block, crc_offset)) {
835+
if (__is_set_ckpt_flags(*cp_block, CP_LARGE_NAT_BITMAP_FLAG)) {
836+
if (crc_offset != CP_MIN_CHKSUM_OFFSET) {
837+
f2fs_put_page(*cp_page, 1);
838+
f2fs_msg(sbi->sb, KERN_WARNING,
839+
"layout of large_nat_bitmap is deprecated, "
840+
"run fsck to repair, chksum_offset: %zu",
841+
crc_offset);
842+
return -EINVAL;
843+
}
844+
}
845+
846+
crc = f2fs_checkpoint_chksum(sbi, *cp_block);
847+
if (crc != cur_cp_crc(*cp_block)) {
785848
f2fs_put_page(*cp_page, 1);
786849
f2fs_msg(sbi->sb, KERN_WARNING, "invalid crc value");
787850
return -EINVAL;
@@ -1009,13 +1072,11 @@ int f2fs_sync_dirty_inodes(struct f2fs_sb_info *sbi, enum inode_type type)
10091072
if (inode) {
10101073
unsigned long cur_ino = inode->i_ino;
10111074

1012-
if (is_dir)
1013-
F2FS_I(inode)->cp_task = current;
1075+
F2FS_I(inode)->cp_task = current;
10141076

10151077
filemap_fdatawrite(inode->i_mapping);
10161078

1017-
if (is_dir)
1018-
F2FS_I(inode)->cp_task = NULL;
1079+
F2FS_I(inode)->cp_task = NULL;
10191080

10201081
iput(inode);
10211082
/* We need to give cpu to another writers. */
@@ -1391,7 +1452,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
13911452
get_sit_bitmap(sbi, __bitmap_ptr(sbi, SIT_BITMAP));
13921453
get_nat_bitmap(sbi, __bitmap_ptr(sbi, NAT_BITMAP));
13931454

1394-
crc32 = f2fs_crc32(sbi, ckpt, le32_to_cpu(ckpt->checksum_offset));
1455+
crc32 = f2fs_checkpoint_chksum(sbi, ckpt);
13951456
*((__le32 *)((unsigned char *)ckpt +
13961457
le32_to_cpu(ckpt->checksum_offset)))
13971458
= cpu_to_le32(crc32);
@@ -1475,7 +1536,11 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
14751536
clear_sbi_flag(sbi, SBI_IS_DIRTY);
14761537
clear_sbi_flag(sbi, SBI_NEED_CP);
14771538
clear_sbi_flag(sbi, SBI_QUOTA_SKIP_FLUSH);
1539+
1540+
spin_lock(&sbi->stat_lock);
14781541
sbi->unusable_block_count = 0;
1542+
spin_unlock(&sbi->stat_lock);
1543+
14791544
__set_cp_next_pack(sbi);
14801545

14811546
/*
@@ -1500,6 +1565,9 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
15001565
unsigned long long ckpt_ver;
15011566
int err = 0;
15021567

1568+
if (f2fs_readonly(sbi->sb) || f2fs_hw_is_readonly(sbi))
1569+
return -EROFS;
1570+
15031571
if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
15041572
if (cpc->reason != CP_PAUSE)
15051573
return 0;
@@ -1516,10 +1584,6 @@ int f2fs_write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
15161584
err = -EIO;
15171585
goto out;
15181586
}
1519-
if (f2fs_readonly(sbi->sb)) {
1520-
err = -EROFS;
1521-
goto out;
1522-
}
15231587

15241588
trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "start block_ops");
15251589

0 commit comments

Comments
 (0)