From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 332C633F8A4; Sat, 30 May 2026 16:28:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780158492; cv=none; b=I65SBp4s7znq5pFU50A7agLcodAoLcbRyF+U3jM/9sXZZkUW063BfUXD2t7Tm5N6Ek7keC5XlS7wzIPsSqEuzvC2fDEconD3CqRPK6UpcTPjIiVz5v1DmJ+KE4Inm9Z5ZK3wXArNUf9fqY8+b/PioZdtFUTmu0QOgzeT69EXm28= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780158492; c=relaxed/simple; bh=DpSGZyHFkynVNasfI/XyN5XTNY9HAWb2cWxRpaCM37M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V/FoMHnPdG9iQzzE8xZfilRwLLNjP0fNX9zKyVV6IiWKdrD1fOlgdAuKwUH0JJbPIzAK16+QoEA9Poql5RtgkFU9RvLuKLPlV9CvIYPaybAdPy+WLT0xz2faLVRtTkWKdNIP1ddzgX4fdF/empm+/yXrE+N6UOafYNK92MOknmQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JjaA4Lgb; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="JjaA4Lgb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 244971F00893; Sat, 30 May 2026 16:28:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780158491; bh=FHY8KN2DM+Pk+D3QZeRwuTgIyPB03xx8naHE2V6GkDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JjaA4Lgb27C97IYa/HVuq7h/Zf7vdnA0nx3ltBUtdNXMRGAfNpRsHMMnPwUzJBS0C zXig61grHl9AiDQqFptMGgO/BmF5GBW3tt933O6kdWeGNLzxosY8zLjDpdbLcLXEPr PjihnN7x9HhmK+wNJ8tt+JgQkO1WVz88TAhboIDc= 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.1 057/969] can: raw: fix ro->uniq use-after-free in raw_rcv() Date: Sat, 30 May 2026 17:53:01 +0200 Message-ID: <20260530160301.963862424@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260530160300.485627683@linuxfoundation.org> References: <20260530160300.485627683@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.1-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;