From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.178 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796027642; b=l3RdZGm97unkqZC8g4NwcqYU69K0RbptQnGpJOiIXOD8rOWElOPDlTEhiXT71yQpmx7Z msEPyFyZD1xuRsGS1UYQqpYDvko1iA3YxRv65Ukv3EHZAgcGnIiMozfnD9l2LiCj9XS5m PGuQ9eCs7BJPOu9p1u6NM1ujC/sW65YAlxi2DM7b2jMKzpu9OtGko7pIWVAiVBgGvJDyT Wf+Tjb3G3EkMAW8hzW/V7qrWtSlt/V1En7cCKkJ1V8oINGtBphzqzcO9UISHlkcnkcUjb n1sDU3noji0D/BWKNdOxGBnnIMTsW4/lnxWQt3Y60FrrwBlbEa/qt17lKG2t6Aqz/eA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796027642; 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=41MRNoyDsVdGHtH5i1XMKmFnmvZ8BbKOd3eXJ0zmvtWrD6nMF9xY3QjN6lcHn1NQWTHh uVa/WK48/RxzyGuN8/TjiEMWGw/RuxyKZeqH1tlYZtv+Nmqv14zpfY33HdxBw2U6n0QB6 9sz7b6g0yatw1TA5sGPTorYtiKTs2RLJZaGdf07iOKBELBr1u5L+zR8iUMbvzMOuJFT3Z fyrc16+c4UtogEw7ANKiafNEcp/HyxcvE+dtasrGy0o7sCLqcjS2sc/ddg67k6mLOd3/S EKKaXUoc7yKs3EZcSX2rgI0aKss+byTOHPbSTx1B3ZEwNVBUB+UQE4+eDp3RvaqOiwQ== 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.178 Received: from mail-dy1-f178.google.com (mail-dy1-f178.google.com [74.125.82.178]) (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 0F0DC606A31C for ; Mon, 30 Nov 2026 08:34:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0F0DC606A31C 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-f178.google.com with SMTP id 5a478bee46e88-385d8a00598so17522553eec.1 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=QFQv6/FiL1FVr9XbYK+zam3xLhaka3Lbri6iP94yC9FM2ZcppD/lierOnxBbvjkY36 Y/7mXTXqImF2lAT7DWjEdCTxkjSbO0hEGNEJa6+FG3/BZk74Xp6ZLT3V+sXOi+bSEVMP pgvNwFMykog1YgfBdeuzfeEDkPkq4LU3+AGz6+WkWem3eMrx1o2c8qL9SRhymMgj3C5T tsnJqUXAkYWmP6zWKpEGmjtH0DX/jcv12vdQDhLrJ1e3W5edQ1BgRlYUNiqqkhT2Atrc f0p/HiBn5x4A8y/GnTfCiH23/31vZYZbCCAnTiRi6yKzlJ4ODRRy/ku+peRkXb+B2VM7 X40Q== X-Forwarded-Encrypted: i=1; AL+hErFVBs4RLJv3mW7A3keQqt6Djzi9mYBjajrb1bPo6BmfWZl4P63mdpIa4eqMSxD68i0kO9jBymU=@vger.kernel.org X-Gm-Message-State: APuU4Z+Lk3xxLoa2XFbrmFJzcBseLcg/cdTVMT5ch8QADm37Fs+vDNCf CIF5uTCaoN5VouKtFYXOC0TcLLBwt6opN/jYlyaIvOQbt4PowFTw2C6T X-Gm-Gg: AZFdTZfl3takBIYOr0DSFlDe3REXekhpqH3v6lba0h6HONrWWWC678JNiXkBWPNcRJZ blXLCaqNYPnNoHZ+DBlgBfv3FjddhbVVp4J5O51oi6UTs9FaFnk0yj5DJrSi8gsHCXYLAzNGbYi a1G4majzdgiesX1SjoYR2w70lArTjW/ON0QnoCLkf9Ho/PdxhhvQ50DA2/0hT2WQiDCIBvELq3w 2K5P84jy/sUQY7cnHrS5CKDuDOcY8lbmwMqxiUV1Sqhw+gfvm2XGRBdz41vsa8n9FaY6vQhKFHR QK2l3ALWJQTb0AF56KO0mSe8ogSf6I7S41IAAkjRf5rz4R2HAPwW+1p/JvUZ1HMX8NLP6USJB0J 8+TWfbK2gsRyfr1bKVtmE6hxUvaUXRqUqnwo1inOVX3ZmLWmme2zxStStWpi08bnnJAJ/MQkMpE F41Q+H+AMX2Fu72tNmUt733GqjW5JJbbSJ3Njt46Lfm944g/ttWuA8MfY25tnAwg5KGkEfnn+cg pkWOGoT9dS+FTPREY1tmkSo9Ek+9jtwiI68K3/gWKDpp31bnufMyeaVLQVWkqfChn1pg5agIiKC AMYW0C0ykr+H+HFvazoLKwr5XB+qJmmLKTDhc39T5mOtXJOUPW9BiKpWudZ1y2Virxd3Utr/Mf2 gQ1llNJoy3wNzwmqgPn33I4c= 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: stable@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)