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 3BAA2425CD5; Tue, 31 Mar 2026 16:53:44 +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=1774976024; cv=none; b=ECN862MPlOGszwXDvAVV5yI/addBORLD/VeCxLt4TJkgUpUGCGmOuBJFR2o/UKWiF3/N3s+8ia51qxnuT9A5qYedlmj1SvnBq752jyV1IMVtDNawFeyPpGt3fh5QZRkR4zwJF8cJ6m2bV6ZrTKr7nWhAsWOiLu+nDSKhJFCZhP8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774976024; c=relaxed/simple; bh=YSILM1EPFu8z6gw4i7Isss1UR5RKewRgqsxV4mivtYg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MTxSGAc5wuHmQMvJjB6HYRYLyardPxThSdNTILBznZdGiLldJfgZhQy2N0Jhewotri9u+P+YmYjnjKLuJR/PZ9TsceMgxEzFjidCBvZ8xaUqpg8gnVol1BSTYWbFG9or8Kri3/2ijkvvrm3ne1fdqm3Bnd80RoE4xJGxCFMB09M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=X8mw86We; 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="X8mw86We" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6D40C19423; Tue, 31 Mar 2026 16:53:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774976024; bh=YSILM1EPFu8z6gw4i7Isss1UR5RKewRgqsxV4mivtYg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X8mw86We8JoraaOIHdsZrSu+AoJo7CJgrMjP+PirnJuBsxn98BXypVMu/Ta/BsUAa d2hFsYjpWtXaUUflzOJ0XTC3KSSFKzU+sqIXcNMhBZFCORl/6+FhHRr8U6fQrvs3Xr Rn8L8U+6ePFqiqa+dwLOdTAJWjOCfxja9RNxa1Yk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ali Norouzi , Oliver Hartkopp , Marc Kleine-Budde Subject: [PATCH 6.12 145/244] can: isotp: fix tx.buf use-after-free in isotp_sendmsg() Date: Tue, 31 Mar 2026 18:21:35 +0200 Message-ID: <20260331161747.121775430@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260331161741.651718120@linuxfoundation.org> References: <20260331161741.651718120@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.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Oliver Hartkopp commit 424e95d62110cdbc8fd12b40918f37e408e35a92 upstream. isotp_sendmsg() uses only cmpxchg() on so->tx.state to serialize access to so->tx.buf. isotp_release() waits for ISOTP_IDLE via wait_event_interruptible() and then calls kfree(so->tx.buf). If a signal interrupts the wait_event_interruptible() inside close() while tx.state is ISOTP_SENDING, the loop exits early and release proceeds to force ISOTP_SHUTDOWN and continues to kfree(so->tx.buf) while sendmsg may still be reading so->tx.buf for the final CAN frame in isotp_fill_dataframe(). The so->tx.buf can be allocated once when the standard tx.buf length needs to be extended. Move the kfree() of this potentially extended tx.buf to sk_destruct time when either isotp_sendmsg() and isotp_release() are done. Fixes: 96d1c81e6a04 ("can: isotp: add module parameter for maximum pdu size") Cc: stable@vger.kernel.org Reported-by: Ali Norouzi Co-developed-by: Ali Norouzi Signed-off-by: Ali Norouzi Signed-off-by: Oliver Hartkopp Link: https://patch.msgid.link/20260319-fix-can-gw-and-can-isotp-v2-2-c45d52c6d2d8@pengutronix.de Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- net/can/isotp.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) --- a/net/can/isotp.c +++ b/net/can/isotp.c @@ -1229,12 +1229,6 @@ static int isotp_release(struct socket * so->ifindex = 0; so->bound = 0; - if (so->rx.buf != so->rx.sbuf) - kfree(so->rx.buf); - - if (so->tx.buf != so->tx.sbuf) - kfree(so->tx.buf); - sock_orphan(sk); sock->sk = NULL; @@ -1602,6 +1596,21 @@ static int isotp_notifier(struct notifie return NOTIFY_DONE; } +static void isotp_sock_destruct(struct sock *sk) +{ + struct isotp_sock *so = isotp_sk(sk); + + /* do the standard CAN sock destruct work */ + can_sock_destruct(sk); + + /* free potential extended PDU buffers */ + if (so->rx.buf != so->rx.sbuf) + kfree(so->rx.buf); + + if (so->tx.buf != so->tx.sbuf) + kfree(so->tx.buf); +} + static int isotp_init(struct sock *sk) { struct isotp_sock *so = isotp_sk(sk); @@ -1648,6 +1657,9 @@ static int isotp_init(struct sock *sk) list_add_tail(&so->notifier, &isotp_notifier_list); spin_unlock(&isotp_notifier_lock); + /* re-assign default can_sock_destruct() reference */ + sk->sk_destruct = isotp_sock_destruct; + return 0; }