android_kernel_sony_sdm845/drivers/md
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Zhiqiang Liu be676835b2 bcache: fix potential deadlock problem in btree_gc_coalesce
[ Upstream commit be23e837333a914df3f24bf0b32e87b0331ab8d1 ]

coccicheck reports:
  drivers/md//bcache/btree.c:1538:1-7: preceding lock on line 1417

In btree_gc_coalesce func, if the coalescing process fails, we will goto
to out_nocoalesce tag directly without releasing new_nodes[i]->write_lock.
Then, it will cause a deadlock when trying to acquire new_nodes[i]->
write_lock for freeing new_nodes[i] before return.

btree_gc_coalesce func details as follows:
	if alloc new_nodes[i] fails:
		goto out_nocoalesce;
	// obtain new_nodes[i]->write_lock
	mutex_lock(&new_nodes[i]->write_lock)
	// main coalescing process
	for (i = nodes - 1; i > 0; --i)
		[snipped]
		if coalescing process fails:
			// Here, directly goto out_nocoalesce
			 // tag will cause a deadlock
			goto out_nocoalesce;
		[snipped]
	// release new_nodes[i]->write_lock
	mutex_unlock(&new_nodes[i]->write_lock)
	// coalesing succ, return
	return;
out_nocoalesce:
	btree_node_free(new_nodes[i])	// free new_nodes[i]
	// obtain new_nodes[i]->write_lock
	mutex_lock(&new_nodes[i]->write_lock);
	// set flag for reuse
	clear_bit(BTREE_NODE_dirty, &ew_nodes[i]->flags);
	// release new_nodes[i]->write_lock
	mutex_unlock(&new_nodes[i]->write_lock);

To fix the problem, we add a new tag 'out_unlock_nocoalesce' for
releasing new_nodes[i]->write_lock before out_nocoalesce tag. If
coalescing process fails, we will go to out_unlock_nocoalesce tag
for releasing new_nodes[i]->write_lock before free new_nodes[i] in
out_nocoalesce tag.

(Coly Li helps to clean up commit log format.)

Fixes: 2a285686c1 ("bcache: btree locking rework")
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-06-30 15:38:30 -04:00
..
bcache bcache: fix potential deadlock problem in btree_gc_coalesce 2020-06-30 15:38:30 -04:00
persistent-data dm space map common: fix to ensure new block isn't already in use 2020-02-14 16:31:01 -05:00
bitmap.c md: Avoid namespace collision with bitmap API 2020-01-29 10:24:40 +01:00
bitmap.h
dm-bio-prison.c dm: Use kzalloc for all structs with embedded biosets/mempools 2019-11-06 12:18:01 +01:00
dm-bio-prison.h
dm-bio-record.h
dm-bufio.c Revert "dm bufio: fix deadlock with loop device" 2019-09-06 10:19:36 +02:00
dm-bufio.h
dm-builtin.c
dm-cache-block-types.h
dm-cache-metadata.c dm cache metadata: ignore hints array being too small during resize 2018-10-13 09:18:55 +02:00
dm-cache-metadata.h
dm-cache-policy-cleaner.c
dm-cache-policy-internal.h
dm-cache-policy-smq.c
dm-cache-policy.c
dm-cache-policy.h
dm-cache-target.c dm cache: fix a crash due to incorrect work item cancelling 2020-03-11 07:53:14 +01:00
dm-core.h dm: allocate struct mapped_device with kvzalloc 2017-11-30 08:39:02 +00:00
dm-crypt.c
dm-delay.c dm delay: fix a crash when invalid device is specified 2019-05-25 18:26:54 +02:00
dm-era-target.c
dm-exception-store.c
dm-exception-store.h
dm-flakey.c dm flakey: check for null arg_name in parse_features() 2020-04-24 07:59:05 +02:00
dm-io.c dm: Use kzalloc for all structs with embedded biosets/mempools 2019-11-06 12:18:01 +01:00
dm-ioctl.c dm ioctl: harden copy_params()'s copy_from_user() from malicious users 2018-11-13 11:17:02 -08:00
dm-kcopyd.c dm: Use kzalloc for all structs with embedded biosets/mempools 2019-11-06 12:18:01 +01:00
dm-linear.c
dm-log-userspace-base.c
dm-log-userspace-transfer.c
dm-log-userspace-transfer.h
dm-log-writes.c
dm-log.c
dm-mpath.c dm mpath: cleanup -Wbool-operation warning in choose_pgpath() 2017-07-27 15:07:55 -07:00
dm-mpath.h
dm-path-selector.c
dm-path-selector.h
dm-queue-length.c
dm-raid.c dm raid: fix rebuild of specific devices by updating superblock 2018-10-10 08:53:21 +02:00
dm-raid1.c
dm-region-hash.c dm: Use kzalloc for all structs with embedded biosets/mempools 2019-11-06 12:18:01 +01:00
dm-round-robin.c
dm-rq.c
dm-rq.h
dm-service-time.c
dm-snap-persistent.c block: fix an integer overflow in logical block size 2020-01-23 08:19:38 +01:00
dm-snap-transient.c
dm-snap.c dm: Use kzalloc for all structs with embedded biosets/mempools 2019-11-06 12:18:01 +01:00
dm-stats.c
dm-stats.h
dm-stripe.c
dm-switch.c
dm-sysfs.c
dm-table.c dm table: fix invalid memory accesses with too high sector number 2019-09-06 10:19:39 +02:00
dm-target.c
dm-thin-metadata.c dm thin: fix passdown_double_checking_shared_status() 2019-01-31 08:12:36 +01:00
dm-thin-metadata.h dm thin: fix passdown_double_checking_shared_status() 2019-01-31 08:12:36 +01:00
dm-thin.c dm: Use kzalloc for all structs with embedded biosets/mempools 2019-11-06 12:18:01 +01:00
dm-uevent.c
dm-uevent.h
dm-verity-fec.c dm verity fec: fix hash block number in verity_fec_decode 2020-05-05 19:14:38 +02:00
dm-verity-fec.h
dm-verity-target.c dm verity: use message limit for data block corruption message 2019-07-21 09:06:07 +02:00
dm-verity.h
dm-zero.c
dm.c dm: fix potential for q->make_request_fn NULL pointer 2020-02-14 16:31:10 -05:00
dm.h
faulty.c
Kconfig
linear.c md/linear: shutup lockdep warnning 2017-10-21 17:21:35 +02:00
linear.h
Makefile
md-cluster.c md-cluster: clear another node's suspend_area after the copy is finished 2018-10-03 17:01:43 -07:00
md-cluster.h
md.c md: don't flush workqueue unconditionally in md_open 2020-06-20 10:24:17 +02:00
md.h
multipath.c
multipath.h
raid0.c block: fix an integer overflow in logical block size 2020-01-23 08:19:38 +01:00
raid0.h
raid1.c md: raid1: check rdev before reference in raid1_sync_request func 2020-01-12 11:24:10 +01:00
raid1.h
raid5-cache.c
raid5.c md/raid6: Set R5_ReadError when there is read failure on parity disk 2019-10-05 12:30:34 +02:00
raid5.h
raid10.c md: Fix failed allocation of md_register_thread 2019-03-23 13:19:53 +01:00
raid10.h