Article View: linux.kernel.netdev
Article #10014Re: [PATCH bpf v2 12/15] bpf, sockmap: Clear the redirect target before the sk_msg prog runs
From: Jiayuan Chen
Date: Tue, 03 Nov 2026 01:58
Date: Tue, 03 Nov 2026 01:58
23 lines
9526 bytes
9526 bytes
On 11/2/26 3:21 PM, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>
>
> bpf_msg_redirect_{map,hash}() store the target in msg->sk_redir, without a
> reference. After the prog has run, sk_psock_msg_verdict() makes SK_PASS a
> redirect if this field is set. But tcp_bpf_send_verdict() runs the prog
> again on a cork, and on the rest of a partly sent message. Nothing clears
> the field between runs. Thus SK_PASS without a new target is a redirect to
> the old target. If that sock is already free, this is a use after free.
>
> Clear msg->sk_redir before each run, as the skb verdict paths do with
> skb_bpf_redirect_clear(). Only SK_PASS without a target changes. It now
> sends the data on psock->sk. Then sendmsg() can return another value. A
> redirect that applies to more bytes uses psock->sk_redir, with its own
> reference. The counts msg->apply_bytes and msg->cork_bytes stay as today.
>
> Fixes: e5cd3abcb31a ("bpf: sockmap, refactor sockmap routines to work with hashmap")
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Reviewed-by: Jiayuan Chen <jiayuan.chen@linux.dev>
Technical Details
Message-ID:
<9d684932-998b-4f78-a445-79f07523d600@linux.dev>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355149-linux-kernel-netdev=dewy.ruReferences:
<20261102072112.4160195-1-alexei.starovoitov@gmail.com> <20261102072112.4160195-13-alexei.starovoitov@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355149-linux-kernel-netdev=dewy.ru From: jiayuan.chen@linux.dev (Jiayuan Chen) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH bpf v2 12/15] bpf, sockmap: Clear the redirect target before the sk_msg prog runs Date: Tue, 3 Nov 2026 09:58:17 +0800 Organization: Usenet Network Message-ID: <9d684932-998b-4f78-a445-79f07523d600@linux.dev> References: <20261102072112.4160195-1-alexei.starovoitov@gmail.com> <20261102072112.4160195-13-alexei.starovoitov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="3076293"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:7ATUWQ62qxRZ1mxHj5hR7rQE9Aw= sha256:fajSdp5RjLyH/stKfmAykF8tpndRcyXLeCv7MAWYj0A= sha1:HY/IvuuJMMJGikfAraoPHYm0AbI= sha256:DLjtPWPj7pUJp9LPcC1FOonO3JFJyFHEumTTYuSsOJ8= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id B8A821126F9; Tue, 3 Nov 2026 04:58:46 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.051 X-Spam-Status: No, score=-2.051 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, HK_RANDOM_FROM=1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key) header.d=linux.dev X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HvhoVf1ozAS7; Tue, 3 Nov 2026 04:58:44 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-355149-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 7A2181126C5; Tue, 3 Nov 2026 04:58:36 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 424A124DDB; Tue, 3 Nov 2026 01:58:33 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1793671112; b=rn/JzYdM4W/U0HBfrGZ8bqNPREHjlzRgGyT4mmLmVypbisFU/SzsxpzNBb0R7L4poEsq m+Gkfp59Tqf+eZFGYecjZT/UrJyCd/5tQIC8yUXiLhcEkH0sAC46z12ggBbulvlBpmZhs 398HF8HF+K+yoIQ6sv2cY3R/V5nPXGr7QTQq0H6wHEm8pybyrMhDrnOQ985Bv67cHEPNw +F/xbK0UrfZmQHrBYk2Jdow4kX/Kym2UKIhiy6wCgatO+mwTFQGq2wAUl4so3A+MIgBRS ojxnbXwnpYjXGS3AyxvGcoHvj9spedhMcZxZ7Ir5FaqshSErEENNN44xLVHCcByhtCg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793671112; h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature: X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=HvlT1XjrX2pqFLgxdO8FZhy56kYrtx0Ju6Likqq4/Is=; b=q1Kn+/futS8LdOPXBXZhagV9Ij5s/7wweBBjL9cE2jexanPQ83lb928PB6ytkINJFFiI PIpAmyfpPnyVYcrrAdXBtFYOrcR912Tkj15mLo6PZRMrakUzMma6ZIaccdjzThVgKRRZn SHmUGBU4wHGlBGRyeDX6LKkiSq8hRKDJTuFzUGTIfaErE5GTn7vYGak82i+1vje9IoGl4 zitzcoAA1237UyUDu4VAu7k/Do1SlG5tL7K0OMtrBvdtzPKJqU3yeIDctg6wdglCVOh8P Q8QmU0m/kVKzcKX15WjO7c42g2zP9+m3FgTNNy4YP337RE1YFqX8YE3vmxWhI4u1Ylg== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=uRZEuZB1; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D46DE606A331; Tue, 3 Nov 2026 01:58:32 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=uRZEuZB1 X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.134 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793671111; b=0lIcaoEBybNqWJK0DOVEOoix1+qx0apVdMGgdxHv5a3ifhTKW3QUI5FccTELPr4Nq90m PVFVTcho4GwLWSwRzt1gvkGgNVWDs4pfoxX4YUDkrmHHtRuidsU+D68SNSbdOH2Qh1Kxa XvBmN5QwGwPtIJzFmeMuAbybYS0qvHhZeBPCRYYSM41J9Y0MlZ/Sh/uLu4XM+f+Gmiefo IPk7EFF0AefRmZrgjkRO5AJ1BZL25m/cghJa2y177EU+Z1Bih9z6bJ4IZt3aBzPUBe5k3 e+xLTKIKH/KephRbDBxQvlzn4eckpsh6UdZysIJoOqbTXdvZE14kL1UwBIxmEaOioYw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793671111; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=HvlT1XjrX2pqFLgxdO8FZhy56kYrtx0Ju6Likqq4/Is=; b=1XlL1ajt4ooCM96sEdVtIPcXpqZ7Zda2jMfH7rPXvvmlGCKb9H4r6HxtiG2DbOkfKgxQ T556BMZAoRYMobJmgUKapr97u/eRpa6IlPv/RfwIHuT6baJC/S8pWmBCgjx8zgINfSVTq mhb8OFaL9lS4Z5JzOPZHezDZHthUE8qpttCAQe9hKu++/sJY0lEboUyYbpABjv9VgHFUX dbYXtAQDJXALCip/wEGkbjLwmLHjjys37N3TDsPALCkBcRZaM85821svK9j4fanVXha6A 7i7nWCNr4sxeVlqaV9Um0HD/QqmwmdXzDvqNP5J9sMxFStKUHSshNPSTJeFWjDQWXmg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; arc=none smtp.remote-ip=95.215.58.134 X-Received: from mta1.migadu.com (out-134.mta1.migadu.com [95.215.58.134]) (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 40F5F606A326 for <netdev@vger.kernel.org>; Tue, 3 Nov 2026 01:58:29 +0000 (UTC) X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 40F5F606A326 X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: netdev@vger.kernel.org X-DKIM-Signature: a=rsa-sha256; bh=HvlT1XjrX2pqFLgxdO8FZhy56kYrtx0Ju6Likqq4/Is=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1793671108; v=1; x=1794275908; b=uRZEuZB1MIG+JrUSRpHgvgMdk2c68Q9U6xzmblMOr/qBg6NjJznPDDiqjHT9QLEmfwar2v3n 7JcO1hG+c2oycIWr7EgKcKhD0yqkJ/ednaDBOvX3pKSLezw/Vj1plVphB51YGhB68zvNGRG6Fmd gSVFl3JRUETARJpNkcEzjjkA= X-Envelope-To: netdev@vger.kernel.org X-Received: by smtp.migadu.com with ESMTPS id fa320ababef1ed04; Tue, 03 Nov 2026 01:58:28 +0000 X-Mizu-Trace-ID: fa320ababef1ed04 X-Migadu-Flow: FLOW_OUT X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-User-Agent: Mozilla Thunderbird X-Cc: daniel@iogearbox.net, andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com, john.fastabend@gmail.com, jakub@cloudflare.com, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, kuniyu@google.com, willemb@google.com, matttbe@kernel.org, mptcp@lists.linux.dev, mason@kernel.org, josef@toxicpanda.com X-In-Reply-To: <20261102072112.4160195-13-alexei.starovoitov@gmail.com>