From mboxrd@z Thu Jan 1 00:00:00 1970 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 31CAB2641CA; Tue, 21 Jul 2026 21:26:30 +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=1784669191; cv=none; b=eVGPDDRJLpquze6WYjvT/x1n4Yv1BGbyXXhBaflpQJt/3BAKW8axiV0LBLuNj25Crx3IVXdr6KNA7RBsQfz/ZG0GryB78tUJUADvRkZA2NscTSxucNT1iImggCiwcvCr3reXg4/EsZuaeK/z9vjSbvVVB/LLg3N2MFR1DCp3mmI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784669191; c=relaxed/simple; bh=CRUq/ZzoVJ+fGuz3rBMRLKGGC4yTNjk3p7G55uJ2jqk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qY1Z3mczIRm/QE6+wUO7Sgthy+tsIeuT18cmB5JZ8gEeNy+SBDJbYWkByqnUVT6xBpVO9To0rTp/4lXUy8bnuR6ekETPqOCMYf+5ONpdc+ttco+8UAObMNqcIe2zK387bB+4lPffqDEJJBPCj3XM+i+GRSsSHYb4HAU7Jrk9PDU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Jk8FmZgy; 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="Jk8FmZgy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8BE521F000E9; Tue, 21 Jul 2026 21:26:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784669190; bh=2FxNDVviHURG7NDNBx4jVvdvxH6lPT/ynSXWL0nxYuc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Jk8FmZgyt+n0pj1wzPwoMDD0mujmR6XCx5o3rSAQsGx59lZc2zOaFyHNguq7Yi1pr +d3xPZDWwZkDysql2oykSrjTkw4cQ2AuMHKd/W88eb4zl5Sb9DXDo0hSrwPgF+wwFL wdLbELWR5UOyp86jn3YVqZsPgnePxSFzh3+R0EzA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Xiang Mei , Xinyu Ma , Jiayuan Chen , Emil Tsalapatis , Kuniyuki Iwashima , Weiming Shi , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.1 0460/1067] bpf, sockmap: reject overflowing copy + len in bpf_msg_push_data() Date: Tue, 21 Jul 2026 17:17:41 +0200 Message-ID: <20260721152434.905583075@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152424.521567757@linuxfoundation.org> References: <20260721152424.521567757@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 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Weiming Shi [ Upstream commit 0c0a8ed85349dae298712d79cb276acfeb794d82 ] When the scatterlist ring is full or nearly full, bpf_msg_push_data() enters a copy fallback path and computes copy + len for the page allocation size. Since len comes from BPF with arg3_type = ARG_ANYTHING and both are u32, a crafted len can wrap the sum to a small value, causing an undersized allocation followed by an out-of-bounds memcpy. BUG: unable to handle page fault for address: ffffed104089a402 Oops: Oops: 0000 [#1] SMP KASAN NOPTI Call Trace: __asan_memcpy (mm/kasan/shadow.c:105) bpf_msg_push_data (net/core/filter.c:2852 net/core/filter.c:2788) bpf_prog_9ed8b5711920a7d7+0x2e/0x36 sk_psock_msg_verdict (net/core/skmsg.c:934) tcp_bpf_sendmsg (net/ipv4/tcp_bpf.c:421 net/ipv4/tcp_bpf.c:584) __sys_sendto (net/socket.c:2206) do_syscall_64 (arch/x86/entry/syscall_64.c:94) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:130) Add an overflow check before the allocation. Link: https://lore.kernel.org/all/20260424155913.A19FDC19425@smtp.kernel.org Fixes: 6fff607e2f14 ("bpf: sk_msg program helper bpf_msg_push_data") Tested-by: Xiang Mei Tested-by: Xinyu Ma Reviewed-by: Jiayuan Chen Reviewed-by: Emil Tsalapatis Reviewed-by: Kuniyuki Iwashima Signed-off-by: Weiming Shi Signed-off-by: Jiayuan Chen Link: https://lore.kernel.org/r/20260615021959.140010-2-jiayuan.chen@linux.dev Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- net/core/filter.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/core/filter.c b/net/core/filter.c index 26762c3825a3dd..2e64f8e85631ef 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2815,6 +2815,9 @@ BPF_CALL_4(bpf_msg_push_data, struct sk_msg *, msg, u32, start, if (!space || (space == 1 && start != offset)) copy = msg->sg.data[i].length; + if (unlikely(copy + len < copy)) + return -EINVAL; + page = alloc_pages(__GFP_NOWARN | GFP_ATOMIC | __GFP_COMP, get_order(copy + len)); if (unlikely(!page)) -- 2.53.0