Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5745559ybl; Tue, 10 Dec 2019 10:48:16 -0800 (PST) X-Google-Smtp-Source: APXvYqwbOt97Ar9gJHqt1pXU+ULanfE1yruqjVq00CJLtBDLI75IrZCg9LhZJf5OWs04T85/GSHl X-Received: by 2002:a05:6830:1415:: with SMTP id v21mr13674764otp.188.1576003696691; Tue, 10 Dec 2019 10:48:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576003696; cv=none; d=google.com; s=arc-20160816; b=AArKUhfNfRfDG/hSqnYjzOvjFBCK4eFdtcwHgLVluESpzDUH+EeMdXIuGReTAGKYmL YdeTWXfZ/MQ4Nmu+vUxXvFv9TTmlyIo1kde0OYdMRx7XLD0zvPPuhs++olfN69+LU93m 23i6YwHhLDgd5GD8Hn2TlxgU3dtsHn0ve0UVHvy/xku4lkxNzFuI8L0gq6H1SUUhElGO /jikfFKTs2e8wIxCfKsqXzugy81KKtKBn283Wkbve7SUewp1DSlyuAN/RSuxmCeH+pwI vJLCXcdGu48+P2ThJ78Y1VMhBBRCaIh6VeoFLYYJWFyzeOg0rWvSu3zZ3p90UrUP7tT7 0K6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:content-transfer-encoding :mime-version:message-id:date:cc:to:from; bh=0ftrDzFmGbAVhiqOuZbjMlRPNeNiXwhQpQlId2xIDPI=; b=uVDNkmWlX5gM5oSxE2MEqE0yv5HshhkdpkQCKsCEd/uLQSVijH6VEaoIGVTf2iAFP5 Xo68UldbAStNaxAcd0kS8Nw6iMXfi0vA5nRCzB91pJ4oEQzmBB6woHELneyK9Y+OvMYp dvEbjihT0rr/TvnJPxn5qOv0xVk7Oh33dHiRvuHk5GhmsBAXUzWjjsXhbxfKhAkc0rTO 9YhdfeAaxjk0w6QwcNjzwi1Ql7fmH3zIRpUGd9kKIM7jXhonW0Y0DxDnuViN+IXMcgx/ bl6QM6N2r3+u3+PnPFBlVoVfd7Du/y2z4iatAB6yz8pf+qgxzElw7Sh6FRvxH3aErHp9 BY7Q== 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 r26si2442746otc.163.2019.12.10.10.48.03; Tue, 10 Dec 2019 10:48:16 -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 S1727663AbfLJSrL (ORCPT + 99 others); Tue, 10 Dec 2019 13:47:11 -0500 Received: from ale.deltatee.com ([207.54.116.67]:39430 "EHLO ale.deltatee.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726771AbfLJSrL (ORCPT ); Tue, 10 Dec 2019 13:47:11 -0500 Received: from cgy1-donard.priv.deltatee.com ([172.16.1.31]) by ale.deltatee.com with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iekXN-00086y-OQ; Tue, 10 Dec 2019 11:47:10 -0700 Received: from gunthorp by cgy1-donard.priv.deltatee.com with local (Exim 4.92) (envelope-from ) id 1iekXL-0006H8-U5; Tue, 10 Dec 2019 11:47:07 -0700 From: Logan Gunthorpe To: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe Cc: Christoph Hellwig , Linus Torvalds , Logan Gunthorpe , kernel test robot Date: Tue, 10 Dec 2019 11:47:04 -0700 Message-Id: <20191210184704.24081-1-logang@deltatee.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SA-Exim-Connect-IP: 172.16.1.31 X-SA-Exim-Rcpt-To: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, axboe@kernel.dk, hch@lst.de, torvalds@linux-foundation.org, logang@deltatee.com, rong.a.chen@intel.com X-SA-Exim-Mail-From: gunthorp@deltatee.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on ale.deltatee.com X-Spam-Level: X-Spam-Status: No, score=-8.7 required=5.0 tests=ALL_TRUSTED,BAYES_00, GREYLIST_ISWHITE,MYRULES_NO_TEXT autolearn=ham autolearn_force=no version=3.4.2 Subject: [PATCH] block: fix NULL pointer dereference in account statistics with IDE X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on ale.deltatee.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The IDE driver creates some passthru requests which never get submitted to the block layer in such a way that blk_account_io_start() gets called. However, the driver still calls __blk_mq_end_request() in ide_end_rq() which will call blk_account_io_completion() which tries to dereferences req->part which is never set. See ide_prep_sense() for an example of where these requests come from. To fix this, blk_account_io_completion() and blk_account_io_done() should do nothing if req->part is not set. The back trace of this bug is: BUG: kernel NULL pointer dereference, address: 000002ac #PF: supervisor write access in kernel mode #PF: error_code(0x0002) - not-present page *pde = 00000000 Oops: 0002 [#1] CPU: 0 PID: 237 Comm: kworker/0:1H Not tainted 5.4.0-rc2-00011-g48d9b0d43105e #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1 04/01/2014 Workqueue: kblockd drive_rq_insert_work EIP: blk_account_io_completion+0x7a/0xf0 Code: 89 54 24 08 31 d2 89 4c 24 04 31 c9 c7 04 24 02 00 00 00 c1 ee 09 e8 f5 21 a6 ff e8 70 5c a7 ff 8b 53 60 8d 04 bd 00 00 00 00 <01> b4 02 ac 02 00 00 8b 9a 88 02 00 00 85 db 74 11 85 d2 74 51 8b EAX: 00000000 EBX: f5b80000 ECX: 00000000 EDX: 00000000 ESI: 00000000 EDI: 00000000 EBP: f3031e70 ESP: f3031e54 DS: 007b ES: 007b FS: 0000 GS: 0000 SS: 0068 EFLAGS: 00010046 CR0: 80050033 CR2: 000002ac CR3: 03c25000 CR4: 000406d0 Call Trace: blk_update_request+0x85/0x420 ide_end_rq+0x38/0xa0 ide_complete_rq+0x3d/0x70 cdrom_newpc_intr+0x258/0xba0 ide_intr+0x135/0x250 __handle_irq_event_percpu+0x3e/0x250 handle_irq_event_percpu+0x1f/0x50 handle_irq_event+0x32/0x60 handle_level_irq+0x6c/0x110 handle_irq+0x72/0xa0 do_IRQ+0x45/0xad common_interrupt+0x115/0x11c Fixes: 48d9b0d43105 ("block: account statistics for passthrough requests") Reported-by: kernel test robot Signed-off-by: Logan Gunthorpe --- block/blk-core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index a1e228752083..68c309ce6735 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1310,7 +1310,7 @@ EXPORT_SYMBOL_GPL(blk_rq_err_bytes); void blk_account_io_completion(struct request *req, unsigned int bytes) { - if (blk_do_io_stat(req)) { + if (req->part && blk_do_io_stat(req)) { const int sgrp = op_stat_group(req_op(req)); struct hd_struct *part; @@ -1328,7 +1328,8 @@ void blk_account_io_done(struct request *req, u64 now) * normal IO on queueing nor completion. Accounting the * containing request is enough. */ - if (blk_do_io_stat(req) && !(req->rq_flags & RQF_FLUSH_SEQ)) { + if (req->part && blk_do_io_stat(req) && + !(req->rq_flags & RQF_FLUSH_SEQ)) { const int sgrp = op_stat_group(req_op(req)); struct hd_struct *part; -- 2.20.1