Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.219.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795486786; b=Eta1lwNsmVHUvcczB7DqKiWKQUtHLXNSRYPdaR3lhpwWpFLUzOwqP7+/wycowXke5Jo/ +xe4mCOZrnL2wCmvWts72aFKbGkBQwDiwJK6YRkLGJ/3Rtk+m3MBAi+nwqE2HVzC/RCiM 5NChZvexKS9ZfRKyCqvpzwII/luD58gKidIeA+bsJDsSnT5lFIsGmL9xGU0WkTLUsIFMk MSAcGY2vcY8gMTkmXO1nRqApJo9sX1IQpr4J/8A0K8ZLH10bmf7OYGN3CnX5Dg03MAYZm IQfWAgksGkpD+iVdMwCkdcS9nt8bmcnz0Bu5X+O7WWrZF/lKOz6qB3BLpyqB+fCwekw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795486786; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding: X-Mailer:From:To:Cc:Subject:References:In-Reply-To; bh=vdBhioH55e2rBpiMMIlOy+uYTgZqubhBTCUnkYbH854=; b=JkxR7TUf7HtXXqiTVn8dN3atSDcpK55udj23bdIPOQcMoYEan1Ro3PjzJNWDGGYy1zc0 zbY+qwWsY8wXdskM0CjI+vmcoEK6lxEmqozVDcAtrVg7qYB8p4cw/xwvi67Z2zGWNIlHe qXECXAbUqVUaXee6LQFlHpvQ2GW+aYd785x7F/pOrpeUmR69tdLlYbzU1AZasR3C7Pqce ll/a0Z3/5LqDTppK8s0KxvHnC8gJ8pf//BehwMwufFyWvtpVh+xjLaDnkatZ6HUM5/ekw iFMDh3sPbEUWenDdYFkw9b4HKtaxtTlTp5lG5wr15mIQ5hbcczeozTx7XEHxvzgnViw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=paul-moore.com; spf=pass smtp.mailfrom=paul-moore.com; dkim=pass header.d=paul-moore.com header.i=@paul-moore.com header.a=rsa-sha256 header.s=google header.b=gXLmoeGp; arc=none smtp.remote-ip=209.85.219.46 Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) (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 E01AB606A321 for ; Tue, 24 Nov 2026 02:19:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E01AB606A321 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=paul-moore.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paul-moore.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=paul-moore.com header.i=@paul-moore.com header.a=rsa-sha256 header.s=google header.b=gXLmoeGp Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-9212a5a66f8so33964836d6.2 for ; Mon, 23 Nov 2026 18:19:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore.com; s=google; t=1795486785; x=1796091585; darn=vger.kernel.org; h=in-reply-to:references:subject:cc:to:from:content-transfer-encoding :content-type:mime-version:message-id:date:from:to:cc:subject:date :message-id:reply-to:content-type; bh=vdBhioH55e2rBpiMMIlOy+uYTgZqubhBTCUnkYbH854=; b=gXLmoeGpp4YC4I6mCpHK2JTvgYkWuqbvABel0yKurKWRD86NbmnEpxOCsbDHXlGUfG 90ysuBuVV3x0DumZtT9aZ/ZMYHhmBy129SlMJwiaN8mAMmz94b1JeI8fEf6sRhtwa81j Hs3DSUfs3f63rbs0OuWXTugp+WQHby0xxjMT3FkjK1iEI4yDhlE4ARTLT1uSz5UzDshf SV9ToAVyt3jXDngs7GhS5kJknl+DexPchuFfLV03z3rNdFKMSbp5yx7q/zNMseIEXVlO lON1hdivcYRYe4Eu6AJ54f6kYbiDY+fOh0nj0OVFyMKjghqT5tPUzbqrQfWKUaAl+Hjm 3CTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795486785; x=1796091585; h=in-reply-to:references:subject:cc:to:from:content-transfer-encoding :content-type:mime-version:message-id:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=vdBhioH55e2rBpiMMIlOy+uYTgZqubhBTCUnkYbH854=; b=rsjg+/BsQVXSnzcjJw5LJ8UhkqMn2EMCfwikntE2LFSXGqGOvfJKXOU4Su5aEycHae uzF9+7MCo6mAXVWSCw/maRU9ZwdeXhyvrj+MQNpQbkkMIqW5IYobZNVmN/CntpkZalHp ruiUmYgE2QY/PEf08t/hAL8m5fSjboC51hX/uc7TfVJsNQCCb4YYQ4C6nSNBsaMWCS6s mOiFmEuNHGfIWtREsjjjlaT4PzbRmv7h6U2e4qZ5wxSI9rSsfmcAZdVQ63JHbT+D7bTu I/lN+ynCSVeRWB+j8WmhBiAmfL+25Gg4uh4/K2LXkDtO2x4Vyks+VAH0Eua7z9E9ua9j KErg== X-Forwarded-Encrypted: i=1; AL+hErFU/2Z5AaJjzySneEU0C6EKTYOS7LM19VI9f3VjVBzgNe59Nd7ufmzS1o+UgI20i6oCeroXAmwI3UXfTBLUJmU=@vger.kernel.org X-Gm-Message-State: APuU4Z/littAxBIEflV1EBgwjUyLNdMtOJIIEcB+AkOVgQBlfajt1T+w ROo+T8RqjFUWj7rIYhig1KSWtyMQfg1Kc3Lvo1uYfO+Oe9zYO7wtrvCCxituOBICrg== X-Gm-Gg: AZFdTZfBaovDXIxQCWjZU5KaIcaDNemvv5uQrG0Bqr1PF83Kr8hWl4CI42SdV758C9W CP9ng3iAlXn12McoCLrBCdVV19oayDX7D6UvWy6RStz37/oJiwWS8O52Ne9B4lIPHuOE/TVfj6y 3Th6fvmXloSmmq4MnkBWOeaK2w8F617YUj2he3As4YFj2aMY+jY5wIR6MerE8iaGHiiRNKYZfmL u32yGzE4t09h9Wm3l0eK8dQoWwaNdilrES6Qtq3NIHcY1VaoF+5PJaJQuDAxVM/LiuR4NOWnfU/ qhFVGQM77Co+pOvjLmB9Lox3vydYZs3Okxi6nhSmV3p6j0mLleQ9wt3IjSyRP933XnbJfGlBRLR 6Di5nz+aIQJDlMpm7b/C4yFOcLa1qiuvMY00GYr4HAzKeZCmcoQ9pRB2BQ0Hb4sCptFyQKvLgfF pmjW06O8tDKrW45WsTkgxyaUGvLjHq/hoIvAUSRZslXlXT33lAJNoFgIge/jtYegC+Z+ZuIQWPQ GB0Vx2ox7sOKNy3gQbLxXEfPZSE249AUI7TCXYXjEqrHPIWo7jxVijim62NEKd9hn2K5O3SoZRY in9WWWxI29UFOME5AGUMZbYII1gmkQ9Z+o3iFp0pb+tkFEu20GNUS0ZYWlkDikot5QQPCw15wbm DLWadqcMZPFSAZQqrUZ610ZgfS7d15Q== X-Received: by 2002:a05:6214:194b:b0:921:1783:1696 with SMTP id 6a1803df08f44-92134a37126mr252343606d6.9.1795486784823; Mon, 23 Nov 2026 18:19:44 -0800 (PST) Received: from localhost (pool-71-126-255-178.bstnma.fios.verizon.net. [71.126.255.178]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-9213479655asm122232776d6.4.2026.11.23.18.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Nov 2026 18:19:44 -0800 (PST) Date: Mon, 23 Nov 2026 21:19:43 -0500 Message-ID: <04e583c2e9045e6a8990d752a1a2d1eb@paul-moore.com> X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Mailer: pstg-pwork:20261123_1724/pstg-lib:20261123_1443/pstg-pwork:20261123_1724 From: Paul Moore To: Arina Kharlamova , Stephen Smalley , =?utf-8?q?Ondrej_Mosn=C3=A1=C4=8Dek?= , Kees Cook , "Gustavo A. R. Silva" Cc: selinux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, stable@vger.kernel.org, Arina Kharlamova Subject: Re: [PATCH] selinux: reject a 65535-byte xfrm context that ctx_len cannot hold References: <20261124-dev-v1-1-00b99ee684ec@mbzuai.ac.ae> In-Reply-To: <20261124-dev-v1-1-00b99ee684ec@mbzuai.ac.ae> On Nov 23, 2026 Arina Kharlamova wrote: > > Commit 86c8db86af43 ("selinux: fix selinux_xfrm_alloc_user() to set > correct ctx_len") made ctx_len count the terminating NUL. ctx_len is a > __u16 and selinux_xfrm_alloc_user() only rejects str_len >= PAGE_SIZE. > With 64K pages, str_len = 65535 passes, and ctx_len = str_len + 1 wraps > to 0 (kmalloc_flex() stores the same truncated value first). > > ctx_str[] is __counted_by(ctx_len), so the following memcpy() of > str_len bytes is checked against a buffer of size 0. With > CONFIG_FORTIFY_SOURCE this ends in __fortify_panic(): > > memcpy: detected buffer overflow: 65535 byte write of buffer size 0 > kernel BUG at lib/string_helpers.c:1044! > ... > selinux_xfrm_state_alloc+0x18/0x24 > security_xfrm_state_alloc+0x3c/0x6c > > The memory written stays inside the allocation (65536 bytes for the > string); without FORTIFY_SOURCE the context is stored with ctx_len 0. > > A user context of 65535 bytes can reach this hook through PF_KEY > (af_key.c only limits sadb_x_ctx_len to PAGE_SIZE); the xfrm netlink > path cannot, because there uctx->len (a __u16) includes the header. > > Reject a str_len that does not leave room for the NUL in ctx_len. > > Found while surveying callers of kmalloc_flex() whose __counted_by() > counter is narrower than the count, with the help of an AI coding > assistant (Claude); I reviewed the analysis and the fix. Tested on > v7.4-rc2, arm64 with ARM64_64K_PAGES, FORTIFY_SOURCE and SELinux, under > QEMU (GCC 15.2.0), with a KUnit case that passes a 65535-byte context to > security_xfrm_state_alloc(): the unpatched kernel hits the BUG above, > the patched one returns -ENOMEM. The PF_KEY path itself was not > exercised. > > Fixes: 86c8db86af43 ("selinux: fix selinux_xfrm_alloc_user() to set correct ctx_len") > Cc: stable@vger.kernel.org > Signed-off-by: Arina Kharlamova > --- > security/selinux/xfrm.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) Thanks, merged into selinux/stable-7.4. -- paul-moore.com