From b177b46f9114fcfe86875ced6f5a9fc7214c367f Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Mon, 30 Sep 2019 09:22:17 -0400 Subject: [PATCH] fixes for 5.2 Signed-off-by: Sasha Levin --- ...s-use-generic-efsbadcrc-efscorrupted.patch | 443 ++++++++++++++++++ ...-check-laddr_check-before-calling-it.patch | 48 ++ queue-5.2/series | 2 + 3 files changed, 493 insertions(+) create mode 100644 queue-5.2/f2fs-use-generic-efsbadcrc-efscorrupted.patch create mode 100644 queue-5.2/net-rds-check-laddr_check-before-calling-it.patch diff --git a/queue-5.2/f2fs-use-generic-efsbadcrc-efscorrupted.patch b/queue-5.2/f2fs-use-generic-efsbadcrc-efscorrupted.patch new file mode 100644 index 00000000000..5104a5a30a9 --- /dev/null +++ b/queue-5.2/f2fs-use-generic-efsbadcrc-efscorrupted.patch @@ -0,0 +1,443 @@ +From 17cbad3d844d29e9e44a2e7b01ad8c6cb3a6a094 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Thu, 20 Jun 2019 11:36:14 +0800 +Subject: f2fs: use generic EFSBADCRC/EFSCORRUPTED + +From: Chao Yu + +[ Upstream commit 10f966bbf521bb9b2e497bbca496a5141f4071d0 ] + +f2fs uses EFAULT as error number to indicate filesystem is corrupted +all the time, but generic filesystems use EUCLEAN for such condition, +we need to change to follow others. + +This patch adds two new macros as below to wrap more generic error +code macros, and spread them in code. + +EFSBADCRC EBADMSG /* Bad CRC detected */ +EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ + +Reported-by: Pavel Machek +Signed-off-by: Chao Yu +Acked-by: Pavel Machek +Signed-off-by: Jaegeuk Kim +Signed-off-by: Sasha Levin +--- + fs/f2fs/checkpoint.c | 12 +++++++++--- + fs/f2fs/data.c | 16 ++++++++-------- + fs/f2fs/dir.c | 2 +- + fs/f2fs/f2fs.h | 3 +++ + fs/f2fs/file.c | 2 +- + fs/f2fs/gc.c | 4 ++-- + fs/f2fs/inline.c | 4 ++-- + fs/f2fs/inode.c | 4 ++-- + fs/f2fs/node.c | 6 +++--- + fs/f2fs/recovery.c | 6 +++--- + fs/f2fs/segment.c | 10 +++++----- + fs/f2fs/segment.h | 4 ++-- + fs/f2fs/super.c | 2 +- + fs/f2fs/xattr.c | 4 ++-- + 14 files changed, 44 insertions(+), 35 deletions(-) + +diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c +index d0539ddad6e2a..7d9fce215f46b 100644 +--- a/fs/f2fs/checkpoint.c ++++ b/fs/f2fs/checkpoint.c +@@ -894,6 +894,7 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi) + unsigned int cp_blks = 1 + __cp_payload(sbi); + block_t cp_blk_no; + int i; ++ int err; + + sbi->ckpt = f2fs_kzalloc(sbi, array_size(blk_size, cp_blks), + GFP_KERNEL); +@@ -921,6 +922,7 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi) + } else if (cp2) { + cur_page = cp2; + } else { ++ err = -EFSCORRUPTED; + goto fail_no_cp; + } + +@@ -933,8 +935,10 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi) + sbi->cur_cp_pack = 2; + + /* Sanity checking of checkpoint */ +- if (f2fs_sanity_check_ckpt(sbi)) ++ if (f2fs_sanity_check_ckpt(sbi)) { ++ err = -EFSCORRUPTED; + goto free_fail_no_cp; ++ } + + if (cp_blks <= 1) + goto done; +@@ -948,8 +952,10 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi) + unsigned char *ckpt = (unsigned char *)sbi->ckpt; + + cur_page = f2fs_get_meta_page(sbi, cp_blk_no + i); +- if (IS_ERR(cur_page)) ++ if (IS_ERR(cur_page)) { ++ err = PTR_ERR(cur_page); + goto free_fail_no_cp; ++ } + sit_bitmap_ptr = page_address(cur_page); + memcpy(ckpt + i * blk_size, sit_bitmap_ptr, blk_size); + f2fs_put_page(cur_page, 1); +@@ -964,7 +970,7 @@ int f2fs_get_valid_checkpoint(struct f2fs_sb_info *sbi) + f2fs_put_page(cp2, 1); + fail_no_cp: + kvfree(sbi->ckpt); +- return -EINVAL; ++ return err; + } + + static void __add_dirty_inode(struct inode *inode, enum inode_type type) +diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c +index 923923603a7d8..85f3879a31cbf 100644 +--- a/fs/f2fs/data.c ++++ b/fs/f2fs/data.c +@@ -455,7 +455,7 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio) + if (!f2fs_is_valid_blkaddr(fio->sbi, fio->new_blkaddr, + fio->is_por ? META_POR : (__is_meta_io(fio) ? + META_GENERIC : DATA_GENERIC_ENHANCE))) +- return -EFAULT; ++ return -EFSCORRUPTED; + + trace_f2fs_submit_page_bio(page, fio); + f2fs_trace_ios(fio, 0); +@@ -734,7 +734,7 @@ struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index, + dn.data_blkaddr = ei.blk + index - ei.fofs; + if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), dn.data_blkaddr, + DATA_GENERIC_ENHANCE_READ)) { +- err = -EFAULT; ++ err = -EFSCORRUPTED; + goto put_err; + } + goto got_it; +@@ -754,7 +754,7 @@ struct page *f2fs_get_read_data_page(struct inode *inode, pgoff_t index, + !f2fs_is_valid_blkaddr(F2FS_I_SB(inode), + dn.data_blkaddr, + DATA_GENERIC_ENHANCE)) { +- err = -EFAULT; ++ err = -EFSCORRUPTED; + goto put_err; + } + got_it: +@@ -1100,7 +1100,7 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, + + if (__is_valid_data_blkaddr(blkaddr) && + !f2fs_is_valid_blkaddr(sbi, blkaddr, DATA_GENERIC_ENHANCE)) { +- err = -EFAULT; ++ err = -EFSCORRUPTED; + goto sync_out; + } + +@@ -1570,7 +1570,7 @@ static int f2fs_read_single_page(struct inode *inode, struct page *page, + + if (!f2fs_is_valid_blkaddr(F2FS_I_SB(inode), block_nr, + DATA_GENERIC_ENHANCE_READ)) { +- ret = -EFAULT; ++ ret = -EFSCORRUPTED; + goto out; + } + } else { +@@ -1851,7 +1851,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio) + + if (!f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr, + DATA_GENERIC_ENHANCE)) +- return -EFAULT; ++ return -EFSCORRUPTED; + + ipu_force = true; + fio->need_lock = LOCK_DONE; +@@ -1878,7 +1878,7 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio) + if (__is_valid_data_blkaddr(fio->old_blkaddr) && + !f2fs_is_valid_blkaddr(fio->sbi, fio->old_blkaddr, + DATA_GENERIC_ENHANCE)) { +- err = -EFAULT; ++ err = -EFSCORRUPTED; + goto out_writepage; + } + /* +@@ -2536,7 +2536,7 @@ static int f2fs_write_begin(struct file *file, struct address_space *mapping, + } else { + if (!f2fs_is_valid_blkaddr(sbi, blkaddr, + DATA_GENERIC_ENHANCE_READ)) { +- err = -EFAULT; ++ err = -EFSCORRUPTED; + goto fail; + } + err = f2fs_submit_page_read(inode, page, blkaddr); +diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c +index 59bc460178554..4be433f20930a 100644 +--- a/fs/f2fs/dir.c ++++ b/fs/f2fs/dir.c +@@ -820,7 +820,7 @@ int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d, + "%s: corrupted namelen=%d, run fsck to fix.", + __func__, le16_to_cpu(de->name_len)); + set_sbi_flag(sbi, SBI_NEED_FSCK); +- err = -EINVAL; ++ err = -EFSCORRUPTED; + goto out; + } + +diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h +index cbdc2f88a98c6..b545beb8b04e3 100644 +--- a/fs/f2fs/f2fs.h ++++ b/fs/f2fs/f2fs.h +@@ -3718,4 +3718,7 @@ static inline bool is_journalled_quota(struct f2fs_sb_info *sbi) + return false; + } + ++#define EFSBADCRC EBADMSG /* Bad CRC detected */ ++#define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ ++ + #endif /* _LINUX_F2FS_H */ +diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c +index 45b45f37d347e..33c6e14d0c87e 100644 +--- a/fs/f2fs/file.c ++++ b/fs/f2fs/file.c +@@ -1026,7 +1026,7 @@ static int __read_out_blkaddrs(struct inode *inode, block_t *blkaddr, + !f2fs_is_valid_blkaddr(sbi, *blkaddr, + DATA_GENERIC_ENHANCE)) { + f2fs_put_dnode(&dn); +- return -EFAULT; ++ return -EFSCORRUPTED; + } + + if (!f2fs_is_checkpointed_data(sbi, *blkaddr)) { +diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c +index bb6fd5a506d39..08224776618ed 100644 +--- a/fs/f2fs/gc.c ++++ b/fs/f2fs/gc.c +@@ -658,7 +658,7 @@ static int ra_data_block(struct inode *inode, pgoff_t index) + dn.data_blkaddr = ei.blk + index - ei.fofs; + if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr, + DATA_GENERIC_ENHANCE_READ))) { +- err = -EFAULT; ++ err = -EFSCORRUPTED; + goto put_page; + } + goto got_it; +@@ -676,7 +676,7 @@ static int ra_data_block(struct inode *inode, pgoff_t index) + } + if (unlikely(!f2fs_is_valid_blkaddr(sbi, dn.data_blkaddr, + DATA_GENERIC_ENHANCE))) { +- err = -EFAULT; ++ err = -EFSCORRUPTED; + goto put_page; + } + got_it: +diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c +index 404d2462a0fe6..aa9b5b6d1b239 100644 +--- a/fs/f2fs/inline.c ++++ b/fs/f2fs/inline.c +@@ -144,7 +144,7 @@ int f2fs_convert_inline_page(struct dnode_of_data *dn, struct page *page) + "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, " + "run fsck to fix.", + __func__, dn->inode->i_ino, dn->data_blkaddr); +- return -EINVAL; ++ return -EFSCORRUPTED; + } + + f2fs_bug_on(F2FS_P_SB(page), PageWriteback(page)); +@@ -387,7 +387,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct page *ipage, + "%s: corrupted inline inode ino=%lx, i_addr[0]:0x%x, " + "run fsck to fix.", + __func__, dir->i_ino, dn.data_blkaddr); +- err = -EINVAL; ++ err = -EFSCORRUPTED; + goto out; + } + +diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c +index ccb02226dd2c0..e269959755705 100644 +--- a/fs/f2fs/inode.c ++++ b/fs/f2fs/inode.c +@@ -74,7 +74,7 @@ static int __written_first_block(struct f2fs_sb_info *sbi, + if (!__is_valid_data_blkaddr(addr)) + return 1; + if (!f2fs_is_valid_blkaddr(sbi, addr, DATA_GENERIC_ENHANCE)) +- return -EFAULT; ++ return -EFSCORRUPTED; + return 0; + } + +@@ -374,7 +374,7 @@ static int do_read_inode(struct inode *inode) + + if (!sanity_check_inode(inode, node_page)) { + f2fs_put_page(node_page, 1); +- return -EINVAL; ++ return -EFSCORRUPTED; + } + + /* check data exist */ +diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c +index 18a038a2a9fab..ad024b7b1d431 100644 +--- a/fs/f2fs/node.c ++++ b/fs/f2fs/node.c +@@ -37,7 +37,7 @@ int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) + f2fs_msg(sbi->sb, KERN_WARNING, + "%s: out-of-range nid=%x, run fsck to fix.", + __func__, nid); +- return -EINVAL; ++ return -EFSCORRUPTED; + } + return 0; + } +@@ -1291,7 +1291,7 @@ static int read_node_page(struct page *page, int op_flags) + if (PageUptodate(page)) { + if (!f2fs_inode_chksum_verify(sbi, page)) { + ClearPageUptodate(page); +- return -EBADMSG; ++ return -EFSBADCRC; + } + return LOCKED_PAGE; + } +@@ -1375,7 +1375,7 @@ static struct page *__get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid, + } + + if (!f2fs_inode_chksum_verify(sbi, page)) { +- err = -EBADMSG; ++ err = -EFSBADCRC; + goto out_err; + } + page_hit: +diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c +index e04f82b3f4fc8..d728858ac95d4 100644 +--- a/fs/f2fs/recovery.c ++++ b/fs/f2fs/recovery.c +@@ -557,7 +557,7 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, + "Inconsistent ofs_of_node, ino:%lu, ofs:%u, %u", + inode->i_ino, ofs_of_node(dn.node_page), + ofs_of_node(page)); +- err = -EFAULT; ++ err = -EFSCORRUPTED; + goto err; + } + +@@ -569,13 +569,13 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, + + if (__is_valid_data_blkaddr(src) && + !f2fs_is_valid_blkaddr(sbi, src, META_POR)) { +- err = -EFAULT; ++ err = -EFSCORRUPTED; + goto err; + } + + if (__is_valid_data_blkaddr(dest) && + !f2fs_is_valid_blkaddr(sbi, dest, META_POR)) { +- err = -EFAULT; ++ err = -EFSCORRUPTED; + goto err; + } + +diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c +index 0a6be0212e390..eab59d6ea9452 100644 +--- a/fs/f2fs/segment.c ++++ b/fs/f2fs/segment.c +@@ -2784,7 +2784,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) + if (is_sbi_flag_set(sbi, SBI_NEED_FSCK)) { + f2fs_msg(sbi->sb, KERN_WARNING, + "Found FS corruption, run fsck to fix."); +- return -EIO; ++ return -EFSCORRUPTED; + } + + /* start/end segment number in main_area */ +@@ -3207,7 +3207,7 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio) + + if (!IS_DATASEG(get_seg_entry(sbi, segno)->type)) { + set_sbi_flag(sbi, SBI_NEED_FSCK); +- return -EFAULT; ++ return -EFSCORRUPTED; + } + + stat_inc_inplace_blocks(fio->sbi); +@@ -4110,7 +4110,7 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) + "Wrong journal entry on segno %u", + start); + set_sbi_flag(sbi, SBI_NEED_FSCK); +- err = -EINVAL; ++ err = -EFSCORRUPTED; + break; + } + +@@ -4151,7 +4151,7 @@ static int build_sit_entries(struct f2fs_sb_info *sbi) + "SIT is corrupted node# %u vs %u", + total_node_blocks, valid_node_count(sbi)); + set_sbi_flag(sbi, SBI_NEED_FSCK); +- err = -EINVAL; ++ err = -EFSCORRUPTED; + } + + return err; +@@ -4271,7 +4271,7 @@ static int sanity_check_curseg(struct f2fs_sb_info *sbi) + "segno:%u, type:%u, next_blkoff:%u, blkofs:%u", + i, curseg->segno, curseg->alloc_type, + curseg->next_blkoff, blkofs); +- return -EINVAL; ++ return -EFSCORRUPTED; + } + } + return 0; +diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h +index 429007b8036eb..4bd151f2b9547 100644 +--- a/fs/f2fs/segment.h ++++ b/fs/f2fs/segment.h +@@ -697,7 +697,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi, + "Mismatch valid blocks %d vs. %d", + GET_SIT_VBLOCKS(raw_sit), valid_blocks); + set_sbi_flag(sbi, SBI_NEED_FSCK); +- return -EINVAL; ++ return -EFSCORRUPTED; + } + + /* check segment usage, and check boundary of a given segment number */ +@@ -707,7 +707,7 @@ static inline int check_block_count(struct f2fs_sb_info *sbi, + "Wrong valid blocks %d or segno %u", + GET_SIT_VBLOCKS(raw_sit), segno); + set_sbi_flag(sbi, SBI_NEED_FSCK); +- return -EINVAL; ++ return -EFSCORRUPTED; + } + return 0; + } +diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c +index 4b47ac994daf5..973f1e8187706 100644 +--- a/fs/f2fs/super.c ++++ b/fs/f2fs/super.c +@@ -2908,7 +2908,7 @@ static int read_raw_super_block(struct f2fs_sb_info *sbi, + f2fs_msg(sb, KERN_ERR, + "Can't find valid F2FS filesystem in %dth superblock", + block + 1); +- err = -EINVAL; ++ err = -EFSCORRUPTED; + brelse(bh); + continue; + } +diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c +index e791741d193b8..9632420186636 100644 +--- a/fs/f2fs/xattr.c ++++ b/fs/f2fs/xattr.c +@@ -346,7 +346,7 @@ static int lookup_all_xattrs(struct inode *inode, struct page *ipage, + + *xe = __find_xattr(cur_addr, last_txattr_addr, index, len, name); + if (!*xe) { +- err = -EFAULT; ++ err = -EFSCORRUPTED; + goto out; + } + check: +@@ -622,7 +622,7 @@ static int __f2fs_setxattr(struct inode *inode, int index, + /* find entry with wanted name. */ + here = __find_xattr(base_addr, last_base_addr, index, len, name); + if (!here) { +- error = -EFAULT; ++ error = -EFSCORRUPTED; + goto exit; + } + +-- +2.20.1 + diff --git a/queue-5.2/net-rds-check-laddr_check-before-calling-it.patch b/queue-5.2/net-rds-check-laddr_check-before-calling-it.patch new file mode 100644 index 00000000000..3c75d6b74b3 --- /dev/null +++ b/queue-5.2/net-rds-check-laddr_check-before-calling-it.patch @@ -0,0 +1,48 @@ +From 1390c20aa7b9c67252e26015e3fa9e9b5b417b1d Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 24 Sep 2019 08:51:16 -0700 +Subject: net/rds: Check laddr_check before calling it + +From: Ka-Cheong Poon + +[ Upstream commit 05733434ee9ae6548723a808647248583e347cca ] + +In rds_bind(), laddr_check is called without checking if it is NULL or +not. And rs_transport should be reset if rds_add_bound() fails. + +Fixes: c5c1a030a7db ("net/rds: An rds_sock is added too early to the hash table") +Reported-by: syzbot+fae39afd2101a17ec624@syzkaller.appspotmail.com +Signed-off-by: Ka-Cheong Poon +Acked-by: Santosh Shilimkar +Signed-off-by: David S. Miller +Signed-off-by: Sasha Levin +--- + net/rds/bind.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/net/rds/bind.c b/net/rds/bind.c +index 05464fd7c17af..93e336535d3b6 100644 +--- a/net/rds/bind.c ++++ b/net/rds/bind.c +@@ -244,7 +244,8 @@ int rds_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) + */ + if (rs->rs_transport) { + trans = rs->rs_transport; +- if (trans->laddr_check(sock_net(sock->sk), ++ if (!trans->laddr_check || ++ trans->laddr_check(sock_net(sock->sk), + binding_addr, scope_id) != 0) { + ret = -ENOPROTOOPT; + goto out; +@@ -263,6 +264,8 @@ int rds_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) + + sock_set_flag(sk, SOCK_RCU_FREE); + ret = rds_add_bound(rs, binding_addr, &port, scope_id); ++ if (ret) ++ rs->rs_transport = NULL; + + out: + release_sock(sk); +-- +2.20.1 + diff --git a/queue-5.2/series b/queue-5.2/series index fdbce5873b5..b374483a01f 100644 --- a/queue-5.2/series +++ b/queue-5.2/series @@ -43,3 +43,5 @@ netfilter-nft_socket-fix-erroneous-socket-assignment.patch bluetooth-btrtl-additional-realtek-8822ce-bluetooth-.patch net_sched-check-cops-tcf_block-in-tc_bind_tclass.patch net-rds-an-rds_sock-is-added-too-early-to-the-hash-t.patch +net-rds-check-laddr_check-before-calling-it.patch +f2fs-use-generic-efsbadcrc-efscorrupted.patch -- 2.47.3