Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1114590imm; Wed, 1 Aug 2018 10:25:10 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdwG3EFbo6vPP5zquKy9cGqXQnc2ancy8FuHfnkftdIpmcuAgL7zklUyqj6lkOx4g7I2U/e X-Received: by 2002:a65:6551:: with SMTP id a17-v6mr25408685pgw.132.1533144310456; Wed, 01 Aug 2018 10:25:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533144310; cv=none; d=google.com; s=arc-20160816; b=xn2ouqJ/B4K6Znp0R0JWFGx2COLjAyKauHyA9LXxW3VNGSaamOAUTiof3k0Usw2/Bz lmUZp0ICiG+PtZ/feSZxpZAeC8yEHw9thhgnVtokuawAxHwy50MnFEKEnPgHjW+B30vm qOfYfPnljeDFgMYPqv/ERRFjYGwehjPAnw2lFQVlm3zsetVowsz0L+IHdFnPANTGxi6s y5BKGdQUom3GcnJsZcku7P9/DujUcNLQ3M6PbK05DUx1YBYqPlif92YvAnoxMh/CuzD7 iAsA3zsrAnq5nTF4jET6PgFWMYRpNLsmt61zrBB84bMtGJqOPi8bgqbfAdbXTF3A7Oy1 l2UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=AZ4QJ0Nsq4Wz6fRivtVqVvxsmTOVWiFelkamp4MD+3I=; b=XUI/lgRhIx3Hd4qlNRdYxwhfaf6HqhyIZMc7lB+CbYPGciu1PgwJVSu6wzktq5lWyU yJ1wdhmqB065AbxXE1pganSAZ1osulD7dtctPLEhHRgdq3tmWGU14SroZ/BayrZjvZgu NzKz/M3xPzojw8ci9ZRtU+pVRZ7iCV7bbl/c6kolzscLaMkQGSvtbpP5TyJFf00/pyyU QQbMx5ZiguDj1jKpCLlRw2enBrmpaTfeAK97F37JplOfZLwi6JJEed2aV9Rs7hXvEizw lwojmsUaLiB0EuUApeOfFKXZrP6J1ZxZ1MfWjk47Stb62CRhw6f1w4XDd+WqPWMcqAPA vGkg== 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 a1-v6si16502422pgg.326.2018.08.01.10.24.55; Wed, 01 Aug 2018 10:25: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; 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 S2406323AbeHATJl (ORCPT + 99 others); Wed, 1 Aug 2018 15:09:41 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:50820 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390400AbeHATJk (ORCPT ); Wed, 1 Aug 2018 15:09:40 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 8272CD2F; Wed, 1 Aug 2018 17:22:58 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Theodore Tso , stable@kernel.org Subject: [PATCH 4.14 221/246] ext4: check for allocation block validity with block group locked Date: Wed, 1 Aug 2018 18:52:11 +0200 Message-Id: <20180801165022.280911165@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801165011.700991984@linuxfoundation.org> References: <20180801165011.700991984@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Theodore Ts'o commit 8d5a803c6a6ce4ec258e31f76059ea5153ba46ef upstream. With commit 044e6e3d74a3: "ext4: don't update checksum of new initialized bitmaps" the buffer valid bit will get set without actually setting up the checksum for the allocation bitmap, since the checksum will get calculated once we actually allocate an inode or block. If we are doing this, then we need to (re-)check the verified bit after we take the block group lock. Otherwise, we could race with another process reading and verifying the bitmap, which would then complain about the checksum being invalid. https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1780137 Signed-off-by: Theodore Ts'o Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/balloc.c | 3 +++ fs/ext4/ialloc.c | 3 +++ 2 files changed, 6 insertions(+) --- a/fs/ext4/balloc.c +++ b/fs/ext4/balloc.c @@ -379,6 +379,8 @@ static int ext4_validate_block_bitmap(st return -EFSCORRUPTED; ext4_lock_group(sb, block_group); + if (buffer_verified(bh)) + goto verified; if (unlikely(!ext4_block_bitmap_csum_verify(sb, block_group, desc, bh))) { ext4_unlock_group(sb, block_group); @@ -401,6 +403,7 @@ static int ext4_validate_block_bitmap(st return -EFSCORRUPTED; } set_buffer_verified(bh); +verified: ext4_unlock_group(sb, block_group); return 0; } --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -91,6 +91,8 @@ static int ext4_validate_inode_bitmap(st return -EFSCORRUPTED; ext4_lock_group(sb, block_group); + if (buffer_verified(bh)) + goto verified; blk = ext4_inode_bitmap(sb, desc); if (!ext4_inode_bitmap_csum_verify(sb, block_group, desc, bh, EXT4_INODES_PER_GROUP(sb) / 8)) { @@ -108,6 +110,7 @@ static int ext4_validate_inode_bitmap(st return -EFSBADCRC; } set_buffer_verified(bh); +verified: ext4_unlock_group(sb, block_group); return 0; }