[PATCH v3 4/8] fs/acl: Add default ACL inheritance test
Sachin Sant <[email protected]>
| Newsgroups | gmane.linux.ltp |
|---|---|
| Message-ID | <[email protected]> |
Add acl_inherit01 test to validate default ACL inheritance from parent directory to newly created files. The test verifies that: - Default ACLs set on a directory are inherited by new files - New file permissions reflect the default ACL entries - File created with umask 0 gets permissions from default ACL This test sets default ACL with read-only permissions (r--r--r--) on the parent directory, creates a new file with umask 0, and verifies the file has 0444 permissions inherited from the default ACL. Signed-off-by: Sachin Sant <[email protected]> --- V3 changes: - Remove unused acl_get_file() block - keep mode-bit validation with explanatory comment - v2 link https://lore.kernel.org/ltp/[email protected]/T/#t V2 changes: - Updated copyright header as per LTP format. - v1 link https://lore.kernel.org/ltp/[email protected]/T/#t V1 changes: - Use HAVE_LIBACL guards in .c code - Report TCONF when libacl is not available - rfc link https://lore.kernel.org/ltp/[email protected]/T/#t --- runtest/fs | 1 + testcases/kernel/fs/acl/.gitignore | 1 + testcases/kernel/fs/acl/acl_inherit01.c | 116 ++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 testcases/kernel/fs/acl/acl_inherit01.c diff --git a/runtest/fs b/runtest/fs index f25487a33..fd295edc7 100644 --- a/runtest/fs +++ b/runtest/fs @@ -92,3 +92,4 @@ squashfs01 squashfs01 acl_user_obj01 acl_user_obj01 acl_mask01 acl_mask01 acl_other01 acl_other01 +acl_inherit01 acl_inherit01 diff --git a/testcases/kernel/fs/acl/.gitignore b/testcases/kernel/fs/acl/.gitignore index c3ec0fad3..bc03ba1fd 100644 --- a/testcases/kernel/fs/acl/.gitignore +++ b/testcases/kernel/fs/acl/.gitignore @@ -1,3 +1,4 @@ /acl_user_obj01 /acl_mask01 /acl_other01 +/acl_inherit01 diff --git a/testcases/kernel/fs/acl/acl_inherit01.c b/testcases/kernel/fs/acl/acl_inherit01.c new file mode 100644 index 000000000..eabfc4bd1 --- /dev/null +++ b/testcases/kernel/fs/acl/acl_inherit01.c @@ -0,0 +1,116 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2026 IBM + * + * Original shell test by Kai Zhao ([email protected]) + * Converted to C by Sachin Sant <[email protected]> + */ + +/*\ + * Test default ACL inheritance. + * + * Verify that files created in a directory with default ACLs inherit + * those ACLs as their access ACLs. Default ACLs are only applicable + * to directories and define the access ACLs that files and subdirectories + * created within that directory will inherit. + * + * [Algorithm] + * + * 1. Set default ACL on parent directory with read-only permissions + * 2. Create a new file in that directory with umask 0 + * 3. Verify the file inherits the default ACL as its access ACL + * 4. Check that file permissions match the inherited ACL (0444) + */ + +#include "acl_lib.h" + +uid_t user1_uid, user2_uid, user3_uid; +gid_t user1_gid, user2_gid, user3_gid; +int users_created = 0; + +#ifdef HAVE_LIBACL + +static void run(void) +{ + acl_t acl; + struct stat st; + int err; + + tst_res(TINFO, "Testing default ACL inheritance"); + reset_test_path(); + + acl = acl_init(3); + if (!acl) + tst_brk(TBROK | TERRNO, "acl_init failed"); + + add_acl_entry(acl, ACL_USER_OBJ, ACL_READ); + add_acl_entry(acl, ACL_GROUP_OBJ, ACL_READ); + add_acl_entry(acl, ACL_OTHER, ACL_READ); + + set_acl_file(TESTDIR, ACL_TYPE_DEFAULT, acl); + safe_acl_free(acl); + + err = create_with_umask_as(user1_uid, user1_gid, 0666, 0); + if (err) { + errno = err; + tst_res(TFAIL | TERRNO, "Failed to create test file"); + return; + } + + SAFE_STAT(TESTFILE, &st); + + /* + * For a minimal ACL (containing only ACL_USER_OBJ, ACL_GROUP_OBJ, + * and ACL_OTHER), the mode bits are the canonical representation. + * Verifying the mode bits confirms the inherited ACL was applied. + */ + if ((st.st_mode & 0777) != 0444) { + tst_res(TFAIL, + "File permissions 0%o, expected 0444 from default ACL", + st.st_mode & 0777); + cleanup_testfile(); + return; + } + + cleanup_testfile(); + tst_res(TPASS, "Default ACL inheritance works correctly"); +} + +static void setup(void) +{ + init_test_users(); + reset_test_path(); +} + +static void cleanup(void) +{ + cleanup_test_paths(); + cleanup_test_users(); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .needs_root = 1, + .mount_device = 1, + .mntpoint = MNTPOINT, + .forks_child = 1, + .filesystems = (struct tst_fs[]) { + {.type = "ext2", .mnt_data = "acl"}, + {.type = "ext3", .mnt_data = "acl"}, + {.type = "ext4", .mnt_data = "acl"}, + {.type = "xfs"}, + {.type = "btrfs"}, + {} + }, + .needs_cmds = (struct tst_cmd[]) { + {.cmd = "useradd"}, + {.cmd = "userdel"}, + {} + } +}; + +#else +TST_TEST_TCONF("libacl or ACL headers are not available"); +#endif -- 2.39.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp