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 6020A3B9930; Tue, 21 Jul 2026 22:10:54 +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=1784671855; cv=none; b=m5+2a7iPhYLx4MuAOlgXbf8q8FQgX/nfrYQRioA+Zzjwx6qmOz0pxPFY1gcxYcYmhfm1E8Pme9mXVaO/st2nvG7J4LY1aTaHf0K1v4U86W8Lfw/MY9BnCar1f2w5mzTS4ZmsbZYaMUyKjYmToh3o8Obg/CKs81IMNEMdiz8qJ1k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784671855; c=relaxed/simple; bh=UIh+mhXmPsBPOy5Ls6KuZniPwpHhpyRtLhGhEY8MNKQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BQn7ogrLuHfViGxAFVkMFxWbccqj7Za1OM0jq/qS11Mz1GEqCjEzCBFsmwdy+FDvQOmjdHx1Odz7zk4FMVG5Y+9h+Fu0GZiRaPx6ZUQSnMDT5IHvGKjrJY//iX8vNB8feuzvr+sDpiBilnrL//LCn+kE2mhFLGBnVlbJWvvxN/A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=gPg3FPEM; 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="gPg3FPEM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC4A71F000E9; Tue, 21 Jul 2026 22:10:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784671854; bh=5qKX68lyPK1NuMlwRgx85sLKRA4/Edm++wc0NyS9KC4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gPg3FPEMpP3gnA96P3S4tQfo3aD3CJmbyz401ejxixjKA/GKrI8R1G0CL5ZK+M6+t IM+FuOMASlQmgjw4up7BzCWzD9hTYhYOjRkE/gSYyZzuiLrmoK2UPscAXxMbfERmiQ T8qtKG+cySlJE5r/7ObKX/XpmFE2ME9JZCRrf2HI= 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 5.15 361/843] bpf, sockmap: reject overflowing copy + len in bpf_msg_push_data() Date: Tue, 21 Jul 2026 17:19:56 +0200 Message-ID: <20260721152414.151403204@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152405.946368001@linuxfoundation.org> References: <20260721152405.946368001@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 5.15-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 2b413e9b6d02a6..4594ad6e6694f7 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2802,6 +2802,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