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 21C7AA00C4 for ; Tue, 3 Jan 2023 19:57:47 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 444E241133; Tue, 3 Jan 2023 19:57:46 +0100 (CET) Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by mails.dpdk.org (Postfix) with ESMTP id A3FD440697; Tue, 3 Jan 2023 19:57:44 +0100 (CET) Received: by mail-pf1-f170.google.com with SMTP id k137so16443868pfd.8; Tue, 03 Jan 2023 10:57:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qIO9rK9S7oabGfEUXyp5suyrEAHyS0P+yKgfI4QCoRI=; b=MasMb7CCxp1xjqMph1h66Sxhv21h+rp6rhoXd4QVIeQkEx6/HwLH6+O/U/Ez0RjM4a lW4tftjR9AB8oWuw1Uhpb4HPdcHtotkflJo74kO/Dp87Zfk+hJV5q8W7gbvXP9jQDyXD FXBqVo+fw9MkNc1VDfXD/hdYmBwZjBZcQ8YxxoJA2p4Hht6aFBe+HB4jEu/oRddUOLlG ctKXbaAmDvkNgI9uadpS675xazTIBK7iHXHHsGqhC4xW5N19Kji5Ut9ltfuyTGhbBYne xO5Pvv7jJigWN6Jk3bhkf1Vi5ShIQzc96jparsfT5oIpDLION2s94myJhgOiyA9GULn6 ww0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=qIO9rK9S7oabGfEUXyp5suyrEAHyS0P+yKgfI4QCoRI=; b=gq4+hIFM6gtJTLG1V25Cp6X5Hqo2PlvCdiyEjqUyMFbBPabcykDod1I54bLUaz7vdj g5IjvbZWqAF6YQYUIu3S/BhxxikKZKIv96cZAYcqocNNvrrOPorig1v3eG/TzuVlHzgN 0H1wWp93kgxz7lPKAAzNy7sZloWQMQIYLd5RVHncG16TJkaEm83mV4ud3yME9JF0CmZ7 Mt9ZbouEN3SCBslMN0uGLa+tH/ZdxM0ofXhgf7KjxvUtHxovxiLg7vmdekQx06tHHChl hHONu5pWyzcd4X/IsxBhSKU5PDNHNOvBTpBT3sN/XAtURDsIkGe2BNhAz7HP+1rbtmXS wmIQ== X-Gm-Message-State: AFqh2kpgwZqQGd1Lf/gok2Ih4HTdwB2n6FgcAnwRIxbEK7Vr0VcD3muH ExjxFCmgpusLOkeRs17gg01rc3AVKzSdwemr X-Google-Smtp-Source: AMrXdXvn8CWOsdNXWKLRQo1xk1llxCJY05nuX81oUWQoK6VuH/1JzTt7Da7cZA6KU7g64/r2gIyTqg== X-Received: by 2002:a62:1754:0:b0:582:1145:a946 with SMTP id 81-20020a621754000000b005821145a946mr15844232pfx.8.1672772263232; Tue, 03 Jan 2023 10:57:43 -0800 (PST) Received: from tbs-1052-sim.qualcomm.com (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id u11-20020a62790b000000b00580a0bb411fsm20080558pfc.174.2023.01.03.10.57.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 10:57:42 -0800 (PST) From: Ashish Sadanandan To: dev@dpdk.org Cc: Ashish Sadanandan , john.levon@nutanix.com, stable@dpdk.org Subject: [PATCH 1/1] eal/linux: reject mountpt shorter than --huge-dir Date: Tue, 3 Jan 2023 11:57:32 -0700 Message-Id: <20230103185732.2007210-1-ashish.sadanandan@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 The code added for allowing --huge-dir to specify hugetlbfs sub-directories has a bug where it incorrectly matches mounts that contain a prefix of the specified --huge-dir. Consider --huge-dir=/dev/hugepages1G is passed to rte_eal_init. Given the following hugetlbfs mounts $ mount | grep hugetlbfs hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M) hugetlbfs on /dev/hugepages1G type hugetlbfs (rw,relatime,pagesize=1024M) hugetlbfs on /mnt/huge type hugetlbfs (rw,relatime,pagesize=2M) get_hugepage_dir is first called with hugepage_sz=2097152. While iterating over all mount points, /dev/hugepages is incorrectly determined to be a match because it's a prefix of --huge-dir. The caller then obtains an exclusive lock on --huge-dir. In the next call to get_hugepage_dir, hugepage_sz=1073741824. This call correctly determines /dev/hugepages1G is a match. The caller again attempts to obtain an exclusive lock on --huge-dir and deadlocks because it's already holding a lock. This has been corrected by rejecting the mount point being considered if its length is smaller than the specified --huge-dir. Fixes: 24d5a1ce6b85 ("eal/linux: allow hugetlbfs sub-directories") Cc: john.levon@nutanix.com Cc: stable@dpdk.org --- lib/eal/linux/eal_hugepage_info.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/eal/linux/eal_hugepage_info.c b/lib/eal/linux/eal_hugepage_info.c index a1b6cb31ff..fcc3d82fdf 100644 --- a/lib/eal/linux/eal_hugepage_info.c +++ b/lib/eal/linux/eal_hugepage_info.c @@ -269,16 +269,19 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len) * Ignore any mount that doesn't contain the --huge-dir * directory. */ - if (strncmp(internal_conf->hugepage_dir, splitstr[MOUNTPT], - strlen(splitstr[MOUNTPT])) != 0) { + size_t mountpt_len = strlen(splitstr[MOUNTPT]); + + if (strlen(internal_conf->hugepage_dir) > mountpt_len) + continue; + else if (strncmp(internal_conf->hugepage_dir, splitstr[MOUNTPT], + mountpt_len) != 0) continue; - } /* * We found a match, but only prefer it if it's a longer match * (so /mnt/1 is preferred over /mnt for matching /mnt/1/2)). */ - if (strlen(splitstr[MOUNTPT]) > strlen(found)) + if (mountpt_len > strlen(found)) strlcpy(found, splitstr[MOUNTPT], len); } /* end while fgets */ -- 2.27.0