Received: by 10.223.185.116 with SMTP id b49csp821359wrg; Sat, 10 Feb 2018 21:10:33 -0800 (PST) X-Google-Smtp-Source: AH8x226i1aIg2zCrVVkafKLCuQl0ljBI+LIRfSlItDrGzTVa6Szb5R4x3NOJ9fiku6c9hFYnEgXS X-Received: by 2002:a17:902:3183:: with SMTP id x3-v6mr7208295plb.290.1518325833615; Sat, 10 Feb 2018 21:10:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518325833; cv=none; d=google.com; s=arc-20160816; b=U+1oA4qqzIt+ooatQI1CotbmVUDoDHs3d2mrM8s7HjXWjrPs5dUAd3+OUlf3+RqEZx rdhlyi6xGp2nMGkyjA1x/uhQkSKZMdaJ10M5o4/rJc0tiFSvGLAKwbz6y/9Ftx4BS6PF efJh4N3b6wxMPE3aqX6NMJafPD32vPcvWK5bcflgADZbHJozMcNkffisccNXN3aeC1Ce WKxuo9YAwwspMutocYABcZ47vyCoxplCABJCQtvjhH3lnsJtqeyB9AHmEXJBK/UOs04K 1b0IkddDxjJ/nxLQQrTYEOSKKOdUhMT6/EAE5e4NDsVr4DA+7dhLS3rZuOYsoJVz4GzW sALg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=x2eQH7J24ZFxMWPjfCBSlqeE0yXc0mBKi0R+NkdQ1Z0=; b=c8hn7QHobJcT0LzVDmG7QPbqHFllF4FR754ym6oi/5BxAn2WUqGBgVKcW1OHvmb6k7 o6l3843zXNAMn7MRRPKm4ISCsdnKtldJB+csDOBQDTMLzyWOllaCpoOQIDOtQvRxu+65 0fAT+0BOBPi1ePiuIXQkkUDVVui1EuCp85jaagwxH/nC2UVGz+DjvyV/NmDt4w8Rv7wH 2wM5qDSocK81RMLk9t4CKdguz3vG/YRnTRUgzgOub33SSR3qQhJTUXEmquVMSBhem8wD skHoujXPncs8gWr59XCp1tfYuAxRc7vEds4cRP4bnOU+Tg88SX+vRkE5idezw7nJcPPS G7rw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e17si2087860pgo.189.2018.02.10.21.10.20; Sat, 10 Feb 2018 21:10:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753463AbeBKFH3 (ORCPT + 99 others); Sun, 11 Feb 2018 00:07:29 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41471 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752664AbeBKEdm (ORCPT ); Sat, 10 Feb 2018 23:33:42 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ekjKe-0002hO-OR; Sun, 11 Feb 2018 04:33:40 +0000 Received: from ben by deadeye with local (Exim 4.90) (envelope-from ) id 1ekjKX-0004UK-VE; Sun, 11 Feb 2018 04:33:33 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Dmitry Vyukov" , "Jens Axboe" Date: Sun, 11 Feb 2018 04:20:06 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.2 36/79] blktrace: fix unlocked access to init/start-stop/teardown In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.2.99-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Jens Axboe commit 1f2cac107c591c24b60b115d6050adc213d10fc0 upstream. sg.c calls into the blktrace functions without holding the proper queue mutex for doing setup, start/stop, or teardown. Add internal unlocked variants, and export the ones that do the proper locking. Fixes: 6da127ad0918 ("blktrace: Add blktrace ioctls to SCSI generic devices") Tested-by: Dmitry Vyukov Signed-off-by: Jens Axboe Signed-off-by: Ben Hutchings --- kernel/trace/blktrace.c | 58 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 10 deletions(-) --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -296,7 +296,7 @@ static void blk_trace_cleanup(struct blk blk_unregister_tracepoints(); } -int blk_trace_remove(struct request_queue *q) +static int __blk_trace_remove(struct request_queue *q) { struct blk_trace *bt; @@ -309,6 +309,17 @@ int blk_trace_remove(struct request_queu return 0; } + +int blk_trace_remove(struct request_queue *q) +{ + int ret; + + mutex_lock(&q->blk_trace_mutex); + ret = __blk_trace_remove(q); + mutex_unlock(&q->blk_trace_mutex); + + return ret; +} EXPORT_SYMBOL_GPL(blk_trace_remove); static int blk_dropped_open(struct inode *inode, struct file *filp) @@ -538,9 +549,8 @@ err: return ret; } -int blk_trace_setup(struct request_queue *q, char *name, dev_t dev, - struct block_device *bdev, - char __user *arg) +static int __blk_trace_setup(struct request_queue *q, char *name, dev_t dev, + struct block_device *bdev, char __user *arg) { struct blk_user_trace_setup buts; int ret; @@ -559,6 +569,19 @@ int blk_trace_setup(struct request_queue } return 0; } + +int blk_trace_setup(struct request_queue *q, char *name, dev_t dev, + struct block_device *bdev, + char __user *arg) +{ + int ret; + + mutex_lock(&q->blk_trace_mutex); + ret = __blk_trace_setup(q, name, dev, bdev, arg); + mutex_unlock(&q->blk_trace_mutex); + + return ret; +} EXPORT_SYMBOL_GPL(blk_trace_setup); #if defined(CONFIG_COMPAT) && defined(CONFIG_X86_64) @@ -596,7 +619,7 @@ static int compat_blk_trace_setup(struct } #endif -int blk_trace_startstop(struct request_queue *q, int start) +static int __blk_trace_startstop(struct request_queue *q, int start) { int ret; struct blk_trace *bt = q->blk_trace; @@ -629,6 +652,17 @@ int blk_trace_startstop(struct request_q return ret; } + +int blk_trace_startstop(struct request_queue *q, int start) +{ + int ret; + + mutex_lock(&q->blk_trace_mutex); + ret = __blk_trace_startstop(q, start); + mutex_unlock(&q->blk_trace_mutex); + + return ret; +} EXPORT_SYMBOL_GPL(blk_trace_startstop); /* @@ -659,7 +693,7 @@ int blk_trace_ioctl(struct block_device switch (cmd) { case BLKTRACESETUP: bdevname(bdev, b); - ret = blk_trace_setup(q, b, bdev->bd_dev, bdev, arg); + ret = __blk_trace_setup(q, b, bdev->bd_dev, bdev, arg); break; #if defined(CONFIG_COMPAT) && defined(CONFIG_X86_64) case BLKTRACESETUP32: @@ -670,10 +704,10 @@ int blk_trace_ioctl(struct block_device case BLKTRACESTART: start = 1; case BLKTRACESTOP: - ret = blk_trace_startstop(q, start); + ret = __blk_trace_startstop(q, start); break; case BLKTRACETEARDOWN: - ret = blk_trace_remove(q); + ret = __blk_trace_remove(q); break; default: ret = -ENOTTY; @@ -691,10 +725,14 @@ int blk_trace_ioctl(struct block_device **/ void blk_trace_shutdown(struct request_queue *q) { + mutex_lock(&q->blk_trace_mutex); + if (q->blk_trace) { - blk_trace_startstop(q, 0); - blk_trace_remove(q); + __blk_trace_startstop(q, 0); + __blk_trace_remove(q); } + + mutex_unlock(&q->blk_trace_mutex); } /*