From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B527A17993; Tue, 12 Aug 2025 18:03:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755021819; cv=none; b=TrpfnnGKKUUxlXoqPf+dVmjQKf0BVwDm5MvjLB5+9O0/0SZpKzfa1Djtnl3fbtPZhnuT2CZUA4zSl3RphNVpVHn7Bpaaozp19rQWKwvjZjNyhzMpYdBBi/Qhr/ysJGWN46HZJDO4a7X6AonWIa8I/a+5abp/OAMd8vwrILKJyRo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755021819; c=relaxed/simple; bh=V1F3mDbZneFN/pjrP+Su1Txb/WXrqERt2gKKeCBeqIY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gUxsxW8jhaMkG3F6JUqQzlWvwkWRMV992Spl/kA6Oggjd8QM7sdSu+GXvCddzmUS1M5lV9udELe9Lfm/RwnlVWTb+GpgdwpL+xerCUHuC1YcPNaExnUMsoElTlmsOpAPMjUA+0wqwk2+f9L1jY1+1Wr1ZxFjXay8r98GKdU5Gp4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=DkuphTCD; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="DkuphTCD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22E89C4CEF0; Tue, 12 Aug 2025 18:03:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1755021819; bh=V1F3mDbZneFN/pjrP+Su1Txb/WXrqERt2gKKeCBeqIY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DkuphTCD0gNW3dC/OYgV7R3laVEdZk0aM3iPF/RYeJhFEFTE930SKkuuMD39pXVeL ke++FBqcAIUWIMoCIU4SfDmlGgBeojh1lahVaWhbBEC0Aa7nbjZAdRgfq6/mRbviEX /Dz4/ATi9W+PcSKHjCLfnBgNtl9fV8AA9vkskE/U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Quang Le , Willem de Bruijn , Jakub Kicinski Subject: [PATCH 6.6 235/262] net/packet: fix a race in packet_set_ring() and packet_notifier() Date: Tue, 12 Aug 2025 19:30:23 +0200 Message-ID: <20250812173003.166147511@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250812172952.959106058@linuxfoundation.org> References: <20250812172952.959106058@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Quang Le commit 01d3c8417b9c1b884a8a981a3b886da556512f36 upstream. When packet_set_ring() releases po->bind_lock, another thread can run packet_notifier() and process an NETDEV_UP event. This race and the fix are both similar to that of commit 15fe076edea7 ("net/packet: fix a race in packet_bind() and packet_notifier()"). There too the packet_notifier NETDEV_UP event managed to run while a po->bind_lock critical section had to be temporarily released. And the fix was similarly to temporarily set po->num to zero to keep the socket unhooked until the lock is retaken. The po->bind_lock in packet_set_ring and packet_notifier precede the introduction of git history. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Signed-off-by: Quang Le Signed-off-by: Willem de Bruijn Link: https://patch.msgid.link/20250801175423.2970334-1-willemdebruijn.kernel@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/packet/af_packet.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -4566,10 +4566,10 @@ static int packet_set_ring(struct sock * spin_lock(&po->bind_lock); was_running = packet_sock_flag(po, PACKET_SOCK_RUNNING); num = po->num; - if (was_running) { - WRITE_ONCE(po->num, 0); + WRITE_ONCE(po->num, 0); + if (was_running) __unregister_prot_hook(sk, false); - } + spin_unlock(&po->bind_lock); synchronize_net(); @@ -4601,10 +4601,10 @@ static int packet_set_ring(struct sock * mutex_unlock(&po->pg_vec_lock); spin_lock(&po->bind_lock); - if (was_running) { - WRITE_ONCE(po->num, num); + WRITE_ONCE(po->num, num); + if (was_running) register_prot_hook(sk); - } + spin_unlock(&po->bind_lock); if (pg_vec && (po->tp_version > TPACKET_V2)) { /* Because we don't support block-based V3 on tx-ring */