Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3324662rwa; Tue, 23 Aug 2022 02:52:15 -0700 (PDT) X-Google-Smtp-Source: AA6agR4p/0GVsB5ACs/8eQ3qWdWMNE7HTLuG1ci3zNPxGyPZH8iPthjSXad4VG2TI0XxaA4nCEeO X-Received: by 2002:a17:902:ea0e:b0:16f:11bf:efe5 with SMTP id s14-20020a170902ea0e00b0016f11bfefe5mr23980940plg.57.1661248335351; Tue, 23 Aug 2022 02:52:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661248335; cv=none; d=google.com; s=arc-20160816; b=jpWbPJqMpYiBZ/yUdyFOKPP24DCce3cKGqi+VIfEx1kxmshX/EGgy1gA3HwYRbJKxk IUHNpewvbScviqwOco1+IvCedkhLBzcAgXIQRycyMpzu18wyOgY/EWFI1FmNj9o9LEjp QZQgGzAXmakG6xCMcNToX8jzO0Iki+bAdi2NMGv1W1mm7AsOIWg+D2e9z4oPX0nR4Vs3 mcP+KixCtUOqFRPZn6UL/3lowuS+dmfuoyHqQi5tZc2ZYsDcMCgEhZHXxX0N4p4+WYUP AB7kirmwFhobrvratOb7YGces+lo9DzTF7huOYHx6yYcotsmryEAmUTQvbzqk6THIR8z KEtQ== 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=bg9S2uW9eO53vtVaPxy/oxq4HXzsYrStjd9IYiI6wM0=; b=pfBzLPvN9jZdaXAp0BQRifYRXDslyxIP8Sa/S4sRamh21k+L1s2RZ/LH4x88awDo5M SZ68h56L97mBpZCQpQOZMvaRiGjryaMD0c+UXe9UT/ZPAx1o7JmkUPDAVo4auu9UOblG RsQR2YFjsVVzUncOGSi7Snul6tIdvAtlRtSsUl6jCky6Rl/GatUA463hZjGNXbS4owbg eV5Vz3CGvGEgElH6mw/BuD2uWECA0abB/LJMrwCpxUcO+qwQp6f2rQ/N0U0X8cHM+8ZQ w7lxh9WtEHgw01qli1EdJ0o2vyZJBILsefMIetzX3SwYaQUhI0Q3EzTpaDOo3Dg5bqt+ UsGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rHPoG+k0; 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 s7-20020a637707000000b004159dcfc653si15757862pgc.40.2022.08.23.02.52.05; Tue, 23 Aug 2022 02:52:15 -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=rHPoG+k0; 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 S243376AbiHWIYw (ORCPT + 99 others); Tue, 23 Aug 2022 04:24:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243370AbiHWIVE (ORCPT ); Tue, 23 Aug 2022 04:21:04 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2D016EF14; Tue, 23 Aug 2022 01:12:27 -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 ams.source.kernel.org (Postfix) with ESMTPS id C94E9B81C25; Tue, 23 Aug 2022 08:12:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 342EAC433D6; Tue, 23 Aug 2022 08:12:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661242330; bh=Dk8WOCncWIQfD3LI7kIaw3Mjv8xoez6Dudme09wCtIo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rHPoG+k0n271BG4JRbg6Noj+V84CcxUZUVeJfbmqfm9qRYsdvHbNVYyh5Xun40C1S 6bNu/1cFh1q0KYvg1RqnhYe+vibHsxPJGoD1jLZ53XSS2poRwtD/G6C0YNhFvJLBvQ BXC5YjMrZW2ywzG2utoc51RVAXw9uqzgbbkdJFnk= 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.9 054/101] ext4: fix extent status tree race in writeback error recovery path Date: Tue, 23 Aug 2022 10:03:27 +0200 Message-Id: <20220823080036.617733993@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080034.579196046@linuxfoundation.org> References: <20220823080034.579196046@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 @@ -1659,7 +1659,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, 0);