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 8509980726 for ; Thu, 8 Oct 2026 03:55:00 +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 6983remC019086; Thu, 8 Oct 2026 06:53:41 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6983remC019086 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="ZYK7vOQp" Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6983rcmN019074 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 8 Oct 2026 06:53:39 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6983rcmN019074 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-48b00febba3so3196487f8f.1 for ; Wed, 07 Oct 2026 20:53:39 -0700 (PDT) X-Gm-Message-State: AFq9FYKkyJiGwwgYtrfn8dq6mCCjmzOMeMp8Dwd1Zpwa3eYo8PU1GFnq t6CD2ZEo4Pg+AcLuO/p+uQGvITz0gJeZqz66AWcKfLL/oJcMMq+cewHbWBEBxYPTGZ22EE2r3Bv bpDz676UAYoeVLd7Yes3rtU4eH24nyeDZS2HDgipUIm7EP9hYH2It2Q== X-Gm-Gg: AYBFou3Y1390unEr11FjSiXl5OQSaAqdrknmxq6WZBvNc90CRVkMfqJFmNNmEB+D2tG fD/FEx/nTaFcUIkLjSsW0B09/X2weMVdBuJRXTzANjhdK6gvcCPgocvABzE6vDEnJ3ZCT/xrKgt 5VO9u0sPwu2ncoGmyUVhLqwBrQ/t2rVNyFvpaIHETiPXIWMlxwKX2HKxztMNulNe5iq34K9qi6s Fqypye1hebz5T9zCJYvuBSkXokKDDCEefr174F+QhQZPfjutw+zElT3rTqiEHBlBf9AUt4egvvp gbrdkXteje05FscEnVslyEEcFHMCeMbXeKhoQUXI0bsuUJuAKc3OoRR9hl4AaeuRn/7zs5/iwyv 3yB6dkXXUSpjpAqK3r5rd0C1a X-Received: by 2002:a05:6000:4211:b0:488:844f:6034 with SMTP id ffacd0b85a97d-48c72890e64mr7620056f8f.48.1791431618666; Wed, 07 Oct 2026 20:53:38 -0700 (PDT) X-Received: by 2002:a05:6000:4211:b0:488:844f:6034 with SMTP id ffacd0b85a97d-48c72890e64mr7620036f8f.48.1791431618286; Wed, 07 Oct 2026 20:53:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1791431618; cv=none; d=google.com; s=arc-20260327; b=T7RXqZKd2ran4bTVSFRIXVyn+ZnftCgyrOqh7sjWBeliwFBbpEKDFHvkZNAeC+XtV5 jx3foha06iRv0iDA56ecip/zd3HAxtwKp1lVE/v8w2qWWyQjIPkzCHEbYv5vEqfs+5ov UYcn04u2ry7A0BJVW20l//yAP82bM7nzDrQNfwUxsgDuKZ15n80GaYlDT9bY1TUMKjNN /QY6c8k3mDeNLLrLKMUrJ2rslng71trBqktNCQeM5MtGbJPv7NXeVDvdvrGlIj/MgLyP zsXEPm20eC10O/rVI+bk6FD85BSli1gtLLPUX7P9PCqarAzJjFvEjh2lzaF5SCUlMiiZ CwPA== 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=VuvqbIVShxksG7Ia5xRoCJJs7tWkOee497F4hriY6SA=; fh=WpT6aB7RBAGHZeWZzqAr71yzRFbPTYkPWKsRagLn48Q=; b=sfAF8hj0ODooW7/mGYiYuH5LFHqdOOijQ0qaciLo8dGPbXqrO8mPT4FVIYmUYr5ALb Vp6CFYmLtN8HzwtuM0JbftnTsAazpONYolMCs3PPDIcCd0KzPeLbJLySidofE+DkQqAZ RFtl6Xl1Eac6IuB8B3D2C7/a1GryU9xGnYlPj/CIgK8ND70EvO5eXDTpUQBaqjwHnRzW NTv9YZY2digdd2M7aRK+h5rA4hVk9OuXRDX65wiPtqaDYtmt624sQzNc7bUUZuOpImJ1 By1TwAnrDlaUoD4ORqxB4vZdYJrSZ7yx+kHutImL498E/9YTMuAFoFNox3tTqSUy6d8L /U3w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=ZYK7vOQp; 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-48c76a80c35si5715975f8f.257.2026.10.07.20.53.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2026 20:53:38 -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=ZYK7vOQp; 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=VuvqbIVShxksG7Ia5xRoCJJs7tWkOee497F4hriY6SA=; b=ZYK7vOQpwjsZ xCKx4yit/dI8uuLwkXf+JLKjFaf3qtI0xud2Klp2hRe3v/ULJmngFBq01y3smVLBrZgT9rm3AjJmv RO0bNM/wDJ93m2skkMA7hTRzwCvdaioxJ36MMj6S7c1mKDihaEtSgBi3NJdiJyMDR8Rqw5dkrC9nt 42TJKZl1gMz3CDGdD1ojHBdIP9rp3oZ9Jv6xN0mbtI+ZDxaJCI+wcReCXykF8/Pl4Qa9qNDXXORSd uzSmFynt042/argkDUfXtw1bFTKpgomSU7Uog7YTVSNnzMeI9/gIXIYPGDUqoV/3B93gwYdrWZ5Ez uqET2In/EA/TIvbsKXCs9w==; 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 1xEf94-003Uck-2O; Thu, 08 Oct 2026 05:53:36 +0200 From: Eva Kurchatova To: khorenko@virtuozzo.com Date: Thu, 8 Oct 2026 06:52:18 +0300 Message-ID: <20261008035335.2823931-2-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261008035335.2823931-1-eva.kurchatova@virtuozzo.com> References: <20261008035335.2823931-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v8 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: not ok 14 ve_perms.sysfs.enforce_allows not ok 15 ve_perms.sysfs.enforce_denies 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