Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2397674lqp; Sun, 24 Mar 2024 17:44:56 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUq9bo3EQnblEX21TaV9EoANyBZ6vkVIO7m9bECpNfJIjjUHG126GtpvHLs5CoDtezzOSy0dOUvSKqZN/m+VNIrVjZ4eso5g70VlItiww== X-Google-Smtp-Source: AGHT+IFWEwD3iw+6gDtSTw3gexKtps/dGP2tYigBK4bI/D75nZTZSxDFuJ6oHmPIz4spCoGfn/XU X-Received: by 2002:a37:ef13:0:b0:788:7299:e79a with SMTP id j19-20020a37ef13000000b007887299e79amr6358054qkk.28.1711327496327; Sun, 24 Mar 2024 17:44:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711327496; cv=pass; d=google.com; s=arc-20160816; b=ZGtwQCiG0GaQXX6E5sjdUJUvdobtKpfcVZieogoYOeEe8Vh4mCGzasf9F4S8HB19i7 OoQwbfd1tMXGyuIIb4z45Ytj1ZL9quz+nX4LO+cgrEvM5zlPIKLHuI2sIcs2jQZXgUcq rAHTL6f9E++Bk1FPH0u8gk7udWtSHcC6DbL0PBzScALyfGgpgm0ZUcmgKliFJeljRIm9 nmKa9bmCG0x24evRldc3G+QaTSxIPvP4ICzLK+5zZ0nb+FO3jak4DXWIsntEFcevfEnI 0SQFxqQJnZ+FEjy3gZJsiA3FdpDnNCb+zg/v7TF73fcQhMH5ZbAJG7TwzpJyneCreKWs AWhw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=d6fFb2RzE1p3vdT+tgjAonKtdQRLbaS8r3yDcZQq8Aw=; fh=Uz1B+o+VWDBLD8wsX0OJ/UBCy0+BprZzgpiNkp0GQcM=; b=Wenb7jNHDpXgMQY1A14vyjYsbWC/U9g+OfKQVZdnHjMabHBR8IDGlTm9/zPgiSnyNs kkqiFRh5CPt7yO5qy7AR8ZkkTtXczPBvcm3rKdwwCeFQoJK1Jy/eQfKWMOSFcDbyoBne VwBv7AXu0g2UfrTtid1wxPE1o3x/AegrYcJ35kbZYhdK6XQj7LIXOd45cS1C+37HvW3f J9ia7jk/dFwWDbWXD5VUK0no4OYi7t2T7RvEyrziy3IIUUJ3kFseJouC/OKmcA0Rq/38 oULHvuIEyRVBR73ySUOr/nH2/d2df9Kyu8IhQ8aD69pf5iplJ5gF8QyojnJPOxgD0Lpk MqpQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=n68QrK2d; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113469-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113469-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id z1-20020ae9e601000000b00789db8e7058si4435693qkf.54.2024.03.24.17.44.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 17:44:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113469-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=n68QrK2d; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113469-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113469-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0011C1C23E91 for ; Mon, 25 Mar 2024 00:44:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FF251B3A3D; Sun, 24 Mar 2024 22:44:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="n68QrK2d" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0AD47175B; Sun, 24 Mar 2024 22:44:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320270; cv=none; b=JtGlrEL6/MQNLgnBMWhJIiQhampPRXfsIiZ8ivzSle1hN2OTQ7didyRVwcHYOhPYb3rQR7pGYuKQ/uLuDVoGszY5vz8R/WLXr7824HcPT7I128CgrSZOjPmxDD7Rl4M9NNdzsp05fpWxMMIxFq1YVz1mi7EKu1Gl6qTjOGAMdlg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320270; c=relaxed/simple; bh=g1ekMzSm4txgtotmTsA3S1y1NJqyvLL1l8D4Mk/0VZ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VFkPJrT3vaPrJMBjBq8DaIAB3g00mW1yU5SPgeIm10DKbHgsEgTS23KgtsxDFP4o052KhOCythtDl2dqA4oRSavRR8deZWQ1EdXSpTknc6M4Tuxs6wYx9T5jihlkeRgZtQAONscKj7/Jg4F2gNCYcdlIumQ6pJezU4rMSDHpNWA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n68QrK2d; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74A56C43390; Sun, 24 Mar 2024 22:44:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320270; bh=g1ekMzSm4txgtotmTsA3S1y1NJqyvLL1l8D4Mk/0VZ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n68QrK2doKmdWq4Rm+Q2xb0VJyeQJu3gHJF5CKXhhqdTMRgCUhYj6INVmb6YXgqxs RVN9YDnOFp8qxMiraMTsvw9kDVLmkma+Fxje6UQM1GwtXR1NjKqs5BcWBAFB0tI9eF iIviCTFVvMnh5s/vkFjLKENcfazcZUSt8DPA15ajPDjRs4OX0kW+/K+M1BpCAgoclU 8/mYYKQdSyskBim+v1IhXcjlyw/hJoHrmAiyY+drd8Lfmd7DUJzIJ6PE/nioBbqveK DVNHAgFc8zabGzTXDOQA5bSrDiEc3s9rKj/tfYu/VT8jtEu+L+N9iXC8wyUtv4P7Dp Tf89KUuMOQ09A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jorge Mora , Jorge Mora , Benjamin Coddington , Trond Myklebust , Sasha Levin Subject: [PATCH 6.8 578/715] NFSv4.2: fix listxattr maximum XDR buffer size Date: Sun, 24 Mar 2024 18:32:37 -0400 Message-ID: <20240324223455.1342824-579-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Jorge Mora [ Upstream commit bcac8bff90a6ee1629f90669cdb9d28fb86049b0 ] Switch order of operations to avoid creating a short XDR buffer: e.g., buflen = 12, old xdrlen = 12, new xdrlen = 20. Having a short XDR buffer leads to lxa_maxcount be a few bytes less than what is needed to retrieve the whole list when using a buflen as returned by a call with size = 0: buflen = listxattr(path, NULL, 0); buf = malloc(buflen); buflen = listxattr(path, buf, buflen); For a file with one attribute (name = '123456'), the first call with size = 0 will return buflen = 12 ('user.123456\x00'). The second call with size = 12, sends LISTXATTRS with lxa_maxcount = 12 + 8 (cookie) + 4 (array count) = 24. The XDR buffer needs 8 (cookie) + 4 (array count) + 4 (name count) + 6 (name len) + 2 (padding) + 4 (eof) = 28 which is 4 bytes shorter than the lxa_maxcount provided in the call. Fixes: 04a5da690e8f ("NFSv4.2: define limits and sizes for user xattr handling") Signed-off-by: Jorge Mora Reviewed-by: Benjamin Coddington Signed-off-by: Trond Myklebust Signed-off-by: Sasha Levin --- fs/nfs/nfs42.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/nfs/nfs42.h b/fs/nfs/nfs42.h index b59876b01a1e3..0282d93c8bccb 100644 --- a/fs/nfs/nfs42.h +++ b/fs/nfs/nfs42.h @@ -55,11 +55,14 @@ int nfs42_proc_removexattr(struct inode *inode, const char *name); * They would be 7 bytes long in the eventual buffer ("user.x\0"), and * 8 bytes long XDR-encoded. * - * Include the trailing eof word as well. + * Include the trailing eof word as well and make the result a multiple + * of 4 bytes. */ static inline u32 nfs42_listxattr_xdrsize(u32 buflen) { - return ((buflen / (XATTR_USER_PREFIX_LEN + 2)) * 8) + 4; + u32 size = 8 * buflen / (XATTR_USER_PREFIX_LEN + 2) + 4; + + return (size + 3) & ~3; } #endif /* CONFIG_NFS_V4_2 */ #endif /* __LINUX_FS_NFS_NFS4_2_H */ -- 2.43.0