All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] blktrace: put bounds on BLKTRACESETUP buf_size and buf_nr
@ 2020-06-04  5:44 Harshad Shirwadkar
  2020-06-04  7:10 ` Chaitanya Kulkarni
  2020-06-05  4:31 ` Bart Van Assche
  0 siblings, 2 replies; 15+ messages in thread
From: Harshad Shirwadkar @ 2020-06-04  5:44 UTC (permalink / raw)
  To: linux-block; +Cc: Harshad Shirwadkar

Make sure that user requested memory via BLKTRACESETUP is within
bounds. This can be easily exploited by setting really large values
for buf_size and buf_nr in BLKTRACESETUP ioctl.

blktrace program has following hardcoded values for bufsize and bufnr:
BUF_SIZE=(512 * 1024)
BUF_NR=(4)

We add buffer to this and define the upper bound to be as follows:
BUF_SIZE=(1024 * 1024)
BUF_NR=(16)

This is very easy to exploit. Setting buf_size / buf_nr in userspace
program to big values make kernel go oom.  Verified that the fix makes
BLKTRACESETUP return -E2BIG if the buf_size * buf_nr crosses the upper
bound.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
---
 include/uapi/linux/blktrace_api.h | 3 +++
 kernel/trace/blktrace.c           | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/include/uapi/linux/blktrace_api.h b/include/uapi/linux/blktrace_api.h
index 690621b610e5..4d9dc44a83f9 100644
--- a/include/uapi/linux/blktrace_api.h
+++ b/include/uapi/linux/blktrace_api.h
@@ -129,6 +129,9 @@ enum {
 };
 
 #define BLKTRACE_BDEV_SIZE	32
+#define BLKTRACE_MAX_BUFSIZ	(1024 * 1024)
+#define BLKTRACE_MAX_BUFNR	16
+#define BLKTRACE_MAX_ALLOC	((BLKTRACE_MAX_BUFNR) * (BLKTRACE_MAX_BUFNR))
 
 /*
  * User setup structure passed with BLKTRACESETUP
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index ea47f2084087..b3b0a8164c05 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -482,6 +482,9 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
 	if (!buts->buf_size || !buts->buf_nr)
 		return -EINVAL;
 
+	if (buts->buf_size * buts->buf_nr > BLKTRACE_MAX_ALLOC)
+		return -E2BIG;
+
 	if (!blk_debugfs_root)
 		return -ENOENT;
 
-- 
2.27.0.rc2.251.g90737beb825-goog


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

end of thread, other threads:[~2020-06-09  0:00 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-04  5:44 [PATCH] blktrace: put bounds on BLKTRACESETUP buf_size and buf_nr Harshad Shirwadkar
2020-06-04  7:10 ` Chaitanya Kulkarni
2020-06-04 15:26   ` harshad shirwadkar
2020-06-05  4:31 ` Bart Van Assche
2020-06-05  5:02   ` harshad shirwadkar
2020-06-05 13:43     ` Bart Van Assche
2020-06-05 17:39       ` harshad shirwadkar
2020-06-08  6:42         ` Chaitanya Kulkarni
2020-06-08  6:40       ` Chaitanya Kulkarni
2020-06-08 14:20         ` Bart Van Assche
2020-06-08 21:59           ` Chaitanya Kulkarni
2020-06-08 23:40             ` harshad shirwadkar
2020-06-09  0:00               ` Chaitanya Kulkarni
2020-06-08  6:34   ` Chaitanya Kulkarni
2020-06-08 14:13     ` Bart Van Assche

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.