From patchwork Fri Nov 15 00:38:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ihor Solodrai X-Patchwork-Id: 13875792 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20FB263B9 for ; Fri, 15 Nov 2024 00:39:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.43.22 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731631150; cv=none; b=cI/rGATYlHol2ba0JLn2S4qUzhIgL900wBUgO/Vwln+rXtI32pqwoUCKd+sW5WoyYLvOGh4TVsD1GTDCUI3YSMeI1pKbQnEGxUy+jldqY4kLIZGRfs7dVKkyGAprbT2y9wEaFRHer2Cvps3O1XlfR466K7xcIIOrK2D5ajMpkCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731631150; c=relaxed/simple; bh=xqVTrsJgaqYLpCuVFY8b5Yeks6WAioT3ytYzblQoCLs=; h=Date:To:From:Cc:Subject:Message-ID:MIME-Version:Content-Type; b=ErCjEgTKQDJEUMdQZtvZ8Nl0gbRMW1+FCofFg8pXKF2jrIe+W8Atl/zqWdFWKrOg55MDvygf7E/fj7WsnMa3p3wIAOCs1P3R6URfezVRavoIuDEfWYyk9ZCg05h7NEKoEqegFafwiS6U5kX7tb9g0LkV1yyyVB0VnEHbwxG3uaw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me; spf=pass smtp.mailfrom=pm.me; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b=cG/R3c/S; arc=none smtp.client-ip=185.70.43.22 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pm.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pm.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pm.me header.i=@pm.me header.b="cG/R3c/S" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail3; t=1731631141; x=1731890341; bh=xqVTrsJgaqYLpCuVFY8b5Yeks6WAioT3ytYzblQoCLs=; h=Date:To:From:Cc:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector: List-Unsubscribe:List-Unsubscribe-Post; b=cG/R3c/SzOZLaOi56Im1pHa963Dw1uxyuVnQHtGkQFHsyXd8WEy3Syq5oSNHW9ph8 F9S1fw2W6nkBzCRSuihHkUf9UBSpe0yyo0NMrTQJHquMZ+f0KE6WkVvs8d+M8MUdhq 1mXCaWlFMnaFZ4BQkMm+tUdEHgTbWehmNrD0O44IkOimLf9lMTwJdMJHB+hiCEYYLe 8MWD37MgPrs0UH/ULtdDOm6rNCM+cBBuKaBCZlpv15MpgtFvAVXQqp+jEVwuFy3C09 hzSh1bMJX3QoaBd8Se+lomWtXhHUm0WVzUuNHP9m2hGSHgYa3VHWmYWKygEDGRG5+F 2UKJzFnT9XsJA== Date: Fri, 15 Nov 2024 00:38:55 +0000 To: bpf@vger.kernel.org, andrii@kernel.org From: Ihor Solodrai Cc: ast@kernel.org, daniel@iogearbox.net, eddyz87@gmail.com, mykolal@fb.com Subject: [PATCH bpf-next] selftests/bpf: set test path for token/obj_priv_implicit_token_envvar Message-ID: <20241115003853.864397-1-ihor.solodrai@pm.me> Feedback-ID: 27520582:user:proton X-Pm-Message-ID: 0425275de50b34d359522147cbb07ae0e9d29707 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: bpf@iogearbox.net token/obj_priv_implicit_token_envvar test may fail in an environment where the process executing tests can not write to the root path. Example: https://github.com/libbpf/libbpf/actions/runs/11844507007/job/33007897936 Change default path used by the test to /tmp/bpf-token-fs, and make it runtime configurable via an environment variable. Signed-off-by: Ihor Solodrai --- tools/testing/selftests/bpf/prog_tests/token.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/token.c b/tools/testing/selftests/bpf/prog_tests/token.c index fe86e4fdb89c..39f5414b674b 100644 --- a/tools/testing/selftests/bpf/prog_tests/token.c +++ b/tools/testing/selftests/bpf/prog_tests/token.c @@ -828,8 +828,11 @@ static int userns_obj_priv_btf_success(int mnt_fd, struct token_lsm *lsm_skel) return validate_struct_ops_load(mnt_fd, true /* should succeed */); } +static const char* token_bpffs_custom_dir() { + return getenv("BPF_SELFTESTS_BPF_TOKEN_DIR") ? : "/tmp/bpf-token-fs"; +} + #define TOKEN_ENVVAR "LIBBPF_BPF_TOKEN_PATH" -#define TOKEN_BPFFS_CUSTOM "/bpf-token-fs" static int userns_obj_priv_implicit_token(int mnt_fd, struct token_lsm *lsm_skel) { @@ -892,6 +895,7 @@ static int userns_obj_priv_implicit_token(int mnt_fd, struct token_lsm *lsm_skel static int userns_obj_priv_implicit_token_envvar(int mnt_fd, struct token_lsm *lsm_skel) { + const char *custom_dir = token_bpffs_custom_dir(); LIBBPF_OPTS(bpf_object_open_opts, opts); struct dummy_st_ops_success *skel; int err; @@ -909,10 +913,10 @@ static int userns_obj_priv_implicit_token_envvar(int mnt_fd, struct token_lsm *l * BPF token implicitly, unless pointed to it through * LIBBPF_BPF_TOKEN_PATH envvar */ - rmdir(TOKEN_BPFFS_CUSTOM); - if (!ASSERT_OK(mkdir(TOKEN_BPFFS_CUSTOM, 0777), "mkdir_bpffs_custom")) + rmdir(custom_dir); + if (!ASSERT_OK(mkdir(custom_dir, 0777), "mkdir_bpffs_custom")) goto err_out; - err = sys_move_mount(mnt_fd, "", AT_FDCWD, TOKEN_BPFFS_CUSTOM, MOVE_MOUNT_F_EMPTY_PATH); + err = sys_move_mount(mnt_fd, "", AT_FDCWD, custom_dir, MOVE_MOUNT_F_EMPTY_PATH); if (!ASSERT_OK(err, "move_mount_bpffs")) goto err_out; @@ -925,7 +929,7 @@ static int userns_obj_priv_implicit_token_envvar(int mnt_fd, struct token_lsm *l goto err_out; } - err = setenv(TOKEN_ENVVAR, TOKEN_BPFFS_CUSTOM, 1 /*overwrite*/); + err = setenv(TOKEN_ENVVAR, custom_dir, 1 /*overwrite*/); if (!ASSERT_OK(err, "setenv_token_path")) goto err_out; @@ -951,11 +955,11 @@ static int userns_obj_priv_implicit_token_envvar(int mnt_fd, struct token_lsm *l if (!ASSERT_ERR(err, "obj_empty_token_path_load")) goto err_out; - rmdir(TOKEN_BPFFS_CUSTOM); + rmdir(custom_dir); unsetenv(TOKEN_ENVVAR); return 0; err_out: - rmdir(TOKEN_BPFFS_CUSTOM); + rmdir(custom_dir); unsetenv(TOKEN_ENVVAR); return -EINVAL; }