From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (unknown [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 89FF8802A5 for ; Tue, 6 Oct 2026 22:18:23 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 696MHApZ028414; Wed, 7 Oct 2026 01:17:11 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 696MHApZ028414 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="O2Ps7UZF" Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 696MH9KI028403 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Wed, 7 Oct 2026 01:17:10 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 696MH9KI028403 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4a028616bebso28527495e9.1 for ; Tue, 06 Oct 2026 15:17:10 -0700 (PDT) X-Gm-Message-State: AFuF++mrs9f54GwImhPgYF+1OKzmS1Tv3LZ8BXgmCdpCae/BySQtQYSr vdaL7pg7IZGN/lEiaOtLDjq2jrYekri43jRVOyCeJPCCHGGNUfl6mBm943nfY8FlHdvdVB3yPEl cLoqcsI7O90UIyI3GhI2ckzhV9CKgTUW0pKDr4p0N3QCrsBGUtP0q7Q== X-Gm-Gg: AYBFou3Ap+9BbJfkZ1A1ODQERRQhM8ePp6hP1CqKTRuYDyGPT6qWVbdPG4YzbcOM9Rl oq2kBthGeFxTAa/OhVIc+KjCF735XdEG5w9MCWX6bP5hRx75drol9ozhZhtkeXTHY1h/EUI50dV N/NcRCn2IJb+omSzWhkchI3t6iGK8zOULI9+yc31LHDTDmnZ5WXIeWuOzN14cuoAByexvEcd4Do ZSFY2Hntn1ACkA4xdGdeSK0CCJHW8nanvJVDVmY2M6zE9dxATGuQkK2rHtChxBy2Qd1VmAEOK7s lD0NuTeL3aomEFP7vNUkoQJq9GWSuboL/0aLTDsFUOhGeyllnq9Md4a4OyP5sIuL0XP9wkUrJ8R gFHg6rGp4qDQyVDyUBVCrBlIBdA== X-Received: by 2002:a05:600c:4694:b0:4a0:1fe2:d4f1 with SMTP id 5b1f17b1804b1-4a1806483ddmr2845215e9.28.1791325029699; Tue, 06 Oct 2026 15:17:09 -0700 (PDT) X-Received: by 2002:a05:600c:4694:b0:4a0:1fe2:d4f1 with SMTP id 5b1f17b1804b1-4a1806483ddmr2845025e9.28.1791325029273; Tue, 06 Oct 2026 15:17:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1791325029; cv=none; d=google.com; s=arc-20260327; b=qVqS8ix85tHmg4HjdjgXYnNXF5k7Gyd7tGMurxJy8yEg4ujCGWt8Kex9zwAHzYBC/u r6gE9u+nc6fuXNcfXLTCKZ1DPcf5UaZgWpGuhPPYGgy07dmfIkSJEyMWtlOM2j4Nkc0x baPnKfvIsH6tpIMuNjLvwz6VczHD5B944MjZ853w3sTNIzMqGwe9gku7K8lstH4ZdvSJ R/smZgULchNntfxFn0RIYhFnYV2Ip7FUooVo/Hp/TekQ6ebfh51yKagnUTdX8r8XN7QX B4t4L7o2auGy8yN1EopjtIKUss/0VVyPiBBt2YHs8VnTH7t8OyokdQFzLI+SnyFQ1H6v ranw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=AbJjJkZeZ8aXRApFhbeRL22S5TP0KxCI1qW24wg8cgQ=; fh=WpT6aB7RBAGHZeWZzqAr71yzRFbPTYkPWKsRagLn48Q=; b=TrLP2uKLG/qyl5OS5nd5vympTzFP/QbTnpbTRkKY+dpl+NmgrHj8zAJqX7HlHbD5Ss 8eA9Evuu9zuXb7IEfj6+IuJGbKEbZQLutIr8wASWA2/jaWmf2OvQ1z74YGgcIQeIgcoD m0ker/A0PUY70ug3vSvGoNfIzw8VsibqXWc7TD9f025aVmhaHTHjZcU0ppza6em5o4vV D8VSE9WuAkeOJa2BrNaTmnAPgunhM2TS0ZfkG77UGDQSTxXJYlT1rh56qOTLv2dwcZbG rpaysumZAnihYiE8o6l4w70IWOhat2yRZUJ7jpCjM1WK0osbRhW5zin2dJST6NggiGOy if+w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=O2Ps7UZF; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-48c72467a30si1501971f8f.72.2026.10.06.15.17.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Oct 2026 15:17:09 -0700 (PDT) Received-SPF: pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=O2Ps7UZF; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=AbJjJkZeZ8aXRApFhbeRL22S5TP0KxCI1qW24wg8cgQ=; b=O2Ps7UZFK1N/ hO/dd54wZOGtztH5Q9nLF9pyRGr6L3xBZ9JNRY5nQnxvmjGDH7saxbuFLblMZThTUt2rSPu/5O7ei 7OYN9qTi4dU9ke+Wsrf4a10QcUCGNiNDdwhHrXWUU7T8GgVmEIwbhxK1v2vap04tsPhhzj6uWWXz4 kAl+jiULhfq0tEFaOYksCv67RPU4aeAP/ieoZILUQ7qBKxA2rYF0vHh2EKC/loqgJKEGBq76OEGwb gZejIkg00Yaf1MiKti1poI3rhPpytXL01O7S+Pr3nQZ1vbLVrrcuWqoleWCQ256jBVgZ/1z3kmWuA QllVJIBm9XVrwnehkkJqhw==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=LekKit-T14) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xEDPv-004f1D-21; Wed, 07 Oct 2026 00:16:58 +0200 From: Eva Kurchatova To: khorenko@virtuozzo.com Date: Wed, 7 Oct 2026 01:15:50 +0300 Message-ID: <20261006221704.2507107-2-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261006221704.2507107-1-eva.kurchatova@virtuozzo.com> References: <20261006221704.2507107-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v7 1/2] selftests: ve: grant the directories the files sit in X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org The sysfs variant names nested leaves, kernel/vmcoreinfo and kernel/notes, while the proc one names files at the top of the filesystem. Both enforcement tests grant the leaves and nothing else, so in the sysfs case the lookup stops at /sys/kernel, which a fresh VE cannot traverse, and every open answers ENOENT. Grant x on each directory along the way, taken from the path the variant already gives. set_entry() gets a PATH_MAX buffer and fails on truncation instead of writing a cut entry, as ve_open_rel() does. Fixes: 303ce49b7446 ("selftests/ve: add ve_perms test for proc and sysfs") https://virtuozzo.atlassian.net/browse/VSTOR-144955 Feature: fix selftests Signed-off-by: Eva Kurchatova --- tools/testing/selftests/ve/ve_perms_test.c | 34 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/ve/ve_perms_test.c b/tools/testing/selftests/ve/ve_perms_test.c index 25ffbd42c380..8096b1fa3b43 100644 --- a/tools/testing/selftests/ve/ve_perms_test.c +++ b/tools/testing/selftests/ve/ve_perms_test.c @@ -114,9 +114,11 @@ static int ve_open_rel(int cgv2_fd, int ctid, const char *prefix, static int set_entry(int cgv2_fd, const char *path, const char *entry, const char *mask) { - char line[256]; + char line[PATH_MAX]; - snprintf(line, sizeof(line), "%s %s", entry, mask); + if (snprintf(line, sizeof(line), "%s %s", entry, mask) >= + (int)sizeof(line)) + return -1; return write_file_at(cgv2_fd, path, line); } @@ -343,6 +345,32 @@ TEST_F(ve_perms, write_parser) EXPECT_LT(write_file_at(self->cgv2_fd, path, file), 0); } +/* A leaf is reachable only once every directory above it can be traversed */ +static int allow_path(int cgv2_fd, const char *path, const char *file) +{ + char dir[PATH_MAX]; + const char *sep; + + for (sep = strchr(file, '/'); sep; sep = strchr(sep + 1, '/')) { + if (snprintf(dir, sizeof(dir), "%.*s", (int)(sep - file), + file) >= (int)sizeof(dir)) + return -1; + if (set_entry(cgv2_fd, path, dir, "x") < 0) + return -1; + } + return 0; +} + +static int allow_paths(int cgv2_fd, const char *path, const char *const files[]) +{ + int i; + + for (i = 0; i < NR_FILES; i++) + if (allow_path(cgv2_fd, path, files[i]) < 0) + return -1; + return 0; +} + /* * Enforcement, allowed side: from inside a VE, granting r lets each file be * read, and granting x on the directory lets it be traversed (the lookup then @@ -358,6 +386,7 @@ TEST_F(ve_perms, enforce_allows) ve_file(path, sizeof(path), self->ctid_a, variant->fs); + ASSERT_EQ(allow_paths(self->cgv2_fd, path, variant->files), 0); ASSERT_EQ(set_entries(self->cgv2_fd, path, variant->files, "r"), 0); for (i = 0; i < NR_FILES; i++) EXPECT_EQ(ve_open_rel(self->cgv2_fd, self->ctid_a, @@ -400,6 +429,7 @@ TEST_F(ve_perms, enforce_denies) O_RDONLY), 0); /* Granted w only: visible but not readable. */ + ASSERT_EQ(allow_paths(self->cgv2_fd, path, variant->files), 0); ASSERT_EQ(set_entries(self->cgv2_fd, path, variant->files, "w"), 0); for (i = 0; i < NR_FILES; i++) EXPECT_EQ(ve_open_rel(self->cgv2_fd, self->ctid_a, -- 2.56.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel