Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp90003yba; Mon, 20 May 2019 05:32:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqy5Oyexmkdglj5p4kBS3EE7I+ikzqRExjBlCaFb7CKDdaMXaxhuBHOj3apC/ZpzfMRer2gq X-Received: by 2002:a62:414a:: with SMTP id o71mr81098808pfa.240.1558355530536; Mon, 20 May 2019 05:32:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558355530; cv=none; d=google.com; s=arc-20160816; b=zqOaYJC/C0UFhNMJg3qeCnEghMvgqfsA2PqfNeCd0R+HnaJyafn9XcPSiO7nyGMJoT YzQXpAFmlkcG3YCAXVwYW6y9Kvh3Ei9o2aSIl2bTrokd9OtjWih5fjpWlerIqLrpFCxe GPJTlT5vf/OAjKV0alUdaELwjy9xjP7LJRpJR9EtV1FAbwV7X+vF91Ooq8Jl6Yc9gxre sXCbb/QAdYbbS6a8kmOjVfXD+wPnDvE12WY/zwxLNf0N5QpeB/yOaB6JZI+CwGSPP+AP qfbu+CD7NliK6jd/OhTjSphML0Uk7Im5CcwzqlA8MqpKH0QIPHUu9q09CIsYISgqGVpf HSiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=77CqfDRExSZQ24GPTCalHmzoSLsqh24m+M8Cm29qoq4=; b=rNAXO7uZQrMhibOMd3pVVIWJxyAnfnVmkC7jVPh+Zki2BDnzngZrFiHN5g7iS6O//C /KuJ1IuqsHn2aWQW8hX3hsLYyvjeWnTOaU+RjDMC2veWUhbSIbta9Kv8KAE7Dmdvznnr axGLOf79kurgD2g5AIUQx+M+FgyDib27iFYve+aCr4lKEa+r50wKMyIGa3nn687AxX+k 6MTt3ekxKb/XTWfP9JZUxyUxhIMsWoVy7VnvCC3/n3jqco3Df9aItOeZ7bfy6fYmOyaT BNGXNicvOpoC+GyXJxb/04ycnR3YcuUA51cQnqQmDsF7syVtykZOaShgncobPHf/uNTD n3dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SK2pPgzK; 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 67si18510361plf.382.2019.05.20.05.31.55; Mon, 20 May 2019 05:32:10 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=SK2pPgzK; 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 S2389791AbfETM3D (ORCPT + 99 others); Mon, 20 May 2019 08:29:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:44936 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389773AbfETM26 (ORCPT ); Mon, 20 May 2019 08:28:58 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DE7B220815; Mon, 20 May 2019 12:28:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355338; bh=L/Cv3EAR9jLgZ9/NL7/jp4JloC3gs6Kc1Nk8kU4hPu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SK2pPgzKktoB3kiUohi9nnyIfOOazAf4AOPEzCVDmBtifWDOMOnvQGIyc2kxBdAiP F4Q/nVLShO4eolAo6IWWdjgdrtsNHoYW45SZ91CBbBM35V9cHCAYOQQnv2OmR+xSh9 7YT8x/p+d48l0q79kEcsuFf4+XGCwumYMLvF/sWQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Ren , Jiufei Xue , Theodore Tso , Jan Kara , stable@kernel.org Subject: [PATCH 5.0 081/123] jbd2: check superblock mapped prior to committing Date: Mon, 20 May 2019 14:14:21 +0200 Message-Id: <20190520115250.234230887@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115245.439864225@linuxfoundation.org> References: <20190520115245.439864225@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jiufei Xue commit 742b06b5628f2cd23cb51a034cb54dc33c6162c5 upstream. We hit a BUG at fs/buffer.c:3057 if we detached the nbd device before unmounting ext4 filesystem. The typical chain of events leading to the BUG: jbd2_write_superblock submit_bh submit_bh_wbc BUG_ON(!buffer_mapped(bh)); The block device is removed and all the pages are invalidated. JBD2 was trying to write journal superblock to the block device which is no longer present. Fix this by checking the journal superblock's buffer head prior to submitting. Reported-by: Eric Ren Signed-off-by: Jiufei Xue Signed-off-by: Theodore Ts'o Reviewed-by: Jan Kara Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/jbd2/journal.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -1366,6 +1366,10 @@ static int jbd2_write_superblock(journal journal_superblock_t *sb = journal->j_superblock; int ret; + /* Buffer got discarded which means block device got invalidated */ + if (!buffer_mapped(bh)) + return -EIO; + trace_jbd2_write_superblock(journal, write_flags); if (!(journal->j_flags & JBD2_BARRIER)) write_flags &= ~(REQ_FUA | REQ_PREFLUSH);