From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 11E7342F9A for ; Tue, 1 Aug 2023 17:39:20 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0A9B943254; Tue, 1 Aug 2023 17:39:20 +0200 (CEST) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) by mails.dpdk.org (Postfix) with ESMTP id A209F40A89; Tue, 1 Aug 2023 17:39:17 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BjgnIJJo5fubt0SbJ1ej97Mj/5+im/RUJhH6pRGY9zfx0vMUVnmoXJJ3HH7vs1jA0L+8NEwho14iPlJFR5z4eURTiGWS7Zk05PPbm+JIigOWNLW6UOkkjWfq15/Krj/KuiJYvFJXf5/7Ct9Dlvm5Jc1K1l7s3ONTPN7QFsOsBzDrse8kDT5eMUoMOCinzTQLjUdv2NEVfcOZWSjqXSUMl6OEL3+7WhWXOsKEzh5LkGUm063PnrCa58WNPkyC1MKvJsVkQRZRpcVOZpl6gvdIFCzsbLtj2Wx5B/QN2H7gOY/OF1oQy/OfvOfVnP3zcj9ORBzAMDFxDE4Y+mGSg71cSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=X/KJIfHswoMTU46nP6i0TOX0npKH3L2NjW/bqXQER4g=; b=B3uoKfHnE8hxH9YW3wcehLb/lPHd7x/f+rIkhdDvoG8NHLy/GsPlIkOZ4qrpHAkC24M/e++Rkls0Jvecjtg8mLMOrysTg03dyi+jyBIWxlluV/7xPiqNsUSbicok45q4rjT7nebf5im9z7rwxoMWzPYfFVr0nnzeofRLUr6r0d5WW/o5I+c9sk7HJidzV26LHYQmDspKqac20zWLLlXeFwFz7zlnLyeRVKH4YB6LnFqeN06eggegX/zcJigSu53PHC2x3fhRYDuCNJ6Nuz3mHhYIey4vi330Rao58EnW+hTZo70VZaVsfttvAjTNRLHcdcZwzVSpBlvNB+87Q/pVDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=X/KJIfHswoMTU46nP6i0TOX0npKH3L2NjW/bqXQER4g=; b=LKTUzddqqpr6+OrQ7bO86goX7liOebg6Lxj3YvUzdut3oa+SM4mJPN3DjKyuo0MFFepYbUzZEF1R0K8Dr2TwtHZmY8wsYfHH34xmSMyUCH09Yd6oUvkTnBnyqMbYywS0f4zEXuPqK6LR4182TojP35TIX3sMOq+oxMGle2VJ0KWRcPtEkPtrEGycjRpWqKk8B653xklTU0E09DuY3HtkAqMOV6nIEfe5IZF/KaE1dHRo7VSdq3uQaac/55I77uNbePL9zvphjqsaftTPqKBbh0WVIHOtTG/ebXl/c1mXk/bQKZgu7KUIMGIUJhYnHBTt9Do//MASGJdoOsjlw9kxKQ== Received: from DM4PR12MB5184.namprd12.prod.outlook.com (2603:10b6:5:397::18) by SJ0PR12MB6901.namprd12.prod.outlook.com (2603:10b6:a03:47e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Tue, 1 Aug 2023 15:39:15 +0000 Received: from DM4PR12MB5184.namprd12.prod.outlook.com ([fe80::825:396b:c937:b56a]) by DM4PR12MB5184.namprd12.prod.outlook.com ([fe80::825:396b:c937:b56a%4]) with mapi id 15.20.6631.043; Tue, 1 Aug 2023 15:39:15 +0000 From: Bing Zhao To: David Marchand , "dev@dpdk.org" CC: "stable@dpdk.org" , Matan Azrad , Slava Ovsiienko , Ori Kam , Suanming Mou Subject: RE: [PATCH] net/mlx5: fix leak in sysfs port name translation Thread-Topic: [PATCH] net/mlx5: fix leak in sysfs port name translation Thread-Index: AQHZxItz3RE4g8JfAkKmoIyFfd5kHq/Vk3Rg Date: Tue, 1 Aug 2023 15:39:15 +0000 Message-ID: References: <20230801151831.3703427-1-david.marchand@redhat.com> In-Reply-To: <20230801151831.3703427-1-david.marchand@redhat.com> Accept-Language: en-US, zh-CN Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM4PR12MB5184:EE_|SJ0PR12MB6901:EE_ x-ms-office365-filtering-correlation-id: c8fb3f99-f05d-4fc8-d81c-08db92a5763a x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Yc6mSqaEg5Ls1O6z3drCKNT8UoAsPzcMpZ/YtpBSTzN+i+coazRQDKiyXl8qp8X3fPYxfH8BU+XQd1Hu6BjsNbCEgY8sCLPdY9a59ArygStkPthyFxdwyPw21WTe/CjFnPUcU5n3AoHG/Vu3HDn6j0e7jNbk+iYezeImBrMeUymO1ohwP08kD4ryfnvUmCD2PZTeFA+7UJcNo7UWQZb0VNw7WivPCtD/MDct6QRVzMaHnd25OsPsrcd0+RSjwVYYlTUwwiNUazz3uCcY995Thn1oaa4KJORly2l3sp9ArSHaaOJ2LdyuXiH6frByfkYBsuHgttH6tEOFdD0/M14OHBUBqnBFIxyfuImQJLybQel3AZAJ0f2R45E+PTA24BEejcIMBilPEwDHy9kMwz6co4c7WCrkC9mzIRS7km196P48sR2WLpPxUtTFLUEk1zbOGpqSeedzWzlC4AaxniWCtxAhrpdXlY+LZmhJnO9WjN5Cv3z/LTyOwiGdQSXKxUF2K3BLBnjSZLPzmmqBqusH+L9A0y1vkttzKKNGJCiQHJ/v8jcB97saJf99NEICTpPmQBOTo7F8Q71E8DFTsh122kGE4rm5ZnXf7r4ssV0vQcXbwv4oDor4BSjDE0nMb0ut x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR12MB5184.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(4636009)(396003)(39860400002)(136003)(366004)(376002)(346002)(451199021)(26005)(71200400001)(6506007)(186003)(2906002)(8936002)(41300700001)(54906003)(8676002)(110136005)(86362001)(7696005)(38070700005)(478600001)(66476007)(52536014)(66556008)(4326008)(9686003)(107886003)(316002)(38100700002)(122000001)(55016003)(33656002)(76116006)(5660300002)(66946007)(64756008)(66446008)(53546011)(83380400001); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?SbXUvCataxchRF2O9WSWGnq1GxqQGjimnRO5qZvf/wCwn2yVsCMSAeYH1y5K?= =?us-ascii?Q?ex6JCknCKOhEEeUxhqrG1k30CG9VQhxP67kcHMepO5/O0iBv9bTXeCkWYAmc?= =?us-ascii?Q?yNSpkSQQ3WURoAa/xbiOBiJjsMVI3nC2ZsVJ+g8j7bvO8XUyBvtg6UDhRx3R?= =?us-ascii?Q?K8ONJwh8SWhJvXUf1ieyeh5rfG1ovRnbNHp0dTjd/FWhc+maODSSjIQC2NOO?= =?us-ascii?Q?Wn75M2VnLAAQ9sDwO+VKgVGhqwCd72B6JnPOEaF49CewRyr2XLDZSKcOzrNh?= =?us-ascii?Q?hcq32gUCC+HWSnGDRiz3HLPx60FrAXOM9km6rBTb+gatkQVcqNaLkPyl12RG?= =?us-ascii?Q?nq/z8JlvgplJPtGzfLS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ZN4K?= =?us-ascii?Q?jq16NOwwERcTBx9mQKqV0tG1lTeeO+egTu9Qocx0nq0sZ6jkkpz9ZhZVed9u?= =?us-ascii?Q?/KuiSFqgZTYM4ecD/bg06u2r7v232BRjBlfoNLiC2pSTSaiKT/909j/dOGvE?= =?us-ascii?Q?KlVSB3jR8I7DliNFgUHGT+Dman4/ImGokbHWMEjqnam3J4Rn6879HvLJwmQi?= =?us-ascii?Q?aOsOgJNbnyVkHQiNvWq4xNBJ3RuaOhHkM5hUBCaP85yvaoVRQyacUpzSJdBw?= =?us-ascii?Q?5o2oPuENMPnJcVRYnOynXSDuk0rV2OM9mMUgnTWH0NaYJXqBSiuvYzhe0QR+?= =?us-ascii?Q?L6C2M3yq79T3H9aXJPU=3D?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5184.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c8fb3f99-f05d-4fc8-d81c-08db92a5763a X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Aug 2023 15:39:15.3812 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 2IztMDI4lbwZ1kPQK+4OYEPS8cCWQ9dHAx389d26KqezhjOSURLbXPFuEyAXmwOEm2l00zgY2PhBm+Bi5vZITw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6901 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Hi David, Thanks for catching this. BR. Bing > -----Original Message----- > From: David Marchand > Sent: Tuesday, August 1, 2023 11:19 PM > To: dev@dpdk.org > Cc: stable@dpdk.org; Matan Azrad ; Slava Ovsiienko > ; Ori Kam ; Suanming Mou > ; Bing Zhao > Subject: [PATCH] net/mlx5: fix leak in sysfs port name translation >=20 > External email: Use caution opening links or attachments >=20 >=20 > getline() may allocate a buffer even though it returns -1: > """ > If *lineptr is set to NULL before the call, then getline() will allocat= e a buffer for > storing the line. This buffer should be freed by the user program even i= f > getline() failed. > """ >=20 > This leak has been observed on a RHEL8 system with two CX5 PF devices (no > VFs). >=20 > ASan reports: > =3D=3D8899=3D=3DERROR: LeakSanitizer: detected memory leaks >=20 > Direct leak of 120 byte(s) in 1 object(s) allocated from: > #0 0x7fe58576aba8 in __interceptor_malloc > (/lib64/libasan.so.5+0xefba8) > #1 0x7fe583e866b2 in __getdelim (/lib64/libc.so.6+0x886b2) > #2 0x327bd23 in mlx5_sysfs_switch_info > ../drivers/net/mlx5/linux/mlx5_ethdev_os.c:1084 > #3 0x3271f86 in mlx5_os_pci_probe_pf > ../drivers/net/mlx5/linux/mlx5_os.c:2282 > #4 0x3273c83 in mlx5_os_pci_probe > ../drivers/net/mlx5/linux/mlx5_os.c:2497 > #5 0x327475f in mlx5_os_net_probe > ../drivers/net/mlx5/linux/mlx5_os.c:2578 > #6 0xc6eac7 in drivers_probe > ../drivers/common/mlx5/mlx5_common.c:937 > #7 0xc6f150 in mlx5_common_dev_probe > ../drivers/common/mlx5/mlx5_common.c:1027 > #8 0xc8ef80 in mlx5_common_pci_probe > ../drivers/common/mlx5/mlx5_common_pci.c:168 > #9 0xc21b67 in rte_pci_probe_one_driver > ../drivers/bus/pci/pci_common.c:312 > #10 0xc2224c in pci_probe_all_drivers > ../drivers/bus/pci/pci_common.c:396 > #11 0xc222f4 in pci_probe ../drivers/bus/pci/pci_common.c:423 > #12 0xb71fff in rte_bus_probe ../lib/eal/common/eal_common_bus.c:78 > #13 0xbe6888 in rte_eal_init ../lib/eal/linux/eal.c:1300 > #14 0x5ec717 in main ../app/test-pmd/testpmd.c:4515 > #15 0x7fe583e38d84 in __libc_start_main (/lib64/libc.so.6+0x3ad84) >=20 > As far as why getline() errors, strace gives a hint: > 8516 openat(AT_FDCWD, "/sys/class/net/enp130s0f0/phys_port_name", > O_RDONLY) =3D 34 > 8516 fstat(34, {st_mode=3DS_IFREG|0444, st_size=3D4096, ...}) =3D 0 > 8516 read(34, 0x621000098900, 4096) =3D -1 EOPNOTSUPP (Operation > not supported) >=20 > Fixes: f8a226ed65fa ("net/mlx5: fix sysfs port name translation") > Cc: stable@dpdk.org >=20 > Signed-off-by: David Marchand > --- > drivers/net/mlx5/linux/mlx5_ethdev_os.c | 1 + > 1 file changed, 1 insertion(+) >=20 > diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c > b/drivers/net/mlx5/linux/mlx5_ethdev_os.c > index 639e629fe4..dd5a0c546d 100644 > --- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c > +++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c > @@ -1083,6 +1083,7 @@ mlx5_sysfs_switch_info(unsigned int ifindex, struct > mlx5_switch_info *info) >=20 > line_size =3D getline(&port_name, &port_name_size, file); > if (line_size < 0) { > + free(port_name); > fclose(file); > rte_errno =3D errno; > return -rte_errno; > -- > 2.41.0