Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5388606imm; Tue, 12 Jun 2018 07:10:32 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLWGhb86rNo0Y/3PbxF5u8ZSfbDQV516B0VrkUP1UmT8YUywvaQWplSSDkGu2+o+QXY7NFk X-Received: by 2002:a17:902:bc44:: with SMTP id t4-v6mr592247plz.139.1528812632506; Tue, 12 Jun 2018 07:10:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528812632; cv=none; d=google.com; s=arc-20160816; b=wVy0rooVb0UL3K+kxL2Ah3IgcoqP5ROua7DSngW479kGGgTf2LAUeK26hB/0gBakjM /zlw0NkLb7/bp020FFsVooVW+h4R6uRoe7uTyqw3e/RF6v64Em2JKCUtla9ySEZEuxLI w/C2jDasizvsJzkOeADWPPCMz2aJsBSMeOLrSkB1jTFU2/4AA8yJPVbNbOrKIRAwkZbH KqUf/wCHFPJUu17xsnrwa9kAYdEHaNb2me7hAhRIZa1QmHC6Fp41SlONnfpqfYzFaVRQ IAojwz7wYTAT/XuEXKea10y466bxPpvwLV18FAEEOaSMj25VDl9fEcjsSw7BupZnnaYY Wxog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:cc:to:from:subject :arc-authentication-results; bh=MVG/I2heFNVq0jV1aZOVDQv6Eh5ubVpb68tlQEWY4tk=; b=V6RlvB4qgDPNnAQPfpkMFaU4glAqHMvS3OK0fMlWkumTJEweOudgaABwsc7tdCAAf9 15KGbfG/Or0Km1HDwxNjNmdmmWyf8DmAtuR87ZvzYtzBBNO5rmyBrbPvF5Nh3inVG/J3 Z9xRP8EmzVtuyLhETfPEbYXiSd0YpkDXlo9KEub4CZDdB3YDhMpRs0LF2HQLdA4jB69b KfKQxioWnOQPk8A3Te+ukmITKS9QYDUkk4edug+d8qKILMGe5GP3oW+R69yML3Yd6o58 pjIkB3zKNtfG90dGmBiCBXIVCaRU9m1H4hTH3vwU/s8pvMEDLYi3Jox+Tz4MmNL1pfmk yXMA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t69-v6si209402pgd.55.2018.06.12.07.10.10; Tue, 12 Jun 2018 07:10:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934030AbeFLOJI (ORCPT + 99 others); Tue, 12 Jun 2018 10:09:08 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:58314 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934130AbeFLOIx (ORCPT ); Tue, 12 Jun 2018 10:08:53 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w5CDwlFR033920 for ; Tue, 12 Jun 2018 10:08:53 -0400 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 2jje8awcvt-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 12 Jun 2018 10:08:53 -0400 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 12 Jun 2018 08:08:52 -0600 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 12 Jun 2018 08:08:49 -0600 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w5CE8msm42532996 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 12 Jun 2018 07:08:48 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C3EF6BE056; Tue, 12 Jun 2018 08:08:48 -0600 (MDT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B3AE5BE051; Tue, 12 Jun 2018 08:08:47 -0600 (MDT) Received: from jarvis.ext.hansenpartnership.com (unknown [9.85.159.203]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTPS; Tue, 12 Jun 2018 08:08:47 -0600 (MDT) Subject: Re: [PATCH] scsi: qla4xxx: add error handling for try_module_get From: James Bottomley To: Zhouyang Jia Cc: QLogic-Storage-Upstream@qlogic.com, "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Date: Tue, 12 Jun 2018 07:08:45 -0700 In-Reply-To: <1528778910-42113-1-git-send-email-jiazhouyang09@gmail.com> References: <1528778910-42113-1-git-send-email-jiazhouyang09@gmail.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.22.6 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 18061214-0020-0000-0000-00000E2B2111 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00009175; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000265; SDB=6.01045907; UDB=6.00535611; IPR=6.00824885; MB=3.00021602; MTD=3.00000008; XFM=3.00000015; UTC=2018-06-12 14:08:51 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18061214-0021-0000-0000-000061E7CE3E Message-Id: <1528812525.3171.1.camel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-06-12_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1805220000 definitions=main-1806120160 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2018-06-12 at 12:48 +0800, Zhouyang Jia wrote: > When try_module_get fails, the lack of error-handling code may > cause unexpected results. > > This patch adds error-handling code after calling try_module_get. > > Signed-off-by: Zhouyang Jia > --- >  drivers/scsi/qla4xxx/ql4_os.c | 9 +++++++-- >  1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/drivers/scsi/qla4xxx/ql4_os.c > b/drivers/scsi/qla4xxx/ql4_os.c > index 0e13349..6b677ab 100644 > --- a/drivers/scsi/qla4xxx/ql4_os.c > +++ b/drivers/scsi/qla4xxx/ql4_os.c > @@ -7687,7 +7687,10 @@ static int qla4xxx_sysfs_ddb_logout_sid(struct > iscsi_cls_session *cls_sess) >    * to be seamless without actually destroying the >    * session >    **/ > - try_module_get(qla4xxx_iscsi_transport.owner); > + if (!try_module_get(qla4xxx_iscsi_transport.owner)) > + ql4_printk(KERN_WARNING, ha, > + "%s: cannot get module.\n", __func__); > + This isn't error handling at all. If try_module_get() fails it means you're about to get the text segment freed from underneath you if the code can be executed concurrently with the module_exit function. The comment implies that qla4xxx operates with a zero module use count even when there are logged in sessions, so module_exit can race with logout (or indeed any other userspace initiated function). This means that the entire module reference counting of qla4xxx looks to be racy and wrong. Can we get a description of what the expected theoretical model is so we can validate (or invalidate) this theory? James