linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC v2 0/5] blktrace: fix use after free
@ 2020-04-09 21:45 Luis Chamberlain
  2020-04-09 21:45 ` [RFC v2 1/5] block: move main block debugfs initialization to its own file Luis Chamberlain
                   ` (4 more replies)
  0 siblings, 5 replies; 20+ messages in thread
From: Luis Chamberlain @ 2020-04-09 21:45 UTC (permalink / raw)
  To: axboe, viro, gregkh, rostedt, mingo, jack, ming.lei, nstange, akpm
  Cc: mhocko, yukuai3, linux-block, linux-fsdevel, linux-mm,
	linux-kernel, Luis Chamberlain

This series fixes a use after free on block trace. This v2 adjusts the
commit log feedback from the first iteration, and also expands on the
series to include a few additional fixes which would be needed for us
to continue with a synchronous request_queue removal. The refcount added
for blktrace resolves the kobject issues pointed out by yukuai. Note
that CONFIG_DEBUG_KOBJECT_RELEASE purposely was added to create
situations where drivers misbehave, and so you should not use it to
test expected userspace behaviour, but just to catch possible kernel
issues. For details refer to the commit which introduced it, which
actually helps a bit more than just reading the kconfig description,
its commit was c817a67ecba7 ("kobject: delayed kobject release: help
find buggy drivers"). This series also fixes a small build issue
discovered by 0-day.

The QUEUE_FLAG_DEFER_REMOVAL flag is added as part of the last patch,
just in case for now. However, given creative use of refcounting
I don't think we need it anymore. An example use case of creative
use of refcounting is provided for mm/swapfile.

I've extended break-blktrace [0] with 3 test cases which now pass
for the most part:

run_0001.sh
run_0002.sh
run_0003.sh

The exception to this is when we get an EBUSY on loopback removal. This
only happens every now and then, and upon further investigation, I
suspect this is happening due to the same race Dave Chinner ran into
with using loopback devices and fstests, which made explicit loopback
destruction lazy via commit a1ecac3b0656 ("loop: Make explicit loop
device destruction lazy"). Further eyeballs on this are appreciated,
perhaps break-blktrace can be extended a bit to account for this.

After a bit of brushing up, I am considering just upstreaming this
as a self tests for blktrace, instead of keeping this out of tree.

Worth noting as well was that it seems odd we didn't consider the
userspace impact of commit dc9edc44de6c ("block: Fix a blk_exit_rl()
regression") merged on v4.12 moved, as that deferral work sure did
have an impact what userspace can expect upon device removal or races
on addition/removal. Its not clear if mentioning any of this on the
commit logs is worth it... Shouldn't have that deferral been a
userspace regression?

If you want this on a git tree you can find it on my 20200409-blktrace-fix-uaf
branch on kernel.org based on linux-next next-20200409.

Feedback, reviews, rants are all greatly appreciated.

[0] https://github.com/mcgrof/break-blktrace
[1] https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux-next.git/log/?h=20200409-blktrace-fix-uaf

Luis Chamberlain (5):
  block: move main block debugfs initialization to its own file
  blktrace: fix debugfs use after free
  blktrace: ref count the request_queue during ioctl
  mm/swapfile: refcount block and queue before using
    blkcg_schedule_throttle()
  block: revert back to synchronous request_queue removal

 block/Makefile               |  1 +
 block/blk-core.c             |  9 +-------
 block/blk-debugfs.c          | 27 ++++++++++++++++++++++
 block/blk-mq-debugfs.c       |  5 -----
 block/blk-sysfs.c            | 43 +++++++++++++++++++++++++++++-------
 block/blk.h                  | 17 ++++++++++++++
 include/linux/blkdev.h       |  7 +++++-
 include/linux/blktrace_api.h |  1 -
 kernel/trace/blktrace.c      | 25 ++++++++++++---------
 mm/swapfile.c                | 11 +++++++++
 10 files changed, 112 insertions(+), 34 deletions(-)
 create mode 100644 block/blk-debugfs.c

-- 
2.25.1


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

end of thread, other threads:[~2020-04-14  3:38 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-09 21:45 [RFC v2 0/5] blktrace: fix use after free Luis Chamberlain
2020-04-09 21:45 ` [RFC v2 1/5] block: move main block debugfs initialization to its own file Luis Chamberlain
2020-04-10  2:48   ` Bart Van Assche
2020-04-09 21:45 ` [RFC v2 2/5] blktrace: fix debugfs use after free Luis Chamberlain
2020-04-10  2:52   ` Bart Van Assche
2020-04-10 19:58     ` Luis Chamberlain
2020-04-11 23:09       ` Bart Van Assche
2020-04-14  3:32         ` Luis Chamberlain
2020-04-09 21:45 ` [RFC v2 3/5] blktrace: ref count the request_queue during ioctl Luis Chamberlain
2020-04-10  2:58   ` Bart Van Assche
2020-04-09 21:45 ` [RFC v2 4/5] mm/swapfile: refcount block and queue before using blkcg_schedule_throttle() Luis Chamberlain
2020-04-10  3:02   ` Bart Van Assche
2020-04-10 14:34     ` Luis Chamberlain
2020-04-09 21:45 ` [RFC v2 5/5] block: revert back to synchronous request_queue removal Luis Chamberlain
2020-04-10  3:12   ` Bart Van Assche
2020-04-10 14:34     ` Luis Chamberlain
2020-04-10 20:50       ` Luis Chamberlain
2020-04-10 21:27         ` Luis Chamberlain
2020-04-11 23:21           ` Bart Van Assche
2020-04-14  3:38             ` Luis Chamberlain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).