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 9C9AFA00C4 for ; Wed, 4 Jan 2023 01:00:39 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9497542B8E; Wed, 4 Jan 2023 01:00:39 +0100 (CET) Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by mails.dpdk.org (Postfix) with ESMTP id 715BF40697; Wed, 4 Jan 2023 01:00:38 +0100 (CET) Received: by mail-pj1-f48.google.com with SMTP id o8-20020a17090a9f8800b00223de0364beso37396112pjp.4; Tue, 03 Jan 2023 16:00:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=E7ihUaAw/P30wdHrLRSZ9upuLJn2ScE6WyA/yrJK2hE=; b=BkbfomRGjUd7/F64oqjWumd/yvGyE0TEpM3KktGaXkwuTkyyET5Zwx4DZoUMewy7/q Wk59/+nfDhl1qL7Aa1hCmlA6aYdMlY8ovDCTY+P5vWo2hW69YYmEncIafe3+eFHT+TcS qIjfr8vO+GSlrI+a3ZxjVrBEmTHoHF1RdUJMk9y0G590s5dlM1oecTgyxLnTcD++Gz2P GXtNtaMC1aZ1mrPmy5m0G8gFpvSS8amnhOobG8hAcjPdvf7LLhrlHPZ91ttJRXn9CpJt 2s3aNkga4g0BjZgFRSrRHeZXg136K3br+MwAF7JPd5hf9HQN8Y98HUVY62IAYjhXYwV1 Ef1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E7ihUaAw/P30wdHrLRSZ9upuLJn2ScE6WyA/yrJK2hE=; b=K17AdwX68t8qvImLBNUvY1ijcf4Gh/D0mdfPtOPYQzHKkfpyHB7gW9d+KT7tqGQQ9T 6SifBbJKCxVzCJwACeZbnfq1mWdY68KaG9jGG9FqBkybooVd1ko8erVsd/jdiVFgJVzq 50qg95YrejxQmX22Tek5rogZLwTUcOrspceb+Y1CtZUmHI7qEzbB8mWA+3DhBq4SR+AE jo9t9wBvQKZ599qDGfgH5FAlIfDC2+zvglt7otfLe57mqvb7U8wIAvqYFiCfqiPfHclo 7CwybssSJFswF6yzH4raFH5k8XQDqnldtfnVdeBuqP3+JQ+/94JpV63Qa9bf1rXu/1pt qclA== X-Gm-Message-State: AFqh2koSVer3Odp/yum6z4tAq/6OddRYO9AGcX0hWjcIBmB6/TxVB87a q/Q8XBEegr48AIMw7gpk4yy4SSN0r1JkFEJH X-Google-Smtp-Source: AMrXdXutCup0psAk1STrzLZrZbkxK1xAF4aSy9+SUO3fBmJ33qTA7Jf0IyumKku0JGVZTyqbBOlOnQ== X-Received: by 2002:a05:6a20:d695:b0:a2:c1f4:3c70 with SMTP id it21-20020a056a20d69500b000a2c1f43c70mr55151464pzb.8.1672790436845; Tue, 03 Jan 2023 16:00:36 -0800 (PST) Received: from tbs-1052-sim.qualcomm.com (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id f4-20020a170902684400b001892af9472esm22853531pln.261.2023.01.03.16.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Jan 2023 16:00:36 -0800 (PST) From: Ashish Sadanandan To: dev@dpdk.org Cc: Ashish Sadanandan , john.levon@nutanix.com, stable@dpdk.org Subject: [PATCH v2 1/1] eal/linux: reject --huge-dir not parent of mountpt Date: Tue, 3 Jan 2023 17:00:30 -0700 Message-Id: <20230104000030.187857-1-ashish.sadanandan@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230103185732.2007210-1-ashish.sadanandan@gmail.com> References: <20230103185732.2007210-1-ashish.sadanandan@gmail.com> 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 ensuring any matched mount point is either an exact match or a parent path of --huge-dir. Fixes: 24d5a1ce6b85 ("eal/linux: allow hugetlbfs sub-directories") Cc: john.levon@nutanix.com Cc: stable@dpdk.org Signed-off-by: Ashish Sadanandan --- lib/eal/linux/eal_hugepage_info.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/eal/linux/eal_hugepage_info.c b/lib/eal/linux/eal_hugepage_info.c index a1b6cb31ff..180abd930c 100644 --- a/lib/eal/linux/eal_hugepage_info.c +++ b/lib/eal/linux/eal_hugepage_info.c @@ -265,12 +265,23 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len) break; } + size_t mountpt_len = strlen(splitstr[MOUNTPT]); + size_t hugepage_dir_len = strlen(internal_conf->hugepage_dir); + /* * Ignore any mount that doesn't contain the --huge-dir * directory. */ if (strncmp(internal_conf->hugepage_dir, splitstr[MOUNTPT], - strlen(splitstr[MOUNTPT])) != 0) { + mountpt_len) != 0) { + continue; + } + /* + * Ignore any mount where hugepage_dir is not a parent path of + * the mount + */ + else if(hugepage_dir_len > mountpt_len && + internal_conf->hugepage_dir[mountpt_len] != '/') { continue; } @@ -278,7 +289,7 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len) * 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