Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933751AbdDFMD6 (ORCPT ); Thu, 6 Apr 2017 08:03:58 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:34092 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755551AbdDFMCz (ORCPT ); Thu, 6 Apr 2017 08:02:55 -0400 From: Dmitry Monakhov To: linux-kernel@vger.kernel.org Cc: darrick.wong@oracle.com, axboe@kernel.dk, tytso@mit.edu, jack@suse.cz, hch@infradead.org, Dmitry Monakhov Subject: [PATCH 1/5] bh: Prevent panic on invalid BHs Date: Thu, 6 Apr 2017 16:02:45 +0400 Message-Id: <1491480169-1889-2-git-send-email-dmonakhov@openvz.org> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1491480169-1889-1-git-send-email-dmonakhov@openvz.org> References: <1491480169-1889-1-git-send-email-dmonakhov@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1920 Lines: 66 - Convert BUG_ON to WARN_ON+EIO on submit_bh. Leave BUG_ON(!bh->b_end_io) as is because this is static bug in submission logic which can not be handled at runtime anyway. unmapped BH is also special case which signal about user misbehavior, so just dump error messageю - guard __find_get_block from null pointer bdev. Signed-off-by: Dmitry Monakhov --- fs/buffer.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 9196f2a..4c8ce74 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -1355,8 +1355,12 @@ lookup_bh_lru(struct block_device *bdev, sector_t block, unsigned size) struct buffer_head * __find_get_block(struct block_device *bdev, sector_t block, unsigned size) { - struct buffer_head *bh = lookup_bh_lru(bdev, block, size); + struct buffer_head *bh; + + if (WARN_ON_ONCE(!bdev)) + return NULL; + bh = lookup_bh_lru(bdev, block, size); if (bh == NULL) { /* __find_get_block_slow will mark the page accessed */ bh = __find_get_block_slow(bdev, block); @@ -3099,11 +3103,18 @@ static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh, { struct bio *bio; - BUG_ON(!buffer_locked(bh)); - BUG_ON(!buffer_mapped(bh)); BUG_ON(!bh->b_end_io); - BUG_ON(buffer_delay(bh)); - BUG_ON(buffer_unwritten(bh)); + + if (WARN_ON_ONCE(!buffer_locked(bh))) + goto bad_bh; + if (WARN_ON_ONCE(buffer_delay(bh))) + goto bad_bh; + if (WARN_ON_ONCE(buffer_unwritten(bh))) + goto bad_bh; + if (unlikely(!buffer_mapped(bh))) { + buffer_io_error(bh, ", bh not mapped"); + goto bad_bh; + } /* * Only clear out a write error when rewriting @@ -3143,6 +3154,9 @@ static int submit_bh_wbc(int op, int op_flags, struct buffer_head *bh, submit_bio(bio); return 0; +bad_bh: + bh->b_end_io(bh, 0); + return -EIO; } int _submit_bh(int op, int op_flags, struct buffer_head *bh, -- 2.9.3