Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3764189pxk; Tue, 29 Sep 2020 05:50:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyIzgZ3lawY2HPGwV/pCQkesQrxyqyMkwYc6oDWQeqw5BStowHySDdo19WiGw7B5sBnP11 X-Received: by 2002:a05:6402:ca7:: with SMTP id cn7mr2984336edb.143.1601383804333; Tue, 29 Sep 2020 05:50:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601383804; cv=none; d=google.com; s=arc-20160816; b=LUfX+v6AbmaTXLH0xJybZHtc5ClVCji8jfTkDU9U6Fl0pZ0TKyofzz1XwfR5p6K/u3 EyaQ/TrVTuinkNWw9R53bWMROpDc03Dlf/0oY4GU5uCL8YPa/PXbj5cBNm5mm1gf8PXp kJ5/GTvgATt6XcS6DlgdHRccjMt0/LwqDFon82Z7jZZ8gWchdDH9c69fuvCS1WXZqRLZ vH6uk7lzv+QoHAO0vVgXH69u19a6fbQF1K3pkjMa5hn2wX61roYvtVnpQ5bb8kXMIDxe 5pMQ8ILamoRAV3xmnn6JByjMZPzt6Pc8WC5w9GiQDgIRcIgoSvVVxfOEnE4AW5QzQtqq NVmQ== 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=ukyy+J93v7PIZ2ZT5wD3RViniwtLb42yOwWygn7Q1+Y=; b=haOKXHFRZepXnXFPKqZoGEP1So93N3Zpb+TZmV9dwSSU1Szn3Dz3ndy2X3n0OH/V3O Uyjdfl2YgEPG0cLdwJcQLsyhSXoU7y2b6XwcbkUsejwJLvEaIOWoe6L5zhHAbVa1NwCB +pODdQLA5YY9fStdarQ5ng7DPCT9sWc4JumOjCX6zrKU5BNy6fXo/+Ctfunn5wI4xHga Icm1KRD6kYV+6ua7RtOjcbRme4mKHg8eQQ9d4Q20rdoIn5uitQNt0f++cmrlDVMV8v3J vP2Hy2xVHqhPPrb93VFCvDXCPa1ZjD7x6EWYwqC+nsTRjCU2HH+p3nRKddhuP4iomkay nYoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=E5GCIY+c; 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 bu5si2621539ejb.750.2020.09.29.05.49.41; Tue, 29 Sep 2020 05:50:04 -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=E5GCIY+c; 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 S1728406AbgI2LDW (ORCPT + 99 others); Tue, 29 Sep 2020 07:03:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:38968 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728337AbgI2LDT (ORCPT ); Tue, 29 Sep 2020 07:03:19 -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 EEE6321D41; Tue, 29 Sep 2020 11:03:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1601377398; bh=mHHxkIzXOTC2isNxEZdMuSwlzOD4/OnX+lG+fgZxp8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E5GCIY+cfmIBmKTATqSAE1kGQiMjl/WunQFtLMUaP3RBWgTRzHDokmSg++biYc+Sx oQUbjQ/+PRl6FCEEQHtg8eVPDy/85apTSul7gzGD902umulK6xIK7F3yurYZ6CVoUl ykU2nbtsGrKf6k/9ighw37Rab9ZpFHW7+m2iVoYA= 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.4 21/85] xfs: fix attr leaf header freemap.size underflow Date: Tue, 29 Sep 2020 12:59:48 +0200 Message-Id: <20200929105929.284644336@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200929105928.198942536@linuxfoundation.org> References: <20200929105928.198942536@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 da8747b870df3..4539ff4d351f9 100644 --- a/fs/xfs/libxfs/xfs_attr_leaf.c +++ b/fs/xfs/libxfs/xfs_attr_leaf.c @@ -1326,7 +1326,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