Unverified Commit 2035ea2c authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!9296 CVE-2021-47599

Merge Pull Request from: @ci-robot 
 
PR sync from: Yifan Qiao <qiaoyifan4@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/YF23PVGURMORC3EJY24N6UZXEF3Y5HL6/ 
Anand Jain (4):
  btrfs: convert latest_bdev type to btrfs_device and rename
  btrfs: use latest_dev in btrfs_show_devname
  btrfs: update latest_dev when we create a sprout device
  btrfs: remove stale comment about the btrfs_show_devname


-- 
2.39.2
 
https://gitee.com/src-openeuler/kernel/issues/IA77UW 
 
Link:https://gitee.com/openeuler/kernel/pulls/9296

 

Reviewed-by: default avatarzhangyi (F) <yi.zhang@huawei.com>
Signed-off-by: default avatarJialin Zhang <zhangjialin11@huawei.com>
parents 34666a54 760515d2
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -2953,12 +2953,12 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
	mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
	btrfs_init_btree_inode(fs_info);

	invalidate_bdev(fs_devices->latest_bdev);
	invalidate_bdev(fs_devices->latest_dev->bdev);

	/*
	 * Read super block and check the signature bytes only
	 */
	disk_super = btrfs_read_dev_super(fs_devices->latest_bdev);
	disk_super = btrfs_read_dev_super(fs_devices->latest_dev->bdev);
	if (IS_ERR(disk_super)) {
		err = PTR_ERR(disk_super);
		goto fail_alloc;
@@ -3182,7 +3182,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
	 */
	btrfs_free_extra_devids(fs_devices, 0);

	if (!fs_devices->latest_bdev) {
	if (!fs_devices->latest_dev->bdev) {
		btrfs_err(fs_info, "failed to read devices");
		goto fail_tree_roots;
	}
+1 −1
Original line number Diff line number Diff line
@@ -3080,7 +3080,7 @@ static int submit_extent_page(unsigned int opf,
	if (wbc) {
		struct block_device *bdev;

		bdev = BTRFS_I(page->mapping->host)->root->fs_info->fs_devices->latest_bdev;
		bdev = BTRFS_I(page->mapping->host)->root->fs_info->fs_devices->latest_dev->bdev;
		bio_set_dev(bio, bdev);
		wbc_init_bio(wbc, bio);
		wbc_account_cgroup_owner(wbc, page, page_size);
+1 −1
Original line number Diff line number Diff line
@@ -7560,7 +7560,7 @@ static int btrfs_dio_iomap_begin(struct inode *inode, loff_t start,
		iomap->type = IOMAP_MAPPED;
	}
	iomap->offset = start;
	iomap->bdev = fs_info->fs_devices->latest_bdev;
	iomap->bdev = fs_info->fs_devices->latest_dev->bdev;
	iomap->length = len;

	free_extent_map(em);
+6 −20
Original line number Diff line number Diff line
@@ -1676,7 +1676,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,
		goto error_close_devices;
	}

	bdev = fs_devices->latest_bdev;
	bdev = fs_devices->latest_dev->bdev;
	s = sget(fs_type, btrfs_test_super, btrfs_set_super, flags | SB_NOSEC,
		 fs_info);
	if (IS_ERR(s)) {
@@ -2411,30 +2411,16 @@ static int btrfs_unfreeze(struct super_block *sb)
static int btrfs_show_devname(struct seq_file *m, struct dentry *root)
{
	struct btrfs_fs_info *fs_info = btrfs_sb(root->d_sb);
	struct btrfs_device *dev, *first_dev = NULL;

	/*
	 * Lightweight locking of the devices. We should not need
	 * device_list_mutex here as we only read the device data and the list
	 * is protected by RCU.  Even if a device is deleted during the list
	 * traversals, we'll get valid data, the freeing callback will wait at
	 * least until the rcu_read_unlock.
	 * There should be always a valid pointer in latest_dev, it may be stale
	 * for a short moment in case it's being deleted but still valid until
	 * the end of RCU grace period.
	 */
	rcu_read_lock();
	list_for_each_entry_rcu(dev, &fs_info->fs_devices->devices, dev_list) {
		if (test_bit(BTRFS_DEV_STATE_MISSING, &dev->dev_state))
			continue;
		if (!dev->name)
			continue;
		if (!first_dev || dev->devid < first_dev->devid)
			first_dev = dev;
	}

	if (first_dev)
		seq_escape(m, rcu_str_deref(first_dev->name), " \t\n\\");
	else
		WARN_ON(1);
	seq_escape(m, rcu_str_deref(fs_info->fs_devices->latest_dev->name), " \t\n\\");
	rcu_read_unlock();

	return 0;
}

+7 −12
Original line number Diff line number Diff line
@@ -1133,7 +1133,7 @@ void btrfs_free_extra_devids(struct btrfs_fs_devices *fs_devices, int step)
	list_for_each_entry(seed_dev, &fs_devices->seed_list, seed_list)
		__btrfs_free_extra_devids(seed_dev, step, &latest_dev);

	fs_devices->latest_bdev = latest_dev->bdev;
	fs_devices->latest_dev = latest_dev;

	mutex_unlock(&uuid_mutex);
}
@@ -1265,7 +1265,7 @@ static int open_fs_devices(struct btrfs_fs_devices *fs_devices,
		return -EINVAL;

	fs_devices->opened = 1;
	fs_devices->latest_bdev = latest_dev->bdev;
	fs_devices->latest_dev = latest_dev;
	fs_devices->total_rw_bytes = 0;
	fs_devices->chunk_alloc_policy = BTRFS_CHUNK_ALLOC_REGULAR;

@@ -2014,7 +2014,7 @@ static struct btrfs_device * btrfs_find_next_active_device(
}

/*
 * Helper function to check if the given device is part of s_bdev / latest_bdev
 * Helper function to check if the given device is part of s_bdev / latest_dev
 * and replace it with the provided or the next active device, in the context
 * where this function called, there should be always be another device (or
 * this_dev) which is active.
@@ -2033,8 +2033,8 @@ void __cold btrfs_assign_next_active_device(struct btrfs_device *device,
			(fs_info->sb->s_bdev == device->bdev))
		fs_info->sb->s_bdev = next_device->bdev;

	if (fs_info->fs_devices->latest_bdev == device->bdev)
		fs_info->fs_devices->latest_bdev = next_device->bdev;
	if (fs_info->fs_devices->latest_dev->bdev == device->bdev)
		fs_info->fs_devices->latest_dev = next_device;
}

/*
@@ -2317,13 +2317,6 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev)

	mutex_unlock(&fs_devices->device_list_mutex);

	/*
	 * The update_dev_time() with in btrfs_scratch_superblocks()
	 * may lead to a call to btrfs_show_devname() which will try
	 * to hold device_list_mutex. And here this device
	 * is already out of device list, so we don't have to hold
	 * the device_list_mutex lock.
	 */
	btrfs_scratch_superblocks(tgtdev->fs_info, tgtdev->bdev,
				  tgtdev->name->str);

@@ -2629,6 +2622,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path
			btrfs_abort_transaction(trans, ret);
			goto error_trans;
		}
		btrfs_assign_next_active_device(fs_info->fs_devices->latest_dev,
						device);
	}

	device->fs_devices = fs_devices;
Loading