mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/3] md: fix uaf for sync_thread
@ 2023-03-30 20:20 Yu Kuai
  2023-03-30 20:20 ` [PATCH v3 1/3] md: pass a md_thread pointer to md_register_thread() Yu Kuai
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Yu Kuai @ 2023-03-30 20:20 UTC (permalink / raw)
  To: logang, song
  Cc: linux-kernel, linux-raid, yukuai3, yukuai1, yi.zhang, yangerkun

From: Yu Kuai <yukuai3@huawei.com>

Changes in v3:
 - remove patch 3 from v2
 - use rcu instead of a new lock

Changes in v2:
 - fix a compile error for md-cluster in patch 2
 - replace spin_lock/unlock with spin_lock/unlock_irq in patch 5
 - don't wake up inside the new lock in md wakeup_thread in patch 5

Our test reports a uaf for 'mddev->sync_thread':

T1                      T2
md_start_sync
 md_register_thread
			raid1d
			 md_check_recovery
			  md_reap_sync_thread
			   md_unregister_thread
			    kfree

 md_wakeup_thread
  wake_up
  ->sync_thread was freed

Currently, a global spinlock 'pers_lock' is borrowed to protect
'mddev->thread', this problem can be fixed likewise, however, there might
be similar problem for other md_thread, and I really don't like the idea to
borrow a global lock.

This patchset do some refactor and use rcu to protect md_thread.

Yu Kuai (3):
  md: pass a md_thread pointer to md_register_thread()
  md: refactor md_wakeup_thread()
  md: protect md_thread with rcu

 drivers/md/dm-raid.c      |   4 +-
 drivers/md/md-bitmap.c    |   6 +-
 drivers/md/md-cluster.c   |  31 +++++----
 drivers/md/md-multipath.c |   8 +--
 drivers/md/md.c           | 129 ++++++++++++++++++--------------------
 drivers/md/md.h           |  11 ++--
 drivers/md/raid1.c        |  15 +++--
 drivers/md/raid10.c       |  29 ++++-----
 drivers/md/raid5-cache.c  |  17 +++--
 drivers/md/raid5-ppl.c    |   2 +-
 drivers/md/raid5.c        |  45 +++++++------
 11 files changed, 139 insertions(+), 158 deletions(-)

-- 
2.39.2


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

end of thread, other threads:[~2023-03-31 15:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-30 20:20 [PATCH v3 0/3] md: fix uaf for sync_thread Yu Kuai
2023-03-30 20:20 ` [PATCH v3 1/3] md: pass a md_thread pointer to md_register_thread() Yu Kuai
2023-03-30 20:20 ` [PATCH v3 2/3] md: pass a md_thread pointer to md_wakeup_thread() Yu Kuai
2023-03-30 20:20 ` [PATCH v3 3/3] md: protect md_thread with rcu Yu Kuai
2023-03-30 18:40   ` kernel test robot
2023-03-30 19:35   ` Logan Gunthorpe
2023-03-31  1:08     ` Yu Kuai
2023-03-31  6:36       ` Yu Kuai
2023-03-31 15:41         ` Logan Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®