Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3760242pxk; Tue, 29 Sep 2020 05:43:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxF/99hk0+mLuFbV1+4Nbj8leO6fScQss8tTEpBUY9o2TPCgayYj4hHKsltZnuAeHEPl8sn X-Received: by 2002:a50:d4d8:: with SMTP id e24mr3080505edj.1.1601383438440; Tue, 29 Sep 2020 05:43:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601383438; cv=none; d=google.com; s=arc-20160816; b=KmVTFTnIvChLzt948bro0aw+TVKlco9JUMW0GSPcCM/qLkM/tvLK2EV8zJdSWvfIex NEwWnRdfi07KNRd8M43LN1QFk8VOKxhgP8EKn9zVT8hp70ygVwUGR7rLlHv4Nc84QY+V di3soNxs8coQSS9M3vTre+/FdQ2x/oVgO9SCBEZhbXYOf4pS+oOnGJO5hTK4WrUXCdkP UZ0tQmkB8oGktU81mL0xM7WTfKV2raHAF6yQsut2BCZfYJ1yC6Ce907q3jqKiKbpmAFx lMFBykcN3LzTljA5/tTgw+GBdL7KMzxDGP+aXIU3AYpbH+DyeSH7SWqlB3MmxermYrlh RrXw== 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=blZNnCjtOr6RWTJXQeT6co1Z+m4cZVISJMnbdaIyNuo=; b=Vc7jpFLp7omcUAtAI2zKPRCrLEprPMLwp0TklRMNmzBK9lkMXbeUGhTSJHsBHt3sS+ YK9M0yW5cB6sgA7Rdr/7kNIVpcY1FGfbR94SsnhGzh0bRu6y2HkIisuxMX9A8IwL424/ W5iVaDAuEBIe+GQpW4uSIINvL+VgF3auozCpD+RceeaBT+xwI04EnEn2bnKezBewWqxp hWyfxEDNgu2F5NsOtJN2YA9Tp+MVwo7bd0FJpP/kaN0wL8Ef93ferVcknLlXJjJlQl0e EWv1/CLtzbxhYcsQneYQr+i28qBvYBn81AsICavAV2OaB9uVPmxpdgZO0S4K+7lUCLFB DnjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nQ4S2ZWe; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h24si2516875edv.391.2020.09.29.05.43.35; Tue, 29 Sep 2020 05:43:58 -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=nQ4S2ZWe; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729646AbgI2MlY (ORCPT + 99 others); Tue, 29 Sep 2020 08:41:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:56356 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729389AbgI2LNr (ORCPT ); Tue, 29 Sep 2020 07:13:47 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 0090721924; Tue, 29 Sep 2020 11:13:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601378026; bh=yqRipaG9eyydr+dy1Kt9Iuj9ECa+KtOXIpqR2On9Yu0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nQ4S2ZWeL+BEtAIbbCXdtcCAG+9mXkvgtVChP3YFUOrfqoWRdcXK3W/koNsKIoAao wuBqso0sMGA3Gq+NfckwZhrQ7cVYk14OP/Dqf+IVshwpEXV9NiO5MZj2DTX8cTmK+o 5LqKSn8mP/cfKQvWGnvST/n4gYM/QbE5jAFVVHho= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian Foster , "Darrick J. Wong" , Sasha Levin Subject: [PATCH 4.14 036/166] xfs: fix attr leaf header freemap.size underflow Date: Tue, 29 Sep 2020 12:59:08 +0200 Message-Id: <20200929105937.007738158@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105935.184737111@linuxfoundation.org> References: <20200929105935.184737111@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Brian Foster [ Upstream commit 2a2b5932db67586bacc560cc065d62faece5b996 ] The leaf format xattr addition helper xfs_attr3_leaf_add_work() adjusts the block freemap in a couple places. The first update drops the size of the freemap that the caller had already selected to place the xattr name/value data. Before the function returns, it also checks whether the entries array has encroached on a freemap range by virtue of the new entry addition. This is necessary because the entries array grows from the start of the block (but end of the block header) towards the end of the block while the name/value data grows from the end of the block in the opposite direction. If the associated freemap is already empty, however, size is zero and the subtraction underflows the field and causes corruption. This is reproduced rarely by generic/070. The observed behavior is that a smaller sized freemap is aligned to the end of the entries list, several subsequent xattr additions land in larger freemaps and the entries list expands into the smaller freemap until it is fully consumed and then underflows. Note that it is not otherwise a corruption for the entries array to consume an empty freemap because the nameval list (i.e. the firstused pointer in the xattr header) starts beyond the end of the corrupted freemap. Update the freemap size modification to account for the fact that the freemap entry can be empty and thus stale. Signed-off-by: Brian Foster Reviewed-by: Darrick J. Wong Signed-off-by: Darrick J. Wong Signed-off-by: Sasha Levin --- fs/xfs/libxfs/xfs_attr_leaf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c index 299d17b088e21..facb83031ba77 100644 --- a/fs/xfs/libxfs/xfs_attr_leaf.c +++ b/fs/xfs/libxfs/xfs_attr_leaf.c @@ -1335,7 +1335,9 @@ xfs_attr3_leaf_add_work( for (i = 0; i < XFS_ATTR_LEAF_MAPSIZE; i++) { if (ichdr->freemap[i].base == tmp) { ichdr->freemap[i].base += sizeof(xfs_attr_leaf_entry_t); - ichdr->freemap[i].size -= sizeof(xfs_attr_leaf_entry_t); + ichdr->freemap[i].size -= + min_t(uint16_t, ichdr->freemap[i].size, + sizeof(xfs_attr_leaf_entry_t)); } } ichdr->usedbytes += xfs_attr_leaf_entsize(leaf, args->index); -- 2.25.1