Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3851987pxb; Tue, 17 Nov 2020 05:24:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJzi8fGvfI9Jl/sgICH9j/IFK19JWZ07MnCNL9ej2Ap+2YSdUzldSHZQY0WRcBip6PaSmTZ1 X-Received: by 2002:a17:906:f05:: with SMTP id z5mr20001783eji.8.1605619465253; Tue, 17 Nov 2020 05:24:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605619465; cv=none; d=google.com; s=arc-20160816; b=0RCO5ZfjZuMYgFm5vaeYF4inRi6KVYCh731KY82xkG620ikWTAPp84Sh3icMAKNySp 0UAJaNKh/rSg0z61zsh1CWyzy/7CnAyrUp5Et+OMoB09gKI7Q0MtxqIBDORZ+5ijXuQ4 +oiIrs2pXfx7dk8TlNik7b2WH6/OphkZEXUdq2gvRrCiCTQl1uHA9G97rwE/I5tS5mM0 Kpn3Vc0l090N2HHTp1Ar8usny1rVHJglJjlnBz3EX3lASlN0PAYn2U07gDH0Q29LH2tW TONf16DD1/oq8aDjcRsXuygjsZAk8KKB8p5Nt+cakgF6+dn0ebXcjqKPWVCC7Ffc8ZoA ATqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CZPfSgsYVYlzsEqBl9mMTsGGymejRPBLBXraFDRFEYM=; b=r1oApjFkDl9MgDWMKAYSzpKG64ihgNAxiQD/LmCY1OR6XRAjW+WoGkFn3wzS5newkH LalgZTUV3hdfE285Dk5Ffb145yo2ehjxvYMKcRnSLglhW11t22BkZkmuwMzSV6hoLsH1 4HMccWCkYZVfrD2aZFj04V+FQNAR2P+old2BVNTBMC4DshOYFIP6eu7Yf+iTU89DrplC FFl0d6uM/NU1CU6gDRjPNNSY2hBOmVKZpqX7N7hBZ9LsQB2hbBCNdG43KiMUoncYOomS 4u3zGymCCHZ40EIWHe6ri805VeUHdRAr9V0PDzUhCCXY1U338ajo6wbPLivNpbRepXrO VCaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=h5+oikQQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v10si13474659ejg.0.2020.11.17.05.24.02; Tue, 17 Nov 2020 05:24:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=h5+oikQQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730860AbgKQNVZ (ORCPT + 99 others); Tue, 17 Nov 2020 08:21:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:54888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729652AbgKQNVR (ORCPT ); Tue, 17 Nov 2020 08:21:17 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 648C62463D; Tue, 17 Nov 2020 13:21:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605619277; bh=gcG2k5DQTOg52gdBoyUjQrcO/jdVWTkLEeSIDdECy2M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h5+oikQQVGZyD1pcG+mFTQvz4uCmRaUujs2qSCnmcOm7UHLRM7X6fx94vi+MhaEYv 52OBginVdRPetM3WC67lgGOWILeXKn9IPGo2fbsHT4OEEvrFwJqfImYC/bgCTHdF6v M3e9z+PJGv21TApmjyURd/vVlHtZwIOjWjMNQjp4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vasily Gorbik , Ursula Braun , Julian Wiedmann , Jakub Kicinski Subject: [PATCH 4.19 088/101] net/af_iucv: fix null pointer dereference on shutdown Date: Tue, 17 Nov 2020 14:05:55 +0100 Message-Id: <20201117122117.418042206@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122113.128215851@linuxfoundation.org> References: <20201117122113.128215851@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ursula Braun [ Upstream commit 4031eeafa71eaf22ae40a15606a134ae86345daf ] syzbot reported the following KASAN finding: BUG: KASAN: nullptr-dereference in iucv_send_ctrl+0x390/0x3f0 net/iucv/af_iucv.c:385 Read of size 2 at addr 000000000000021e by task syz-executor907/519 CPU: 0 PID: 519 Comm: syz-executor907 Not tainted 5.9.0-syzkaller-07043-gbcf9877ad213 #0 Hardware name: IBM 3906 M04 701 (KVM/Linux) Call Trace: [<00000000c576af60>] unwind_start arch/s390/include/asm/unwind.h:65 [inline] [<00000000c576af60>] show_stack+0x180/0x228 arch/s390/kernel/dumpstack.c:135 [<00000000c9dcd1f8>] __dump_stack lib/dump_stack.c:77 [inline] [<00000000c9dcd1f8>] dump_stack+0x268/0x2f0 lib/dump_stack.c:118 [<00000000c5fed016>] print_address_description.constprop.0+0x5e/0x218 mm/kasan/report.c:383 [<00000000c5fec82a>] __kasan_report mm/kasan/report.c:517 [inline] [<00000000c5fec82a>] kasan_report+0x11a/0x168 mm/kasan/report.c:534 [<00000000c98b5b60>] iucv_send_ctrl+0x390/0x3f0 net/iucv/af_iucv.c:385 [<00000000c98b6262>] iucv_sock_shutdown+0x44a/0x4c0 net/iucv/af_iucv.c:1457 [<00000000c89d3a54>] __sys_shutdown+0x12c/0x1c8 net/socket.c:2204 [<00000000c89d3b70>] __do_sys_shutdown net/socket.c:2212 [inline] [<00000000c89d3b70>] __s390x_sys_shutdown+0x38/0x48 net/socket.c:2210 [<00000000c9e36eac>] system_call+0xe0/0x28c arch/s390/kernel/entry.S:415 There is nothing to shutdown if a connection has never been established. Besides that iucv->hs_dev is not yet initialized if a socket is in IUCV_OPEN state and iucv->path is not yet initialized if socket is in IUCV_BOUND state. So, just skip the shutdown calls for a socket in these states. Fixes: eac3731bd04c ("[S390]: Add AF_IUCV socket support") Fixes: 82492a355fac ("af_iucv: add shutdown for HS transport") Reviewed-by: Vasily Gorbik Signed-off-by: Ursula Braun [jwi: correct one Fixes tag] Signed-off-by: Julian Wiedmann Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/iucv/af_iucv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/net/iucv/af_iucv.c +++ b/net/iucv/af_iucv.c @@ -1571,7 +1571,8 @@ static int iucv_sock_shutdown(struct soc break; } - if (how == SEND_SHUTDOWN || how == SHUTDOWN_MASK) { + if ((how == SEND_SHUTDOWN || how == SHUTDOWN_MASK) && + sk->sk_state == IUCV_CONNECTED) { if (iucv->transport == AF_IUCV_TRANS_IUCV) { txmsg.class = 0; txmsg.tag = 0;