Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp251241pxb; Wed, 4 Nov 2020 21:45:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJxozWjoXlICMk/KdicdwyxFPBhLgGEyHrRlBkl56CERrOqYdGljbdKW16o15IDMAkmJewYs X-Received: by 2002:a17:906:383:: with SMTP id b3mr655901eja.351.1604555116500; Wed, 04 Nov 2020 21:45:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604555116; cv=none; d=google.com; s=arc-20160816; b=r+YS6Ylm6AThwrizMYISx3CvW2Oz3/QIUxk1CIgJiraas3uQUUMqwV+SSx3/vKTs+9 uNJYBhpWDwKuEVUCK9AsaSeWh4RTktweOZcGvcivhVIQ9uKISgBez91U0r1GsaiJEEL3 6mQM6NHmKqc1B18QiAuqhedyLwqAQwB7Twy5Kjwx7wwav+BiVpZQ4C4ZEYTP5CbQxQif Em8kck1Cnh0+fg1o2ZlqJMYPYEiZJP0YU9f2NS5gDr7xxvJ4/v1kbShNtKaGYvcHoCn/ HyhHOlPXmXx0Rr/J+uG3hTnzuFts5I9VB+E/yiF6xktkq9gzkvavo3PIIxoXX5JJrU8Y 3DuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :subject:cc:to:sender:from:date:message-id:mime-version :dkim-signature; bh=K8Kl2iHpO5POu3iueaA7vs9t7V/Id+v7k4XyYIiSXvY=; b=hE7824a0nLX6gVDtk6ohUnsPrBqh7L0kq87TFJ6Mj+h1e37NLbHRQsxomreUFA1oFb y73JEofEeRIsflAl5WDy/K0yDwOhPxl/4dUMrVM42XHOQIJ7hZQpkdiSJaxZvjFcx0PS RLlZpS8nYYLykECp7hUlLlUrLC7yvxDIkqhgZhkeGgu5CchxKX5pqTK/fdZz3hOdM3r0 +azIBTROHb/ZvoH7uDsQHVF97kuo52kYAAw8KCS112LjHzP1AGV88HE6KTB9g4p4nt+c LepnNnvM1K+TqF/nzfPtMtYcamtz2vgysV1ol5IhIqF2dqyWs+n2DrmeV/Cw5txR2nfe bNQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=nnJBTOrX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k25si469705ejk.10.2020.11.04.21.44.54; Wed, 04 Nov 2020 21:45:16 -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=@oracle.com header.s=corp-2020-01-29 header.b=nnJBTOrX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730878AbgKEFlI (ORCPT + 99 others); Thu, 5 Nov 2020 00:41:08 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:41144 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726214AbgKEFlH (ORCPT ); Thu, 5 Nov 2020 00:41:07 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0A55SvfB162524; Thu, 5 Nov 2020 05:40:58 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : cc : subject : references : in-reply-to : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=K8Kl2iHpO5POu3iueaA7vs9t7V/Id+v7k4XyYIiSXvY=; b=nnJBTOrXuQKPplubPvStO8yPl1tsO8Li6N9yt3qDJ8zPUJGA0mYNt4vWS2mmjmROIjBS SeTWpM5ri54wsfhRvVWbYke/zpqomFrjqED7YgoQnqpbidhQ+cj2h8q8ceRNCcBnKXTf Tv8QvOtX/pI6JAvbY+tLDmUwZJ+9V25Hwz9YmslWWhxVqESgM7FVF32dsDUeIZY+E1gY LM/F79CZ//WDO1miwPv9JyHvurZL8+jdqf3elfvCrsmqwRK7jYRWaNyZq3pK+qzqT1xA qqIQMKtSsOxJRGyy/bzdRyS14Yq2fSiW+JNZHImHRHLTKcgNfSpAdQlCRSORvaR59eL3 8w== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2120.oracle.com with ESMTP id 34hhw2t3kn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 05 Nov 2020 05:40:58 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0A55UYKg008905; Thu, 5 Nov 2020 05:40:57 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 34hw0m4e8m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 05 Nov 2020 05:40:57 +0000 Received: from abhmp0003.oracle.com (abhmp0003.oracle.com [141.146.116.9]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0A55euWr018275; Thu, 5 Nov 2020 05:40:56 GMT MIME-Version: 1.0 Message-ID: <9df96d73-015c-4de6-96fa-2f315b066909@default> Date: Wed, 4 Nov 2020 21:40:54 -0800 (PST) From: Gulam Mohamed Sender: Gulam Mohamed To: Lee Duncan , Chris Leech , "James E.J. Bottomley" , "Martin K. Petersen" , open-iscsi@googlegroups.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Junxiao Bi Subject: [PATCH] iscsi: Do Not set param when sock is NULL References: <1a8aaa17-b1a3-4d6a-b87a-ff49d61a0d0b@default> In-Reply-To: <1a8aaa17-b1a3-4d6a-b87a-ff49d61a0d0b@default> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.5056.0 (x86)] Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9795 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 adultscore=0 bulkscore=0 mlxscore=0 suspectscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011050041 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9795 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 malwarescore=0 mlxscore=0 suspectscore=0 clxscore=1011 priorityscore=1501 impostorscore=0 spamscore=0 lowpriorityscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011050041 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Description =3D=3D=3D=3D=3D=3D=3D=3D=3D 1. This Kernel panic could be due to a timing issue when there is a race be= tween the sync thread and the initiator was processing of a login response = from the target. The session re-open can be invoked from two places a.=09Sessions sync thread when the iscsid restart b.=09From iscsid through iscsi error handler 2. The session reopen sequence is as follows in user-space (iscsi-initiator= -utils) a.=09Disconnect the connection b.=09Then send the stop connection request to the kernel which re= leases the connection (releases the socket) c.=09Queues the reopen for 2 seconds delay d.=09Once the delay expires, create the TCP connection again by ca= lling the connect() call e.=09Poll for the connection f.=09When poll is successful i.e when the TCP connection is estab= lished, it performs =09i. Creation of session and connection data structures =09ii. Bind the connection to the session. This is the place where we assig= n the sock to tcp_sw_conn->sock =09iii. Sets the parameters like target name, persistent address etc . =09iv. Creates the login pdu =09v. Sends the login pdu to kernel =09vi. Returns to the main loop to process further events. The kernel then = sends the login request over to the target node =09g. Once login response with success is received, it enters into full fea= ture phase and sets the negotiable parameters like max_recv_data_length, ma= x_transmit_length, data_digest etc . 3. While setting the negotiable parameters by calling "iscsi_session_set_ne= g_params()", kernel panicked as sock was NULL What happened here is -------------------------------- 1.=09Before initiator received the login response mentioned in above point = 2.f.v, another reopen request was sent from the error handler/sync session = for the same session, as the initiator utils was in main loop to process fu= rther events (as=20 =09mentioned in point 2.f.vi above).=20 2.=09While processing this reopen, it stopped the connection which released= the socket and queued this connection and at this point of time the login = response was received for the earlier one 3.=09The kernel passed over this response to user-space which then sent the= set_neg_params request to kernel 4.=09As the connection was stopped, the sock was NULL and hence while the k= ernel was processing the set param request from user-space, it panicked Fix ---- 1.=09While setting the set_param in kernel, we need to check if sock is NUL= L 2.=09If the sock is NULL, then return EPERM (operation not permitted) 3.=09Due to this error handler will be invoked in user-space again to recov= er the session Signed-off-by: Gulam Mohamed Reviewed-by: Junxiao Bi --- diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c index df47557a02a3..fd668a194053 100644 --- a/drivers/scsi/iscsi_tcp.c +++ b/drivers/scsi/iscsi_tcp.c @@ -711,6 +711,12 @@ static int iscsi_sw_tcp_conn_set_param(struct iscsi_cl= s_conn *cls_conn, struct iscsi_tcp_conn *tcp_conn =3D conn->dd_data; struct iscsi_sw_tcp_conn *tcp_sw_conn =3D tcp_conn->dd_data; + if (!tcp_sw_conn->sock) { + iscsi_conn_printk(KERN_ERR, conn, + "Cannot set param as sock is NULL\n"); + return -ENOTCONN; + } + switch(param) { case ISCSI_PARAM_HDRDGST_EN: iscsi_set_param(cls_conn, param, buf, buflen); --=20 2.18.4