Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1511991imm; Fri, 14 Sep 2018 20:42:31 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYlMGoJNcv+2NVNu0XgJ2Ttfoq0Urqw0B6ZYq2vNxnW9nqEdW9lyOicBrK1msCUnIokLnD1 X-Received: by 2002:a62:c60e:: with SMTP id m14-v6mr15438055pfg.40.1536982951817; Fri, 14 Sep 2018 20:42:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536982951; cv=none; d=google.com; s=arc-20160816; b=iM8vxZPhx5L80pF1cANByUmqU7zTU/szNkH3279F/kaQqBiDJnontCCAeYST48iTRe WnmEFNsb7mLAvtjRnhd+ECnbDYZchWpSNpVTWPE9M+lWHY0rBoerFqqcTkZhKArNOeFf GK996biyhNAjPWkU2hqs0yGTZgCKgMCE7bmKXh3YaE/uOkDnKVyoHFtghLbPSmw1Zxg8 F+s7o8SwMFnGVAp2gPRCTA/LntJD0v/0nFmgFXxshOD6sOeObCnDCYwVQOCE9BklP28v WZ8YDHFLkEeqy4D67T5DbOSxJEQxH3wduEKdohtq7379mPH01BP8n8wyOMVQ0wlaTFau +FkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=Vfr12jueS7IwKDDThU1niCwYcDuAznByJMLt5etNfo8=; b=IRo5iMRgP5yeGBhN3u1ikai3FcqxQOqvwgxVhdlJKnkqeiESS9XPHXi5UEEix2bbRq D2yTeDK+xK8VZNWshNCzPLwH6/VQkRymWsg444Xyu0bloBDgV4u9nfHtnH3TdR7Nab4e TYScnECluN+rhmk6X/HGDf1pqwvKCYvNuSxnSz+K6aJg/46CrHtc6SwkGPiDmc3DXYHy GxdxnZQTUSjA6PnPhIq5QOTlRu7DtvzoDIb2Z8w77KZCHKfcPoh+V/RRpd8fNI+7AxkD 1gaDIbLq+1V/utFXroxxbdg8LLqrCd9QNbMAnA81I5E8hL1OLOivOLp40NO72HCHjPaA I1/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BbIOi1rs; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l2-v6si9277375pfb.69.2018.09.14.20.42.02; Fri, 14 Sep 2018 20:42:31 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=BbIOi1rs; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727795AbeIOI7M (ORCPT + 99 others); Sat, 15 Sep 2018 04:59:12 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:43049 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725907AbeIOI7M (ORCPT ); Sat, 15 Sep 2018 04:59:12 -0400 Received: by mail-pl1-f193.google.com with SMTP id f66-v6so5015505plb.10; Fri, 14 Sep 2018 20:41:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Vfr12jueS7IwKDDThU1niCwYcDuAznByJMLt5etNfo8=; b=BbIOi1rsP7IkJO8zT51b63Bj7XlEqbe0cIes+kvODE+zIX20UYpQFkLp2yEHGIv6Dz /ZfKIcWyCmvFJVOZdrg5r5VSDYkVL4p8ngpqNOnSyTXQIZx3Z4a02G4RqepR7C6ZxQWl xKYjgoIXbu+WkIdAkopQXiE6poDKmDDb7vH07RwdJeimHKv6GI4ZN0BZogV/EwKANYvE XXd3WHLMUGVXgmE21O/ktKzvOR3ppf0DYDWhvpY+1YMkxv6N37HQ+X5Bn3lgAh8hVUdF Q80T0lBupYlKRP0rh5IFHAqfgTWuLuJjwNbCjbHEW/exx13vLONtZee11DMeD1y7Zk+e rgvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Vfr12jueS7IwKDDThU1niCwYcDuAznByJMLt5etNfo8=; b=JYwnzGSzazyOABz8jiZjANiy6d0rabq/VYUzNuhuhJp16ZWHy90IfOxq0uRrEIxApw Lk8ZNuWsxYPL/iiap068yI75u9EX9dXir7KT9deGQjKqOZKmyTTgY6fBrQFp3iohMvzj QuHRsx+pIh7ISN7M5pdxnO/nJSF2sIpORDV5UyY2C3IJS/uCn9DkzvUJIiF9fyzA4V8s n2YeJqmrqKsC8/KDhyrkID5QHM8+o0YmX6l9zY9BZkwHJGGV2Fcr0TA8BKF2Qydzmqg/ yMKavgp0tbD+lju9ho40mqqp+h5YTo4LrfMzLwtxaSNKBKeKBpUeWzCDJEWm6vqthqeB 3YNw== X-Gm-Message-State: APzg51BWIOewTUCUkOsEx442lO+zxlPYPqN6zp0c4rNrK28kIPdLWnpB BPEDw0DycHTbcfMTW4Petr6BY+ej X-Received: by 2002:a17:902:8d8c:: with SMTP id v12-v6mr14559921plo.94.1536982907076; Fri, 14 Sep 2018 20:41:47 -0700 (PDT) Received: from localhost.localdomain ([2402:f000:1:4414:947c:62c0:a59c:7c99]) by smtp.gmail.com with ESMTPSA id y69-v6sm11949912pfd.36.2018.09.14.20.41.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Sep 2018 20:41:46 -0700 (PDT) From: Jia-Ju Bai To: james.smart@broadcom.com, dick.kennedy@broadcom.com, jejb@linux.vnet.ibm.com, martin.petersen@oracle.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] scsi: lpfc: Fix three sleep-in-atomic-context bugs in lpfc_prep_els_iocb() Date: Sat, 15 Sep 2018 11:41:27 +0800 Message-Id: <20180915034127.6597-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The driver may sleep with holding a spinlock. The function call paths (from bottom to top) in Linux-4.17 are: [FUNC] kmalloc(GFP_KERNEL) drivers/scsi/lpfc/lpfc_els.c, 205: kmalloc in lpfc_prep_els_iocb drivers/scsi/lpfc/lpfc_els.c, 2010: lpfc_prep_els_iocb in lpfc_issue_els_plogi drivers/scsi/lpfc/lpfc_els.c, 4914: lpfc_issue_els_plogi in lpfc_els_disc_plogi drivers/scsi/lpfc/lpfc_els.c, 1486: lpfc_els_disc_plogi in lpfc_more_plogi drivers/scsi/lpfc/lpfc_els.c, 3123: lpfc_more_plogi in lpfc_cancel_retry_delay_tmo drivers/scsi/lpfc/lpfc_nportdisc.c, 279: lpfc_cancel_retry_delay_tmo in lpfc_els_abort drivers/scsi/lpfc/lpfc_nportdisc.c, 259: spin_lock_irq in lpfc_els_abort [FUNC] kmalloc(GFP_KERNEL) drivers/scsi/lpfc/lpfc_els.c, 226: kmalloc in lpfc_prep_els_iocb drivers/scsi/lpfc/lpfc_els.c, 2010: lpfc_prep_els_iocb in lpfc_issue_els_plogi drivers/scsi/lpfc/lpfc_els.c, 4914: lpfc_issue_els_plogi in lpfc_els_disc_plogi drivers/scsi/lpfc/lpfc_els.c, 1486: lpfc_els_disc_plogi in lpfc_more_plogi drivers/scsi/lpfc/lpfc_els.c, 3123: lpfc_more_plogi in lpfc_cancel_retry_delay_tmo drivers/scsi/lpfc/lpfc_nportdisc.c, 279: lpfc_cancel_retry_delay_tmo in lpfc_els_abort drivers/scsi/lpfc/lpfc_nportdisc.c, 259: spin_lock_irq in lpfc_els_abort [FUNC] kmalloc(GFP_KERNEL) drivers/scsi/lpfc/lpfc_els.c, 215: kmalloc in lpfc_prep_els_iocb drivers/scsi/lpfc/lpfc_els.c, 2010: lpfc_prep_els_iocb in lpfc_issue_els_plogi drivers/scsi/lpfc/lpfc_els.c, 4914: lpfc_issue_els_plogi in lpfc_els_disc_plogi drivers/scsi/lpfc/lpfc_els.c, 1486: lpfc_els_disc_plogi in lpfc_more_plogi drivers/scsi/lpfc/lpfc_els.c, 3123: lpfc_more_plogi in lpfc_cancel_retry_delay_tmo drivers/scsi/lpfc/lpfc_nportdisc.c, 279: lpfc_cancel_retry_delay_tmo in lpfc_els_abort drivers/scsi/lpfc/lpfc_nportdisc.c, 259: spin_lock_irq in lpfc_els_abort To fix these bugs, GFP_KERNEL is replaced with GFP_ATOMIC. These bugs are found by my static analysis tool DSAC. Signed-off-by: Jia-Ju Bai --- drivers/scsi/lpfc/lpfc_els.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c index 4dda969e947c..e21b360eb764 100644 --- a/drivers/scsi/lpfc/lpfc_els.c +++ b/drivers/scsi/lpfc/lpfc_els.c @@ -202,7 +202,7 @@ lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, /* fill in BDEs for command */ /* Allocate buffer for command payload */ - pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); + pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_ATOMIC); if (pcmd) pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys); if (!pcmd || !pcmd->virt) @@ -212,7 +212,7 @@ lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, /* Allocate buffer for response payload */ if (expectRsp) { - prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); + prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_ATOMIC); if (prsp) prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &prsp->phys); @@ -223,7 +223,7 @@ lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp, prsp = NULL; /* Allocate buffer for Buffer ptr list */ - pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL); + pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_ATOMIC); if (pbuflist) pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pbuflist->phys); -- 2.17.0