From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ua2-f43.google.com (mail-ua2-f43.google.com [74.125.226.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 124A848AE16 for ; Wed, 23 Sep 2026 11:58:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.226.235 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790164722; cv=none; b=ioOhk6ZkCvyCEkRk3xV04R268xNGaS27wxfmSFQXCNhhq6SStLR0RnQFVV6Ge0isCZxk6zt+FsTcpHoFbRz7clH7bfpBok3vpof9aAaWlOPmiSBKUlnvWOrYwo4OLBnMbeS1s6ABrGV7QuW5WcLVcgRraI+g3UgPo8XhIu2+Cho= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790164722; c=relaxed/simple; bh=J3Qov41MlfghPvhRovLY0AKfP5UMN0aeIFvDOXPBh5w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WMjMVEYSJsFUtr09fgtCnLAMWYNIVTL0yL2QZnmeS09ofrlTwS2JlDFFtM/Mo2fVzgLOnu1WLWGvquuCyjb7eD677dQy2O6K1rE7EkE1R5BZjtxb/Kajb6thVHxfeBqijhBdz+AF2mNjGrWe/+eeH3iGOFRC5KksOc66QcI8ETI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ac/lmtWx; arc=none smtp.client-ip=74.125.226.235 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ac/lmtWx" Received: by mail-ua2-f43.google.com with SMTP id a1e0cc1a2514c-9851d513a70so249347241.0 for ; Wed, 23 Sep 2026 04:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790164715; x=1790769515; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=nj94AZGep7yfFM2zqSs8rxQVirPiCBiLnqyMKAGPXrw=; b=Ac/lmtWxeuFne/DEBAHBEUJovI9UngNj9PvkWkJIdNRleLj8YDzroi0KyMhRtuiD9d Tb0WrEBNKZ+m3IDnQTBxaLBzav0v1JCkxPqejU/pC6Hnoyx1VJdYbnlEL17AlC6XnEn8 efOgV48kduZBZldvxCGzr3T7hQQTM5QKA1ywUddEP8owodwqY3kZ6m0gVLiO8t+Gm6xz Jf6YD6XJK0SZYrTiZPkqi6Ff9IG3frsWDzemKSV7xZ0igAwjz9lV+u6WajMdWY04Oi1Y BT2cxrUqogWBBLuAjnBxS925N+GkvL/Hi1SnBqHv1sqkjKaKTlAck+ocQll0s0OQzB+a tq0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790164715; x=1790769515; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=nj94AZGep7yfFM2zqSs8rxQVirPiCBiLnqyMKAGPXrw=; b=1qw1vXwtfp+zJnPGQwdGe8EhWP0qpKYXP/ndNN1LrwkNyT03gQnA3AmqvhABvU0JuH KmlE+HJDZLdLLow0wLw55Ma4L0eKwIdM+7dPzvhWmHV/MGZHuOHfVjeVp5CjxCOyxwXX VvRMVUNGqWxnSIvKkILl3bgnhRBiSodN6/b9zQBfZG146QjTXywATrUElJl3Mpd5BW9F Ngl1i4J7Z+TkLQC0rruSId6gUUelGeoIIytW7W23+WfVlmAnOfYgyfQqQPUiC/GfAq2V MENa7DjBAaN9oUaehWgotm4nM18y+Ms9bgs1GCCsMLncRApEK9WQhL4oMylyMyE8XjCl dc6g== X-Forwarded-Encrypted: i=1; AKwUvBzT/5OdXBmTc+OooEVTQFsI0EN5vMhpg3ZrRYFQTFoQJQ1Tk8GJf5QTbA4nVnUAuQIChvwT5PW5n1UnaHY=@vger.kernel.org X-Gm-Message-State: AFuF++kbdOva4Wisxsno2hxtGTwTrOHtChWYK6gNHp2i5BpB1TFFEYl5 L4YL7kQ71B7CUiQYZ9QQDgMqp230DvhmKpWZo6Po46jYaX211odwA3hS X-Gm-Gg: AYBFou1gM2W4GeoQ4pDX3KfIUDqfQdmwII0HvTRTTpeqjPR8HCQOwv0YLQ52irS04LD WlTBQVDf9b1/0sYL5N6+lcEkhRFgGHCOKAzmhPlmdESc6TjGc3JGzPd94g3uyeG78S8M+Gs+6yo UkkRaLh6Gm739jNZAcUekmlwTG7agaMMvzDPBvyLLntgW9xI+SYCSoB1LyzqcynJWTOf1fF2AeI T7YTyba8bgw50mZX6FeknuX+Ha7kbzOsbJ+va3/IZEDuBN+4H/adLnnUc1YCxdIAnRpK7uIv4jX 4Nzlmey7LBZkQ+DPWiHgtGAUeAMGG2XaW+GEwV/w0YyN8po/ycHNo31WBvd5YLqcEchqLUkr+zb 7pWC1l0rEg/aYNiO49F+IfJCgrF0WAHoSAZgvRUB3A3DLCCo09vLGRqD0j7TEVtW6+YqUrpt9TW KcWSVkYFKOTiObht1BaXwEl8gtdFf1DGFa9bKxjnyD6LuG1BD67z4ohoR9laC7Ycfh3QEV3vukE w== X-Received: by 2002:a05:6102:a158:b0:7ae:c2ca:906 with SMTP id ada2fe7eead31-7aec2ca1672mr19473137.13.1790164715537; Wed, 23 Sep 2026 04:58:35 -0700 (PDT) Received: from beelink.. ([187.13.30.172]) by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-985167e6fcfsm3257250241.0.2026.09.23.04.58.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Sep 2026 04:58:35 -0700 (PDT) From: Aldo Ariel Panzardo To: linux-xfs@vger.kernel.org, Carlos Maiolino Cc: "Darrick J . Wong" , linux-kernel@vger.kernel.org, Aldo Ariel Panzardo , stable@vger.kernel.org Subject: [PATCH v2 RESEND 1/2] xfs: reject out-of-range attribute value lengths in xfs_attr_copy_value Date: Wed, 23 Sep 2026 08:58:22 -0300 Message-ID: <20260923115823.3305596-2-qwe.aldo@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260923115823.3305596-1-qwe.aldo@gmail.com> References: <20260923115823.3305596-1-qwe.aldo@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit xfs_attr_copy_value() takes the value length as a signed int and, for a remote xattr, is handed args->rmtvaluelen. That field is filled from the on-disk __be32 xfs_attr_leaf_name_remote.valuelen in xfs_attr3_leaf_getvalue(), so a crafted length such as 0x80000000 is stored into the signed rmtvaluelen as a negative number. The "buffer too small" guard in xfs_attr_copy_value() is a signed comparison: if (args->valuelen < valuelen) return -ERANGE; A negative valuelen therefore compares as smaller than the caller's buffer size, skips the -ERANGE path, and is then used as a copy length, leading to an out-of-bounds copy of a full remote block into a small getxattr(2) buffer on a mounted crafted image. Reject a value length that is negative or larger than the maximum xattr size before it is used, so a bogus on-disk length can no longer slip through the value copier. Fixes: 9df243a1a9e6 ("xfs: consolidate attribute value copying") Cc: Signed-off-by: Aldo Ariel Panzardo --- v2: new patch (see the 0/2 cover letter). Fixes the signed value-length check in the consumer, xfs_attr_copy_value(), which is the root cause Darrick pointed at in his review of the v1 verifier patch. fs/xfs/libxfs/xfs_attr_leaf.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c index 86c5c09a5db4..d0f7753659c9 100644 --- a/fs/xfs/libxfs/xfs_attr_leaf.c +++ b/fs/xfs/libxfs/xfs_attr_leaf.c @@ -628,6 +628,17 @@ xfs_attr_copy_value( unsigned char *value, int valuelen) { + /* + * A value length that is negative or larger than the maximum xattr + * size is on-disk corruption. The remote value length is an on-disk + * __be32 stored into the signed args->rmtvaluelen, so a crafted value + * such as 0x80000000 becomes negative and would slip past the + * "args->valuelen < valuelen" check below and be used as a copy + * length. Reject it before that can happen. + */ + if (valuelen < 0 || valuelen > XFS_XATTR_SIZE_MAX) + return -EFSCORRUPTED; + /* * Parent pointer lookups require the caller to specify the name and * value, so don't copy anything. -- 2.53.0