From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380511; b=hPtSzuTuyq8T4GDeIMgQXwn+wbVZ8CtkwmCLhgEWUcxWAN9sz+s0iQ4MX+PhBFPLeIeG xmk2aG0as7fsVzJghRCRgDAxPHxcYl5yrHPa9ACsBcJPTqThTjCB4zOCJwozO3Z94+e9O m0tqmGM2FqfLN2LMg8/0UBNNrKIdTeXzlA7xL8oqT3EgltvUgYBszdtzZrewCHAzp/pUC 1ZDV/BbZ8d7WfGRpwyNQQquBKGkGoCbzB3NS7jO2ZBK/WFYVO0KYYzqhdIqT2C/KSsUx3 lEwtNkGyjfQkyIB8MERRZ+CvpbbJx3yFsRKtygkTYtQf3jepKYGeIBBdnFAoPOKY3Ug== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380511; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=5Wc18GV9ifIBG/5Lh1Y4w7C7iJwJuYv1NWJ6ByivhKI=; b=LG4HAPxwSytMYOOpof1tvxkksq7JgmczGCw2AU23MmHarU0yGVBP3LU7Ju5eEHewnYL9 Ep2MYtHA543bCpFcFqsWNrzsrVMExae6UxruPKqTuuB0FUTt4ts8lbd0M6gAeDD+FrGBf 9KR8KqRcLvxyCqUi/OCqB5SjS20x8AtGeEqkZYqKay6y7GvEyVGI93fose6a1N67mAfj3 ookYu82xELVjwhg2ABb0XH6h+Nwbi8C7aJ40RuD7/ei5z+WcK6A4de/BcKBUzX3viMSQk hvuFF+O0WMfPrf/0hL1mEaEhqNevoomV9jxHjFeQZEWNIxMFwYFy3+nRIubyAa/VJ/Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=hdCoFxpi; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3619606A689; Fri, 4 Dec 2026 10:35:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=hdCoFxpi Received: by smtp.kernel.org (Postfix) with ESMTPSA id 521A31F000C2; Fri, 4 Dec 2026 10:35:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380510; bh=5Wc18GV9ifIBG/5Lh1Y4w7C7iJwJuYv1NWJ6ByivhKI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hdCoFxpiqZpgM0T1OWWmKTUo+UsKkz+QpJs5pXaCVkBZy/FkFd1aVZwxqaRdgVZNn MUAjGznDySmH+Gf1N6D62OKGtLSIApWI27wAGKCk31BEywZLkZflh3V4F9oUZkAWvS At/SItqTzdHMHkKDyauWiXaIKW2p00pHl165vrVE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alexei Starovoitov , Sasha Levin Subject: [PATCH 7.3 303/742] bpf, sockmap: Keep the parser and sk_data_ready in sync Date: Fri, 4 Dec 2026 19:02:47 +0900 Message-ID: <20261204100643.085108879@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexei Starovoitov [ Upstream commit b3a433f20f0a247cb2c4664b6e1400253287da63 ] sk_psock_strp_data_ready() takes the psock that the socket has at the call. An update from a program does not wait for the owner of the socket, so that is not always the psock that has set the callback, and it may have no parser. strp_data_ready() dereferences a NULL strp->sk then. Look at SK_PSOCK_RX_STRP_ENABLED, it is set under sk_callback_lock. The event is dropped, as it is when the socket has no psock. A socket can be in a map with a verdict program and not have it, the program was attached after the update. Another map can start the parser then. The delete from the first map restores sk_data_ready and nobody stops the parser: WARNING: net/strparser/strparser.c:451 at strp_done+0xef/0x130 Stop the parser when its callback goes away. The psock can outlive the stop, and a later update must not run strp_init() on works that are still pending. Start the stopped parser again instead. Fixes: 0126240f448d ("bpf: sockmap: Allow update from BPF") Fixes: ef5659280eb1 ("bpf, sockmap: Allow skipping sk_skb parser program") Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261125032938.670542-45-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- net/core/skmsg.c | 12 +++++++++--- net/core/sock_map.c | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/net/core/skmsg.c b/net/core/skmsg.c index df385a5a961e8..9d6cbde8ed1f1 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -1138,7 +1138,9 @@ static void sk_psock_strp_data_ready(struct sock *sk) psock = sk_psock(sk); if (likely(psock)) { read_lock_bh(&sk->sk_callback_lock); - strp_data_ready(&psock->strp); + /* This psock may be not the one that has set the callback */ + if (likely(sk_psock_test_state(psock, SK_PSOCK_RX_STRP_ENABLED))) + strp_data_ready(&psock->strp); read_unlock_bh(&sk->sk_callback_lock); } rcu_read_unlock(); @@ -1146,7 +1148,7 @@ static void sk_psock_strp_data_ready(struct sock *sk) int sk_psock_init_strp(struct sock *sk, struct sk_psock *psock) { - int ret; + int ret = 0; static const struct strp_callbacks cb = { .rcv_msg = sk_psock_strp_read, @@ -1154,7 +1156,11 @@ int sk_psock_init_strp(struct sock *sk, struct sk_psock *psock) .parse_msg = sk_psock_strp_parse, }; - ret = strp_init(&psock->strp, sk, &cb); + /* A stopped parser keeps its works and its skb until strp_done() */ + if (sk_psock_test_state(psock, SK_PSOCK_RX_STRP_ENABLED)) + psock->strp.stopped = 0; + else + ret = strp_init(&psock->strp, sk, &cb); if (!ret) sk_psock_set_state(psock, SK_PSOCK_RX_STRP_ENABLED); diff --git a/net/core/sock_map.c b/net/core/sock_map.c index 20fb605bc1adf..0f58a0786f246 100644 --- a/net/core/sock_map.c +++ b/net/core/sock_map.c @@ -169,7 +169,8 @@ static void sock_map_del_link(struct sock *sk, write_lock_bh(&sk->sk_callback_lock); if (psock->saved_data_ready) { - if (strp_stop) + /* The parser can be from another map, it loses sk_data_ready too */ + if (strp_stop || psock->progs.stream_parser) sk_psock_stop_strp(sk, psock); if (verdict_stop) sk_psock_stop_verdict(sk, psock); -- 2.53.0