From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A275C43464 for ; Fri, 18 Sep 2020 02:29:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 227E123730 for ; Fri, 18 Sep 2020 02:29:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600396145; bh=6d5G6ztBV2ohm/Tp6EC+gnx574VGASS7C/V4nPwvvSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=bM2tAanFrzZGv16ObET/rAq7V6liefPesu3mCfxK1PtyWvZ0YkIRrxacj5tk4CCyq 2olABRvgyQW9oYn3s/dfu1b+PxIsZy3iy25jP4U787hGrGYl13Z27jeA6Ib4UaOGAf HNz2Xf3XckVwPGbZR+x9VovQKedMSdXnFjr/tAZo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729813AbgIRC3E (ORCPT ); Thu, 17 Sep 2020 22:29:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:43862 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729193AbgIRCPL (ORCPT ); Thu, 17 Sep 2020 22:15:11 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 659FE2376E; Fri, 18 Sep 2020 02:15:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600395311; bh=6d5G6ztBV2ohm/Tp6EC+gnx574VGASS7C/V4nPwvvSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lisn5kLQzgGYcloqU1O4tg2rQ55reDachizE+ADXToSWgsCLLuj/1Z21Ob/QtI+oe kqDt+WlYIut/dhuo+uZ21iCxwCVJreeG0j152MlHHtXDBIrRaZpVdwwR9/Wiez3Rfw /5lKyr2YZGdkdfAc0cvCARdIpjjvrjbHxMsaNJRg= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Brian Foster , "Darrick J . Wong" , Sasha Levin , xfs@oss.sgi.com Subject: [PATCH AUTOSEL 4.9 13/90] xfs: fix attr leaf header freemap.size underflow Date: Thu, 17 Sep 2020 22:13:38 -0400 Message-Id: <20200918021455.2067301-13-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918021455.2067301-1-sashal@kernel.org> References: <20200918021455.2067301-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 70da4113c2baf..ead6fdd41712b 100644 --- a/fs/xfs/libxfs/xfs_attr_leaf.c +++ b/fs/xfs/libxfs/xfs_attr_leaf.c @@ -1332,7 +1332,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