All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v4 2/2] btrfs: insert tree mod log move in push_node_left
@ 2023-06-03 23:40 kernel test robot
  0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2023-06-03 23:40 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Dan Carpenter

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <cbcc2be3a79a2af9885a0e23251788562f8bf2e9.1685645613.git.boris@bur.io>
References: <cbcc2be3a79a2af9885a0e23251788562f8bf2e9.1685645613.git.boris@bur.io>
TO: Boris Burkov <boris@bur.io>

Hi Boris,

kernel test robot noticed the following build warnings:

[auto build test WARNING on kdave/for-next]
[also build test WARNING on linus/master v6.4-rc4 next-20230602]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Boris-Burkov/btrfs-warn-on-invalid-slot-in-tree-mod-log-rewind/20230602-025629
base:   https://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux.git for-next
patch link:    https://lore.kernel.org/r/cbcc2be3a79a2af9885a0e23251788562f8bf2e9.1685645613.git.boris%40bur.io
patch subject: [PATCH v4 2/2] btrfs: insert tree mod log move in push_node_left
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: openrisc-randconfig-m041-20230531 (https://download.01.org/0day-ci/archive/20230604/202306040704.9cbCpyUP-lkp@intel.com/config)
compiler: or1k-linux-gcc (GCC) 12.3.0

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202306040704.9cbCpyUP-lkp@intel.com/

New smatch warnings:
fs/btrfs/tree-mod-log.c:290 btrfs_tree_mod_log_insert_move() warn: passing a valid pointer to 'PTR_ERR'
fs/btrfs/tree-mod-log.c:527 btrfs_tree_mod_log_eb_copy() warn: passing a valid pointer to 'PTR_ERR'

Old smatch warnings:
fs/btrfs/tree-mod-log.c:305 btrfs_tree_mod_log_insert_move() warn: missing error code 'ret'
fs/btrfs/tree-mod-log.c:537 btrfs_tree_mod_log_eb_copy() warn: passing a valid pointer to 'PTR_ERR'
fs/btrfs/tree-mod-log.c:562 btrfs_tree_mod_log_eb_copy() warn: missing error code 'ret'
fs/btrfs/tree-mod-log.c:633 btrfs_tree_mod_log_free_eb() warn: missing error code 'ret'

vim +/PTR_ERR +290 fs/btrfs/tree-mod-log.c

5ed7d21303c76e Boris Burkov  2023-06-01  270  
f3a84ccd28d0b0 Filipe Manana 2021-03-11  271  int btrfs_tree_mod_log_insert_move(struct extent_buffer *eb,
f3a84ccd28d0b0 Filipe Manana 2021-03-11  272  				   int dst_slot, int src_slot,
f3a84ccd28d0b0 Filipe Manana 2021-03-11  273  				   int nr_items)
f3a84ccd28d0b0 Filipe Manana 2021-03-11  274  {
f3a84ccd28d0b0 Filipe Manana 2021-03-11  275  	struct tree_mod_elem *tm = NULL;
f3a84ccd28d0b0 Filipe Manana 2021-03-11  276  	struct tree_mod_elem **tm_list = NULL;
f3a84ccd28d0b0 Filipe Manana 2021-03-11  277  	int ret = 0;
f3a84ccd28d0b0 Filipe Manana 2021-03-11  278  	int i;
406808ab2f0ba3 Filipe Manana 2021-03-11  279  	bool locked = false;
f3a84ccd28d0b0 Filipe Manana 2021-03-11  280  
f3a84ccd28d0b0 Filipe Manana 2021-03-11  281  	if (!tree_mod_need_log(eb->fs_info, eb))
f3a84ccd28d0b0 Filipe Manana 2021-03-11  282  		return 0;
f3a84ccd28d0b0 Filipe Manana 2021-03-11  283  
f3a84ccd28d0b0 Filipe Manana 2021-03-11  284  	tm_list = kcalloc(nr_items, sizeof(struct tree_mod_elem *), GFP_NOFS);
f3a84ccd28d0b0 Filipe Manana 2021-03-11  285  	if (!tm_list)
f3a84ccd28d0b0 Filipe Manana 2021-03-11  286  		return -ENOMEM;
f3a84ccd28d0b0 Filipe Manana 2021-03-11  287  
5ed7d21303c76e Boris Burkov  2023-06-01  288  	tm = tree_mod_log_alloc_move(eb, dst_slot, src_slot, nr_items);
5ed7d21303c76e Boris Burkov  2023-06-01  289  	if (IS_ERR(tm)) {
5ed7d21303c76e Boris Burkov  2023-06-01 @290  		ret = PTR_ERR(tm);
5ed7d21303c76e Boris Burkov  2023-06-01  291  		tm = NULL;
f3a84ccd28d0b0 Filipe Manana 2021-03-11  292  		goto free_tms;
f3a84ccd28d0b0 Filipe Manana 2021-03-11  293  	}
f3a84ccd28d0b0 Filipe Manana 2021-03-11  294  
f3a84ccd28d0b0 Filipe Manana 2021-03-11  295  	for (i = 0; i + dst_slot < src_slot && i < nr_items; i++) {
f3a84ccd28d0b0 Filipe Manana 2021-03-11  296  		tm_list[i] = alloc_tree_mod_elem(eb, i + dst_slot,
33cff222faffef Filipe Manana 2022-10-14  297  				BTRFS_MOD_LOG_KEY_REMOVE_WHILE_MOVING);
f3a84ccd28d0b0 Filipe Manana 2021-03-11  298  		if (!tm_list[i]) {
f3a84ccd28d0b0 Filipe Manana 2021-03-11  299  			ret = -ENOMEM;
f3a84ccd28d0b0 Filipe Manana 2021-03-11  300  			goto free_tms;
f3a84ccd28d0b0 Filipe Manana 2021-03-11  301  		}
f3a84ccd28d0b0 Filipe Manana 2021-03-11  302  	}
f3a84ccd28d0b0 Filipe Manana 2021-03-11  303  
f3a84ccd28d0b0 Filipe Manana 2021-03-11  304  	if (tree_mod_dont_log(eb->fs_info, eb))
f3a84ccd28d0b0 Filipe Manana 2021-03-11  305  		goto free_tms;
406808ab2f0ba3 Filipe Manana 2021-03-11  306  	locked = true;
f3a84ccd28d0b0 Filipe Manana 2021-03-11  307  
f3a84ccd28d0b0 Filipe Manana 2021-03-11  308  	/*
f3a84ccd28d0b0 Filipe Manana 2021-03-11  309  	 * When we override something during the move, we log these removals.
f3a84ccd28d0b0 Filipe Manana 2021-03-11  310  	 * This can only happen when we move towards the beginning of the
f3a84ccd28d0b0 Filipe Manana 2021-03-11  311  	 * buffer, i.e. dst_slot < src_slot.
f3a84ccd28d0b0 Filipe Manana 2021-03-11  312  	 */
f3a84ccd28d0b0 Filipe Manana 2021-03-11  313  	for (i = 0; i + dst_slot < src_slot && i < nr_items; i++) {
f3a84ccd28d0b0 Filipe Manana 2021-03-11  314  		ret = tree_mod_log_insert(eb->fs_info, tm_list[i]);
f3a84ccd28d0b0 Filipe Manana 2021-03-11  315  		if (ret)
f3a84ccd28d0b0 Filipe Manana 2021-03-11  316  			goto free_tms;
f3a84ccd28d0b0 Filipe Manana 2021-03-11  317  	}
f3a84ccd28d0b0 Filipe Manana 2021-03-11  318  
f3a84ccd28d0b0 Filipe Manana 2021-03-11  319  	ret = tree_mod_log_insert(eb->fs_info, tm);
f3a84ccd28d0b0 Filipe Manana 2021-03-11  320  	if (ret)
f3a84ccd28d0b0 Filipe Manana 2021-03-11  321  		goto free_tms;
f3a84ccd28d0b0 Filipe Manana 2021-03-11  322  	write_unlock(&eb->fs_info->tree_mod_log_lock);
f3a84ccd28d0b0 Filipe Manana 2021-03-11  323  	kfree(tm_list);
f3a84ccd28d0b0 Filipe Manana 2021-03-11  324  
f3a84ccd28d0b0 Filipe Manana 2021-03-11  325  	return 0;
f3a84ccd28d0b0 Filipe Manana 2021-03-11  326  
f3a84ccd28d0b0 Filipe Manana 2021-03-11  327  free_tms:
f3a84ccd28d0b0 Filipe Manana 2021-03-11  328  	for (i = 0; i < nr_items; i++) {
f3a84ccd28d0b0 Filipe Manana 2021-03-11  329  		if (tm_list[i] && !RB_EMPTY_NODE(&tm_list[i]->node))
f3a84ccd28d0b0 Filipe Manana 2021-03-11  330  			rb_erase(&tm_list[i]->node, &eb->fs_info->tree_mod_log);
f3a84ccd28d0b0 Filipe Manana 2021-03-11  331  		kfree(tm_list[i]);
f3a84ccd28d0b0 Filipe Manana 2021-03-11  332  	}
f3a84ccd28d0b0 Filipe Manana 2021-03-11  333  	if (locked)
f3a84ccd28d0b0 Filipe Manana 2021-03-11  334  		write_unlock(&eb->fs_info->tree_mod_log_lock);
f3a84ccd28d0b0 Filipe Manana 2021-03-11  335  	kfree(tm_list);
f3a84ccd28d0b0 Filipe Manana 2021-03-11  336  	kfree(tm);
f3a84ccd28d0b0 Filipe Manana 2021-03-11  337  
f3a84ccd28d0b0 Filipe Manana 2021-03-11  338  	return ret;
f3a84ccd28d0b0 Filipe Manana 2021-03-11  339  }
f3a84ccd28d0b0 Filipe Manana 2021-03-11  340  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 3+ messages in thread
* [PATCH v4 0/2] btrfs: fix logical_to_ino panic in btrfs_map_bio
@ 2023-06-01 18:55 Boris Burkov
  2023-06-01 18:55 ` [PATCH v4 2/2] btrfs: insert tree mod log move in push_node_left Boris Burkov
  0 siblings, 1 reply; 3+ messages in thread
From: Boris Burkov @ 2023-06-01 18:55 UTC (permalink / raw)
  To: linux-btrfs, kernel-team, fdmanana

The gory details are in the second patch, but it is possible to panic
the kernel by running the ioctl BTRFS_IOC_LOGICAL_INO (and V2 of that
ioctl).

The TL;DR of the problem is that we do not properly handle logging a
move from a push_node_left btree balancing operation in the tree mod
log, so it is possible for backref walking using the tree mod log to
construct an invalid extent_buffer and ultimately try to map invalid
bios for block 0 which ultimately hits a null pointer error and panics.

The patch set introduces additional bookkeeping in tree mod log to warn
on this issue and also fixes the issue itself.

---
Changelog:
v4:
- actually include the changes to Patch 1 cited in v3, my mistake.
v3:
- fix bug from missing RB_CLEAR_NODE
- assert on move nr_items = 0 and max_slot < -1
- document max_slot with a comment
- change to ints for max_slot
- get rid of now redundant warning. max_slot=-1, move_dst_end=-1 is "OK"
  though it will assert.
- re-add max_slot setting after move that got lost in v2...
- remove unrelated formatting changes
v2:
- move WARN to before the bad memmove
- change WARN to WARN_ON + btrfs_warn
- fix tm freeing bug in tree_mod_log_insert_move
- unify error handling for tm alloc failures on setting tm=NULL after
  setting ret=PTR_ERR(tm) and then calling kfree unconditionally
- tidying/nits

Boris Burkov (2):
  btrfs: warn on invalid slot in tree mod log rewind
  btrfs: insert tree mod log move in push_node_left

 fs/btrfs/ctree.c        |  11 ++--
 fs/btrfs/tree-mod-log.c | 114 ++++++++++++++++++++++++++++++++++++----
 2 files changed, 112 insertions(+), 13 deletions(-)

-- 
2.40.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-03 23:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-03 23:40 [PATCH v4 2/2] btrfs: insert tree mod log move in push_node_left kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2023-06-01 18:55 [PATCH v4 0/2] btrfs: fix logical_to_ino panic in btrfs_map_bio Boris Burkov
2023-06-01 18:55 ` [PATCH v4 2/2] btrfs: insert tree mod log move in push_node_left Boris Burkov
2023-06-02 10:10   ` Filipe Manana

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.