From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793213623; b=ewzXju/2XaeUsjxleGYF00cWsXkkeXtrJUc61Pks7NZt7TphrguQAkFCEaU1SQ24U06L qN8ECDFB08DEUgKxe9NiSobW33PJkcQR4PUvXkcdiwxQRIvRWPkXBxyulc1sglGGJt4um fCHy4LV6begbQ2iBIfEganZXlkMGFTzocluTZcCRaZNXmaLM8LUnK0GpCLRL4Xb9XK3RC XtvFjV8lmbdmT8kW/7lQsiCfTIgbrfYzZUzViuVmeGuCAma7GgKNlOHN7TZoHzhcNzRVo RkS1/X6XS9jfMSGoG/PAckfnz6I5gEyMjvVB3YxMkHBKNMInsYlrTNKxx8B/owccUeg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793213623; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=fKMSB4GUJZD8+lLNzDNylae+Vz5nVlhp4iMi26Zpdcs=; b=NJTfE/UEelLXcHDp1ori1YB3RIMl1pxaT5SpBK2NrcGLLs5bNiv3Jbu3KmUXy+SBznFo FZJteSfISxicMrRYRoXQnCg5mgAQjtVT15F5sADbgBU/fukJzYfTs74BxESsTP8AU6m9l Bb9vSq5hOG4D7dHxTnCmhun10Ek8wyGgPcYpPNcnHZVb0dXadRtHCxM8VaG4l3AwgxXYX O7v8Ek2+zzpiR2pMjT0YaJam+fhbM+/vYckYkVQRvgp4rFr/Z+J55flWAgc+fIgwlQ1QV VGT1xnOuDSDlD4ggY+afuGrA44fu+q/UvFKNySTp49Pu7zbI/nV4i/cW6Vt4+ClTPpg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=kyYGN0fF; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CC9E606A31A; Wed, 28 Oct 2026 18:53:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=kyYGN0fF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D5121F01825; Wed, 28 Oct 2026 18:53:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1793213622; bh=fKMSB4GUJZD8+lLNzDNylae+Vz5nVlhp4iMi26Zpdcs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kyYGN0fFpesj4qzDSASM2f8fvMhQeg9eFgoDk5WwiruhBcWNCiUo6Nmim4qwMt8MV gprdHo+d0n7Y8VI6QNeipAGbViCxq5aVE/jKxBJxUY1nhOO31vBJerEpHiN1zN6ftU iRrmnk1OULB/yo3vWxcZvvAtFCiGuZjDxvfgPhes= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+7e1e1bdb852961150198@syzkaller.appspotmail.com, Kuniyuki Iwashima , Tony Lu , "David S. Miller" , Sasha Levin Subject: [PATCH 6.1 0569/1887] smc: Fix use-after-free in tcp_write_timer_handler(). Date: Wed, 28 Oct 2026 17:44:25 +0100 Message-ID: <20261028170512.349981984@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261028170459.200466217@linuxfoundation.org> References: <20261028170459.200466217@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kuniyuki Iwashima [ Upstream commit 9744d2bf19762703704ecba885b7ac282c02eacf ] With Eric's ref tracker, syzbot finally found a repro for use-after-free in tcp_write_timer_handler() by kernel TCP sockets. [0] If SMC creates a kernel socket in __smc_create(), the kernel socket is supposed to be freed in smc_clcsock_release() by calling sock_release() when we close() the parent SMC socket. However, at the end of smc_clcsock_release(), the kernel socket's sk_state might not be TCP_CLOSE. This means that we have not called inet_csk_destroy_sock() in __tcp_close() and have not stopped the TCP timers. The kernel socket's TCP timers can be fired later, so we need to hold a refcnt for net as we do for MPTCP subflows in mptcp_subflow_create_socket(). [0]: leaked reference. sk_alloc (./include/net/net_namespace.h:335 net/core/sock.c:2108) inet_create (net/ipv4/af_inet.c:319 net/ipv4/af_inet.c:244) __sock_create (net/socket.c:1546) smc_create (net/smc/af_smc.c:3269 net/smc/af_smc.c:3284) __sock_create (net/socket.c:1546) __sys_socket (net/socket.c:1634 net/socket.c:1618 net/socket.c:1661) __x64_sys_socket (net/socket.c:1672) do_syscall_64 (arch/x86/entry/common.c:50 arch/x86/entry/common.c:80) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:120) ================================================================== BUG: KASAN: slab-use-after-free in tcp_write_timer_handler (net/ipv4/tcp_timer.c:378 net/ipv4/tcp_timer.c:624 net/ipv4/tcp_timer.c:594) Read of size 1 at addr ffff888052b65e0d by task syzrepro/18091 CPU: 0 PID: 18091 Comm: syzrepro Tainted: G W 6.3.0-rc4-01174-gb5d54eb5899a #7 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.0-1.amzn2022.0.1 04/01/2014 Call Trace: dump_stack_lvl (lib/dump_stack.c:107) print_report (mm/kasan/report.c:320 mm/kasan/report.c:430) kasan_report (mm/kasan/report.c:538) tcp_write_timer_handler (net/ipv4/tcp_timer.c:378 net/ipv4/tcp_timer.c:624 net/ipv4/tcp_timer.c:594) tcp_write_timer (./include/linux/spinlock.h:390 net/ipv4/tcp_timer.c:643) call_timer_fn (./arch/x86/include/asm/jump_label.h:27 ./include/linux/jump_label.h:207 ./include/trace/events/timer.h:127 kernel/time/timer.c:1701) __run_timers.part.0 (kernel/time/timer.c:1752 kernel/time/timer.c:2022) run_timer_softirq (kernel/time/timer.c:2037) __do_softirq (./arch/x86/include/asm/jump_label.h:27 ./include/linux/jump_label.h:207 ./include/trace/events/irq.h:142 kernel/softirq.c:572) __irq_exit_rcu (kernel/softirq.c:445 kernel/softirq.c:650) irq_exit_rcu (kernel/softirq.c:664) sysvec_apic_timer_interrupt (arch/x86/kernel/apic/apic.c:1107 (discriminator 14)) Fixes: ac7138746e14 ("smc: establish new socket family") Reported-by: syzbot+7e1e1bdb852961150198@syzkaller.appspotmail.com Link: https://lore.kernel.org/netdev/000000000000a3f51805f8bcc43a@google.com/ Signed-off-by: Kuniyuki Iwashima Reviewed-by: Tony Lu Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/smc/af_smc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index 9e142f49a8102..35cf30486916e 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -3315,6 +3315,16 @@ static int __smc_create(struct net *net, struct socket *sock, int protocol, sk_common_release(sk); goto out; } + + /* smc_clcsock_release() does not wait smc->clcsock->sk's + * destruction; its sk_state might not be TCP_CLOSE after + * smc->sk is close()d, and TCP timers can be fired later, + * which need net ref. + */ + sk = smc->clcsock->sk; + sk->sk_net_refcnt = 1; + get_net_track(net, &sk->ns_tracker, GFP_KERNEL); + sock_inuse_add(net, 1); } else { smc->clcsock = clcsock; } -- 2.53.0