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=1795032356; b=jmaaKyjiwqjKxAat2uTSlcNeQFrxNf0OOCFIk8vWg6dI7BPw92P03M0imybndj0/hXN4 qBthjwG2WGOzsrq2IJOx9GSsmikJ2eTvfg7ZWQP4ixiF+exMwXEpDT+9vgaELUr5rzZaH 1x0zZBtDa9ia7nyCsR2o8gDy493jQ7j7H7SA2s+pYBmRpCBpne+asCrseYQC+dRN88IZX HRjNCPSwz96eoq3E8FnY5yDeR+ktDoUJX4dCqS7OeurYEMsLxkTxApfyjznBXFKVKzr3r YpjSAZXC81EiTt/poXb8JvWI57NyayvFfMILx298Giqy/bATQV2kRUQMkGxq0q9cAMw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795032356; 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=C+fTAATYPo7OR7FByRTLkR+nz9tIvvJ2GsjntqaC8Uc=; b=KP5YvV/IsmTePLzsASBcwaGBxGgIGBu+CfUHShlfWk/Svn9s3WQ4DCoezHzdxoPl6xo7 TIcXD0C3+KtXOk2cybQs8xBbx6tN5CWw7Iyam9i2urIDOLfclBpNGrQqzrWgDE5EZmI3k 3EQxRlMHJ56NpqaGnto+0IWwXMJuCyNMnSUerfHsyial3NxKfjf6v5ceCkpXY4hbE4y44 ccxePngw3shKBRvn/+JK0coZqGD9y7+b3ofA+2Vuei+a91qdhXyTFh5mR7r5Z5LJny6cH 5H6lwgmizNYsnFgPzFW8XInLKqq7CXZ5LM9wTW8pCKYul2Ua972I7woi17AjlVXi8EA== 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=GrAJgoae; 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 6F688606A337; Wed, 18 Nov 2026 20:05:56 +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=GrAJgoae Received: by smtp.kernel.org (Postfix) with ESMTPSA id C277C1F000C4; Wed, 18 Nov 2026 20:05:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795032356; bh=C+fTAATYPo7OR7FByRTLkR+nz9tIvvJ2GsjntqaC8Uc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GrAJgoaePX3JdBKaQ5FPsHG/YHC7flXKnmD32ulj7mSYm2N9IIFfngn1Zyy6pspkZ swXMObluyzU0sDMBHB/uBpRJbDSoFD/trxQxm+EEvKK/sR/AmJguprI64UawAkNcdM 83A44WCSQFOP1JMJ8Ktyll1SmM3Zvpyd7cnQzClE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Josef Bacik , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.12 1384/1756] bpf: Use the socket of a sk_lookup test run under RCU Date: Wed, 18 Nov 2026 15:58:31 +0100 Message-ID: <20261118150104.277588068@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150007.957976754@linuxfoundation.org> References: <20261118150007.957976754@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik [ Upstream commit 6aff0129f327b159c86a54e6bea64a027630ff6b ] bpf_sk_lookup_assign() accepts only sockets which are freed by RCU, and takes no reference. bpf_prog_test_run_sk_lookup() looks at sk_reuseport of the selected socket and generates its cookie, which is a write, behind bpf_test_timer_leave(), that is outside of the RCU read side critical section in which the program ran. If the socket is closed in the meantime it may be gone. Do both before the section ends. Fixes: 7c32e8f8bc33 ("bpf: Add PROG_TEST_RUN support for sk_lookup programs") Signed-off-by: Josef Bacik Signed-off-by: Alexei Starovoitov Link: https://patch.msgid.link/20261017230950.802052-7-alexei.starovoitov@gmail.com Signed-off-by: Sasha Levin --- net/bpf/test_run.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c index 44cbd850a4092..a287e8fb8b89f 100644 --- a/net/bpf/test_run.c +++ b/net/bpf/test_run.c @@ -1613,20 +1613,19 @@ int bpf_prog_test_run_sk_lookup(struct bpf_prog *prog, const union bpf_attr *kat ctx.selected_sk = NULL; retval = BPF_PROG_SK_LOOKUP_RUN_ARRAY(progs, ctx, bpf_prog_run); } while (bpf_test_timer_continue(&t, 1, repeat, &ret, &duration)); - bpf_test_timer_leave(&t); - - if (ret < 0) - goto out; + /* Nothing but RCU keeps the selected socket */ user_ctx->cookie = 0; - if (ctx.selected_sk) { - if (ctx.selected_sk->sk_reuseport && !ctx.no_reuseport) { + if (!ret && ctx.selected_sk) { + if (ctx.selected_sk->sk_reuseport && !ctx.no_reuseport) ret = -EOPNOTSUPP; - goto out; - } - - user_ctx->cookie = sock_gen_cookie(ctx.selected_sk); + else + user_ctx->cookie = sock_gen_cookie(ctx.selected_sk); } + bpf_test_timer_leave(&t); + + if (ret < 0) + goto out; ret = bpf_test_finish(kattr, uattr, NULL, NULL, 0, 0, retval, duration); if (!ret) -- 2.53.0