Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2430260lqz; Tue, 2 Apr 2024 18:28:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWBGUrIIcDY5uwIijgqwmuw+g4iY4xIW3IQcsdLNlezD9Z2IjMn1ogu+ucwe0ww54ipHfIhsj4rgL6kOpz5RAYgkEdL9tnOfw9Y6Dz8qQ== X-Google-Smtp-Source: AGHT+IGVZExRa/9JltcJ26mVGJL4aprUINU1Kx8oVqGxggDbAWvyfGvX8gRTI3QaBI38hHwCvQE4 X-Received: by 2002:a05:620a:4152:b0:78d:398f:7377 with SMTP id k18-20020a05620a415200b0078d398f7377mr18188qko.58.1712107705203; Tue, 02 Apr 2024 18:28:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712107705; cv=pass; d=google.com; s=arc-20160816; b=yLUW+iBbLJjiMci6fLatHCPn1zjfp58PleZfNKhwhL1PQa+r1ereYXJThrFhC2vF+D kB/32kdy8V5G8tc4vnEFCR8UqeeXSDxTtRZty8qZA2zm7oIGaAleur3yS1RMknN879yJ xX7DvG7wX5JpLBTw3kRdvbOcWzV5XJXt4owwgVBQgCHOJWBzQEsnWCZ07Q4QpBzPs+s4 OX02kaHYEVnGJVQPM3sXiw+EP3UuPVlvS66+U34m92MoPXrwqSv1TNgH91Mp+RFpylDF cjVs2fys15oeUseRr4qDVWJePvHfPgShEWpJIZHDrzxCIQ6AT3PZTK1vZqZHrRBK1gAg 0mGg== 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=QgF+noOD10kOlj0U+9VFK/2VpTAYYndo6kiRXQ7BdA4=; fh=B8YKUk/kNc77+Z4NamyOuA4UnWJ0DYoiec6i2k4CYFQ=; b=xY8dZQEBwDF8yocqxt6I4X01wmH64KW3PlPz6gmfNy79TFpr9VqY+pCwXXkiwoeDh8 HcdJ0NZInagPaRNac3pMjpx2fgbXjBthL1J27Pxk/rH9JSfhp7O3kQ1juWwiNhA31NVb 0aW7fkFHhvViRvPXXS3633WdlufZGermfJClsagPGT8XjVhBUzI7bfdmvCcFSjXIpiTX d+kFcZCcBTOHbIdf0wUeOABtXaTB9qE+pktjWLfHl7185VAUj9hDQaLBYaEuHXbC/Smw RgSItUnC99c927k/9f8P/N371pxctFw9sLqNtFNCM65zwVfWyygFAmDVyBS7eRbHBJb1 5haQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fVxnuDC0; 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-128929-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128929-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s23-20020a05620a081700b00788578065f4si12798567qks.753.2024.04.02.18.28.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 18:28:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-128929-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fVxnuDC0; 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-128929-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128929-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 051F71C23D07 for ; Wed, 3 Apr 2024 01:27:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 59D0813FF5; Wed, 3 Apr 2024 01:27:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fVxnuDC0" Received: from mail-oo1-f65.google.com (mail-oo1-f65.google.com [209.85.161.65]) (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 2B524168A8; Wed, 3 Apr 2024 01:27:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.65 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712107647; cv=none; b=cO9q+zrZRr0W36WtEoLXactc8XljbLmazy9WNMwZF6avBT8mvCM0MlzaAKSbePtlIXmj55chrk6aRSYvGZ5JD6E3oln6nfljVG3iop1RwmkwmXsJajcGrsjJKQpjZbaacmaRWmfG+TZVNU3Y8tH8kg6TFoGwze66EV4GXyq/U0I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712107647; c=relaxed/simple; bh=gpiz8ytPP4xNPIcRFhDKhFYNxujxRb4J0v0+KGwLOhQ=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=gMPcKzwpeJFwNpjU4GZQzOEgkUJYiRlAf4Jn+W9FiGZx9BK+ERLk1T0DYSVRDSHKlWgbNoNJ0exe192oOE7JArvDu3MQg6W1hTPcEOZepHk/U0XpizkChUyq2i5P/jleTVUMdY+oxOZWOY0N8I1qip2jrCt5BAitgzlp0Eo6VoU= 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=fVxnuDC0; arc=none smtp.client-ip=209.85.161.65 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-oo1-f65.google.com with SMTP id 006d021491bc7-5a5272035d3so3489772eaf.1; Tue, 02 Apr 2024 18:27:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712107645; x=1712712445; 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=QgF+noOD10kOlj0U+9VFK/2VpTAYYndo6kiRXQ7BdA4=; b=fVxnuDC08rvIXdDsInSahAPw/zX8d721ZLyOBtj+DbyD2de5IJWrn/GmXd54NH+XSC nGWAV7l0sfU51qLfqHxRKf2F+BYCTV2c7tSpEySEiH0zVDbGYzxMOnC1J+D3Z1uCMRG7 u24gWVoOVKOyGiPtKnAIsvP6lu41YMab5sXuX5OWWd8CUN5LfZVzFAgx45b1P6B8khUY 2DEsL06qWRZ/f/G0eF7s+yJavj5kE8r2Shu3QlqyPZZQp4JY8HTWYeESQWW09iwSIf0f dkpwABVuM5IkoB007trBvkCb1PlnU34yep14YRPickAyWpWuA0FUNVYPVEK/W6XMUUjH mRug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712107645; x=1712712445; 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=QgF+noOD10kOlj0U+9VFK/2VpTAYYndo6kiRXQ7BdA4=; b=LZ33+59CfcIsBw9RkhK01sXRq380Q8EPyT7KHMdxB5zxqRct8uJm5HpkxvPfVWev0m /0JyIVYLfXBAUGgLzVCt/oEyXpiHbxxCGvwSnssSCP+AmIvI2t11t+6FVEY2zLe6K/vf KEdg1NelGXEla8StXytW06DATKYeVQ/80x2UfZPmCiGeyDIj9xDTsp60UwvKd10+6Lx6 SIgu3tqHWAljX/jQv6F6NF0GaMEMM1fflKjKVOScqiXQhnzmsHrzKOplrKlT3qcOanQ7 GU8B8bOQpJ2it9jfpZxkKJMOKD4gdZSVY+PMo5G06w3ssSh7/vwCUn+Kf1vGWoSRV+7c jbaw== X-Forwarded-Encrypted: i=1; AJvYcCX/nQ9jKALimfg0ghZm2f4d477Pm52Kka/4BOGT1uWV3hi7aIVI7SXTpWHViiFYfp/4sC5PJ3dOFZhC/QysOybibYzicvauWt3ePY43 X-Gm-Message-State: AOJu0YyAj3mVoWygTjJ4m/BB1rOtcM0BxYwJpKKGexEFAuAtFrBwcW// MbfRoPabMcTrFQzJj1/94HG83KfE92EzfGode2EtD5OZvYZNZ/z8 X-Received: by 2002:a05:6358:5411:b0:17b:f672:4abe with SMTP id u17-20020a056358541100b0017bf6724abemr1260296rwe.16.1712107645033; Tue, 02 Apr 2024 18:27:25 -0700 (PDT) Received: from test-virtual-machine.localdomain ([106.39.42.164]) by smtp.gmail.com with ESMTPSA id l4-20020a639844000000b005dc9439c56bsm10278665pgo.13.2024.04.02.18.27.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 18:27:24 -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: Date: Wed, 3 Apr 2024 09:27:15 +0800 Message-Id: <20240403012715.3058-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 Subject: [PATCH] scsi: lpfc: Fix a possible null pointer dereference 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