Received: by 10.213.65.68 with SMTP id h4csp419834imn; Tue, 13 Mar 2018 08:30:08 -0700 (PDT) X-Google-Smtp-Source: AG47ELtUW52OdmWyTtO0x3o+TrLUbpQCpAVteu5nv6xjx5TlaF9Gz8vM/7lF9C7SoBnFGO8II/m5 X-Received: by 2002:a17:902:8697:: with SMTP id g23-v6mr925082plo.393.1520955008767; Tue, 13 Mar 2018 08:30:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520955008; cv=none; d=google.com; s=arc-20160816; b=LGST8qTmSAWNRRdtm/pV6MJZRR64e+y6RlgHyuxUL/ozKG6QhPnDetec38zPM18QQ1 gB+qPO5AaJojNifpeYh1R2M83t8XOwRo34LRyucEyZtzcYNraYFc5IDHNtfh84uAwZLw l6lgHo9pY6awnk2N3VZ//Wp4vEbcCd7+w9aOB6kkAg+wiDRGBuVK9OqxdGShNppc23hA Fket76BarYqXSGCEyeISad+AU60nNZfyvTCa+jFbxoJvbqHIU4TCXGuT1o3XPA5qayCa 1J+Ura51oizVu2yN0f/Hm9eD3k3GJrTdcrp4tjdExQC7IaCNFGvEWhKwIu4t2w/jSanI lUpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=8s18KT+N/Kz324u14CuQdl8Mk0AVHxFutCEDcNinUqg=; b=Qs1o52FmT0yKU70HlC58PgTT44Ua188vWcjCWXLgsN22kRe8mKeRG6Lr4aGRQcwnwi 5424u+FtlXAdE0B1YM1n0cNB5TCCD3riOkqQDR3BQ5tFYsHnLAlm8YpPniESgEkjXyjw 73j4tdsZhwNOM3Fz3Eb8jQHblCKIAT/hWb/boHZoCkUYhvb2CcUCQ7cBCH3VwquSpJJy SRuIHSgBCu2Bt5Dr+kolVS0LZgqyJNGy7ITQP409lH6LWeMZjckio3yuPoU4YCWYAfSJ ESdv+5FTdMoj6f/m+VhCGfY1Pr5EgfAdBVkntrISN29+xC1CGVyLvNjXGsfEon5nhxRK /i9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b3si257000pga.503.2018.03.13.08.29.46; Tue, 13 Mar 2018 08:30:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752143AbeCMP2K (ORCPT + 99 others); Tue, 13 Mar 2018 11:28:10 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:57412 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932673AbeCMP2H (ORCPT ); Tue, 13 Mar 2018 11:28:07 -0400 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1A33C11CD; Tue, 13 Mar 2018 15:28:05 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Davide Caratti , Ursula Braun , "David S. Miller" Subject: [PATCH 4.15 007/146] net/smc: fix NULL pointer dereference on sock_create_kern() error path Date: Tue, 13 Mar 2018 16:22:54 +0100 Message-Id: <20180313152321.194503396@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180313152320.439085687@linuxfoundation.org> References: <20180313152320.439085687@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Davide Caratti commit a5dcb73b96a9d21431048bdaac02d9e96f386da3 upstream. when sock_create_kern(..., a) returns an error, 'a' might not be a valid pointer, so it shouldn't be dereferenced to read a->sk->sk_sndbuf and and a->sk->sk_rcvbuf; not doing that caused the following crash: general protection fault: 0000 [#1] SMP KASAN Dumping ftrace buffer: (ftrace buffer empty) Modules linked in: CPU: 0 PID: 4254 Comm: syzkaller919713 Not tainted 4.16.0-rc1+ #18 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 RIP: 0010:smc_create+0x14e/0x300 net/smc/af_smc.c:1410 RSP: 0018:ffff8801b06afbc8 EFLAGS: 00010202 RAX: dffffc0000000000 RBX: ffff8801b63457c0 RCX: ffffffff85a3e746 RDX: 0000000000000004 RSI: 00000000ffffffff RDI: 0000000000000020 RBP: ffff8801b06afbf0 R08: 00000000000007c0 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000000 R12: 0000000000000000 R13: ffff8801b6345c08 R14: 00000000ffffffe9 R15: ffffffff8695ced0 FS: 0000000001afb880(0000) GS:ffff8801db200000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000020000040 CR3: 00000001b0721004 CR4: 00000000001606f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: __sock_create+0x4d4/0x850 net/socket.c:1285 sock_create net/socket.c:1325 [inline] SYSC_socketpair net/socket.c:1409 [inline] SyS_socketpair+0x1c0/0x6f0 net/socket.c:1366 do_syscall_64+0x282/0x940 arch/x86/entry/common.c:287 entry_SYSCALL_64_after_hwframe+0x26/0x9b RIP: 0033:0x4404b9 RSP: 002b:00007fff44ab6908 EFLAGS: 00000246 ORIG_RAX: 0000000000000035 RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00000000004404b9 RDX: 0000000000000000 RSI: 0000000000000001 RDI: 000000000000002b RBP: 00007fff44ab6910 R08: 0000000000000002 R09: 00007fff44003031 R10: 0000000020000040 R11: 0000000000000246 R12: ffffffffffffffff R13: 0000000000000006 R14: 0000000000000000 R15: 0000000000000000 Code: 48 c1 ea 03 80 3c 02 00 0f 85 b3 01 00 00 4c 8b a3 48 04 00 00 48 b8 00 00 00 00 00 fc ff df 49 8d 7c 24 20 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 82 01 00 00 4d 8b 7c 24 20 48 b8 00 00 00 00 RIP: smc_create+0x14e/0x300 net/smc/af_smc.c:1410 RSP: ffff8801b06afbc8 Fixes: cd6851f30386 smc: remote memory buffers (RMBs) Reported-and-tested-by: syzbot+aa0227369be2dcc26ebe@syzkaller.appspotmail.com Signed-off-by: Davide Caratti Signed-off-by: Ursula Braun Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/smc/af_smc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -1369,8 +1369,10 @@ static int smc_create(struct net *net, s 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);