Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3403407rwa; Tue, 23 Aug 2022 04:19:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR4isQB4WGmrS28PZ2jqF3Lsgw9S++s7/cHHnvhnZPwIvSx38ZDWGd+HOp419akNco1Gwqfj X-Received: by 2002:a63:1913:0:b0:41d:10af:1b23 with SMTP id z19-20020a631913000000b0041d10af1b23mr19835263pgl.485.1661253553008; Tue, 23 Aug 2022 04:19:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253553; cv=none; d=google.com; s=arc-20160816; b=hzlWTmLNyG1TE4uqdh+cR+EWvA2mVhQN/sCz9bNE3w7kt0ZT8esEIJ/X6fw6gPcSma Ub96SzdskuxIbQLK1oRyCUwdGtbyYcKExkDTXdxa+vwgP+rXMCvfkwhlbfzb6LRh0TLe o9DmdeuccBNFQefQOy1NdWk48Q7urHnxNNCwEhBU1eaP/GMXgS1zLrz6cku2GDK0MmjM XsqiMe/q92tj7pSUmsidkkoxJ8uF2emBVLfIc1UK8V0/vNC5XcwZz4F1b1DLidre+Qf5 EXveVW889rNSkbbdZl8MvhjZQgGq404pDpSiAo5lJoVeJySeRhOE2hbVB7Hl5kMCURWx rDgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=pqHHaLJHkrMh5qmWNJKaJOCn/8CO5qKPHEDA+dL4SpA=; b=VKKT8SZUSx/mu5+bVcPUIIv/A3peX9sLTXHNGUW1oOvkrQcbCSZXF6gT3/Qr0Poj44 qjxAz8Whdnt5QUoq3qjQ4oJmXAZDe4qdBBpdvkdUuEGDMXBSERnVwiF9H5Fb/TwthRIt YeiPxRNRq0LTInr/Lerjx0Aa8qrUCHA27mT9t0s1ctCovM7oORO3Wi0WtNMqsFSFV6ih FJn3kkctGcYgr3P1UGrwvCNn/G302lraA174kxJO3fdK3mDKz/b/Lmxe3I1mtQjwReSp K1TR5TMNK0o78OuKKK0f4QG2hYq7eSsrpwed4sQ4Cp0NJkDhuS2fBKGE7Z+U2Ha1+rZp zQ1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2SvVshs2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n13-20020a17090a670d00b001e895fed1e2si17233096pjj.130.2022.08.23.04.19.02; Tue, 23 Aug 2022 04:19:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2SvVshs2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244050AbiHWKth (ORCPT + 99 others); Tue, 23 Aug 2022 06:49:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356499AbiHWKm0 (ORCPT ); Tue, 23 Aug 2022 06:42:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 078D8AA3D0; Tue, 23 Aug 2022 02:09:55 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 55BD160112; Tue, 23 Aug 2022 09:09:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 426DAC433C1; Tue, 23 Aug 2022 09:09:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245793; bh=DnpzbKthLavNueaPHkVIQtqpVn8Kryaf8GGCHKbV0DM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2SvVshs2oMYms6RiPhbG79zhm5XJDSjgMD4WayqFur+seuybfJUd5Aq3mCme3Zqif N97E/bWa55nTIyI1aFxeTEap01CKXxEw3q8yYLmm3G23PU/iCBLcMj6vZNpt0dNtVA VVRJ3sKi8QMmsSXWGU+JNLGpudkOdA8V/TZakqQQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Ye Bin , Eric Whitney , Theodore Tso Subject: [PATCH 4.19 191/287] ext4: fix extent status tree race in writeback error recovery path Date: Tue, 23 Aug 2022 10:26:00 +0200 Message-Id: <20220823080107.251245068@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Whitney commit 7f0d8e1d607c1a4fa9a27362a108921d82230874 upstream. A race can occur in the unlikely event ext4 is unable to allocate a physical cluster for a delayed allocation in a bigalloc file system during writeback. Failure to allocate a cluster forces error recovery that includes a call to mpage_release_unused_pages(). That function removes any corresponding delayed allocated blocks from the extent status tree. If a new delayed write is in progress on the same cluster simultaneously, resulting in the addition of an new extent containing one or more blocks in that cluster to the extent status tree, delayed block accounting can be thrown off if that delayed write then encounters a similar cluster allocation failure during future writeback. Write lock the i_data_sem in mpage_release_unused_pages() to fix this problem. Ext4's block/cluster accounting code for bigalloc relies on i_data_sem for mutual exclusion, as is found in the delayed write path, and the locking in mpage_release_unused_pages() is missing. Cc: stable@kernel.org Reported-by: Ye Bin Signed-off-by: Eric Whitney Link: https://lore.kernel.org/r/20220615160530.1928801-1-enwlinux@gmail.com Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/inode.c | 7 +++++++ 1 file changed, 7 insertions(+) --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1755,7 +1755,14 @@ static void mpage_release_unused_pages(s ext4_lblk_t start, last; start = index << (PAGE_SHIFT - inode->i_blkbits); last = end << (PAGE_SHIFT - inode->i_blkbits); + + /* + * avoid racing with extent status tree scans made by + * ext4_insert_delayed_block() + */ + down_write(&EXT4_I(inode)->i_data_sem); ext4_es_remove_extent(inode, start, last - start + 1); + up_write(&EXT4_I(inode)->i_data_sem); } pagevec_init(&pvec);