Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3151206ybi; Mon, 29 Jul 2019 01:47:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqzj+jhp2O5lSZGAYfFeKE4tRvMk+I5h6br/vBc1eHxfwZ9HLYgPe5Oix/DB6OkAxSrBVsnV X-Received: by 2002:a62:1750:: with SMTP id 77mr35736710pfx.172.1564390066334; Mon, 29 Jul 2019 01:47:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564390066; cv=none; d=google.com; s=arc-20160816; b=OovVkeKkvQ0vuMtXeeoQQKh5j0+j+FP8oRXhFeOaYgGX60I/r6//NxScKRY9VGPX4i P90IDmZ7t7eH5Hp99dN7oreYwxxHizOCw7uDMatxXwKlHV7cmQ5QK6whATE4leyhlkam iW5+mjIzIxhEvsakPOLMAEiNNfQr5hAVlnr8YG6X7owJfqHHp/+dHUjmU9Stk21pgy3Y 2tt+oLIuf4cRGNoxVKALIu4ep6EVpAKiZCj1qHEcYbK6EYv0GkQiaL1nnjhcOv+LxjxL +pP2ToS41BUZJvB5ZlPau0RYk4FnK4aCp9eLQE6iNLRjtzB+oVWBvhK3CxAWsMijmDxE Q3tw== 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=/+k1cCW3hB4jfxvc/1cVEskjGWMvsmOcHLSENoPU7GI=; b=IZMhucCiBajhq9e7ySXYcT+uiGGgQ1w7THo0xfmw/kK7j7IxlO2LKxjtIhwfOe1nle f+Fw17/4fqNntiTwAHRZsg6kGl6TrC2ir8P0v6vxJLwjG+BVjbgm4+vgLk1wHMPgiWWh q5wHz34Br1JJOE45NMfUTroGUYUcji+4PhrO6u1XNtvtjo7rQL0ZCIuqHybGEiNxDCnF P6HIHWn6D0IDYWbkn2GOKvhp78bd8CeXY8lvOBnJDaHdhGxolTQ8rq42dXTL8l74ep3m R45soca0LmmlSS5rKGqfdAhtoB9a63dA43+RHJS+cRjctqXu/Sc+YnPZ/4aowWc4QxxP ZtdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=QgsPjR6+; 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 u21si28722247pgn.290.2019.07.29.01.47.28; Mon, 29 Jul 2019 01:47:46 -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=QgsPjR6+; 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 S1727821AbfG2Io7 (ORCPT + 99 others); Mon, 29 Jul 2019 04:44:59 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:35693 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727109AbfG2Io6 (ORCPT ); Mon, 29 Jul 2019 04:44:58 -0400 Received: by mail-pl1-f196.google.com with SMTP id w24so27236379plp.2; Mon, 29 Jul 2019 01:44:58 -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=/+k1cCW3hB4jfxvc/1cVEskjGWMvsmOcHLSENoPU7GI=; b=QgsPjR6+2ydKYWsEeSqNt36OdA3VK9LDM1mcbMdX+VeR9RlzAB+rXipZBmLJslJbsa vMxQgFbpOsNmF0weY6+7gMWlI23LQF3u5avrnO5ZqFizWofBu8EkUh46zTz9HSa27Ow1 SuMynRhriZQhm2/9OWniLJIWyR0jNrQBk/nd9cj+/DIFqgcMLw/ZZbhA5V9sjXAMlv4m Gt7cy7gLcAFFCuLj1okXKOfaJ88ACvERBS9x9vB/Z/nM8ZVQBTWtmnPs1oCr5bxrA0+Z Tk5QLMNegGTf5X2MxJ49oC0HGhoOtPmiKeZfLfqyZnkV8klD1p4sFfFe6S4LGJkcgNiO xyIw== 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=/+k1cCW3hB4jfxvc/1cVEskjGWMvsmOcHLSENoPU7GI=; b=I1dUICZd5gsrbv1qqwbUDQAY2zO5cLjcNOdyJRqQyy1adrKE5wqGQm5r4Tcsv6R52B fObljxWdE427Pg+haWpwC4muYbzwqxM2Hx/H5VcI8SyeEppWILpuB3RYO0YDniYzDNfG jTgCNV5dQdHPhGBSmXweAlY+5AHqDWdFkqbt/vSNrGK4mQlDigQvKdjHvaapuBWSRyTv oCFzmUbrRe28OU98Xzp3yaemisd0sMe6MzN+GNL+GIrE7MoDOpyNx7x+24DkBdo7XMq3 2li8WkPANhPuY8Xwm9o7r5q9E2DN3gduR5iUgDIf9eNvI8x6AGL9ONdaAyL9oFFuoQ57 BlQw== X-Gm-Message-State: APjAAAVwrYuzjpNMcN34ujU6rahr+89MgBDV+dRJKf05Oi680tmS9tFt F6XzSPip0t2TpenAAMIsXjw= X-Received: by 2002:a17:902:6a85:: with SMTP id n5mr101625957plk.73.1564389898217; Mon, 29 Jul 2019 01:44:58 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:4:72:808::3ca]) by smtp.gmail.com with ESMTPSA id r18sm59992863pfg.77.2019.07.29.01.44.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 Jul 2019 01:44:57 -0700 (PDT) From: Jia-Ju Bai To: jejb@linux.ibm.com, martin.petersen@oracle.com Cc: qla2xxx-upstream@qlogic.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] scsi: qla2xxx: Fix possible null-pointer dereferences in qla2x00_alloc_fcport() Date: Mon, 29 Jul 2019 16:44:51 +0800 Message-Id: <20190729084451.29290-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 In qla2x00_alloc_fcport(), fcport is assigned to NULL in the error handling code on line 4880: fcport = NULL; Then fcport is used on lines 4883-4886: INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn); INIT_WORK(&fcport->reg_work, qla_register_fcport_fn); INIT_LIST_HEAD(&fcport->gnl_entry); INIT_LIST_HEAD(&fcport->list); Thus, possible null-pointer dereferences may occur. To fix these bugs, qla2x00_alloc_fcport() directly returns NULL in the error handling code. These bugs are found by a static analysis tool STCheck written by us. Signed-off-by: Jia-Ju Bai --- drivers/scsi/qla2xxx/qla_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c index 4059655639d9..da83034d4759 100644 --- a/drivers/scsi/qla2xxx/qla_init.c +++ b/drivers/scsi/qla2xxx/qla_init.c @@ -4877,7 +4877,7 @@ qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) ql_log(ql_log_warn, vha, 0xd049, "Failed to allocate ct_sns request.\n"); kfree(fcport); - fcport = NULL; + return NULL; } INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn); -- 2.17.0