From: Andrea Cervesato <andrea.cervesato@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 5/5] Add error coverage for landlock network support
Date: Thu, 19 Sep 2024 12:23:11 +0200 [thread overview]
Message-ID: <20240919-landlock_network-v1-5-9c997f03bd0a@suse.com> (raw)
In-Reply-To: <20240919-landlock_network-v1-0-9c997f03bd0a@suse.com>
From: Andrea Cervesato <andrea.cervesato@suse.com>
Add two more errors checks inside the landlock02 which is testing
landlock_add_rule syscall. In particular, test now verifies when the
syscall is raising EINVAL due to invalid network attributes.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/syscalls/landlock/landlock02.c | 71 +++++++++++++++++++------
1 file changed, 55 insertions(+), 16 deletions(-)
diff --git a/testcases/kernel/syscalls/landlock/landlock02.c b/testcases/kernel/syscalls/landlock/landlock02.c
index bdef57b55..56ed9c00c 100644
--- a/testcases/kernel/syscalls/landlock/landlock02.c
+++ b/testcases/kernel/syscalls/landlock/landlock02.c
@@ -23,22 +23,26 @@
static struct tst_landlock_ruleset_attr *ruleset_attr;
static struct landlock_path_beneath_attr *path_beneath_attr;
static struct landlock_path_beneath_attr *rule_null;
+static struct landlock_net_port_attr *net_port_attr;
static int ruleset_fd;
static int invalid_fd = -1;
static struct tcase {
int *fd;
int rule_type;
- struct landlock_path_beneath_attr **attr;
+ struct landlock_path_beneath_attr **path_attr;
+ struct landlock_net_port_attr **net_attr;
int access;
int parent_fd;
+ int net_port;
uint32_t flags;
int exp_errno;
char *msg;
} tcases[] = {
{
.fd = &ruleset_fd,
- .attr = &path_beneath_attr,
+ .path_attr = &path_beneath_attr,
+ .net_attr = NULL,
.access = LANDLOCK_ACCESS_FS_EXECUTE,
.flags = 1,
.exp_errno = EINVAL,
@@ -46,7 +50,8 @@ static struct tcase {
},
{
.fd = &ruleset_fd,
- .attr = &path_beneath_attr,
+ .path_attr = &path_beneath_attr,
+ .net_attr = NULL,
.access = LANDLOCK_ACCESS_FS_EXECUTE,
.exp_errno = EINVAL,
.msg = "Invalid rule type"
@@ -54,13 +59,15 @@ static struct tcase {
{
.fd = &ruleset_fd,
.rule_type = LANDLOCK_RULE_PATH_BENEATH,
- .attr = &path_beneath_attr,
+ .path_attr = &path_beneath_attr,
+ .net_attr = NULL,
.exp_errno = ENOMSG,
.msg = "Empty accesses"
},
{
.fd = &invalid_fd,
- .attr = &path_beneath_attr,
+ .path_attr = &path_beneath_attr,
+ .net_attr = NULL,
.access = LANDLOCK_ACCESS_FS_EXECUTE,
.exp_errno = EBADF,
.msg = "Invalid file descriptor"
@@ -68,7 +75,8 @@ static struct tcase {
{
.fd = &ruleset_fd,
.rule_type = LANDLOCK_RULE_PATH_BENEATH,
- .attr = &path_beneath_attr,
+ .path_attr = &path_beneath_attr,
+ .net_attr = NULL,
.access = LANDLOCK_ACCESS_FS_EXECUTE,
.parent_fd = -1,
.exp_errno = EBADF,
@@ -77,26 +85,56 @@ static struct tcase {
{
.fd = &ruleset_fd,
.rule_type = LANDLOCK_RULE_PATH_BENEATH,
- .attr = &rule_null,
+ .path_attr = &rule_null,
+ .net_attr = NULL,
.exp_errno = EFAULT,
.msg = "Invalid rule attr"
},
+ {
+ .fd = &ruleset_fd,
+ .rule_type = LANDLOCK_RULE_NET_PORT,
+ .path_attr = NULL,
+ .net_attr = &net_port_attr,
+ .access = LANDLOCK_ACCESS_FS_EXECUTE,
+ .net_port = 448,
+ .exp_errno = EINVAL,
+ .msg = "Invalid access rule for network type"
+ },
+ {
+ .fd = &ruleset_fd,
+ .rule_type = LANDLOCK_RULE_NET_PORT,
+ .path_attr = NULL,
+ .net_attr = &net_port_attr,
+ .access = LANDLOCK_ACCESS_NET_BIND_TCP,
+ .net_port = INT16_MAX + 1,
+ .exp_errno = EINVAL,
+ .msg = "Socket port greater than 65535"
+ },
};
static void run(unsigned int n)
{
struct tcase *tc = &tcases[n];
- if (*tc->attr) {
- (*tc->attr)->allowed_access = tc->access;
- (*tc->attr)->parent_fd = tc->parent_fd;
- }
+ if (tc->path_attr) {
+ if (*tc->path_attr) {
+ (*tc->path_attr)->allowed_access = tc->access;
+ (*tc->path_attr)->parent_fd = tc->parent_fd;
+ }
+
+ TST_EXP_FAIL(tst_syscall(__NR_landlock_add_rule,
+ *tc->fd, tc->rule_type, *tc->path_attr, tc->flags),
+ tc->exp_errno, "%s", tc->msg);
+ } else if (tc->net_attr) {
+ if (*tc->net_attr) {
+ (*tc->net_attr)->allowed_access = tc->access;
+ (*tc->net_attr)->port = tc->net_port;
+ }
- TST_EXP_FAIL(tst_syscall(__NR_landlock_add_rule,
- *tc->fd, tc->rule_type, *tc->attr, tc->flags),
- tc->exp_errno,
- "%s",
- tc->msg);
+ TST_EXP_FAIL(tst_syscall(__NR_landlock_add_rule,
+ *tc->fd, tc->rule_type, *tc->net_attr, tc->flags),
+ tc->exp_errno, "%s", tc->msg);
+ }
}
static void setup(void)
@@ -124,6 +162,7 @@ static struct tst_test test = {
.bufs = (struct tst_buffers []) {
{&ruleset_attr, .size = sizeof(struct tst_landlock_ruleset_attr)},
{&path_beneath_attr, .size = sizeof(struct landlock_path_beneath_attr)},
+ {&net_port_attr, .size = sizeof(struct landlock_net_port_attr)},
{},
},
.caps = (struct tst_cap []) {
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
prev parent reply other threads:[~2024-09-19 10:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-19 10:23 [LTP] [PATCH 0/5] landlock network coverage support Andrea Cervesato
2024-09-19 10:23 ` [LTP] [PATCH 1/5] Fallback landlock network support Andrea Cervesato
2024-10-23 14:37 ` Cyril Hrubis
2024-09-19 10:23 ` [LTP] [PATCH 2/5] Network helpers in landlock suite common functions Andrea Cervesato
2024-09-19 10:23 ` [LTP] [PATCH 3/5] Fix landlock06 creating multiple ruleset Andrea Cervesato
2024-09-19 10:23 ` [LTP] [PATCH 4/5] Add landlock08 test Andrea Cervesato
2024-09-19 10:23 ` Andrea Cervesato [this message]
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=20240919-landlock_network-v1-5-9c997f03bd0a@suse.com \
--to=andrea.cervesato@suse.de \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.