From patchwork Wed Mar 20 08:12:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 10860977 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7B6A91708 for ; Wed, 20 Mar 2019 08:13:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6D67E28C28 for ; Wed, 20 Mar 2019 08:13:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61B1429A81; Wed, 20 Mar 2019 08:13:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D065428C28 for ; Wed, 20 Mar 2019 08:12:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727588AbfCTIM5 (ORCPT ); Wed, 20 Mar 2019 04:12:57 -0400 Received: from mx2.suse.de ([195.135.220.15]:51652 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727555AbfCTIM5 (ORCPT ); Wed, 20 Mar 2019 04:12:57 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 3394FAF56; Wed, 20 Mar 2019 08:12:56 +0000 (UTC) From: Hannes Reinecke To: Jan Kara Cc: Jens Axboe , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Hannes Reinecke , Hannes Reinecke Subject: [PATCH] block_dev: fix crash on chained bios with O_DIRECT Date: Wed, 20 Mar 2019 09:12:53 +0100 Message-Id: <20190320081253.129688-1-hare@suse.de> X-Mailer: git-send-email 2.16.4 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP __blkdev_direct_IO_simple() is allocating a bio on the stack. When that bio needs to be split bio_chain_endio() invokes bio_put() on this bio, causing the kernel to crash in mempool_free() as the bio was never allocated from a mempool in the first place. So call bio_get() before submitting to avoid this problem. Signed-off-by: Hannes Reinecke Signed-off-by: Johannes Thumshirn --- fs/block_dev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/block_dev.c b/fs/block_dev.c index c546cdce77e6..4b3a04c3b8bd 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -235,6 +235,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter, if (iocb->ki_flags & IOCB_HIPRI) bio.bi_opf |= REQ_HIPRI; + bio_get(&bio); qc = submit_bio(&bio); for (;;) { set_current_state(TASK_UNINTERRUPTIBLE); @@ -254,7 +255,7 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct iov_iter *iter, if (unlikely(bio.bi_status)) ret = blk_status_to_errno(bio.bi_status); - + bio_put(&bio); out: if (vecs != inline_vecs) kfree(vecs);