Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3606443pxb; Mon, 16 Nov 2020 21:12:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5mHhzNOpjisnGigRkGopeSwTBtN62qDUorIGuZEocilTKlEVP8KFTCOEjMx5dFzQ2UL10 X-Received: by 2002:a17:906:4495:: with SMTP id y21mr18434357ejo.209.1605589942470; Mon, 16 Nov 2020 21:12:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605589942; cv=none; d=google.com; s=arc-20160816; b=HUGXNvtj6TZo837atXGyaZ3r3aw/G41FwV5Dzjt64/lnw1DUfhe79NVzIvBfBzzdBC /kdGper/+kb/FTJpVBb2vNQR9E2ogmQl3O1THWUde6REDs+DzhNGGaonofbFQi1+mc8+ wFpSfyzC5XiNG+iNtWYOXRJCykJzHKBAW61PBuhXuuElZ5ecpTmLpoDlNOlj2Mt7qCRq oVLYHlTVy0XnI/ZkdxZrkAyn4fjs+EXGsSIuAbqJ0O8OYHrh2rPQK+MOwwVLyLdkqjuA maAcUCYFmy3ut3C8+mhTtH1GpgjzNVdBH6DSASkmspzgyzBBRXZA7WPYBJ9trq/rgrzE X6tQ== 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=JPFAvW3nwCtBjHj95lKDgrg4Zm+QWmvC+LDlS0/00vw=; b=0a7FH4N/Ox9Mbez1Ohvu7sJgLL0heAC/wPS81TRNks2eMVTnXQGBvFNEbg2rGDBNMC xOXTL5JJHd40JhOeADyr9SLCb0ugJsCRSMOL4JanytxeC3Fu8AkYDAbsB3jg1H7leCxl CrX3hzsVPZ5R9STgsbFrf7AS/sjkO+tOeTuARA7yYi3HFW2vsmPr88uGQWy3eUvai9kq OFdcThlgrOljf0/y4z51tzSX31US8kUjsWC+3tpXN2Rx0C88kerRQX/QIKLlRj7zjVTf jsdR/V1nl8RvB4scd1/Dod8lToaGX28N2b0Shv9oa118tvQIbJgyESfRrmu9P3N0ldEt 3+JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=y31QKlvU; 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 a2si12813081eju.633.2020.11.16.21.11.59; Mon, 16 Nov 2020 21:12:22 -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=y31QKlvU; 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 S1726844AbgKQFJD (ORCPT + 99 others); Tue, 17 Nov 2020 00:09:03 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:55782 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725355AbgKQFJC (ORCPT ); Tue, 17 Nov 2020 00:09:02 -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 0AH543Qe103066; Tue, 17 Nov 2020 05:08:53 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=JPFAvW3nwCtBjHj95lKDgrg4Zm+QWmvC+LDlS0/00vw=; b=y31QKlvUzrn25sVA1aRn/t40CHbjKiqW7XG0rdE9WcCFwV+gncPj5B5G352Z6k704Gn7 V7KvIhFWqtZVl+YzyX4O3P8Gz75JSntv2/O78xfVONnHZy+W7dMqhl2gs8MUi+I/93oe Ye91eElxDmLGy0HoWEp5h3J9ihZLsXxcqlNhBxVU/W2dyyuxGK9hnF/aae6UIOgU3/nZ x2TgnGh8ig7FTIy6nGO1pAa4VHgDu9NYKCcOhPvexzoBzNCUoM8w+hW/EmqJiCJGO2pV xCy4I6PnaQqrnUWU7vmJDmI4qTchVRoEz+1j99rS2DdoVxdl7AbUMqsxDcMfKg2FDFKb iA== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2120.oracle.com with ESMTP id 34t7vn0gqc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 17 Nov 2020 05:08:53 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0AH51Rcc110521; Tue, 17 Nov 2020 05:08:53 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 34ts0qcuhe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 17 Nov 2020 05:08:52 +0000 Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0AH58p0I010793; Tue, 17 Nov 2020 05:08:51 GMT MIME-Version: 1.0 Message-ID: <48883f4d-edfa-4a8d-9d45-aa5225f82e57@default> Date: Mon, 16 Nov 2020 21:08:45 -0800 (PST) From: Gulam Mohamed Sender: Gulam Mohamed To: Lee Duncan , Chris Leech , "James E.J. Bottomley" , Martin Petersen , open-iscsi@googlegroups.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Junxiao Bi Subject: RE: [PATCH] iscsi: Do Not set param when sock is NULL References: <1a8aaa17-b1a3-4d6a-b87a-ff49d61a0d0b@default> <9df96d73-015c-4de6-96fa-2f315b066909@default> In-Reply-To: <9df96d73-015c-4de6-96fa-2f315b066909@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=9807 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 bulkscore=0 suspectscore=0 spamscore=0 malwarescore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011170036 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9807 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=0 malwarescore=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 spamscore=0 adultscore=0 mlxscore=0 priorityscore=1501 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011170036 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Gentle reminder. Regards, Gulam Mohamed. -----Original Message----- From: Gulam Mohamed=20 Sent: Thursday, November 5, 2020 11:11 AM To: Lee Duncan ; Chris Leech ; James E= .J. Bottomley ; Martin K. Petersen ; open-iscsi@googlegroups.com; linux-scsi@vger.kernel.org; linux-ke= rnel@vger.kernel.org Cc: Junxiao Bi Subject: [PATCH] iscsi: Do Not set param when sock is NULL 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 parame= ters by calling "iscsi_session_set_neg_params()", kernel panicked as sock w= as 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 df47= 557a02a3..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); -- 2.18.4