Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3866020pxb; Tue, 17 Nov 2020 05:44:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJzpCQZN+g3Si+eXnQrD6OHm0fRyFIV5SLCJ0SGBtrzzPJPQkP3adOobtig2VBrvD58Go63N X-Received: by 2002:a17:906:5fd6:: with SMTP id k22mr1005507ejv.333.1605620682867; Tue, 17 Nov 2020 05:44:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605620682; cv=none; d=google.com; s=arc-20160816; b=Q8uUoNwu6fhANLUN1SNtqQ35VA4il8fjo3qi4CzwZ1kW6FQ7VIGyeVBIg4iasLD+3U ahM2/iSWOgUlFCXnRTWeUdjKTtBcaPEpL7YE6sWfZAN5DggHRjbCQpEIYEWImMBoCCMP lqWLzH9I+X4ursm83Nt61Pd4h594a+Rqggr9xrvBGs+QzwCCSqlfurK5Hzh1EDmVK2mC t7DgAqBuMZLB3bi6qa+LanSl/A7/tytwhbVQsjr0Ea+ufX0nnH3IYE4CC6uffFKUVtzf R3OjE3czuIwUbeG0dVpAPW/j+gtWIRefQuxnbCUTK9QZTIEzY9C5wuetsYEuc6QiROwx 174A== 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=EMSh7c7KhyMzACHgI37LsyS0iChIpmm/ez28ZfVgO5s=; b=Yz8gT+NKaekxGdyWjYxQuOlARlt9ArogW7uOff50udc6rWkM7FZoErK8Xr6/yb6oMW diyE/W09WLhotHY7rEFl3TqdJ/Au5X3HKfepB3iPQvENUFTCU9ktGFaED2A42hF0CRON 4J4uitgqxyh54G2HQBj1pW00m+FeGKbGK4JZxtCk2SXhOIN810TNUfzRe/qtWDAevjvx yg3UCg3uLtJyXkGRTt6SGQe8wQ2w79QSn7dZ8s1NS4Jh+pYrGgJcpMvS20anB1XIWSfk cHbqxrATpLSdmyQfLzuypQbk3yY9mAbY2ptnPGiWHDoueCwKE3hC2X195lMRuzsZ9osc t/kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HX4EDhKB; 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 g17si9493818edu.507.2020.11.17.05.44.20; Tue, 17 Nov 2020 05:44:42 -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=HX4EDhKB; 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 S1733277AbgKQNl7 (ORCPT + 99 others); Tue, 17 Nov 2020 08:41:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:54186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732699AbgKQNlq (ORCPT ); Tue, 17 Nov 2020 08:41:46 -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 8DF4E20870; Tue, 17 Nov 2020 13:41:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605620504; bh=ODf+Z5znTF54N2XSzy4qnHCfoUpUh/ML/m467xVflwM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HX4EDhKB5TcC/+Ysnygx0EN5T/8Sx/qKPmEADBwLvMBwWtxyhsz9Uf8/VyTIcstrX N52TKCU3DlgPkyxokyFDpRm2yNPP1TSAn2IO9mEGXh8HF5RiMeDJv6MUIyL7Ft+RyZ E+e0GLKl79dU7LAT8Tdq6KB0rcY1Ze4ZlpGoUqbM= 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 5.9 241/255] net/af_iucv: fix null pointer dereference on shutdown Date: Tue, 17 Nov 2020 14:06:21 +0100 Message-Id: <20201117122150.668598740@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122138.925150709@linuxfoundation.org> References: <20201117122138.925150709@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 @@ -1434,7 +1434,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;