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 512DE42F9A for ; Tue, 1 Aug 2023 17:18:44 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 35BF04325C; Tue, 1 Aug 2023 17:18:44 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 19C2E43253 for ; Tue, 1 Aug 2023 17:18:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690903121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=P0IPysLLF0XVvzEmNUItwBCE6yZ1ZyOBxLeNxOcmcqw=; b=R3VeQNe23MDnbL9Dsbq5Tn/Hzzfp9a4yecVuU6YEq4beS6Anoj/NYPgIngj0NB1PUi+uWH nPKz9PNqifzXZ+4T4MicVX84wiE6YA5J5noAZB6FR8FxdJ9znIim4BGIDkBALU/TJ1kRaD 8LgSpv+ahSdkihhMJ1s60M54LbuipEY= Received: from mimecast-mx02.redhat.com (66.187.233.73 [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-548-_ndKRZ6vMC6bzAJXRuh2SQ-1; Tue, 01 Aug 2023 11:18:37 -0400 X-MC-Unique: _ndKRZ6vMC6bzAJXRuh2SQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C4AD42A59541; Tue, 1 Aug 2023 15:18:36 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.224.120]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D3DDF7821; Tue, 1 Aug 2023 15:18:35 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: stable@dpdk.org, Matan Azrad , Viacheslav Ovsiienko , Ori Kam , Suanming Mou , Bing Zhao Subject: [PATCH] net/mlx5: fix leak in sysfs port name translation Date: Tue, 1 Aug 2023 17:18:31 +0200 Message-ID: <20230801151831.3703427-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 getline() may allocate a buffer even though it returns -1: """ If *lineptr is set to NULL before the call, then getline() will allocate a buffer for storing the line. This buffer should be freed by the user program even if getline() failed. """ This leak has been observed on a RHEL8 system with two CX5 PF devices (no VFs). ASan reports: ==8899==ERROR: LeakSanitizer: detected memory leaks 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) As far as why getline() errors, strace gives a hint: 8516 openat(AT_FDCWD, "/sys/class/net/enp130s0f0/phys_port_name", O_RDONLY) = 34 8516 fstat(34, {st_mode=S_IFREG|0444, st_size=4096, ...}) = 0 8516 read(34, 0x621000098900, 4096) = -1 EOPNOTSUPP (Operation not supported) Fixes: f8a226ed65fa ("net/mlx5: fix sysfs port name translation") Cc: stable@dpdk.org Signed-off-by: David Marchand --- drivers/net/mlx5/linux/mlx5_ethdev_os.c | 1 + 1 file changed, 1 insertion(+) 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) line_size = getline(&port_name, &port_name_size, file); if (line_size < 0) { + free(port_name); fclose(file); rte_errno = errno; return -rte_errno; -- 2.41.0