Subject: Re: WARNING in smc_unhash_sk

From: syzbot <[email-masked]>
Date: Tue, 27 Feb 2018 04:38:01 -0800

Hello,

syzbot has tested the proposed patch but the reproducer still triggered  
crash:
WARNING in smc_unhash_sk

IPVS: ftp: loaded support on port[0] = 21
IPVS: ftp: loaded support on port[0] = 21
IPVS: ftp: loaded support on port[0] = 21
IPVS: ftp: loaded support on port[0] = 21
IPVS: ftp: loaded support on port[0] = 21
WARNING: CPU: 0 PID: 4437 at ./include/net/sock.h:639 sk_del_node_init  
include/net/sock.h:639 [inline]
WARNING: CPU: 0 PID: 4437 at ./include/net/sock.h:639  
smc_unhash_sk+0x335/0x450 net/smc/af_smc.c:90
Kernel panic - not syncing: panic_on_warn set ...

CPU: 0 PID: 4437 Comm: syz-executor3 Not tainted 4.16.0-rc2+ #59
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
Google 01/01/2011
Call Trace:
  __dump_stack lib/dump_stack.c:17 [inline]
  dump_stack+0x194/0x24d lib/dump_stack.c:53
  panic+0x1e4/0x41c kernel/panic.c:183
  __warn+0x1dc/0x200 kernel/panic.c:547
  report_bug+0x211/0x2d0 lib/bug.c:184
  fixup_bug.part.11+0x37/0x80 arch/x86/kernel/traps.c:178
  fixup_bug arch/x86/kernel/traps.c:247 [inline]
  do_error_trap+0x2d7/0x3e0 arch/x86/kernel/traps.c:296
  do_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:315
  invalid_op+0x58/0x80 arch/x86/entry/entry_64.S:957
RIP: 0010:sk_del_node_init include/net/sock.h:639 [inline]
RIP: 0010:smc_unhash_sk+0x335/0x450 net/smc/af_smc.c:90
RSP: 0018:ffff8801b95b7198 EFLAGS: 00010293
RAX: ffff8801b8d7a5c0 RBX: 1ffff100372b6e37 RCX: ffffffff85a47785
RDX: 0000000000000000 RSI: dffffc0000000000 RDI: 1ffff100372b6e3b
RBP: ffff8801b95b7280 R08: dffffc0000000000 R09: 0000000000000004
R10: ffff8801b95b7050 R11: 0000000000000005 R12: ffff8801b95b7258
R13: ffffffff87671f00 R14: ffff8801b97c37c0 R15: 1ffff100372b6e3b
  smc_release+0x321/0x580 net/smc/af_smc.c:148
  sock_release+0x8d/0x1e0 net/socket.c:594
  sock_close+0x16/0x20 net/socket.c:1149
  __fput+0x327/0x7e0 fs/file_table.c:209
  ____fput+0x15/0x20 fs/file_table.c:243
  task_work_run+0x199/0x270 kernel/task_work.c:113
  exit_task_work include/linux/task_work.h:22 [inline]
  do_exit+0x9bb/0x1ad0 kernel/exit.c:865
  do_group_exit+0x149/0x400 kernel/exit.c:968
  get_signal+0x73a/0x16d0 kernel/signal.c:2469
  do_signal+0x90/0x1e90 arch/x86/kernel/signal.c:809
  exit_to_usermode_loop+0x258/0x2f0 arch/x86/entry/common.c:162
  prepare_exit_to_usermode arch/x86/entry/common.c:196 [inline]
  syscall_return_slowpath arch/x86/entry/common.c:265 [inline]
  do_syscall_64+0x6e5/0x940 arch/x86/entry/common.c:292
  entry_SYSCALL_64_after_hwframe+0x42/0xb7
RIP: 0033:0x47f4f1
RSP: 002b:0000000000a3ea20 EFLAGS: 00000293 ORIG_RAX: 0000000000000023
RAX: fffffffffffffdfc RBX: 000000000072bea0 RCX: 000000000047f4f1
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000a3ea30
RBP: 000000000072ca20 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000a3ea10 R11: 0000000000000293 R12: 0000000000000059
R13: ffffffffffffffff R14: 0000000000000001 R15: 0000000000000005
Dumping ftrace buffer:
    (ftrace buffer empty)
Kernel Offset: disabled
Rebooting in 86400 seconds..

Tested on net-next commit
3808b51911fe1a2bf8d6f4f2836d4c51aa29a6fd (Tue Feb 27 01:58:25 2018 +0000)
Merge branch '10GbE' of  
git://git.kernel.org/pub/scm/linux/kernel/git/jkirsher/next-queue

compiler: gcc (GCC) 7.1.1 20170620
Patch is attached.
Kernel config is attached.
Raw console output is attached.

--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -1405,8 +1405,10 @@ static int smc_create(struct net *net, struct socket *sock, int protocol,
 	smc->use_fallback = false; /* assume rdma capability first */
 	rc = sock_create_kern(net, PF_INET, SOCK_STREAM,
 			      IPPROTO_TCP, &smc->clcsock);
-	if (rc)
+	if (rc) {
 		sk_common_release(sk);
+		goto out;
+	}
 	smc->sk.sk_sndbuf = max(smc->clcsock->sk->sk_sndbuf, SMC_BUF_MIN_SIZE);
 	smc->sk.sk_rcvbuf = max(smc->clcsock->sk->sk_rcvbuf, SMC_BUF_MIN_SIZE);