From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f175.google.com (mail-dy1-f175.google.com [74.125.82.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D4D740BCD0 for ; Thu, 11 Jun 2026 16:54:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781196859; cv=none; b=CRSVPo93QQRpz1dzWUxeDOYWp0zMbIDIOUM7+RW4FKawuawt/wsAfmro1zteJcd/iZrpGpVcV8ml5CP/OHrd0DZDhaP9IbuBNUbb8UcRf/CbAaQSKQbwlse9/Vs+oh6MHrp7J1I7wgqLeS6xeLCoJpSbl49Zl80HHug43StZ8ws= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781196859; c=relaxed/simple; bh=xQ7CqVM6Cv/wUPHS4u37ELPAUEgOdL1GoqD+eDoxsTw=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=YIhGp1KCgG5Hv7SNPYHlnevGE6lq/F2NO9RI98LLzInLT4BuE9/H7jdlyIG8ELNgFWVpgKAAq/ybkbYd2sy6SgzNjYE+7haTZ5T5A4j8XbRSmMJi13tuQ+h70hYijkrSXA3sRRJzoJf10Sq5F2NuRDmcdGti9dMX2il+l1o7BCc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com; spf=pass smtp.mailfrom=etsalapatis.com; dkim=pass (2048-bit key) header.d=etsalapatis-com.20251104.gappssmtp.com header.i=@etsalapatis-com.20251104.gappssmtp.com header.b=piQdKggZ; arc=none smtp.client-ip=74.125.82.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=etsalapatis.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=etsalapatis-com.20251104.gappssmtp.com header.i=@etsalapatis-com.20251104.gappssmtp.com header.b="piQdKggZ" Received: by mail-dy1-f175.google.com with SMTP id 5a478bee46e88-3078e0dcd67so172425eec.0 for ; Thu, 11 Jun 2026 09:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=etsalapatis-com.20251104.gappssmtp.com; s=20251104; t=1781196856; x=1781801656; darn=vger.kernel.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=u6ceVOGme5lPB581G5XFGTQ1yGvtSh529zyR2h7e/S8=; b=piQdKggZb7scrSLHx6CVg3bcoXXRmB70LzOUxA7VJ/k9a8e50JQE3GQZZ0xyGuhOzx fPXbi7Jb2abCZA/r6sXrdb7UpO1XBE8qIE7pFVSLBadLs8VbXVqFzZRagAtabVIfjx8M kGVUBxcDnm+LF13lASl8u1q/ExUhlCGfCnDr9/KFpeR1jx5mgGM9Li2oxPPC3dOTz85s /xF/MThN2/pD9/uvo5N8N7Ri9LYX763+B5f408FYJR+mmMcKEXWQyM69zohd0/1d2Yyj 4FsWWx6OVZ/+At3P4QdESrGL9I6Y96r0o2BNMs9OSZkU96+Ki8OoqMLSvFUVlqW0+6Wd 9Q7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781196856; x=1781801656; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=u6ceVOGme5lPB581G5XFGTQ1yGvtSh529zyR2h7e/S8=; b=DGLCw/38rVbFHWVIGJSalkRBuPcDQ+XpYAEgBQF52pl92MBDX+jJHPuU1X93FYCtxH kZGlrOT6oPwwAwSAA8aSpgqyx5fAbaqlH2VTVOzE1qEwn6R5QNOjRsd5qGvDKFd9FfaL F85XUAwE8gOXaeZpzDUeNlijhS7ApCpYMEG3MxYMmj1nivpmtEn5D0uPMru6Ebaf7EZv yN8D88X2BhsbSur7u4nYrTyfD/PcpDgCeVra2yhsgLnBYXEjK8zWJB4Yb3HtxUifFLLN jNkkloTBvUqoJF+VDh4ps9y0OA5lAwE+ik+HretYeXiVvs1bqb5jH/fc21ymWfk3pxAm +ZKw== X-Forwarded-Encrypted: i=1; AFNElJ/kpQl3BAhYsR3ejcUX6LSzeC7u9saRIQ+rR3CkQrpL2rArfHFtH8nop2pwnKdTWLfzE0l96bQsUSdNWvY=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1rLhwmQekvP3UvPQcCueG+OWnkW5CRs1jzVMDAqGNTQ+KlfoJ J3YZ3QxBJnSA96jOMI3WmDaa1y4+lR6XryNBNzPR+voXKB1Tipc4Be4bapATul9x4ds= X-Gm-Gg: Acq92OHTVZPW+HO/NsOBW4tDY0OMpM8lKvg+nHzp3vxzLr+dCNhKeSH9u7w//cSE4+6 M6WnInODnLP5JUdJj5nPMBPxlQ5OBHB8GxdgsVQZ9EJ/5ZvzwcDd1V8Ysn/fdtDKcUakMoUWNch X1pqVbxp5sC2tZd5FQxmQ2HmX3mc07QnHMo0cozRDBOyh+vt1iNuUwnrmMOqS9PaArZ/kUajT1O K6piYRLS0WawLADOWi7H216oF5EdwBx4PtBVKFRyWfX1yw5SGNbZXT5smDj+E2r5W0uHyKnJMZ/ il4ivP1l60116kdcdrvy+b55GEX45WRikIEOS1TiKAfIsJK0D8AtvCNHVaHeAUV4LCHbZlrlJeA X/3ymA8+sjW8OxmSZdcAzz+yB4otPRgBnPdnG7LXBRxcfCqupvUF/qg7RlBI0TPi8J2eDVsn6yH uLGXQg X-Received: by 2002:a05:7301:688c:b0:2da:a813:a5fd with SMTP id 5a478bee46e88-308049fbd21mr2915715eec.22.1781196856367; Thu, 11 Jun 2026 09:54:16 -0700 (PDT) Received: from localhost ([2620:10d:c090:600::9f35]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30806c2f3absm2523710eec.5.2026.06.11.09.54.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Jun 2026 09:54:15 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 11 Jun 2026 12:54:12 -0400 Message-Id: Cc: "Sechang Lim" , "Alexei Starovoitov" , "Daniel Borkmann" , "Andrii Nakryiko" , "Eduard Zingerman" , "Kumar Kartikeya Dwivedi" , "Martin KaFai Lau" , "Song Liu" , "Yonghong Song" , "Jiri Olsa" , "Emil Tsalapatis" , "John Fastabend" , "Stanislav Fomichev" , "David S. Miller" , "Eric Dumazet" , "Jakub Kicinski" , "Paolo Abeni" , "Simon Horman" , "Jakub Sitnicki" , "Shuah Khan" , "Jesper Dangaard Brouer" , "Ihor Solodrai" , "Cong Wang" , , , Subject: Re: [PATCH bpf v2 6/7] bpf, sockmap: fix integer overflow in bpf_msg_pop_data() bounds check From: "Emil Tsalapatis" To: "Jiayuan Chen" , X-Mailer: aerc 0.21.0-0-g5549850facc2 References: <20260611123538.156005-1-jiayuan.chen@linux.dev> <20260611123538.156005-7-jiayuan.chen@linux.dev> In-Reply-To: <20260611123538.156005-7-jiayuan.chen@linux.dev> On Thu Jun 11, 2026 at 8:34 AM EDT, Jiayuan Chen wrote: > From: Sechang Lim > > start and len are u32, so > > u64 last =3D start + len; > > evaluates start + len in 32-bit and wraps before storing it in last. > The bounds check > > if (start >=3D offset + l || last > msg->sg.size) > return -EINVAL; > > can then be passed with an out-of-range start/len, after which the pop > loop runs off the end of the scatterlist and sk_msg_shift_left() calls > put_page() on the empty msg->sg.end slot: > > Oops: general protection fault, probably for non-canonical address > 0xdffffc0000000001: 0000 [#1] SMP KASAN PTI > KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] > RIP: 0010:sk_msg_shift_left net/core/filter.c:2957 [inline] > RIP: 0010:____bpf_msg_pop_data net/core/filter.c:3103 [inline] > RIP: 0010:bpf_msg_pop_data+0x753/0x1a10 net/core/filter.c:2984 > Call Trace: > > bpf_prog_4cc92c278f4d5d56+0x1b1/0x1e8 > bpf_prog_run_pin_on_cpu+0x107/0x320 include/linux/filter.h:746 > sk_psock_msg_verdict+0x357/0x7f0 net/core/skmsg.c:934 > tcp_bpf_send_verdict net/ipv4/tcp_bpf.c:420 [inline] > tcp_bpf_sendmsg+0x766/0x1ae0 net/ipv4/tcp_bpf.c:583 > __sock_sendmsg+0x153/0x1c0 net/socket.c:802 > __sys_sendto+0x326/0x430 net/socket.c:2265 > __x64_sys_sendto+0xe3/0x100 net/socket.c:2268 > do_syscall_64+0x14c/0x480 > entry_SYSCALL_64_after_hwframe+0x77/0x7f > > > Widen the addition with a (u64) cast so the bound is evaluated in > 64-bit and a len near U32_MAX no longer wraps below msg->sg.size. > > While here, change pop from int to u32. It counts bytes against the > unsigned scatterlist lengths and can never be negative, so the signed > type only invites sign-confusion in the pop loop. > Reviewed-by: Emil Tsalapatis > Fixes: 7246d8ed4dcc ("bpf: helper to pop data from messages") > Reviewed-by: Jiayuan Chen > Signed-off-by: Sechang Lim > --- > net/core/filter.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/net/core/filter.c b/net/core/filter.c > index e35e681a15dca..742aeeea13c26 100644 > --- a/net/core/filter.c > +++ b/net/core/filter.c > @@ -3048,8 +3048,8 @@ BPF_CALL_4(bpf_msg_pop_data, struct sk_msg *, msg, = u32, start, > u32, len, u64, flags) > { > u32 i =3D 0, l =3D 0, space, offset =3D 0; > - u64 last =3D start + len; > - int pop; > + u64 last =3D (u64)start + len; > + u32 pop; > =20 > if (unlikely(flags)) > return -EINVAL;