All of lore.kernel.org
 help / color / mirror / Atom feed
* [linux-next:master 8348/9291] fs/ext4/extents.c:6155 ext4_ext_clear_bb() error: double free of 'path'
@ 2024-09-04 17:39 Dan Carpenter
  2024-09-05  1:30 ` Baokun Li
  0 siblings, 1 reply; 7+ messages in thread
From: Dan Carpenter @ 2024-09-04 17:39 UTC (permalink / raw)
  To: oe-kbuild, Baokun Li
  Cc: lkp, oe-kbuild-all, Theodore Ts'o, Jan Kara, Ojaswin Mujoo

Hi Baokun,

FYI, the error/warning was bisected to this commit, please ignore it if it's irrelevant.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   fdadd93817f124fd0ea6ef251d4a1068b7feceba
commit: 92bbb922166cd7a829bf60d168372ffa1c54e81d [8348/9291] ext4: make some fast commit functions reuse extents path
config: x86_64-randconfig-161-20240904 (https://download.01.org/0day-ci/archive/20240905/202409050044.EGobujzB-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
| Closes: https://lore.kernel.org/r/202409050044.EGobujzB-lkp@intel.com/

smatch warnings:
fs/ext4/extents.c:6155 ext4_ext_clear_bb() error: double free of 'path'

vim +/path +6155 fs/ext4/extents.c

8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6108  int ext4_ext_clear_bb(struct inode *inode)
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6109  {
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6110  	struct ext4_ext_path *path = NULL;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6111  	struct ext4_extent *ex;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6112  	ext4_lblk_t cur = 0, end;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6113  	int j, ret = 0;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6114  	struct ext4_map_blocks map;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6115  
1ebf21784b19d5 Harshad Shirwadkar 2021-10-15  6116  	if (ext4_test_inode_flag(inode, EXT4_INODE_INLINE_DATA))
1ebf21784b19d5 Harshad Shirwadkar 2021-10-15  6117  		return 0;
1ebf21784b19d5 Harshad Shirwadkar 2021-10-15  6118  
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6119  	/* Determin the size of the file first */
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6120  	path = ext4_find_extent(inode, EXT_MAX_BLOCKS - 1, NULL,
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6121  					EXT4_EX_NOCACHE);
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6122  	if (IS_ERR(path))
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6123  		return PTR_ERR(path);
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6124  	ex = path[path->p_depth].p_ext;
92bbb922166cd7 Baokun Li          2024-08-22  6125  	if (!ex)
92bbb922166cd7 Baokun Li          2024-08-22  6126  		goto out;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6127  	end = le32_to_cpu(ex->ee_block) + ext4_ext_get_actual_len(ex);
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6128  
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6129  	cur = 0;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6130  	while (cur < end) {
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6131  		map.m_lblk = cur;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6132  		map.m_len = end - cur;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6133  		ret = ext4_map_blocks(NULL, inode, &map, 0);
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6134  		if (ret < 0)
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6135  			break;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6136  		if (ret > 0) {
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6137  			path = ext4_find_extent(inode, map.m_lblk, NULL, 0);
b2e662cb86ca9f Li Zetao           2024-08-20  6138  			if (!IS_ERR(path)) {
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6139  				for (j = 0; j < path->p_depth; j++) {
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6140  					ext4_mb_mark_bb(inode->i_sb,
d2f7cf40ea89b4 Kemeng Shi         2023-09-29  6141  							path[j].p_block, 1, false);
599ea31d13617c Xin Yin            2022-01-10  6142  					ext4_fc_record_regions(inode->i_sb, inode->i_ino,
599ea31d13617c Xin Yin            2022-01-10  6143  							0, path[j].p_block, 1, 1);
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6144  				}
7ff5fddaddf2cc Ye Bin             2022-09-24  6145  				ext4_free_ext_path(path);
                                                                                ^^^^^^^^^^^^^^^^^^^^^^^^
Freed

8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6146  			}
d2f7cf40ea89b4 Kemeng Shi         2023-09-29  6147  			ext4_mb_mark_bb(inode->i_sb, map.m_pblk, map.m_len, false);
599ea31d13617c Xin Yin            2022-01-10  6148  			ext4_fc_record_regions(inode->i_sb, inode->i_ino,
599ea31d13617c Xin Yin            2022-01-10  6149  					map.m_lblk, map.m_pblk, map.m_len, 1);
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6150  		}
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6151  		cur = cur + map.m_len;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6152  	}
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6153  
92bbb922166cd7 Baokun Li          2024-08-22  6154  out:
92bbb922166cd7 Baokun Li          2024-08-22 @6155  	ext4_free_ext_path(path);
                                                        ^^^^^^^^^^^^^^^^^^^^^^^^
Double free


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


^ permalink raw reply	[flat|nested] 7+ messages in thread
* [linux-next:master 8348/9291] fs/ext4/extents.c:6155 ext4_ext_clear_bb() error: double free of 'path'
@ 2024-09-04 16:51 kernel test robot
  0 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2024-09-04 16:51 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Dan Carpenter

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
CC: Linux Memory Management List <linux-mm@kvack.org>
TO: Baokun Li <libaokun1@huawei.com>
CC: "Theodore Ts'o" <tytso@mit.edu>
CC: Jan Kara <jack@suse.cz>
CC: Ojaswin Mujoo <ojaswin@linux.ibm.com>

Hi Baokun,

FYI, the error/warning was bisected to this commit, please ignore it if it's irrelevant.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head:   fdadd93817f124fd0ea6ef251d4a1068b7feceba
commit: 92bbb922166cd7a829bf60d168372ffa1c54e81d [8348/9291] ext4: make some fast commit functions reuse extents path
:::::: branch date: 10 hours ago
:::::: commit date: 2 days ago
config: x86_64-randconfig-161-20240904 (https://download.01.org/0day-ci/archive/20240905/202409050044.EGobujzB-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202409050044.EGobujzB-lkp@intel.com/

smatch warnings:
fs/ext4/extents.c:6155 ext4_ext_clear_bb() error: double free of 'path'

vim +/path +6155 fs/ext4/extents.c

8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6107  
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6108  int ext4_ext_clear_bb(struct inode *inode)
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6109  {
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6110  	struct ext4_ext_path *path = NULL;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6111  	struct ext4_extent *ex;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6112  	ext4_lblk_t cur = 0, end;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6113  	int j, ret = 0;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6114  	struct ext4_map_blocks map;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6115  
1ebf21784b19d5 Harshad Shirwadkar 2021-10-15  6116  	if (ext4_test_inode_flag(inode, EXT4_INODE_INLINE_DATA))
1ebf21784b19d5 Harshad Shirwadkar 2021-10-15  6117  		return 0;
1ebf21784b19d5 Harshad Shirwadkar 2021-10-15  6118  
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6119  	/* Determin the size of the file first */
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6120  	path = ext4_find_extent(inode, EXT_MAX_BLOCKS - 1, NULL,
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6121  					EXT4_EX_NOCACHE);
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6122  	if (IS_ERR(path))
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6123  		return PTR_ERR(path);
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6124  	ex = path[path->p_depth].p_ext;
92bbb922166cd7 Baokun Li          2024-08-22  6125  	if (!ex)
92bbb922166cd7 Baokun Li          2024-08-22  6126  		goto out;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6127  	end = le32_to_cpu(ex->ee_block) + ext4_ext_get_actual_len(ex);
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6128  
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6129  	cur = 0;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6130  	while (cur < end) {
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6131  		map.m_lblk = cur;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6132  		map.m_len = end - cur;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6133  		ret = ext4_map_blocks(NULL, inode, &map, 0);
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6134  		if (ret < 0)
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6135  			break;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6136  		if (ret > 0) {
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6137  			path = ext4_find_extent(inode, map.m_lblk, NULL, 0);
b2e662cb86ca9f Li Zetao           2024-08-20  6138  			if (!IS_ERR(path)) {
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6139  				for (j = 0; j < path->p_depth; j++) {
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6140  					ext4_mb_mark_bb(inode->i_sb,
d2f7cf40ea89b4 Kemeng Shi         2023-09-29  6141  							path[j].p_block, 1, false);
599ea31d13617c Xin Yin            2022-01-10  6142  					ext4_fc_record_regions(inode->i_sb, inode->i_ino,
599ea31d13617c Xin Yin            2022-01-10  6143  							0, path[j].p_block, 1, 1);
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6144  				}
7ff5fddaddf2cc Ye Bin             2022-09-24  6145  				ext4_free_ext_path(path);
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6146  			}
d2f7cf40ea89b4 Kemeng Shi         2023-09-29  6147  			ext4_mb_mark_bb(inode->i_sb, map.m_pblk, map.m_len, false);
599ea31d13617c Xin Yin            2022-01-10  6148  			ext4_fc_record_regions(inode->i_sb, inode->i_ino,
599ea31d13617c Xin Yin            2022-01-10  6149  					map.m_lblk, map.m_pblk, map.m_len, 1);
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6150  		}
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6151  		cur = cur + map.m_len;
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6152  	}
8016e29f4362e2 Harshad Shirwadkar 2020-10-15  6153  
92bbb922166cd7 Baokun Li          2024-08-22  6154  out:
92bbb922166cd7 Baokun Li          2024-08-22 @6155  	ext4_free_ext_path(path);

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

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

end of thread, other threads:[~2024-09-06  1:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-04 17:39 [linux-next:master 8348/9291] fs/ext4/extents.c:6155 ext4_ext_clear_bb() error: double free of 'path' Dan Carpenter
2024-09-05  1:30 ` Baokun Li
2024-09-05 13:23   ` Theodore Ts'o
2024-09-05 13:31     ` Baokun Li
2024-09-05 14:07       ` Theodore Ts'o
2024-09-06  1:26         ` Baokun Li
  -- strict thread matches above, loose matches on Subject: below --
2024-09-04 16:51 kernel test robot

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.