aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/filesystems/utils.c
diff options
context:
space:
mode:
authorChristian Brauner <[email protected]>2025-02-19 10:01:52 +0000
committerChristian Brauner <[email protected]>2025-02-19 13:32:12 +0000
commita1579f6bf657d3906de47819e8fd773e2452de0f (patch)
tree566876ff4c47e603c2592214c6c5ab50170541f4 /tools/testing/selftests/filesystems/utils.c
parentselftests/ovl: add second selftest for "override_creds" (diff)
downloadkernel-a1579f6bf657d3906de47819e8fd773e2452de0f.tar.gz
kernel-a1579f6bf657d3906de47819e8fd773e2452de0f.zip
selftests/ovl: add third selftest for "override_creds"
Add a simple test to verify that the new "override_creds" option works. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Amir Goldstein <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
Diffstat (limited to 'tools/testing/selftests/filesystems/utils.c')
-rw-r--r--tools/testing/selftests/filesystems/utils.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/testing/selftests/filesystems/utils.c b/tools/testing/selftests/filesystems/utils.c
index 0e8080bd0aea..e553c89c5b19 100644
--- a/tools/testing/selftests/filesystems/utils.c
+++ b/tools/testing/selftests/filesystems/utils.c
@@ -472,3 +472,30 @@ out:
cap_free(caps);
return fret;
}
+
+/* cap_down - lower an effective cap */
+int cap_down(cap_value_t down)
+{
+ bool fret = false;
+ cap_t caps = NULL;
+ cap_value_t cap = down;
+ int ret = -1;
+
+ caps = cap_get_proc();
+ if (!caps)
+ goto out;
+
+ ret = cap_set_flag(caps, CAP_EFFECTIVE, 1, &cap, 0);
+ if (ret)
+ goto out;
+
+ ret = cap_set_proc(caps);
+ if (ret)
+ goto out;
+
+ fret = true;
+
+out:
+ cap_free(caps);
+ return fret;
+}