From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796069868; b=SKJ/uOvZ6oNFBY/lODm1p+LX0CH8k+rJz6yB9ROnzoy+gvCX/YisDGIQ3Mj1M7kzlgU0 sGFhlSBH6GwqUCVwgvA4zzTfHsnbjvDdOPUY7DIthgbwMrfZpthswaR2Pzq/ZXDyWu+Hu QRQefDUeH2C7gDWvL0pJEHd9y1MzHCAO1y4X30ncGnAX+jquPMBxGAB+4RS27/Di73IRj xz36LdvDQkUsi1KcwhCEXFV2YzqkwFqCrxBUhR+wBiTFLXnUWM8dUitLQfUJsgLFBWZP/ vZm0r7n5q/d7winFXWp/eRPwbW/YpdYs/RYLO6fb6GjHtOWh/paVZ4Z5q+/XAiPFBlg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796069868; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:Content-Language:To: Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=oYIzlhbKG1vDNnVnObVA8NNvgz/s38KqJ+tsMtXJPWI=; b=Li1CGiihaGk8BVBzynGoRBAeCJ99/z3U6TWHKejETzUPfz+nc0aALnpR6BwxAM+6LsZl ZOClGGb5VN46SczJ2ly5Ub1W+lawsVP25OB/aA9AbWv5U1W8XiqBMX8AzpACKzFJ1qlbC gYElgOmwJJnRYPiCoHvOBaW4mFSqIO1ycwGrCWUSoKFFR/M+D+PNc5s3u8YB3COoQ1KtV tuxyIeqUbO8sodzB9lpHuQ8pm79X8Ll/nGFlUQa3h3d5o3e9SjNVrpvxvg6kNzrNR9QFP YYwiyaIlSF+1BE6ZqCYpxVilZI4w2VazaBOoEvbEQdPL+666wkJz5awabFNh7lNY4lA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=blackwall.org; spf=none smtp.mailfrom=blackwall.org; dkim=pass header.d=blackwall.org header.i=@blackwall.org header.a=rsa-sha256 header.s=google header.b=WAaWkurN; arc=none smtp.remote-ip=209.85.221.51 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 702BC606A325 for ; Mon, 30 Nov 2026 20:17:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 702BC606A325 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=blackwall.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=blackwall.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=blackwall.org header.i=@blackwall.org header.a=rsa-sha256 header.s=google header.b=WAaWkurN Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-4a32576da88so6382803f8f.3 for ; Mon, 30 Nov 2026 12:17:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blackwall.org; s=google; t=1796069867; x=1796674667; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=oYIzlhbKG1vDNnVnObVA8NNvgz/s38KqJ+tsMtXJPWI=; b=WAaWkurNiIF7Wkkb0Nx+gnnoxIPCtsolIoYryIEOyoFXsEoWGj+j57Ly1HIwmeMKLg ZkmrT53VuVTfTud8ol7xM648Y6wBYhAxsB8G6gpIlijvx4TquxGEGgmzRyBR4ABomwKf XMkDX0leZMhgE/hc2s7gY6CI/2DDKA1YNIZzaZwpoz9WSgBp/Plwmwd7duLGZha6o5h5 ejg03mAJ/iVQ1LTnoCLzqqXF5r+52C/FOolafoezKTsD10C3VN/4uiBUha+HZ9kIXEYE PL02/Wmjlmgomcpdh80YAs/e+1NE6wsm9NhP+pZEh8DPLF/bJqJ28S0ZPmet2USBZELB 5U9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796069867; x=1796674667; h=content-transfer-encoding:content-type:in-reply-to:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=oYIzlhbKG1vDNnVnObVA8NNvgz/s38KqJ+tsMtXJPWI=; b=QODn2g6cYT4I7N/dCHdr6rUL8vmd2ozVmw/6QOaw9b/6bn7P3y8GC7ThuKaY7+tkmG SZjxMP90mlVrexVpn2YYiL/LtqqtQIJqC54VmkwJN/Qqg06ozD8+U11S1YgzEt0pWWQT I6Obwt/kG4lPH/97TFaCvNqqEuc9MtFgG4C+yeykiLyTAMP17johWfRvFxbPOYEKKgnt xRBP2PoC5pgIQUG1bbjYD3gGXdYSYW4Jcdojl/GMXBXAGQV9gNU9b8KVRm8BuBjThgIC LSaOcAthDGN0A1WZ6Sm27UT31KHBvuEF2WtrMlUKGpS+97Tlc8IzQ2SCg7EBpDkPy/qU MNsw== X-Forwarded-Encrypted: i=1; AL+hErHjU7/uLtetvx7fc/HRecVhwwfFIUS7FsinR9cOlBhhv3/q1HKo7lmb5F1x6GaDhu5Nc5YQFESP/jLvClM=@vger.kernel.org X-Gm-Message-State: APuU4Z/7zbqOgyRkZGPiOtHfeVCPR8d8Hf6hjMnL28IsZTgH9DmC71Oh UR2FOGRoY6qQUUhPcIl31aHefGRvLtQc8qzw1oY0z0QueZJoID8EXqy2Ydl4HdemxYo= X-Gm-Gg: AZFdTZcc1gZlisS+e8nsxRlr+8IFRl2QsHWItCaYFCkfglkKBAyZHBdqFlrFBmVVoH0 SsqaV0CM3ET7WITGzqPDJFOHZvKWZiMPYhtLGut485vkKDlgcVPsrFJrdIUpZoNK7UnbtfqJY6g dln2NoWxVeg1ji/qCS2Mg6OOz/QBK1oe8yMZPpAWF5WLYyc7zD4db8Tn8K3iC40Hqw6vUFPylCS BujqVF7bZERlrKT/qaE2V49QObYS33wp5rd+68SAu6SNCb5/sftCiB+QbDTn20EF11fqhCGk6j/ knfhATTc/4VBo+sn+/YsUrFWpRBblKfuJER/efXZuZDWo2vwaqktEqjh48IUaprwyW6f9DelhIY Yt5p/F0009IxGmWVwaEdbwVSU/Ce7Uk7FnNzCFbAAkKCkNWy+wjPIaf5NoVZytH4ctGFxVA2xQV MiNxa3jizTQKDzjN2kGgFYiqfQrYAtIWjwh4oyfS+gesYVisqs7NcOTxc6KZncJWGka/NyRl+Mr 0qI3InXsnP0AVviKgPjKTKZHJjTjAdPfMj2k+4a0yDJm9eJ9JJsYnWso0+O71gnTWgXgz5VwTHy nmYf2TGJKF28Nqcfw0MP2ce9aJcoG3yAMXx5GSlvcgF8sg0r4aPFzIY7Vzs= X-Received: by 2002:a05:6000:2b94:b0:4a8:714:7ad4 with SMTP id ffacd0b85a97d-4abb59e28a5mr42889009f8f.32.1796069866325; Mon, 30 Nov 2026 12:17:46 -0800 (PST) Received: from [192.168.0.161] (78-154-14-127.ip.btc-net.bg. [78.154.14.127]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6a68048esm69872817f8f.29.2026.11.30.12.17.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Nov 2026 12:17:45 -0800 (PST) Message-ID: Date: Mon, 30 Nov 2026 22:17:44 +0200 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH net] netfilter: nf_queue: do not queue BPF syncookie request sockets Content-Language: en-US, bg To: Pablo Neira Ayuso , Weiming Shi Cc: Florian Westphal , Phil Sutter , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Xiang Mei , co+685321905e91e206@bugs.sh References: <20261129161228.4185092-2-bestswngs@gmail.com> From: Nikolay Aleksandrov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 30/11/2026 13:48, Pablo Neira Ayuso wrote: > On Sun, Nov 29, 2026 at 08:12:29AM -0800, Weiming Shi wrote: >> bpf_sk_assign_tcp_reqsk() allocates a request socket with >> inet_reqsk_alloc(ops, sk, false), stores the listener in >> req->rsk_listener without taking a reference, and attaches it to the >> skb with skb->destructor = sock_pfree. Because neither the request >> socket (rsk_refcnt == 0) nor req->rsk_listener is refcounted, the >> listener pointer is only valid within the ingress RCU read-side >> critical section. >> >> __nf_queue() lets the skb outlive that critical section while waiting >> for a userspace verdict. Its prefetched-socket check only handles >> !sk_is_refcounted(sk), which is false for TCP_NEW_SYN_RECV because >> sk_fullsock() is false for request sockets, and >> nf_queue_entry_get_refs() only pins state->sk (NULL at prerouting). >> If the listener is closed and its RCU grace period elapses while the >> packet is queued, reinjection returns the freed req->rsk_listener from >> skb_steal_sock() into inet_steal_sock() and tcp_v[46]_rcv(): >> >> BUG: KASAN: slab-use-after-free in tcp_v4_rcv (include/net/sock.h:2295 >> include/net/inet_hashtables.h:458 include/net/inet_hashtables.h:496 >> net/ipv4/tcp_ipv4.c:2121) >> Read of size 1 at addr ffff888025542812 by task exploit/194 >> Call Trace: >> tcp_v4_rcv (net/ipv4/tcp_ipv4.c:2121) >> ip_protocol_deliver_rcu (net/ipv4/ip_input.c:207) >> ip_local_deliver_finish (net/ipv4/ip_input.c:241) >> ip_local_deliver (net/ipv4/ip_input.c:262) >> ip_rcv_finish (net/ipv4/ip_input.c:492) >> nfqnl_reinject (net/netfilter/nfnetlink_queue.c:544) >> nfqnl_recv_verdict (net/netfilter/nfnetlink_queue.c:1905) >> ... >> __x64_sys_sendto (net/socket.c:2286) >> >> Reject prefetched unrefcounted TCP_NEW_SYN_RECV request sockets in >> __nf_queue() with -ENOTCONN before the !sk_is_refcounted() check so >> nf_queue() drops the skb. Calling skb_orphan() instead would discard >> the validated request socket and cause tcp_v[46]_rcv() to fail >> cookie_tcp_check() and send a spurious RST on reinjection. Matching >> on !refcount_read(&sk->sk_refcnt) instead of inet_reqsk(sk)->syncookie >> also avoids a data race against reqsk_timer_handler() updating >> num_timeout in the same bitfield byte on hashed request sockets. > > Cc: Nikolay. > > I have seen working on this. I am not sure if this will require more > checks in more spots (and more follow up incremental patches), which > would be better to avoid. > Indeed, this has been a part of larger set of fixes that were deferred recently since a different proposal has been discussed in the past[2]: https://lore.kernel.org/bpf/20261123084138.723275-1-razor@blackwall.org/ https://lore.kernel.org/bpf/3c96d878-0326-43c2-9869-e941cae675f4@linux.dev/ [2] and before that has been discussed: https://lore.kernel.org/netdev/20260403015851.148209-1-jiayuan.chen@linux.dev/ https://lore.kernel.org/netdev/20260608125846.157004-1-jiayuan.chen@linux.dev/ Cheers, Nik