Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 C84153DB62E; Sat, 12 Sep 2026 09:07:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789204030; cv=none; b=flhJMVMCgNUH1Y4fiZp5H1LemWyk6n54uD3L19QVcfNI+r24zoxqk7QIlw/tjhKEHMqrxR+kEejzIMn5MXW3UczdlqZqRxbYjvvI+xpKI4Z70MHUsVfljEE025AR/JzZxE9zU+x7d7avJWHWQ9tiK4Ga7dFraY/Y7MxGl0cR4KI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789204030; c=relaxed/simple; bh=taT3buY9v8xaOw0FhEKbONEXmBKrXO6d9oeqRJjHV3s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=plmyxpJ3yFyIMawQeCClkQfdTr6HbnCD0leUZY+nITJzBgQ1daHmHp8K2kTEbuMBZPegwJwHfmFj/fVa5bMNZiqp7UUqe+MDCXKIewo2q9HlFL/r+A1HBz1wTFNsBTvlyu5sIaBWFxgl8Y9oGY6KpaL5Ws6p57mUD6TvtqCOcks= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=2Cqeoriw; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="2Cqeoriw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B24371F000FF; Sat, 12 Sep 2026 09:07:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789204029; bh=JGaXhiJj4aEi44lXhHm3O/cUtXyvzlyf85Bzz3YIKnY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2CqeoriwgpPBU7PwVdFDfsxk5kQjrrkEeHo8okyB19cXnzFP/KiT63GMknBwkupcW 0lYEEx0JUhADqnyQKX5kR4SCGKDg6zsFbA+hPa2DcI87uGc0K5zWuwVZWuFaWGD+Zt NgwEHQmI3cghrl6etyItuBAsJBEkApXx1PcwbG8E= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sechang Lim , Junseo Lim , Daniel Borkmann , Emil Tsalapatis , Sasha Levin Subject: [PATCH 7.2 1529/1815] bpf: Reject negative optlen in cgroup getsockopt hook Date: Sat, 12 Sep 2026 08:54:39 +0200 Message-ID: <20260912065724.901321789@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065648.999753832@linuxfoundation.org> References: <20260912065648.999753832@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Junseo Lim [ Upstream commit 1b5aacd5b2419b0790e955e466d389a61c79b4b1 ] A cgroup getsockopt BPF program can shrink ctx->optlen after the kernel getsockopt handler has run. The kernel-buffer variant, used by TCP_ZEROCOPY_RECEIVE, only rejects values larger than the original length. If BPF writes a negative optlen, that value is accepted and propagated back to the TCP getsockopt code. It can then be passed to copy_to_sockptr() as a size_t and trigger the hardened usercopy bytes > INT_MAX warning. Reject negative ctx.optlen in __cgroup_bpf_run_filter_getsockopt_kern(), matching the lower-bound validation already present in the sockptr-based getsockopt hook. Fixes: 9cacf81f8161 ("bpf: Remove extra lock_sock for TCP_ZEROCOPY_RECEIVE") Reported-by: Sechang Lim Signed-off-by: Junseo Lim Signed-off-by: Daniel Borkmann Reviewed-by: Emil Tsalapatis Link: https://lore.kernel.org/bpf/187a4d756275aaaee5d65eecb63c1477b3b66554.1786448307.git.zirajs7@gmail.com Signed-off-by: Sasha Levin --- kernel/bpf/cgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index 31c63ff276fa7..44068bdd4f759 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -2260,7 +2260,7 @@ int __cgroup_bpf_run_filter_getsockopt_kern(struct sock *sk, int level, if (ret < 0) return ret; - if (ctx.optlen > *optlen) + if (ctx.optlen > *optlen || ctx.optlen < 0) return -EFAULT; /* BPF programs can shrink the buffer, export the modifications. -- 2.53.0