Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp592225ybt; Fri, 19 Jun 2020 08:54:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbPgTzjII20BqkGBlci3h6w/a0qm9Eu+Y3lMGVShJki9szgCi2dVe1XdqHUqbgYGdfgCl/ X-Received: by 2002:a05:6402:1746:: with SMTP id v6mr4063006edx.236.1592582062562; Fri, 19 Jun 2020 08:54:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592582062; cv=none; d=google.com; s=arc-20160816; b=bPOiYXyukiX6wVT/iq6bA7f5eoFU9Yj58nq3Vcofd307tXt2pZlgAAnpowEQ5lB1XH zqwmUQwe+1rdBJfu8nazhmoMOAhG4gs18eKwJ5rxUHgzPhGWG1UM3n7S1afRTK1MhLX5 XJ4bDBE2Y51Ilt2mx7ZmoDa8ACv7DVkpzW7OCk4WDvxwv8wDCnsKZuPQZJBFuTneycWp f3TPi8/Dxfy5wIaVCmn6WM3z9asT0Bx+a6yH1dbzvyxrpcc6yPzF8XGHAcpP8X0nHtCG VsSaSeSkuiVynTbjIRctOcWJI+8rib8Fuz4EMkGN1EykXjaXGRToIYg7nUEtbVQ6LXdD 6XDw== 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=rjGBQLjR+vdOGS9D14CCYdvyHs59gh68j+CPSONic8M=; b=M0JFPE6yg0QtB52EW8h1LAAtnjaz0azv/AE8fUSHHknQcEfevIIUzq5KwqpXUGfFLJ OGP2Fj3gGmdll+YPRhxzRTzs3UktXXfLkRV4twfGOiK981xf8H/gUnc3EbpWnFi0lJAA B8YFjSiOJkS9wmGZiu9j6PHOdAgO/VpuWCBN6J0rkvxeZCAskLEoIGnouOtoNpHJJtiC y3/l0Msunx5fNN/XVvGJdapybpOcAOFyuhhDBonJ4vOwdSs1VvyS90PdME0WBkcz38WK ZSZFLU1Gw7t0+6fsPUkSlBS5uNiQ9QG7gLXhLMoIsZhicF/tlJ8EyGNjyKnel8j6bH0s OhPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bSTyEepH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x11si3893155ejb.614.2020.06.19.08.53.59; Fri, 19 Jun 2020 08:54:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bSTyEepH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391010AbgFSPtb (ORCPT + 99 others); Fri, 19 Jun 2020 11:49:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:56950 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390865AbgFSPZJ (ORCPT ); Fri, 19 Jun 2020 11:25:09 -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 3FDF121582; Fri, 19 Jun 2020 15:25:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592580308; bh=dvPNjkEX0FRyQBVGbL9mveFmQllKPKlqmbk8N+PJ+1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bSTyEepHQGk1QnoJz5fLBeDPs8S0Yj9ZHggU6mncwAn5JJQeD2l8U7W/kal+Oi0Zd lKTa5rWPoy0dZZd+p1SVDq6ifoPwfJ7iW77oEoOTQUgSCsF4w7rPlG++0+sVBEfjst PkFAh8Jkrg9k1mRgiwgfEzWUHPn1bcyjxsKvsSXw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian Foster , "Darrick J. Wong" , Christoph Hellwig , Sasha Levin Subject: [PATCH 5.7 200/376] xfs: dont fail verifier on empty attr3 leaf block Date: Fri, 19 Jun 2020 16:31:58 +0200 Message-Id: <20200619141719.810025712@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141710.350494719@linuxfoundation.org> References: <20200619141710.350494719@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: Brian Foster [ Upstream commit f28cef9e4daca11337cb9f144cdebedaab69d78c ] The attr fork can transition from shortform to leaf format while empty if the first xattr doesn't fit in shortform. While this empty leaf block state is intended to be transient, it is technically not due to the transactional implementation of the xattr set operation. We historically have a couple of bandaids to work around this problem. The first is to hold the buffer after the format conversion to prevent premature writeback of the empty leaf buffer and the second is to bypass the xattr count check in the verifier during recovery. The latter assumes that the xattr set is also in the log and will be recovered into the buffer soon after the empty leaf buffer is reconstructed. This is not guaranteed, however. If the filesystem crashes after the format conversion but before the xattr set that induced it, only the format conversion may exist in the log. When recovered, this creates a latent corrupted state on the inode as any subsequent attempts to read the buffer fail due to verifier failure. This includes further attempts to set xattrs on the inode or attempts to destroy the attr fork, which prevents the inode from ever being removed from the unlinked list. To avoid this condition, accept that an empty attr leaf block is a valid state and remove the count check from the verifier. This means that on rare occasions an attr fork might exist in an unexpected state, but is otherwise consistent and functional. Note that we retain the logic to avoid racing with metadata writeback to reduce the window where this can occur. Signed-off-by: Brian Foster Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Signed-off-by: Sasha Levin --- fs/xfs/libxfs/xfs_attr_leaf.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c index 1d67cc9f4209..5d0b55281f9d 100644 --- a/fs/xfs/libxfs/xfs_attr_leaf.c +++ b/fs/xfs/libxfs/xfs_attr_leaf.c @@ -308,14 +308,6 @@ xfs_attr3_leaf_verify( if (fa) return fa; - /* - * In recovery there is a transient state where count == 0 is valid - * because we may have transitioned an empty shortform attr to a leaf - * if the attr didn't fit in shortform. - */ - if (!xfs_log_in_recovery(mp) && ichdr.count == 0) - return __this_address; - /* * firstused is the block offset of the first name info structure. * Make sure it doesn't go off the block or crash into the header. @@ -331,6 +323,13 @@ xfs_attr3_leaf_verify( (char *)bp->b_addr + ichdr.firstused) return __this_address; + /* + * NOTE: This verifier historically failed empty leaf buffers because + * we expect the fork to be in another format. Empty attr fork format + * conversions are possible during xattr set, however, and format + * conversion is not atomic with the xattr set that triggers it. We + * cannot assume leaf blocks are non-empty until that is addressed. + */ buf_end = (char *)bp->b_addr + mp->m_attr_geo->blksize; for (i = 0, ent = entries; i < ichdr.count; ent++, i++) { fa = xfs_attr3_leaf_verify_entry(mp, buf_end, leaf, &ichdr, -- 2.25.1