Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3849405pxb; Tue, 17 Nov 2020 05:20:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJy8yNmy8aG+zipYkeEVzgXC6rPvSY714Vie6JBeJKm220XQXivcvBbbGf4/S2c7Tpq4quab X-Received: by 2002:a17:906:4705:: with SMTP id y5mr18817041ejq.112.1605619235974; Tue, 17 Nov 2020 05:20:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605619235; cv=none; d=google.com; s=arc-20160816; b=e0O7DqgACNi58YJxiYsBXq+3rojLXWpbs9kCnZj9rQLx3ZQhePUH1qgBwHl9MXZbqV VCx8U8y+ctkyKyc4Ia/MlkXqOAnONA89J5kkFR4qTHpWDOAi/FZfosVg5vSkwro6Qx9l A7BCErOj5qqzzJQgKmxHBYGHohYHmw/xiEUd3S9t4HvX1mnPSod+6cwQDInedR2VRPz8 /5M0H6wSjidRT4KUkN6+tLke0cxpZnkQ/Kspug73UO+kCOi00TPW2maZMLHVjiTjJsZD EVgHyJMuydzzt7trKxcnsB6veApEPXuLrtx9L8CzCRva3okv7TADvJBVAssvnzZ52W8d 9UDA== 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=iQ8KJp1io7POp3VDO216FsDegATCK0YdwFED4mSs3uM=; b=tVsOtVLS6wlSp7kSndObM2s40VmJHei95g1do1HGaVJJcJTygmrqDymg19jTwlLOF4 dVvDsa1lqHmPYOAwzm87+9ym+QYJ0sOQx5ReJtlW6GBEOyvVTY5YiQBcyHf/ug5HUeuf WQhIRfSkvgwCfDuLqzNNE86H0HLXNhCWyybJCv7aTiJ0FA3W81xlEHVdpz9VXBtOlSsS U92Eqj7fhuKRSka7U4ruZQoOupA1WPVs1DXrVIqU3USA4VQhV1dZTO2t/uAGzgDQ2uMW 47tHQr8nIjTB/wJ9pQ29uYm19O/vHV4xeuyx8oazwsPG0jM0EL6GWa6vtdRDjKdyhkt4 rUrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=01ReNduN; 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 z4si15832646edi.561.2020.11.17.05.20.13; Tue, 17 Nov 2020 05:20:35 -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=01ReNduN; 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 S1730233AbgKQNPr (ORCPT + 99 others); Tue, 17 Nov 2020 08:15:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:47132 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730216AbgKQNPk (ORCPT ); Tue, 17 Nov 2020 08:15:40 -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 C212C246BB; Tue, 17 Nov 2020 13:15:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605618939; bh=yFtHC+uO5knMhaFCfRNp1ahOpUZvlwEh9PLy1vPIGAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=01ReNduNgOqURnx+UaRuOrwpSMJgM4NafvmE0ihWfy6k0qFvEEtd6R9NR1HJF9Qdv zcELQea+C5ffDZLMQCvvWG8DxEL+GexbyNmWD2VUoaj+F8M3yQ1kEhApynP3YzRKwX X4CoiHemu288OA+BpslNQFuV8zUNNTyHOHI4rAOg= 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.14 59/85] net/af_iucv: fix null pointer dereference on shutdown Date: Tue, 17 Nov 2020 14:05:28 +0100 Message-Id: <20201117122113.926875822@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122111.018425544@linuxfoundation.org> References: <20201117122111.018425544@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 @@ -1552,7 +1552,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;