Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp716143lqe; Sat, 6 Apr 2024 23:58:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUeo+AHDbAbEOx6Zj9q2G1Vopb/bU7HSntBcwEzfEAxZxahTPqtqKxeTlSIY+TiBZ8QQbM15rGkqhzGV9zWNfZYgRCfzoG2QMF0EB49Ig== X-Google-Smtp-Source: AGHT+IEJ9ChjuItLo2QGruVO6tI5tMyp3KUCHNQPq4soMo50i38vWsXyMwzVJX7ip8WSu8wf/E/s X-Received: by 2002:a05:6830:630b:b0:6ea:15de:c3ad with SMTP id cg11-20020a056830630b00b006ea15dec3admr140817otb.13.1712473126075; Sat, 06 Apr 2024 23:58:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712473126; cv=pass; d=google.com; s=arc-20160816; b=z47iUcWiOx+sXddjVb5Da03420ofkwoVWyl8LmTXePzZezA5BHFQ5ldtTWhRiUw2vZ iecbATQKfp1+jk7shqXy48BF9liNLnRhEfQD304AKhh3Qy2veAfuu7hMk1Dewwz8BedX bTjZdMGBKfeH+3LN+vvy4uT6q4Ng15at8anlXi+YH0627otoyg+IPs0yHH9jb6b1CwPk +82DWmzySifBcUCw2YicjGvTaCjDkgDrZRRlzGASz2p+wDhs8T6N8ZMML4fFEvZomf81 hTkyrvulGRVfh/DuvQ2JxjOsDCjfOHEYSfieyKtuO/NTTljB1d6sN4vfKxQNM4fME8aH ql3Q== 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=ID8vcKMAuhxPQfV9/bb6FKbXp3VjWvrumIK/fNKJqMQ=; fh=Hh2MXr93yXbp/od2gSjqRFLfUKKK8mMnoGAWI1eWBRE=; b=qYZe7Ttzq/UNRFAqhI921/L3p9j8Ijmnjs/gbxkvijXFuHEFF6PsMnSYMl0OU/3E7C ZRFCYUC0/QgqQ31WsPBcsiJBDoVW6tx0vwJM2KfCoJyZSP+nWh4TdCDmJXuGcV/a0+B5 kqpFQYW2Zv3wz8rCQn78xjul6d9O4ZFWVKL0yFm9BM4tISPzo2z304EncUdQ7KfrJN5G u/DMsj4Ulbn68u77EIwxs7NVbGEug0s2LpzDNvy0PEjuqyXh2m90pHxBHIop/bFAF9yl SRA/sjGOivzaLwR1cacyR6isECPhsDFvTU2zD6X87Bbj0TbcyQzQJ35X1z0fD2PHy2oS osRQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=G+muyBuH; 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-134209-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134209-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id g7-20020a6544c7000000b005e49cde1b64si4273921pgs.190.2024.04.06.23.58.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Apr 2024 23:58:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134209-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=G+muyBuH; 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-134209-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134209-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C30D6B21F1B for ; Sun, 7 Apr 2024 06:58:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 093DD111A1; Sun, 7 Apr 2024 06:58:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="G+muyBuH" Received: from mail-ot1-f67.google.com (mail-ot1-f67.google.com [209.85.210.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 BEFE4D304; Sun, 7 Apr 2024 06:58:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.67 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712473101; cv=none; b=gvP3bQl7biphnW1XyjLDqxuHHgtU7DlfIgMVrSA5VLGApbPrluyMQ4lYIOuqein9r8EQjesesyhI/9hyHrwWHxObRKRGBd8k6JjT+gWNdIfk9xmu0VdhWlFrQgwus8XIBk6vMydE3aSDNLWjiHuJvbMyCUKOeLVQy0SUppilXko= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712473101; c=relaxed/simple; bh=6haZaBoCzYDbs6gYHymH85S6kUGBAmgTaEwCfRsPvpM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=FLpMXVl8766E5fg1rQbxgLqj2AUpfhiVXiXYwSCRXIbw38RvEHn1xzlJ92bYeaDNpnZPfRp9hmEje4d9FUhdDd7Bg4jw7CJeoR6ITwZ1O2A5FbdARQVE6ocQH2OHIaOzi7P+soG41lH++3tqTIrqpzUY5+p3Fb9BbSyY8PHsjGo= 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=G+muyBuH; arc=none smtp.client-ip=209.85.210.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-ot1-f67.google.com with SMTP id 46e09a7af769-6e6b01c3dc3so2393783a34.2; Sat, 06 Apr 2024 23:58:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712473099; x=1713077899; 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=ID8vcKMAuhxPQfV9/bb6FKbXp3VjWvrumIK/fNKJqMQ=; b=G+muyBuHgNcRvwZc2Yx2hyUSOTnulxD1Lq9Oi4rO49qDsHapwYrr0MjmwjA+lLHiVR syvOdkxjtRn+dgV1ncYnCy1wpKHUdDLtqu6bS8x+7Fcr/ZLOkCpQDzANpvHvDPL7Va5M XOlJDehLQoXjW51N4l9s8RIYZAwNX0eVKjCcqj/tFHcMeGKan0PIkplKE/FoKW0DKT1V lPTwMv5+0MVJB3QhurXrkOtZAv6w2qEbKhB3IVZm895MJKuleu+lzKdsCEknhqETkmsQ N9JkwnZKDxTRbLaO1dFzPrW4ivtldj1JSKnu7DTsr4Uygyrxbos2C9umnM2TQtcvg463 shkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712473099; x=1713077899; 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=ID8vcKMAuhxPQfV9/bb6FKbXp3VjWvrumIK/fNKJqMQ=; b=BYWZ0gUJ6khpPGry+G9OOtZrGRVlEK6Fq+Eq8UPkdxVTDNlVFMBsI8CR6o6dfPu+GG CVCT+kMFOPkPEFzblkMUQHpng6eTIoZR5vLAmcfYh8GNeQHaVSVjRBoFoTfQ70/bbHb3 sKpgp50riDkizCtF/YzwGq7jAEwJ6V2La8hhGRpsX/5haE7SG1otQr8BTxzI4HsXFa1D DYgvR0P+cmxq4p/EkKKRChBBNhx/fS5oLmZgvEw9lsZVm1C0fxOLIAeWUpTKCnocA+6L lFtUq1p6TYpoWdgJQjc7wudRNznt9DTPAiQdnBI2r/JwJDr72053n7VPlvY6q3GfQt7m bRoQ== X-Forwarded-Encrypted: i=1; AJvYcCUbtyLkFodQITTUchniBty0/6XslcNtJpdCpAl6qKImksl3VGnOwTcQ8gIghA0vk7wNVuizZlJtznu3g++ObWQ8mL+TbMcm89zQygiO X-Gm-Message-State: AOJu0Yzr7erUhKWAjA4ZWDilU7d1eVxR5lfIhy6o66YVu/SFdrq5bMFQ gLeahcdsnPt1EGDWiojFnHNGBI2j1xRlxpMhqwbq3ynbE0t1EMhC X-Received: by 2002:a05:6870:2052:b0:22e:8647:7570 with SMTP id l18-20020a056870205200b0022e86477570mr6854479oad.54.1712473098776; Sat, 06 Apr 2024 23:58:18 -0700 (PDT) Received: from lhy-a01-ubuntu22.. ([106.39.42.164]) by smtp.gmail.com with ESMTPSA id g10-20020aa79dca000000b006ea80883ce3sm4095645pfq.133.2024.04.06.23.58.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Apr 2024 23:58:18 -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 V2] scsi: lpfc: Fix a possible null pointer dereference Date: Sun, 7 Apr 2024 14:58:09 +0800 Message-Id: <20240407065809.6373-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, just 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 --- V2: * In patch V2, we have removed the unnecessary 'out of memory' message. Thank Bart Van Assche for helpful advice. --- drivers/scsi/lpfc/lpfc_attr.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c index b1c9107d3408..94d968a255ff 100644 --- a/drivers/scsi/lpfc/lpfc_attr.c +++ b/drivers/scsi/lpfc/lpfc_attr.c @@ -1904,6 +1904,8 @@ 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) + goto out_free_rdp; rc = lpfc_get_sfp_info_wait(phba, rdp_context); if (rc) { -- 2.34.1