[LTP] [PATCH v3 03/11] Added three more SAFE_* macros for landlock sandbox:
Andrea Cervesato
andrea.cervesato@suse.de
Thu Jul 11 13:18:14 CEST 2024
From: Andrea Cervesato <andrea.cervesato@suse.com>
- SAFE_LANDLOCK_CREATE_RULESET
- SAFE_LANDLOCK_ADD_RULE
- SAFE_LANDLOCK_RESTRICT_SELF
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/lapi/landlock.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
diff --git a/include/lapi/landlock.h b/include/lapi/landlock.h
index 2ee51b340..6d85eb12e 100644
--- a/include/lapi/landlock.h
+++ b/include/lapi/landlock.h
@@ -12,6 +12,8 @@
# include <linux/landlock.h>
#endif
+#include "lapi/syscalls.h"
+
#ifndef HAVE_STRUCT_LANDLOCK_RULESET_ATTR
struct landlock_ruleset_attr
{
@@ -120,4 +122,63 @@ struct landlock_net_port_attr
# define LANDLOCK_ACCESS_NET_CONNECT_TCP (1ULL << 1)
#endif
+static inline int safe_landlock_create_ruleset(const char *file, const int lineno,
+ const struct landlock_ruleset_attr *attr,
+ size_t size , uint32_t flags)
+{
+ int rval;
+
+ rval = tst_syscall(__NR_landlock_create_ruleset, attr, size, flags);
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "landlock_create_ruleset(%p, %lu, %u)",
+ attr, size, flags);
+ }
+
+ return rval;
+}
+
+static inline int safe_landlock_add_rule(const char *file, const int lineno,
+ int ruleset_fd, enum landlock_rule_type rule_type,
+ const void *rule_attr, uint32_t flags)
+{
+ int rval;
+
+ rval = tst_syscall(__NR_landlock_add_rule,
+ ruleset_fd, rule_type, rule_attr, flags);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "landlock_add_rule(%d, %d, %p, %u)",
+ ruleset_fd, rule_type, rule_attr, flags);
+ }
+
+ return rval;
+}
+
+static inline int safe_landlock_restrict_self(const char *file, const int lineno,
+ int ruleset_fd, int flags)
+{
+ int rval;
+
+ rval = tst_syscall(__NR_landlock_restrict_self, ruleset_fd, flags);
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "landlock_restrict_self(%d, %u)",
+ ruleset_fd, flags);
+ }
+
+ return rval;
+}
+
+#define SAFE_LANDLOCK_CREATE_RULESET(attr, size, flags) \
+ safe_landlock_create_ruleset(__FILE__, __LINE__, (attr), (size), (flags))
+
+#define SAFE_LANDLOCK_ADD_RULE(ruleset_fd, rule_type, rule_attr, flags) \
+ safe_landlock_add_rule(__FILE__, __LINE__, \
+ (ruleset_fd), (rule_type), (rule_attr), (flags))
+
+#define SAFE_LANDLOCK_RESTRICT_SELF(ruleset_fd, flags) \
+ safe_landlock_restrict_self(__FILE__, __LINE__, (ruleset_fd), (flags))
+
#endif
--
2.43.0
More information about the ltp
mailing list