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 1F1443D6690; Fri, 24 Apr 2026 13:36:25 +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=1777037786; cv=none; b=jIUyr7O1hioAFHHHSJzfYQa6BJTAaxDeSDuC0B/uWN4FoXVNLLg7TSAKBqOyFERT6k9lG61NHU1uD2vrSmtVe097gn3OB96zbAteIbTYT+NW0VGNzjiPsGpJXs7BDsAAGYchzsR1uX3SvBFORL44vq3YdazNTjxj6s/m7p4E7HQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777037786; c=relaxed/simple; bh=M1GJlYSRT9YzZ5cVT0EWMv6yf8jwNi/o3dTduYbytys=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FxgCUAKmMLqfYk6FQag7+Ii/sp7NH2MxBVU61J5LDaNBKmo5QguCxgNCS388Cgz2eO9SsENEMjH2bLwF9G6/KiesPeJj1BQ1bmqcOqUSX9qpU8dj+HQGIjfMIfbamrxzG2LG9zFolnbzSCzq0T77ltIxcfkeSpCU0Wa+AdESUfo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=qGYI7wKi; 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="qGYI7wKi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA7E6C19425; Fri, 24 Apr 2026 13:36:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1777037785; bh=M1GJlYSRT9YzZ5cVT0EWMv6yf8jwNi/o3dTduYbytys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qGYI7wKi4L6JcsPRdUxZSVqo+ZJ4D/BnaGkaHfaZqNvh1mc3aQd1bSWW4A7aiABpN XoAEm2e7AVgEvOyvHa+FqCPzW9hYZnlm2ZBfdFZmRPBCj36+I6BjBJRpX0li5hESB6 dK/77975KX/3azsdr9aJiEiXfjK39CV/sTj4VCIY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Samuel Page , Oliver Hartkopp , Marc Kleine-Budde Subject: [PATCH 6.6 068/166] can: raw: fix ro->uniq use-after-free in raw_rcv() Date: Fri, 24 Apr 2026 15:29:42 +0200 Message-ID: <20260424132547.020236621@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260424132532.812258529@linuxfoundation.org> References: <20260424132532.812258529@linuxfoundation.org> User-Agent: quilt/0.69 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: Samuel Page commit a535a9217ca3f2fccedaafb2fddb4c48f27d36dc upstream. raw_release() unregisters raw CAN receive filters via can_rx_unregister(), but receiver deletion is deferred with call_rcu(). This leaves a window where raw_rcv() may still be running in an RCU read-side critical section after raw_release() frees ro->uniq, leading to a use-after-free of the percpu uniq storage. Move free_percpu(ro->uniq) out of raw_release() and into a raw-specific socket destructor. can_rx_unregister() takes an extra reference to the socket and only drops it from the RCU callback, so freeing uniq from sk_destruct ensures the percpu area is not released until the relevant callbacks have drained. Fixes: 514ac99c64b2 ("can: fix multiple delivery of a single CAN frame for overlapping CAN filters") Cc: stable@vger.kernel.org # v4.1+ Assisted-by: Bynario AI Signed-off-by: Samuel Page Link: https://patch.msgid.link/26ec626d-cae7-4418-9782-7198864d070c@bynar.io Acked-by: Oliver Hartkopp [mkl: applied manually] Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- net/can/raw.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) --- a/net/can/raw.c +++ b/net/can/raw.c @@ -336,6 +336,14 @@ static int raw_notifier(struct notifier_ return NOTIFY_DONE; } +static void raw_sock_destruct(struct sock *sk) +{ + struct raw_sock *ro = raw_sk(sk); + + free_percpu(ro->uniq); + can_sock_destruct(sk); +} + static int raw_init(struct sock *sk) { struct raw_sock *ro = raw_sk(sk); @@ -362,6 +370,8 @@ static int raw_init(struct sock *sk) if (unlikely(!ro->uniq)) return -ENOMEM; + sk->sk_destruct = raw_sock_destruct; + /* set notifier */ spin_lock(&raw_notifier_lock); list_add_tail(&ro->notifier, &raw_notifier_list); @@ -409,7 +419,6 @@ static int raw_release(struct socket *so ro->bound = 0; ro->dev = NULL; ro->count = 0; - free_percpu(ro->uniq); sock_orphan(sk); sock->sk = NULL;