From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.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 4C8493B0ADB for ; Mon, 8 Jun 2026 22:16:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780956969; cv=none; b=H1Cyq6PujunHb3xvvC/tuRaBd9x67JP1MjMUDwUe6fscDrbDH0Uacxerr6zMJpB3g53RCGsN28/cRPycRq+O6etiGH5xePhWHzUvNWzOS2Bo+kHUC9bf/kPP9SM4p8oIdnz8ZsGPakZILB+g4pAW3O8P7hHeoVR/1+BwwQfxIMc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780956969; c=relaxed/simple; bh=5S9+Cq5mB6r0CsPwnBf6Bi9EBEMbdFL9VF1fFs2tVh8=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=G9jyvUq1/mBCBzTbIVjAVZc/zEAyxQhpprMJpc12hQNRIlJ40lS3GjaOM9ll8ZsEZmdeEaDfCDmdBRHkh1b3ekkNHva2LnrO/9APGmxGP0Ch1QmfH+Fup3IGlXHhwy2VInt88DiuJ3ty/zVuyul0sm/wcSV6WySHICksz0LVke8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=m/j6uKom; arc=none smtp.client-ip=209.85.167.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m/j6uKom" Received: by mail-oi1-f171.google.com with SMTP id 5614622812f47-4865e953031so5016674b6e.0 for ; Mon, 08 Jun 2026 15:16:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780956967; x=1781561767; 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=5S9+Cq5mB6r0CsPwnBf6Bi9EBEMbdFL9VF1fFs2tVh8=; b=m/j6uKomIznvp+t9zPkrFDexHFl1cwOn80Pf/8nQUwPCopgBZ7vGWIYsmLenqujMG6 aEGvRIunsn5WeX5DaiC5O5pAfTSwoZyK27aKXKdaNu47GUZkec61FlUpWmMuAf0pavgu +OnJ6yTTQJRUc42ZZO4LpzoIzmMLUuftWtMky//J3gLjKXOElPsHMkcEQk5rgbk/3sJh MktBkO+qCF/1lPzqvCuLeQHd4reR2kvbUEt+h7AR8bp71Ogygs4448qeaX3qdupWis1k ebjZiBMNrh4HgWcfMd4WWL7Q8xhUVOz543bl1b5Hz81HPaq+LEjePjFOivpfzxEqhvKP dTpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780956967; x=1781561767; 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=5S9+Cq5mB6r0CsPwnBf6Bi9EBEMbdFL9VF1fFs2tVh8=; b=e7gkxwFhBFBK34pcPt38pN8Yte7pN/iSw4LvvZ4pzffqcuCK+bYXXCUEVQUCctF0Py nBOTmTjSr+vZHparEXdPkC0pgZ9t2H5A5iebH+PBZJDfZuz6youlQzdfpRdaXV0EtDZp fzdsi68fiQxSYKVnCLvc+6TPlu6NZ9bhFbbE+otmx7vir1BD7QnLEgCnIxwAdw8ZbBqn q/sJdPF8t2pBD2+WZhZDBepurBStA+VA6fMOETQlIeh06z4qh7mkD0I0vOtdY/7cVfsL 6JJ59RNwIcSGYUhkTOZPds/ET0awJXWcQgACWUBTsKDE5xcw0O5SyrO2OJ8iTCsp68xy qvnA== X-Forwarded-Encrypted: i=1; AFNElJ+W7NlR8IF4K5oA4x8Kutv82hj3KuN1Ho1PBlTjaCt+fXM13TYAw8tgMTq3J9IV65/A+jE0S16sSSbdxHA=@vger.kernel.org X-Gm-Message-State: AOJu0YxOJt86r8SDvpe+AiCCwXeuudHaoYK1mnMt6Pef6bdqGa2QA/6B bvwK48axL54mnhwd8w/v4ZTWzMHxRdJMUqiw54X0pecSLl5HlVhiLDnRDEIY1g== X-Gm-Gg: Acq92OHYT40iVzqecRJP+apPsM2XsdhTZqvykBjKqi2ZqDrAFAW2POoFoGghtF/Cn/A p18dR5V6uc6NcZNQsrdOMEGgvTc4QjVZ8AVQwjf9GelkFQLthF2KpLAJnpRxznpi3SdS/XqExwe vQ59o1fzT4f2MRC0ms1Qenaf81XFWpFy4twCKo/fow2RmECnGmZ/gW5O2MGIkRHBNT7MsRWyKvm +jJBxfUSg6FhWNktJJ85EVrlE/eh+kQPYFQrrobF8S9TaZINmgq8U8pE5uRzIIURipNlPFEOSSQ HiNpDgpnEFum+4XJrjb7L37tlbCwv19EEWqrU6wRxbIc7MKw2D2piC/SdoPLjZ99g48XG13KDSZ RqvCG+OhFCbTphUP9qx8guL/lzocJKKVKPBWwvdniphYcAnxhZVLDm2LaroheoRNXt9/pj8iSVy 6nDgBkL+FU5a0sZeKXdmApSJYt3E2SZacFF1nAovyTT+PkHzMxTI5q2buP88UlT8O4bd54sXO9Y Mkr1ZfhG+YOKExJiNLyarAT6hx+ X-Received: by 2002:a05:6808:144a:b0:450:b249:71bb with SMTP id 5614622812f47-48692e390c3mr6568858b6e.19.1780956967107; Mon, 08 Jun 2026 15:16:07 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:40::]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e6e79237a1sm13423994a34.19.2026.06.08.15.16.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 08 Jun 2026 15:16:05 -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: Mon, 08 Jun 2026 15:16:04 -0700 Message-Id: Cc: "Jiayuan Chen" , "Alexei Starovoitov" , "bpf" , "David S. Miller" , "Eric Dumazet" , "Jakub Kicinski" , "Paolo Abeni" , "Simon Horman" , "Willem de Bruijn" , "Daniel Borkmann" , "Andrii Nakryiko" , "Martin KaFai Lau" , "Eduard Zingerman" , "Kumar Kartikeya Dwivedi" , "Song Liu" , "Yonghong Song" , "Jiri Olsa" , "Shuah Khan" , "Joe Stringer" , "Network Development" , "LKML" , "open list:KERNEL SELFTEST FRAMEWORK" Subject: Re: [PATCH bpf v8 1/2] net: Validate protocol in skb_steal_sock() for BPF-assigned sockets From: "Alexei Starovoitov" To: "Kuniyuki Iwashima" X-Mailer: aerc References: <20260608125846.157004-1-jiayuan.chen@linux.dev> <20260608125846.157004-2-jiayuan.chen@linux.dev> In-Reply-To: On Mon Jun 8, 2026 at 2:35 PM PDT, Kuniyuki Iwashima wrote: >> >> btw is earlier sashiko TOCTOU concern real? > > Yes, the selftest in patch 2 should reproduce null-ptr-deref. > (I tested one in a prior version) > > >> iph->protocol =3D IPPROTO_TCP; >> bpf_sk_assign_tcp_reqsk(udp_skb, tcp_sk); >> iph->protocol =3D IPPROTO_UDP; >> >> as far as I can tell past bpf_sk_assign_tcp_reqsk() >> the networking stack only looks at skb->protocol, >> so modifying iph->protocol will only mess up >> things on the wire (if this packet goes out). > > ip_rcv_finish_core() uses iph->protocol for early demux > and ip_local_deliver_finish() also uses it for demux. ok. Another idea... we can keep the checks on bpf side and teach the verifier to invalidate packet pointers at bpf_sk_assign_tcp_reqsk= () and introduce new concept of "readonly skb". So after invalidation the reloaded sbk->data will be read only. There is no such thing today. The verifier only understands PTR_TO_PACKET as read/write. So it's not easy, but probably good thing to have for this and other cases where bpf prog shouldn't touch the packet once it called some kfunc/helper.