Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2434185lqz; Tue, 2 Apr 2024 18:40:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUCt61riEzSCFqU6jIUm2biNCrsbdLNX9t1fjuuTiuKA4tRhGM8J1rYdlZgYx/dG7yhh1J4V2tONP2GLIC8z40r8ad9rkrOuHNjyokDcg== X-Google-Smtp-Source: AGHT+IGfFJ96GA31bn9++toFliibKrPhHMAeTBuqrGn9Wu/Xk+L/A2bZPvg6qi443ON6jAG1Wdkw X-Received: by 2002:a17:903:249:b0:1e0:c5e6:c5af with SMTP id j9-20020a170903024900b001e0c5e6c5afmr19233671plh.55.1712108427395; Tue, 02 Apr 2024 18:40:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712108427; cv=pass; d=google.com; s=arc-20160816; b=TyFYuZtr9PHitMZRGhCTnDHxJQnoGMEkqrQxgQyWMKudME9s6yePrSF/D7h01LTeX0 T80Cn6Oar5C9k8oIlWwO9WnPMZD28p5NYgYFDBpFGmZW+GigpOViaaAGeerIANI2roXO 4jYNkhDW4SfXhdgSbr4rTHQM4YYb2ygcP2a7LNDJ3QmWaBh7RoI/Oj9CcxXQNWEyGbS5 +7ThuLH+SGmjhtLhhAfT4qx+noaZ+SCZqsiX8H+Pb1Jo3ibFWqS1gRDiJOQ8be/hlYvS yfdrz5GuDUNB6scHd2y9k4vTJ1OCT5livvLBjbQtxJMfziuCeoPncsOGqjQXgExP9iq3 HXmA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=Fh/SNg739z3tPcMMVWuLhLjyN3VYUDkGO69sFSfgsFE=; fh=CgTSbDxfClwWQKfMsa8xj52EAPZPgd3YClHZcTljkf8=; b=N4pe1x+/ODMna1UiupqN4u3pjrEzYSpeZBME/ajUQNXqy1ColDFNnUKWg1YAQSp7KQ Pj/fdUyeFVEZokZryiw2rUe7Cvk5SFgkR1mD8PflWwo8vIpjq1cLbrMQLcigCHWAwaL0 plCX0EzwDm/WqsLZu6HDgdrkezjQyvL5P7bG51/r92ao2rYoxsExNQWQDd3kvugGJ302 7CwO9CPRF5Uy+QbHe4Mty8qpfMEjjyG8LuviWHHP8Q4GDcO00qfU6iFFLo+nBsHmFyDl JyIZaQbSKYxviaAbyRdL/AzbUygt4wgBtOeXYE/Y8rY7BesgWCu7mIuDa92Ert4VYQ5O Sxug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ONo16Ut1; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-128940-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128940-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bg9-20020a1709028e8900b001dddcb9aaacsi11503191plb.622.2024.04.02.18.40.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 18:40:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-128940-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ONo16Ut1; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-128940-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128940-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 9428F283820 for ; Wed, 3 Apr 2024 01:40:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B7D2815ACB; Wed, 3 Apr 2024 01:40:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ONo16Ut1" Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92331D29B; Wed, 3 Apr 2024 01:40:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.67 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712108417; cv=none; b=T+6P2Hrywf11wHtaZ/TI40aPFkbXCGaX/RXkEsZlgUTQTP2li3uycMF7IobygT11Z70r2LTcv0Z83aWxiSsrrkbeE0c/nK5WaQeYDl+T9W3WLV08KKSq6P3G1hvxCIdgxChGVfgx2FsvkHjSO9Bt5YwfaKuuopbtGGJs00E4Jj4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712108417; c=relaxed/simple; bh=+R0L3fbUAwMuP4zU+FqvteBWJzn7D8l7WzQcKHfHy7M=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=dNkNS92SBj3Wh2Y+ATL2lgHmS750H8UEfr24afzqsMWesfIo0LiXSyoAVE6vNVU8yMQmIJKtoS6d02eyjhNezvWRxNIonMBlj/SDNuPPI9Un+i/+OpTPT5IVxosCG8U9y+2fyiOvavZvkp6BdTYwvHqld+/5Lg4ehkhb6blBc74= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ONo16Ut1; arc=none smtp.client-ip=209.85.216.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f67.google.com with SMTP id 98e67ed59e1d1-2a2601f0562so999097a91.0; Tue, 02 Apr 2024 18:40:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712108416; x=1712713216; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Fh/SNg739z3tPcMMVWuLhLjyN3VYUDkGO69sFSfgsFE=; b=ONo16Ut1dVhWDeUHDSuCHctJNk0aZhyp6BbnpwEqzAFQMpc7h/lpsr6uxtYDYtdRtc HPcQEgwnRWexGmRmDst+POkXjMGB/291up1Jr3G2ZBWTUCVDlq2j94KfsOq7ns29wCy+ 6+/ZT5sKjtPrAZVmIclZW1owJe/OWcwPbQ2FhrrQbJx0lsLgjpXanZUX2fjy44/TtLvj KbCDeAPJpdnAYfUB25EwYHCuVUG1Hq5q7pT/3zD+3yvYkrSX6GsKMl+IxH5A6l5tRDp7 kg2On3fNUxssZPX1QJ02Ci6qDGpELE2bIP3STdx6yh0oFNY7smgrazQXddrBp37j8l5G oyFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712108416; x=1712713216; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Fh/SNg739z3tPcMMVWuLhLjyN3VYUDkGO69sFSfgsFE=; b=QspKFxB6ymUUK2vz7jXrZUuJSS3g8uz/5ftob/CweKC4bS7KxSYk1B+In+X5+yToSy 7cTXXSajtHC+nyNo7vTGSg6WFGqJeBfgZs6puBHxCWTuPDunL1BXB2RoLilMrepD0805 8hZde1tfRJhoom+xqj3ZspT0iijAT4RSXKtMPBTUrZyuaCBO7Z2kQYVFsbevEKRIXGxV RbR5Vld+cRtxcRo+w8L8/8oeQpUbsmhZYPdx9SLfr7RhlqbMf3Vl+cQuGNwgFuMn72sv 6wHOIzN0gBcnGXc1SMUoPNHMxp0jVNtyZwELufroEANmEqzyFZ8LzyDlJjqvyXaIXLH3 Fsgw== X-Forwarded-Encrypted: i=1; AJvYcCXwQZGqu55d3MN/ZIUk6fYVUFMAe/mjoJ1Z/eoMq6RIfGef0iF22XTBsI7KuTOvLiFYODJuut1Eqjk4QtE06/d85/+prVBgoiSFyaUo X-Gm-Message-State: AOJu0YzgpEqaXNGozNIiEb/I6b83nzi40U4GyX7lqdQD/HSpO/4+BV+R owN9D5cLfWt6Q31cRvvNRVhrq99Sn0y2Ak3bvBydzIzlU1i7weo0ZHQamVS2pocV6MVO56c= X-Received: by 2002:a17:90a:62c5:b0:2a0:8f31:a359 with SMTP id k5-20020a17090a62c500b002a08f31a359mr13185913pjs.39.1712108415773; Tue, 02 Apr 2024 18:40:15 -0700 (PDT) Received: from lhy-a01-ubuntu22.. ([106.39.42.164]) by smtp.gmail.com with ESMTPSA id m14-20020a17090ab78e00b0029c68206e2bsm10246894pjr.0.2024.04.02.18.40.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 18:40:15 -0700 (PDT) From: Huai-Yuan Liu To: james.smart@broadcom.com, dick.kennedy@broadcom.com, jejb@linux.ibm.com, martin.petersen@oracle.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, baijiaju1990@outlook.com, Huai-Yuan Liu Subject: [PATCH] scsi: lpfc: Fix a possible null pointer dereference Date: Wed, 3 Apr 2024 09:40:06 +0800 Message-Id: <20240403014006.969441-1-qq810974084@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In function lpfc_xcvr_data_show, the memory allocation with kmalloc might fail, thereby making rdp_context a null pointer. In the following context and functions that use this pointer, there are dereferencing operations, leading to null pointer dereference. To fix this issue, a null pointer check should be added. If it is null, write error message and jump to 'out_free_rdp'. Fixes: 479b0917e447 ("scsi: lpfc: Create a sysfs entry called lpfc_xcvr_data for transceiver info") Signed-off-by: Huai-Yuan Liu --- drivers/scsi/lpfc/lpfc_attr.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c index b1c9107d3408..b11e5114b7f2 100644 --- a/drivers/scsi/lpfc/lpfc_attr.c +++ b/drivers/scsi/lpfc/lpfc_attr.c @@ -1904,6 +1904,11 @@ lpfc_xcvr_data_show(struct device *dev, struct device_attribute *attr, /* Get transceiver information */ rdp_context = kmalloc(sizeof(*rdp_context), GFP_KERNEL); + if (!rdp_context) { + len = scnprintf(buf, PAGE_SIZE - len, + "ERROR: Not enough memory\n"); + goto out_free_rdp; + } rc = lpfc_get_sfp_info_wait(phba, rdp_context); if (rc) { -- 2.34.1