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 666E533E377; Mon, 20 Apr 2026 16:02:29 +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=1776700949; cv=none; b=Sc43CEzXpLGsZi48DreInBKUxfjEDXLFxMsWfbluB3Ct8mFEIX8W2S0iOOQNOznpYeXfAV2lgvL+LaKKDPtI29+0q1G8ks+PonSLXDOzkc4zKV4Y0cUbLqexP6a+qvoMFy+68azQPNQrCOU5snCm1NfUaUQQ6Ywo8pt7aBNLefI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776700949; c=relaxed/simple; bh=zK3Tz81udVBlxWtppuBf2LgK7VWROEKFfG6vdjBN2oo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=evRnbhIDYY0HOk2D24MbUpAfH3nfdTnJEp2k3dfcKb+tth45fYlajSX/8/ewT15xjZFb3sWyoSWM2LNpC0Gbl4LvkdvLeDV/R2H8FvPfBFiLYxV1AWMEIfP+wl8NX8BC2lvDDITfX40YXf/rKGa3+hRQiF+DECFhomRuYwwzsoU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=wP0040SJ; 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="wP0040SJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EED2AC19425; Mon, 20 Apr 2026 16:02:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1776700949; bh=zK3Tz81udVBlxWtppuBf2LgK7VWROEKFfG6vdjBN2oo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wP0040SJ9MhbZFDFzjywJv8VmcnKCf8Rd7q0kaeLtXSC4s2wmSRVNX2uD/PljC2ed hoMh66TWrIb2WU4WH+KQ0Un+dn+LjW0SwIbVkeJdOw6bDMU5BJvpTXwVRSbTSi5ZAY sra9qSyP4EDdVtUuCsgW0PZeeL1Gg4PH8fMWotrI= 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.18 123/198] can: raw: fix ro->uniq use-after-free in raw_rcv() Date: Mon, 20 Apr 2026 17:41:42 +0200 Message-ID: <20260420153940.033979995@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260420153935.605963767@linuxfoundation.org> References: <20260420153935.605963767@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-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 @@ -360,6 +360,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); @@ -386,6 +394,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); @@ -435,7 +445,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;