From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171]) (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 82A3F4BC00F for ; Thu, 11 Jun 2026 16:28:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781195337; cv=none; b=UfShPDj5hdWhnd3Bj+tmAJBxf3bbWUj14kO6g/TXROhYOTdh/wzUp3IRFANSVzfU6YqPZ1rVZY/mBC2eyLJVMUaL7ZyB5euQ0I9wcUcfnnTnsa+Y41wYDvK8TVOSFPzgCvD+gpJWzWOhcsWrQpG2RrFET5jXV7hpeUIl/g1k9U0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781195337; c=relaxed/simple; bh=Dq8U4JeMLdDJZCai9rkKpCchuv1uUA+lqZN3PGfqBIk=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=QfUi92R/TYvHp/qccIUQjvnzQCJpHU1MFy88Ky1n9GjmuN5gMkgQUyPb3ldAulwe1SEw4bKVx7p2m06XzPG2gGTjWEnj6HkD6TcUl+16/OkgNRNMa/qsC/EvGer81QP3wpWSXCK5iQ5OaC/6ZXPGqDGkObMFiSQExEneMxikq2Q= 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=gO86XJ5l; arc=none smtp.client-ip=74.125.82.171 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="gO86XJ5l" Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-30759632453so110673eec.1 for ; Thu, 11 Jun 2026 09:28:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=etsalapatis-com.20251104.gappssmtp.com; s=20251104; t=1781195336; x=1781800136; 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=hmILQTIhg4C2xaf23uaTPKYf63Qsqb45amOoW42QXJM=; b=gO86XJ5lX2WhRMfkazLeKXLf7wv1CkXPx9mPNdIgUvnRG0+aMS1WTVPTkSFyz2/uju f+dl+CDOeVOGYozPh+AO0+g+AgA2I7Wj8aG25z9PsB5fyPphzH2PzL8g7p25qK12h4XW RE1fBgpAck3lEoD+tHqqnHXIFLFe91oecgiTgsV3/5L8YMOhIhmK+3xqnQ5wyeTr6DNp NveThIDMWV2oQieMoMTS/P4+oOR4X/CFU0JecME9HoQLWnVGGNzexXvEn+NmYX+57mMD 8/SRfSGfQ2vSlSUKCnOoHLyi5Jb8wCP3EWlntz/vDnyKTNzvb+FWamw5uieCRTuHLSlo G9Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781195336; x=1781800136; 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=hmILQTIhg4C2xaf23uaTPKYf63Qsqb45amOoW42QXJM=; b=oR2ipy+PNnsdX0qla+vkZhuPO97224/BZD047fi5sShNFC+ivj50RsebbnVB8t3alW QUKm93XMaVz1nXlcPX3oZpUNPC7ihk+YT8d+o1IfxLk6LeJ7dMiPsuuT6HlE89NQXspL kL4uVbJwbXnEvZnza8iE4sJTGHzhmOeKnmQ4Tv++j/7faIY2d1l6lG53ewU/3ON/CavT nufi0qEdW2rC6j2Dh86JFUMqKSlW93qM6j+Rkeo6nyCcXJw4A4rqaroq9GE376yVc2xP CFrSYx4aox6wm6+7xnG5DDlELTu/q1rm2ePylndiu7RZwuLfCushpxO0cL0sL+coSoCc 3ycg== X-Forwarded-Encrypted: i=1; AFNElJ/X5j9MeUaZjPpmsirvmKvl8Y82LtcdvUAQjARWkhvF3ZTWkssBgCq70MehHiqoh4TqPXPaNEM=@vger.kernel.org X-Gm-Message-State: AOJu0YyscwOvm4AXQHnyCJIp3+GHP06umiInagCAlmFpvVJLtJ9skQpG DSnKO5BBOsGhOqlki4SMKwmcuNKYEpGBPxsPFHRTq6p8hguUbYhid2/D2g3locD1lbM= X-Gm-Gg: Acq92OFYpYe2EiiV0p+z4sFK+yrGobhMM7GoURLkPC65DFrKK3m3gOrk5b/qT7OXUFN UeWBBuCl2I2UK5jYfcfk0z2NDa9OKfaH6pE9SfmJllCufH1YEkvLlhTlMSF5cajZYYkLgUadLZz /1ZRv+4GksvhC7HERBW1lZ+IofdTd0iDzo/uWZEh4/qhZXF6h8XyEidVCRuJuLZwE4m6b80RO1Q dHdNDZNGRL3HjOL71c6sJnUzxsCe/TcKCg9wZYgVSe33/4RrC911rnfdtmE1QB85QKXZagFxI5I 6d1SSqws0tHIHIHAJcDZJ/DsR7GIg3wndw29MBKE9tapZ8P38aowM3BvqQN2exD57eiG2FHBfjC N2mj49YMJbIwgmkMJKOfX+6l7+9cGWP0XO+KtwkcMDheZxHGf0MxOKRujYVfM2jhS51zt7dZE5R DBn2qUUX0cs0Ce14U= X-Received: by 2002:a05:7301:1292:b0:2fc:9ae6:e5a8 with SMTP id 5a478bee46e88-308049eb931mr2752590eec.20.1781195335328; Thu, 11 Jun 2026 09:28:55 -0700 (PDT) Received: from localhost ([2620:10d:c090:600::9f35]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30806c47afbsm3701418eec.10.2026.06.11.09.28.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Jun 2026 09:28:54 -0700 (PDT) Precedence: bulk X-Mailing-List: netdev@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:28:51 -0400 Message-Id: Cc: "Weiming Shi" , "Xiang Mei" , "Daniel Borkmann" , "John Fastabend" , "Stanislav Fomichev" , "Martin KaFai Lau" , "Alexei Starovoitov" , "Andrii Nakryiko" , "Eduard Zingerman" , "Kumar Kartikeya Dwivedi" , "Song Liu" , "Yonghong Song" , "Jiri Olsa" , "Emil Tsalapatis" , "David S. Miller" , "Eric Dumazet" , "Jakub Kicinski" , "Paolo Abeni" , "Simon Horman" , "Jakub Sitnicki" , "Shuah Khan" , "Jesper Dangaard Brouer" , "Sechang Lim" , "Ihor Solodrai" , "Cong Wang" , , , Subject: Re: [PATCH bpf v2 2/7] bpf, sockmap: Fix wrong rsge offset in bpf_msg_push_data() From: "Emil Tsalapatis" To: "Jiayuan Chen" , X-Mailer: aerc 0.21.0-0-g5549850facc2 References: <20260611123538.156005-1-jiayuan.chen@linux.dev> <20260611123538.156005-3-jiayuan.chen@linux.dev> In-Reply-To: <20260611123538.156005-3-jiayuan.chen@linux.dev> On Thu Jun 11, 2026 at 8:34 AM EDT, Jiayuan Chen wrote: > From: Weiming Shi > > When bpf_msg_push_data() splits a scatterlist element into head and > tail, the tail's page offset is advanced by `start` (absolute message > byte offset) instead of `start - offset` (byte position within the > element). This makes rsge.offset overshoot by `offset` bytes, pointing > to the wrong location within the page or beyond its boundary. Consumers > of the corrupted entry either silently read wrong data or trigger an > out-of-bounds access. > > BUG: KASAN: slab-use-after-free in bpf_msg_pull_data (net/core/filter.c:= 2728) > Read of size 32752 at addr ffff8881042f0010 by task poc/130 > Call Trace: > __asan_memcpy (mm/kasan/shadow.c:105) > bpf_msg_pull_data (net/core/filter.c:2728) > bpf_prog_run_pin_on_cpu (include/linux/bpf.h:1402) > sk_psock_msg_verdict (net/core/skmsg.c:934) > tcp_bpf_send_verdict (net/ipv4/tcp_bpf.c:421) > sock_sendmsg_nosec (net/socket.c:727) Reviewed-by: Emil Tsalapatis > > Fixes: 6fff607e2f14 ("bpf: sk_msg program helper bpf_msg_push_data") > Reported-by: Xiang Mei > Reviewed-by: Jiayuan Chen > Cc: Jiayuan Chen > Signed-off-by: Weiming Shi > --- > To sashiko: > > Regarding bpf_msg_push_data() reading "copy =3D msg->sg.data[i].length" w= ith > i =3D=3D msg->sg.end (appending at the very end of a full/near-full ring)= : > > This is pre-existing code, not touched by this series, and reproducing it= needs > a narrow combination -- a pure append at the end so the loop exits with > i =3D=3D msg->sg.end, a full/near-full ring, plus a prior push/pop histor= y that > leaves a stale length in the otherwise-unused end slot. A freshly built r= ing > zeroes that slot, so copy stays 0. We don't consider it practically repro= ducible. > > Even then it's already covered: the overflow check in patch 1 ("copy + le= n < > copy") rejects the dangerous case, and __GFP_ZERO in patch 3 prevents any= data > exposure. Not worth fixing here. > --- > net/core/filter.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/core/filter.c b/net/core/filter.c > index 3c8f1cedb217f..3e555f276ba80 100644 > --- a/net/core/filter.c > +++ b/net/core/filter.c > @@ -2872,7 +2872,7 @@ BPF_CALL_4(bpf_msg_push_data, struct sk_msg *, msg,= u32, start, > =20 > psge->length =3D start - offset; > rsge.length -=3D psge->length; > - rsge.offset +=3D start; > + rsge.offset +=3D start - offset; > =20 > sk_msg_iter_var_next(i); > sg_unmark_end(psge);