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 8B032A00C4 for ; Wed, 4 Jan 2023 19:17:44 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 817DB42B8E; Wed, 4 Jan 2023 19:17:44 +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 0108D40041; Wed, 4 Jan 2023 19:17:41 +0100 (CET) Received: by mail-pj1-f48.google.com with SMTP id cp9-20020a17090afb8900b00226a934e0e5so1572841pjb.1; Wed, 04 Jan 2023 10:17:41 -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=A4wYdD6nZ0KYfJAb1chHbIs09SzFpNQ/ERx5d9j7fqQ=; b=TaiHvgkAaL9vdUrj42iZR9lU6BNaIJXtcFfdV/sDwxeQucL0m9MT9ymRqHlNQw6bnb F0gchqlJguTZ4AB7YRAjcImOXMOxGteioLMyfqb4bSZ6L3QOEi5/vS+dZo9pAxKvhQWi 1YhJNH1jqfR1N5dx7JleVNj5ss/fFis6WWTcwvQDH+P9XIdgDgX0tjoyeJuqZ78mrAc+ Vl0ZciiL7Rq9fSNsY/3IhfMtPmnabsg8TXPWwv/sBgWra/QPJBRsA3D+5KSR50h1RVah jU9cHSdEgYebYnO7h2Z+q91HDZTApnNnasNwfnNosxe90udt/zdxVXokum3mowozAWeg evLA== 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=A4wYdD6nZ0KYfJAb1chHbIs09SzFpNQ/ERx5d9j7fqQ=; b=2PtMVGjxzc7UBKioNGODbFerhTxXTjUACkAao732hNOETbFNTRgMibsWx85mL/uLhy b1KX0Y9Yzjy0t8R2JpFIpN2ZVavCk564MbZK0RGzEqYcyxPUdZZ5R4JetLbbJ1hqn4yO 9e+R5sRrz+wNMUAWZ75d5zTperBU1dH7JJeAngFQTiSFfMv7BWauE00kQAtuxUzYsdHH Lhacia3jKfWxX0iQQmIkXsZ5zvh3M1oO9Suwz0KtLlNvWWwrTKQXW7cJrHdHMMvZ7k3l SYBe8RudW9Do2lxOMLm8hiEmYyPY01TBI4ZMkt/rIQd/jKP9FpmByjl+QbQEmvTOC073 fLHQ== X-Gm-Message-State: AFqh2kqWPcXycle5P5olU2CM97OTPP96rmm5nq/D7E8Ioq9XObP9vL/a pFIliDdzo82iAJqciWvjF20xmOWlFArhqIrNtxQ= X-Google-Smtp-Source: AMrXdXv4hKGtWBPFRFwn4Hr7uhPFWZM3EK/wZXiiGh4uHefUOF6muYmX+0QxKhw0uyFAhkiqrvhCmw== X-Received: by 2002:a17:902:7c89:b0:188:59e2:5f91 with SMTP id y9-20020a1709027c8900b0018859e25f91mr47833567pll.59.1672856260544; Wed, 04 Jan 2023 10:17:40 -0800 (PST) Received: from tbs-1052-sim.qualcomm.com (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id x21-20020a17090300d500b00192fad60b72sm245270plc.222.2023.01.04.10.17.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 10:17:40 -0800 (PST) From: Ashish Sadanandan To: dev@dpdk.org Cc: Ashish Sadanandan , john.levon@nutanix.com, stable@dpdk.org Subject: [PATCH v3 1/1] eal/linux: reject --huge-dir not parent of mountpt Date: Wed, 4 Jan 2023 11:17:32 -0700 Message-Id: <20230104181732.514911-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, 11 insertions(+), 4 deletions(-) diff --git a/lib/eal/linux/eal_hugepage_info.c b/lib/eal/linux/eal_hugepage_info.c index a1b6cb31ff..e26e4d7a7a 100644 --- a/lib/eal/linux/eal_hugepage_info.c +++ b/lib/eal/linux/eal_hugepage_info.c @@ -214,6 +214,8 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len) char buf[BUFSIZ]; const struct internal_config *internal_conf = eal_get_internal_configuration(); + const size_t hugepage_dir_len = (internal_conf->hugepage_dir != NULL) ? + strlen(internal_conf->hugepage_dir) : 0; struct stat st; /* @@ -233,6 +235,7 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len) while (fgets(buf, sizeof(buf), fd)){ const char *pagesz_str; + size_t mountpt_len = 0; if (rte_strsplit(buf, sizeof(buf), splitstr, _FIELDNAME_MAX, split_tok) != _FIELDNAME_MAX) { @@ -265,12 +268,16 @@ get_hugepage_dir(uint64_t hugepage_sz, char *hugedir, int len) break; } + mountpt_len = strlen(splitstr[MOUNTPT]); + /* - * Ignore any mount that doesn't contain the --huge-dir - * directory. + * Ignore any mount that doesn't contain the --huge-dir directory + * or where mount point is not a parent path of --huge-dir */ if (strncmp(internal_conf->hugepage_dir, splitstr[MOUNTPT], - strlen(splitstr[MOUNTPT])) != 0) { + mountpt_len) != 0 || + (hugepage_dir_len > mountpt_len && + internal_conf->hugepage_dir[mountpt_len] != '/')) { continue; } @@ -278,7 +285,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