Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2950C6FD1A for ; Tue, 7 Mar 2023 16:58:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230383AbjCGQ6O (ORCPT ); Tue, 7 Mar 2023 11:58:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229754AbjCGQ5o (ORCPT ); Tue, 7 Mar 2023 11:57:44 -0500 Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE5BF96C1C for ; Tue, 7 Mar 2023 08:53:52 -0800 (PST) Received: by mail-qk1-x72b.google.com with SMTP id a65so4670308qkg.13 for ; Tue, 07 Mar 2023 08:53:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1678208032; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=RLjzoBnlY+N8c+BPItOeN27vRL9Wum4fM9tcJ2O3obw=; b=ArKcoU50WA1bub0Rjl6km4fU1VFTN25LL5jAnNotJTiFTjblb7GMuzTfMzSRu0Baid ShEcq6Zj/nVLPfk/WbSVCjTpfF+WAA+FJnJRimjo9PxRfLbx0qh+SQivbHikPlM0rhJW XDYWVDgEePnKfqjl8oYqdwO5XYvRVVG+egUYI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678208032; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RLjzoBnlY+N8c+BPItOeN27vRL9Wum4fM9tcJ2O3obw=; b=kW/HFbNVQwgSfraLpi2kowpprcNXsUavHaiIilL7zCRiTl1KYN8yn5zwpmZHC4ZvwD c/UZkFosBz7VOOZevxejGeljGrsxqpK5a219Y2+f4+zC4lE1Mz+vaiPZTi73KTQCTsLj HoE0DzNQ832wCmkGwYB02DVyDyyqcUqUueN77u+DUfbT8VGTqR2ld8K8swptYBS6KNSB /skUtoQrIHwmgLiA4yIx2c8km8DnPcG6fjqj6ygU0VGoHXyc00P9rhZEx3Gku2HZ7J1l SEvtWOpLXVuWtxQcnFgEUNosW8UUEDMT1ZXpoS1a/0RMlWR22RYimLShdsFTI0nTUGm7 HLgQ== X-Gm-Message-State: AO0yUKWJ9koNjTvEWoTqduiWkC2L64z8lERLYjZ3PBG1cdHK6IRMa5W+ 5avXPoZG52JTX8Fcqzgwep1lONLPF6Qv2K24dyWUNCjArFsLjEolNMToH3Iq9+gmAuAcXA5yMyY ORVdjkvPx1clxCZsJxqflxKG2L9Ey+A== X-Google-Smtp-Source: AK7set+TFuAgbBwvn7lhclTzjFDWa+c6N6vB9e/bBA8YxPohfMd/oXTyxiKUntM12zqJ6O/HUt60F0QytzXVFrpx69A= X-Received: by 2002:a37:6514:0:b0:742:9d0f:775f with SMTP id z20-20020a376514000000b007429d0f775fmr3231324qkb.15.1678208031823; Tue, 07 Mar 2023 08:53:51 -0800 (PST) MIME-Version: 1.0 References: <20230225100135.2109330-1-haowenchao2@huawei.com> In-Reply-To: <20230225100135.2109330-1-haowenchao2@huawei.com> From: Sathya Prakash Veerichetty Date: Tue, 7 Mar 2023 09:53:35 -0700 Message-ID: Subject: Re: [PATCH] scsi: mpt3sas: fix NULL pointer access in mpt3sas_transport_port_add() To: Wenchao Hao Cc: Sreekanth Reddy , Suganath Prabu Subramani , "James E . J . Bottomley" , "Martin K . Petersen" , MPT-FusionLinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, linfeilong@huawei.com Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="0000000000009e6d6505f652419a" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --0000000000009e6d6505f652419a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Feb 25, 2023 at 3:02=E2=80=AFAM Wenchao Hao wrote: > > port is allocated by sas_port_alloc_num() and rphy is allocated by > sas_end_device_alloc() or sas_expander_alloc() which may return NULL, > so we need to check the rphy to avoid possible NULL pointer access. > > If sas_rphy_add() called with failure rphy is set to NULL, we would > access the rphy in next lines which would also result NULL pointer > access. > > Fix commit 78316e9dfc24 ("scsi: mpt3sas: Fix possible resource leaks > in mpt3sas_transport_port_add()") > > Signed-off-by: Wenchao Hao Acked-by: Sathya Prakash Veerichetty > --- > drivers/scsi/mpt3sas/mpt3sas_transport.c | 14 ++++++++++++-- > 1 file changed, 12 insertions(+), 2 deletions(-) > > diff --git a/drivers/scsi/mpt3sas/mpt3sas_transport.c b/drivers/scsi/mpt3= sas/mpt3sas_transport.c > index e5ecd6ada6cd..e8a4750f6ec4 100644 > --- a/drivers/scsi/mpt3sas/mpt3sas_transport.c > +++ b/drivers/scsi/mpt3sas/mpt3sas_transport.c > @@ -785,7 +785,7 @@ mpt3sas_transport_port_add(struct MPT3SAS_ADAPTER *io= c, u16 handle, > goto out_fail; > } > port =3D sas_port_alloc_num(sas_node->parent_dev); > - if ((sas_port_add(port))) { > + if (!port || (sas_port_add(port))) { > ioc_err(ioc, "failure at %s:%d/%s()!\n", > __FILE__, __LINE__, __func__); > goto out_fail; > @@ -824,6 +824,12 @@ mpt3sas_transport_port_add(struct MPT3SAS_ADAPTER *i= oc, u16 handle, > mpt3sas_port->remote_identify.sas_address; > } > > + if (!rphy) { > + ioc_err(ioc, "failure at %s:%d/%s()!\n", > + __FILE__, __LINE__, __func__); > + goto out_delete_port; > + } > + > rphy->identify =3D mpt3sas_port->remote_identify; > > if ((sas_rphy_add(rphy))) { > @@ -831,6 +837,7 @@ mpt3sas_transport_port_add(struct MPT3SAS_ADAPTER *io= c, u16 handle, > __FILE__, __LINE__, __func__); > sas_rphy_free(rphy); > rphy =3D NULL; > + goto out_delete_port; > } > > if (mpt3sas_port->remote_identify.device_type =3D=3D SAS_END_DEVI= CE) { > @@ -857,7 +864,10 @@ mpt3sas_transport_port_add(struct MPT3SAS_ADAPTER *i= oc, u16 handle, > rphy_to_expander_device(rphy), hba_port->port_id); > return mpt3sas_port; > > - out_fail: > +out_delete_port: > + sas_port_delete(port); > + > +out_fail: > list_for_each_entry_safe(mpt3sas_phy, next, &mpt3sas_port->phy_li= st, > port_siblings) > list_del(&mpt3sas_phy->port_siblings); > -- > 2.32.0 > --=20 This electronic communication and the information and any files transmitted= =20 with it, or attached to it, are confidential and are intended solely for=20 the use of the individual or entity to whom it is addressed and may contain= =20 information that is confidential, legally privileged, protected by privacy= =20 laws, or otherwise restricted from disclosure to anyone else. If you are=20 not the intended recipient or the person responsible for delivering the=20 e-mail to the intended recipient, you are hereby notified that any use,=20 copying, distributing, dissemination, forwarding, printing, or copying of= =20 this e-mail is strictly prohibited. If you received this e-mail in error,= =20 please return the e-mail to the sender, delete it from your computer, and= =20 destroy any printed copy of it. --0000000000009e6d6505f652419a Content-Type: application/pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7s" Content-Description: S/MIME Cryptographic Signature MIIQfwYJKoZIhvcNAQcCoIIQcDCCEGwCAQExDzANBglghkgBZQMEAgEFADALBgkqhkiG9w0BBwGg gg3WMIIFDTCCA/WgAwIBAgIQeEqpED+lv77edQixNJMdADANBgkqhkiG9w0BAQsFADBMMSAwHgYD VQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMzETMBEGA1UEChMKR2xvYmFsU2lnbjETMBEGA1UE AxMKR2xvYmFsU2lnbjAeFw0yMDA5MTYwMDAwMDBaFw0yODA5MTYwMDAwMDBaMFsxCzAJBgNVBAYT AkJFMRk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