From: Sachin Sant <sachinp@linux.ibm.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v1 4/8] fs/acl: Add default ACL inheritance test
Date: Wed, 3 Jun 2026 12:27:40 +0530 [thread overview]
Message-ID: <20260603065744.47106-5-sachinp@linux.ibm.com> (raw)
In-Reply-To: <20260603065744.47106-1-sachinp@linux.ibm.com>
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 <sachinp@linux.ibm.com>
---
V1 changes:
- Use HAVE_LIBACL guards in .c code
- Report TCONF when libacl is not available
- rfc link https://lore.kernel.org/ltp/477836fd-80c8-4168-bfe6-00b374bb2534@linux.ibm.com/T/#t
---
runtest/fs | 1 +
testcases/kernel/fs/acl/.gitignore | 1 +
testcases/kernel/fs/acl/acl_inherit01.c | 118 ++++++++++++++++++++++++
3 files changed, 120 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..b9cf51525
--- /dev/null
+++ b/testcases/kernel/fs/acl/acl_inherit01.c
@@ -0,0 +1,118 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) IBM, 2026
+ *
+ * Original shell test by Kai Zhao (ltcd3@cn.ibm.com)
+ * Converted to C by Sachin Sant <sachinp@linux.ibm.com>
+ */
+
+/*\
+ * 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, file_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);
+
+ 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;
+ }
+
+ file_acl = acl_get_file(TESTFILE, ACL_TYPE_ACCESS);
+ if (!file_acl) {
+ cleanup_testfile();
+ tst_brk(TBROK | TERRNO, "acl_get_file failed");
+ }
+
+ safe_acl_free(file_acl);
+ 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
next prev parent reply other threads:[~2026-06-03 6:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-03 6:57 [LTP] [PATCH v2 0/8] Convert shell-based ACL test (tacl_xattr.sh) to C Sachin Sant
2026-06-03 6:57 ` [LTP] [PATCH v1 2/8] fs/acl: Add ACL mask interaction tests Sachin Sant
2026-06-03 6:57 ` [LTP] [PATCH v1 3/8] fs/acl: Add ACL_OTHER permissions test Sachin Sant
2026-06-03 6:57 ` Sachin Sant [this message]
2026-06-03 6:57 ` [LTP] [PATCH v1 5/8] fs/acl: Add chmod/chown ACL interaction tests Sachin Sant
2026-06-03 6:57 ` [LTP] [PATCH v2 6/8] fs/acl: Add symlink ACL operations test Sachin Sant
2026-06-03 6:57 ` [LTP] [PATCH v2 7/8] fs/acl: Add extended attributes test Sachin Sant
2026-06-03 6:57 ` [LTP] [PATCH v1 8/8] fs/acl: Remove old shell-based ACL test Sachin Sant
-- strict thread matches above, loose matches on Subject: below --
2026-06-02 12:19 [LTP] [PATCH v1 0/8] Convert shell-based ACL test (tacl_xattr.sh) to C Sachin Sant
2026-06-02 12:19 ` [LTP] [PATCH v1 4/8] fs/acl: Add default ACL inheritance test Sachin Sant
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260603065744.47106-5-sachinp@linux.ibm.com \
--to=sachinp@linux.ibm.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox