From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796027641; b=HBh4HHeU2Sm27jr9Tc86K11enJFJpqWTJKeYxQ9hEOPD1g73EL+baeL7Pgz6lXNoHhWg OkuicLB6EJVM8idq5MXpZROj2tPSsW7QSYKlvuuehrDk7gBLMOFO1CMN7A5vmwLwI1doF Xqeh81nJZK/MnLaKROfQklHnljJolh9Xx5mIJYw4a3ujvAL+YrPmmlp//xccUA53dVorD 8aJgiLqepVgS0a5thw9QY2IaL/x/5WHBjB9ePnFpT/BvZ51O1fFLl1Rr7cPCVHNvWEmDp eSz4Op994ETdVJG0tAWzeOvB7ZYkAhl2oNLCENhtUhmvwqrwFaSLelavaFhVRUKg/yQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796027641; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=ftyhU7UmMMJXEEs7j1JP5M9rEj/yBjO4fw54RLuZjks=; b=31L0xA/51Qy1WJt0vEX7h9iw4Zw4xBLJcxBmfKMCvTKi7BJ4DRRkAUbIiKuryNbbC4Df munZlmkb5/MjIIbmBnX2Dsv1MP3VT7Dak9gGc/P9XbUS1jJIK1sYeaT3ZAN9HKHF2W8/8 itIq1O80QfFT3dGNiD75tttd1IUOcbEJwQsieucnk7UtJ2PW/L2nHeDcKRNzjNtw2AyOc T6VHR/JpJKUJe4vbX3pWM3Kguzeab/vG3NaMgAAfXC1mKVfpYAdE735ZlZwLoMNKdEnHQ lBCBZniHCm5goA8F4SJDXNHnazEn8ALNQBYglIqauotST7rI7INLnns4eYM7kc0aZRw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=AS+ylSgb; arc=none smtp.remote-ip=74.125.82.170 Received: from mail-dy1-f170.google.com (mail-dy1-f170.google.com [74.125.82.170]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10239606A320 for ; Mon, 30 Nov 2026 08:34:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 10239606A320 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.a=rsa-sha256 header.s=20260707 header.b=AS+ylSgb Received: by mail-dy1-f170.google.com with SMTP id 5a478bee46e88-38644aedba1so17179521eec.0 for ; Mon, 30 Nov 2026 00:34:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796027640; x=1796632440; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=ftyhU7UmMMJXEEs7j1JP5M9rEj/yBjO4fw54RLuZjks=; b=AS+ylSgbHB5E5/J5svpa24X7EKuWJjGpzgIzYQBWfOnHeGBkVWjKMnKGrKq/w0YGrt 4jEjCi44zY7C/9ktwSFOoGT2vdnwHuCe4yr/+8Z9OjdTrIxrASOJ6gZ/LyVkyaQ6JUGL VXr036PeXp0DND6AJnTxdVckLll8hSBRMDnuv6x1nM1YhLQuD6vMCm4lKJ/OZrKqexsS 8axjeEjXoo0e4EcAYSAtzUsGRilEREly1CdTAyRsAc9vIgtjkJVZnr3koMHSoYSAr4M+ gLWFbvTj7ZhgNMgjUyaRZMEmkFEO+aMt5eaqV+NIv+mpIK+BZO2D+lQNzHmhFLB1vcl5 gPeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796027640; x=1796632440; h=content-transfer-encoding:mime-version: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=ftyhU7UmMMJXEEs7j1JP5M9rEj/yBjO4fw54RLuZjks=; b=CMFhp5Ii4wuN0gaYUESTYRnlMMHpN3BCuOjuoRUf1fxOuHuvyl56EGvIkfu78xg8C2 hQJ+rnwLfQVaiZbI3uKLzLXzjHBxTISj3xjHnD8FQLZJ+WbZCxD0Zo2AANksYhEtZz5A GKWqE51cCYYFUmgHQVnEd3uFe60W4NJxlXjPrXt9eZMlbeGuW96cE512t6Yc+y89IZSJ tU5jpcg8+saB2Rhbg7SyJ7VL5oZQE82dz6DpJV3NDvlLswnMYFbrKHwccvzwb/lB2jDf BDb/FoqDo24tM0Cy7KunYc6RqdMJlLWp7knW+myAjgXnaqbJTvZ4fsJzTcezh+tQQgfZ aa5Q== X-Forwarded-Encrypted: i=1; AL+hErFC6hiwqCFthAmLG7FctjmlLK2jPn1TMXyhlVThgFXjENReYgykBAAeJwaSBPMEWIUYQEvpShCR8/E=@vger.kernel.org X-Gm-Message-State: APuU4Z8JT/IA7ZrgzuCCNOEWc6DzTzQgqFsNFIwZpn9ZPIZL1H6I/zjP Y24vu9VfZQpBpq4GUjVgIQZNcoua6xwOGObPSXtwud75pWU1WJZcukl1 X-Gm-Gg: AZFdTZf6vLPVMGm08twUn7nFdV4KfeLr0xPyVw18Smc9NnpZgQRs0I635h9pivJZt6O qV5QV7Q4nqma8VvRgR8ulmrWTGoqrCag3yLw5CYAqdhb5Rb9zXmuK7tcEfApCtnog4o6UO5Zh/J PXS0XuneMwXRJaCh9bk1a+IrwIWYxSi/+Yj2RFRemfo/IPrL11emxOFkN3IyrgFdYDuars5Qc2+ yqHN1cfJhmO1GczKg7XudZEFP6+Y7/5kogRbW6JYKD3V67VvQtybXWIJn9EAHbzz/GwWV/kADlD /4xrY2J68hAdIj+ywLkejC19tiaHDJdIXvcvRpcL3tkcxkds3RJdzTiTZRe8LOkzle5XINw7GA3 kNaZvTHKtbnKML0BieLhNymn/dSDnrejYLumjuT9uLdEb85zLwvsMLIYHMeXmyTwjk0JHTj6Oq9 1YMhSHttMjh+KcHRaTHfztnt3jhg9Njs7c5VZwR0mYyZmKgpKaT6oxHdvU4df1a6hwwuLeKikHh N8OkoDK9ry3Sbwlg1zaksWkMuR5Q+ZUcAnBGNTZLp2wu5rz8XsLx3yCQZujx6TqoXVF0Es9NXJj cxecoJTYX7SJHg1QBBEbaUGyzicgqPgcwbSDYBmXgVlvgdmSTEIerQ6GCBljtSi+pZXkcFbVgBu gIhwXYImB3y/4T4kFXXGTfsU= X-Received: by 2002:a05:693c:88d4:20b0:386:a8de:2bfc with SMTP id 5a478bee46e88-386a8de2f67mr24319926eec.6.1796027639640; Mon, 30 Nov 2026 00:33:59 -0800 (PST) Received: from muumthf.tailc449de.ts.net ([115.23.248.7]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-385672c6f31sm95846130eec.15.2026.11.30.00.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 00:33:59 -0800 (PST) From: Hyunsol Mun To: Chuck Lever , Jeff Layton , Trond Myklebust , Anna Schumaker Cc: NeilBrown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Dan Carpenter , linux-nfs@vger.kernel.org, stable@vger.kernel.org, bobtobabz@gmail.com Subject: [PATCH] SUNRPC: make XDR_QUADLEN() overflow-safe Date: Mon, 30 Nov 2026 17:33:39 +0900 Message-ID: <20261130083340.226981-1-muumthf@gmail.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit XDR_QUADLEN() rounds a byte count up by adding three before dividing by four. On 32-bit systems, a length near UINT_MAX wraps the addition and can produce a zero word count. __xdr_inline_decode() then accepts the length without advancing the stream because its bounds checks operate on the wrapped result. A malformed NFSv4 SETATTR request can supply UINT_MAX as the FATTR4_OWNER length. The zero word count bypasses the XDR bounds check, after which NFSD passes the original length to its name-to-ID mapper and attempts an oversized copy into a fixed-size stack buffer. Dan Carpenter reported the XDR_QUADLEN() overflow in 2024. The proposed size_add() conversion was not usable because XDR_QUADLEN() is also required in integer constant expressions. Use DIV_ROUND_UP_POW2(), which avoids the overflowing addition and remains a constant expression. The decoded word count for UINT_MAX is then 0x40000000, so the existing stream bounds check rejects the request. On nfsd-testing 36fd4049e3c2, an unpatched i386 QEMU server returned NFS4ERR_NOFILEHANDLE for a normal-length control request. The UINT_MAX request reached do_name_to_id(), triggered a double fault, and panicked. With the patch, the control status was unchanged and the malformed request returned NFS4ERR_BADXDR without an Oops, warning, or panic. The unpatched and patched i386 kernels and the patched x86-64 kernel built with GCC 13.3 and W=1. A patched x86-64 NFSv4.2 mount, write, fsync, readback, unlink, and unmount completed successfully. The vulnerability research and validation were conducted by members of the Tobabz team as part of the Best of the Best 15th program. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Dan Carpenter Closes: https://lore.kernel.org/r/bbf929d6-18d2-4b7e-a660-a19460af0a3c@moroto.mountain Link: https://lore.kernel.org/oe-kbuild-all/202405100445.DwegLXyZ-lkp@intel.com/ Cc: stable@vger.kernel.org Signed-off-by: Hyunsol Mun --- include/linux/sunrpc/xdr.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/sunrpc/xdr.h b/include/linux/sunrpc/xdr.h index 2b33fc64be..46151478ee 100644 --- a/include/linux/sunrpc/xdr.h +++ b/include/linux/sunrpc/xdr.h @@ -12,6 +12,7 @@ #define _SUNRPC_XDR_H_ #include +#include #include #include #include @@ -29,7 +30,7 @@ struct rpc_rqst; /* * Buffer adjustment */ -#define XDR_QUADLEN(l) (((l) + 3) >> 2) +#define XDR_QUADLEN(l) DIV_ROUND_UP_POW2(l, XDR_UNIT) /* * Generic opaque `network object.' base-commit: 36fd4049e3c2bb901118e11be63bf7a7922bea8c -- 2.50.1 (Apple Git-155)