Skip to contentSkip to conversation

landlock: Add abstract unix socket connect restrictions

PATCH Superseded TaheraFahimi 2 participants 9 messages Mar 28, 2024 – Jun 3, 2024

Subsystems (4)

v2 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 landlock: Add abstract unix socket connect restrictions

Abstract unix sockets are used for local interprocess communication without relying on filesystem. Since landlock has no restriction for connecting to a UNIX socket in the abstract namespace, a sandboxed process can connect to a socket outside the sandboxed environment. Access to such sockets should be scoped the same way ptrace access is limited.

For a landlocked process to be allowed to connect to a target process, it must have a subset of the target process’s rules (the connecting socket must be in a sub-domain of the listening socket). This patch adds a new LSM hook for connect function in unix socket with the related access rights.

Link to first draft:

	https://lore.kernel.org/outreachy/[email protected]/

----
Changes in v2:
- Remove wrapper functions, noted by Casey Schaufler <[email protected]>

---
 security/landlock/task.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
security/landlock/task.c +40 -0
index 849f5123610b..67528f87b7de 100644
@@ -13,6 +13,7 @@
 #include <linux/lsm_hooks.h>
 #include <linux/rcupdate.h>
 #include <linux/sched.h>
+#include <net/sock.h>
 
 #include "common.h"
 #include "cred.h"
@@ -108,9 +109,48 @@ static int hook_ptrace_traceme(struct task_struct *const parent)
 	return task_ptrace(parent, current);
 }
 
+static bool unix_sock_is_scoped(struct sock *const sock,
+				struct sock *const other)
+{
+	bool is_scoped = true;
+
+	/* get the ruleset of connecting sock*/
+	const struct landlock_ruleset *const dom_sock =
+		landlock_get_current_domain();
+
+	if (!dom_sock)
+		return true;
+
+	/* get credential of listening sock*/
+	const struct cred *cred_other = get_cred(other->sk_peer_cred);
+
+	if (!cred_other)
+		return true;
+
+	/* retrieve the landlock_rulesets */
+	const struct landlock_ruleset *dom_parent;
+
+	rcu_read_lock();
+	dom_parent = landlock_cred(cred_other)->domain;
+	is_scoped = domain_scope_le(dom_parent, dom_sock);
+	rcu_read_unlock();
+
+	return is_scoped;
+}
+
+static int hook_unix_stream_connect(struct sock *const sock,
+				    struct sock *const other,
+				    struct sock *const newsk)
+{
+	if (unix_sock_is_scoped(sock, other))
+		return 0;
+	return -EPERM;
+}
+
 static struct security_hook_list landlock_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(ptrace_access_check, hook_ptrace_access_check),
 	LSM_HOOK_INIT(ptrace_traceme, hook_ptrace_traceme),
+	LSM_HOOK_INIT(unix_stream_connect, hook_unix_stream_connect),
 };
 
 __init void landlock_add_task_hooks(void)
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Thanks for this patch. Please CC the netdev mailing list too, they may be interested by this feature. I also added a few folks that previously showed their interest for this feature.

Quoted 5 lines · TaheraFahimi

Abstract unix sockets are used for local interprocess communication without relying on filesystem. Since landlock has no restriction for connecting to a UNIX socket in the abstract namespace, a sandboxed process can connect to a socket outside the sandboxed environment. Access to such sockets should be scoped the same way ptrace access is limited.

This is good but it would be better to explain that Landlock doesn't currently control abstract unix sockets and that it would make sense for a sandbox.

Quoted 5 lines

For a landlocked process to be allowed to connect to a target process, it must have a subset of the target process’s rules (the connecting socket must be in a sub-domain of the listening socket). This patch adds a new LSM hook for connect function in unix socket with the related access rights.

Because of compatibility reasons, and because Landlock should be flexible, we need to extend the user space interface. As explained in the GitHub issue, we need to add a new "scoped" field to the landlock_ruleset_attr struct. This field will optionally contain a LANDLOCK_RULESET_SCOPED_ABSTRACT_UNIX_SOCKET flag to specify that this ruleset will deny any connection from within the sandbox to its parents (i.e. any parent sandbox or not-sandboxed processes).

Quoted 3 lines

Link to first draft:

	https://lore.kernel.org/outreachy/[email protected]/

You can move this sentence in the below changelog.

Quoted 1 line

You can add this:

Quoted 1 line

Your Git (or email app) configuration doesn't use the same name as here.

Please run ./scripts/checkpatch.pl on this patch and fix the warnings.

Quoted 21 lines

----
Changes in v2:
- Remove wrapper functions, noted by Casey Schaufler <[email protected]>

---
 security/landlock/task.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
security/landlock/task.c +1 -0
index 849f5123610b..67528f87b7de 100644
@@ -13,6 +13,7 @@
 #include <linux/lsm_hooks.h>
 #include <linux/rcupdate.h>
 #include <linux/sched.h>
+#include <net/sock.h>
 
 #include "common.h"
 #include "cred.h"

security/landlock/task.c static int hook_ptrace_traceme(struct task_struct *const parent) · line 112

Quoted 4 lines
security/landlock/task.c +1 -0
@@ -108,9 +109,48 @@ static int hook_ptrace_traceme(struct task_struct *const parent)
 	return task_ptrace(parent, current);
 }
 
+static bool unix_sock_is_scoped(struct sock *const sock,

For consistency with task_is_scoped(), you can rename this to sock_is_scoped().

security/landlock/task.c static int hook_ptrace_traceme(struct task_struct *const parent) · line 117

Quoted 5 lines
security/landlock/task.c +5 -0
+				struct sock *const other)
+{
+	bool is_scoped = true;
+
+	/* get the ruleset of connecting sock*/

These comments don't help more than the following line, you can remove them.

security/landlock/task.c static int hook_ptrace_traceme(struct task_struct *const parent) · line 118

Quoted 1 line
security/landlock/task.c +1 -0
+	const struct landlock_ruleset *const dom_sock =

According to the name it looks like the domain of the socket but it is just the domain of the current task. Just "dom" would be clearer and more consistent with security/landlock/fs.c

security/landlock/task.c static int hook_ptrace_traceme(struct task_struct *const parent) · line 125

Quoted 7 lines
security/landlock/task.c +7 -0
+		landlock_get_current_domain();
+
+	if (!dom_sock)
+		return true;
+
+	/* get credential of listening sock*/
+	const struct cred *cred_other = get_cred(other->sk_peer_cred);

We have a get but not a put call, so the credentials will never be freed. The put call must be called before any return, so you probably need to follow the goto/error pattern.

In the context of these LSM hooks, only unix_listen() sets the "other" socket credential, and unix_listen() is guarded by unix_state_lock() which locks unix_sk(s)->lock . When security_unix_stream_connect() or security_unix_may_send() are called, unix_sk(s)->lock is locked as well, which protects the credentials against race-conditions (TOCTOU:
time-of-check to time-of-use). We should then make that explicit with this assertion (which also documents it):

lockdep_assert_held(&unix_sk(other)->lock);

In theory it is then not required to call get_cred(). However, because the performance impact should be negligible and to avoid a potential use-after-free (not possible in theory with the current code), it would be safer to still call get/put. It would be worse to have a use-after-free rather than an access control issue.

Another thing to keep in mind is that for this hook to be race-condition-free, the credential must not change anyway. A comment should highlight that.

security/landlock/task.c static int hook_ptrace_traceme(struct task_struct *const parent) · line 131

Quoted 6 lines
security/landlock/task.c +6 -0
+
+	if (!cred_other)
+		return true;
+
+	/* retrieve the landlock_rulesets */
+	const struct landlock_ruleset *dom_parent;

All declarations should be at the top of functions.

security/landlock/task.c static int hook_ptrace_traceme(struct task_struct *const parent) · line 133

Quoted 2 lines
security/landlock/task.c +2 -0
+
+	rcu_read_lock();

No need for this RCU lock because the lock is managed by unix_state_lock() in this case.

Quoted 10 lines
security/landlock/task.c +10 -0
+	dom_parent = landlock_cred(cred_other)->domain;
+	is_scoped = domain_scope_le(dom_parent, dom_sock);
+	rcu_read_unlock();
+
+	return is_scoped;
+}
+
+static int hook_unix_stream_connect(struct sock *const sock,
+				    struct sock *const other,
+				    struct sock *const newsk)

security/landlock/task.c static int hook_ptrace_traceme(struct task_struct *const parent) · line 153

Quoted 10 lines
security/landlock/task.c +7 -0
+{
+	if (unix_sock_is_scoped(sock, other))
+		return 0;
+	return -EPERM;
+}
+
 static struct security_hook_list landlock_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(ptrace_access_check, hook_ptrace_access_check),
 	LSM_HOOK_INIT(ptrace_traceme, hook_ptrace_traceme),
+	LSM_HOOK_INIT(unix_stream_connect, hook_unix_stream_connect),

Please add a hook for security_unix_may_send() too, it should be quite similar, and simplify the patch's subject accordingly.

You now need to add tests (in a dedicated patch) extending tools/testing/selftests/landlock/ptrace_test.c (I'll rename the file later).

These tests should also check with unnamed and named unix sockets. I guess the current code doesn't differentiate them and control all kind of unix sockets. Because they must explicitly be passed, sockets created with socketpair(2) (i.e. unnamed socket) should never be denied.

Quoted 7 lines
security/landlock/task.c +0 -0
 };
 
 __init void landlock_add_task_hooks(void)
Signature · 1 line
2.34.1
#2 lore raw
Quoted 22 lines · Mickaël Salaün

Thanks for this patch. Please CC the netdev mailing list too, they may be interested by this feature. I also added a few folks that previously showed their interest for this feature.

Quoted 5 lines · TaheraFahimi

Abstract unix sockets are used for local interprocess communication without relying on filesystem. Since landlock has no restriction for connecting to a UNIX socket in the abstract namespace, a sandboxed process can connect to a socket outside the sandboxed environment. Access to such sockets should be scoped the same way ptrace access is limited.

This is good but it would be better to explain that Landlock doesn't currently control abstract unix sockets and that it would make sense for a sandbox.

Quoted 5 lines

For a landlocked process to be allowed to connect to a target process, it must have a subset of the target process’s rules (the connecting socket must be in a sub-domain of the listening socket). This patch adds a new LSM hook for connect function in unix socket with the related access rights.

Quoted 7 lines

Because of compatibility reasons, and because Landlock should be flexible, we need to extend the user space interface. As explained in the GitHub issue, we need to add a new "scoped" field to the landlock_ruleset_attr struct. This field will optionally contain a LANDLOCK_RULESET_SCOPED_ABSTRACT_UNIX_SOCKET flag to specify that this ruleset will deny any connection from within the sandbox to its parents (i.e. any parent sandbox or not-sandboxed processes).

Thanks for the feedback. Here is what I understood, please correct me if I am wrong. First, I should add another field to the landlock_ruleset_attr (a field like handled_access_net, but for the unix sockets) with a flag LANDLOCK_ACCESS_UNIX_CONNECT (it is a flag like LANDLOCK_ACCESS_NET_CONNECT_TCP but fot the unix sockets connect).

Quoted 149 lines
Quoted 3 lines

Link to first draft:

	https://lore.kernel.org/outreachy/[email protected]/

You can move this sentence in the below changelog.

Quoted 1 line

You can add this:

Quoted 1 line

Your Git (or email app) configuration doesn't use the same name as here.

Please run ./scripts/checkpatch.pl on this patch and fix the warnings.

Quoted 21 lines

----
Changes in v2:
- Remove wrapper functions, noted by Casey Schaufler <[email protected]>

---
 security/landlock/task.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
security/landlock/task.c +1 -0
index 849f5123610b..67528f87b7de 100644
@@ -13,6 +13,7 @@
 #include <linux/lsm_hooks.h>
 #include <linux/rcupdate.h>
 #include <linux/sched.h>
+#include <net/sock.h>
 
 #include "common.h"
 #include "cred.h"

security/landlock/task.c static int hook_ptrace_traceme(struct task_struct *const parent) · line 112

Quoted 4 lines
security/landlock/task.c +1 -0
@@ -108,9 +109,48 @@ static int hook_ptrace_traceme(struct task_struct *const parent)
 	return task_ptrace(parent, current);
 }
 
+static bool unix_sock_is_scoped(struct sock *const sock,

For consistency with task_is_scoped(), you can rename this to sock_is_scoped().

security/landlock/task.c static int hook_ptrace_traceme(struct task_struct *const parent) · line 117

Quoted 5 lines
security/landlock/task.c +5 -0
+				struct sock *const other)
+{
+	bool is_scoped = true;
+
+	/* get the ruleset of connecting sock*/

These comments don't help more than the following line, you can remove them.

security/landlock/task.c static int hook_ptrace_traceme(struct task_struct *const parent) · line 118

Quoted 1 line
security/landlock/task.c +1 -0
+	const struct landlock_ruleset *const dom_sock =

According to the name it looks like the domain of the socket but it is just the domain of the current task. Just "dom" would be clearer and more consistent with security/landlock/fs.c

security/landlock/task.c static int hook_ptrace_traceme(struct task_struct *const parent) · line 125

Quoted 7 lines
security/landlock/task.c +7 -0
+		landlock_get_current_domain();
+
+	if (!dom_sock)
+		return true;
+
+	/* get credential of listening sock*/
+	const struct cred *cred_other = get_cred(other->sk_peer_cred);

We have a get but not a put call, so the credentials will never be freed. The put call must be called before any return, so you probably need to follow the goto/error pattern.

In the context of these LSM hooks, only unix_listen() sets the "other" socket credential, and unix_listen() is guarded by unix_state_lock() which locks unix_sk(s)->lock . When security_unix_stream_connect() or security_unix_may_send() are called, unix_sk(s)->lock is locked as well, which protects the credentials against race-conditions (TOCTOU:
time-of-check to time-of-use). We should then make that explicit with this assertion (which also documents it):

lockdep_assert_held(&unix_sk(other)->lock);

In theory it is then not required to call get_cred(). However, because the performance impact should be negligible and to avoid a potential use-after-free (not possible in theory with the current code), it would be safer to still call get/put. It would be worse to have a use-after-free rather than an access control issue.

Another thing to keep in mind is that for this hook to be race-condition-free, the credential must not change anyway. A comment should highlight that.

security/landlock/task.c static int hook_ptrace_traceme(struct task_struct *const parent) · line 131

Quoted 6 lines
security/landlock/task.c +6 -0
+
+	if (!cred_other)
+		return true;
+
+	/* retrieve the landlock_rulesets */
+	const struct landlock_ruleset *dom_parent;

All declarations should be at the top of functions.

security/landlock/task.c static int hook_ptrace_traceme(struct task_struct *const parent) · line 133

Quoted 2 lines
security/landlock/task.c +2 -0
+
+	rcu_read_lock();

No need for this RCU lock because the lock is managed by unix_state_lock() in this case.

Quoted 10 lines
security/landlock/task.c +10 -0
+	dom_parent = landlock_cred(cred_other)->domain;
+	is_scoped = domain_scope_le(dom_parent, dom_sock);
+	rcu_read_unlock();
+
+	return is_scoped;
+}
+
+static int hook_unix_stream_connect(struct sock *const sock,
+				    struct sock *const other,
+				    struct sock *const newsk)

security/landlock/task.c static int hook_ptrace_traceme(struct task_struct *const parent) · line 153

Quoted 10 lines
security/landlock/task.c +7 -0
+{
+	if (unix_sock_is_scoped(sock, other))
+		return 0;
+	return -EPERM;
+}
+
 static struct security_hook_list landlock_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(ptrace_access_check, hook_ptrace_access_check),
 	LSM_HOOK_INIT(ptrace_traceme, hook_ptrace_traceme),
+	LSM_HOOK_INIT(unix_stream_connect, hook_unix_stream_connect),

Please add a hook for security_unix_may_send() too, it should be quite similar, and simplify the patch's subject accordingly.

You now need to add tests (in a dedicated patch) extending tools/testing/selftests/landlock/ptrace_test.c (I'll rename the file later).

These tests should also check with unnamed and named unix sockets. I guess the current code doesn't differentiate them and control all kind of unix sockets. Because they must explicitly be passed, sockets created with socketpair(2) (i.e. unnamed socket) should never be denied.

Quoted 7 lines
security/landlock/task.c +0 -0
 };
 
 __init void landlock_add_task_hooks(void)
Signature · 1 line
2.34.1
maintainer
#3 lore raw
Quoted 31 lines · Tahera Fahimi
Quoted 22 lines · Mickaël Salaün

Thanks for this patch. Please CC the netdev mailing list too, they may be interested by this feature. I also added a few folks that previously showed their interest for this feature.

Quoted 5 lines · TaheraFahimi

Abstract unix sockets are used for local interprocess communication without relying on filesystem. Since landlock has no restriction for connecting to a UNIX socket in the abstract namespace, a sandboxed process can connect to a socket outside the sandboxed environment. Access to such sockets should be scoped the same way ptrace access is limited.

This is good but it would be better to explain that Landlock doesn't currently control abstract unix sockets and that it would make sense for a sandbox.

Quoted 5 lines

For a landlocked process to be allowed to connect to a target process, it must have a subset of the target process’s rules (the connecting socket must be in a sub-domain of the listening socket). This patch adds a new LSM hook for connect function in unix socket with the related access rights.

Quoted 7 lines

Because of compatibility reasons, and because Landlock should be flexible, we need to extend the user space interface. As explained in the GitHub issue, we need to add a new "scoped" field to the landlock_ruleset_attr struct. This field will optionally contain a LANDLOCK_RULESET_SCOPED_ABSTRACT_UNIX_SOCKET flag to specify that this ruleset will deny any connection from within the sandbox to its parents (i.e. any parent sandbox or not-sandboxed processes).

Quoted 5 lines

Thanks for the feedback. Here is what I understood, please correct me if I am wrong. First, I should add another field to the landlock_ruleset_attr (a field like handled_access_net, but for the unix sockets) with a flag LANDLOCK_ACCESS_UNIX_CONNECT (it is a flag like LANDLOCK_ACCESS_NET_CONNECT_TCP but fot the unix sockets connect).

That was the initial idea, but after thinking more about it and talking with some users, I now think we can get a more generic interface.

Because unix sockets, signals, and other IPCs are fully controlled by the kernel (contrary to inet sockets that get out of the system), we can add ingress and egress control according to the source and the destination.

To control the direction we could add an LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE and a LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND rights (these names are a bit long but at least explicit). To control the source and destination, it makes sense to use Landlock domain (i.e. sandboxes):
LANDLOCK_DOMAIN_HIERARCHY_PARENT, LANDLOCK_DOMAIN_HIERARCHY_SELF, and LANDLOCK_DOMAIN_HIERARCHY_CHILD. This could be used by extending the landlock_ruleset_attr type and adding a new landlock_domain_hierarchy_attr type:

struct landlock_ruleset_attr ruleset_attr = {
.handled_access_dom = LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE | \
LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
}

// Allows sending data to and receiving data from processes in the same // domain or a child domain, through abstract unix sockets. struct landlock_domain_hierarchy_attr dom_attr = {
.allowed_access = LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE | \
LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
.relationship = LANDLOCK_DOMAIN_HIERARCHY_SELF | \
LANDLOCK_DOMAIN_HIERARCHY_CHILD,
};

It should also work with other kind of IPCs:
* LANDLOCK_ACCESS_DOM_UNIX_PATHNAME_RECEIVE/SEND (signal)
* LANDLOCK_ACCESS_DOM_SIGNAL_RECEIVE/SEND (signal)
* LANDLOCK_ACCESS_DOM_XSI_RECEIVE/SEND (XSI message queue)
* LANDLOCK_ACCESS_DOM_MQ_RECEIVE/SEND (POSIX message queue)
* LANDLOCK_ACCESS_DOM_PTRACE_RECEIVE/SEND (ptrace, which would be limited)

What do you think?

#4 lore raw
Quoted 78 lines · Mickaël Salaün
Quoted 31 lines · Tahera Fahimi
Quoted 22 lines · Mickaël Salaün

Thanks for this patch. Please CC the netdev mailing list too, they may be interested by this feature. I also added a few folks that previously showed their interest for this feature.

Quoted 5 lines · TaheraFahimi

Abstract unix sockets are used for local interprocess communication without relying on filesystem. Since landlock has no restriction for connecting to a UNIX socket in the abstract namespace, a sandboxed process can connect to a socket outside the sandboxed environment. Access to such sockets should be scoped the same way ptrace access is limited.

This is good but it would be better to explain that Landlock doesn't currently control abstract unix sockets and that it would make sense for a sandbox.

Quoted 5 lines

For a landlocked process to be allowed to connect to a target process, it must have a subset of the target process’s rules (the connecting socket must be in a sub-domain of the listening socket). This patch adds a new LSM hook for connect function in unix socket with the related access rights.

Quoted 7 lines

Because of compatibility reasons, and because Landlock should be flexible, we need to extend the user space interface. As explained in the GitHub issue, we need to add a new "scoped" field to the landlock_ruleset_attr struct. This field will optionally contain a LANDLOCK_RULESET_SCOPED_ABSTRACT_UNIX_SOCKET flag to specify that this ruleset will deny any connection from within the sandbox to its parents (i.e. any parent sandbox or not-sandboxed processes).

Quoted 5 lines

Thanks for the feedback. Here is what I understood, please correct me if I am wrong. First, I should add another field to the landlock_ruleset_attr (a field like handled_access_net, but for the unix sockets) with a flag LANDLOCK_ACCESS_UNIX_CONNECT (it is a flag like LANDLOCK_ACCESS_NET_CONNECT_TCP but fot the unix sockets connect).

That was the initial idea, but after thinking more about it and talking with some users, I now think we can get a more generic interface.

Because unix sockets, signals, and other IPCs are fully controlled by the kernel (contrary to inet sockets that get out of the system), we can add ingress and egress control according to the source and the destination.

To control the direction we could add an LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE and a LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND rights (these names are a bit long but at least explicit). To control the source and destination, it makes sense to use Landlock domain (i.e. sandboxes):
LANDLOCK_DOMAIN_HIERARCHY_PARENT, LANDLOCK_DOMAIN_HIERARCHY_SELF, and LANDLOCK_DOMAIN_HIERARCHY_CHILD. This could be used by extending the landlock_ruleset_attr type and adding a new landlock_domain_hierarchy_attr type:

struct landlock_ruleset_attr ruleset_attr = {
.handled_access_dom = LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE | \
LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
}

// Allows sending data to and receiving data from processes in the same // domain or a child domain, through abstract unix sockets. struct landlock_domain_hierarchy_attr dom_attr = {
.allowed_access = LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE | \
LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
.relationship = LANDLOCK_DOMAIN_HIERARCHY_SELF | \
LANDLOCK_DOMAIN_HIERARCHY_CHILD,
};

It should also work with other kind of IPCs:
* LANDLOCK_ACCESS_DOM_UNIX_PATHNAME_RECEIVE/SEND (signal)
* LANDLOCK_ACCESS_DOM_SIGNAL_RECEIVE/SEND (signal)
* LANDLOCK_ACCESS_DOM_XSI_RECEIVE/SEND (XSI message queue)
* LANDLOCK_ACCESS_DOM_MQ_RECEIVE/SEND (POSIX message queue)
* LANDLOCK_ACCESS_DOM_PTRACE_RECEIVE/SEND (ptrace, which would be limited)

Quoted 1 line

What do you think?

Indeed, in the case of abstract Unix sockets, both parties can send and receive data when a connection is established. Therefore, we can define a single LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT to represent the right to share data, regardless of direction. However, we should still retain LANDLOCK_DOMAIN_HIERARCHY for SELF, PARENT, and CHILD, as the source and destination are important.
As you said, I believe we should have receive and send rights for another kind of IPCs (which will be used for landlock#8 issue)

#5 lore raw
In reply to Mickaël Salaün
Quoted 78 lines · Mickaël Salaün
Quoted 31 lines · Tahera Fahimi
Quoted 22 lines · Mickaël Salaün

Thanks for this patch. Please CC the netdev mailing list too, they may be interested by this feature. I also added a few folks that previously showed their interest for this feature.

Quoted 5 lines · TaheraFahimi

Abstract unix sockets are used for local interprocess communication without relying on filesystem. Since landlock has no restriction for connecting to a UNIX socket in the abstract namespace, a sandboxed process can connect to a socket outside the sandboxed environment. Access to such sockets should be scoped the same way ptrace access is limited.

This is good but it would be better to explain that Landlock doesn't currently control abstract unix sockets and that it would make sense for a sandbox.

Quoted 5 lines

For a landlocked process to be allowed to connect to a target process, it must have a subset of the target process’s rules (the connecting socket must be in a sub-domain of the listening socket). This patch adds a new LSM hook for connect function in unix socket with the related access rights.

Quoted 7 lines

Because of compatibility reasons, and because Landlock should be flexible, we need to extend the user space interface. As explained in the GitHub issue, we need to add a new "scoped" field to the landlock_ruleset_attr struct. This field will optionally contain a LANDLOCK_RULESET_SCOPED_ABSTRACT_UNIX_SOCKET flag to specify that this ruleset will deny any connection from within the sandbox to its parents (i.e. any parent sandbox or not-sandboxed processes).

Quoted 5 lines

Thanks for the feedback. Here is what I understood, please correct me if I am wrong. First, I should add another field to the landlock_ruleset_attr (a field like handled_access_net, but for the unix sockets) with a flag LANDLOCK_ACCESS_UNIX_CONNECT (it is a flag like LANDLOCK_ACCESS_NET_CONNECT_TCP but fot the unix sockets connect).

That was the initial idea, but after thinking more about it and talking with some users, I now think we can get a more generic interface.

Because unix sockets, signals, and other IPCs are fully controlled by the kernel (contrary to inet sockets that get out of the system), we can add ingress and egress control according to the source and the destination.

To control the direction we could add an LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE and a LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND rights (these names are a bit long but at least explicit). To control the source and destination, it makes sense to use Landlock domain (i.e. sandboxes):
LANDLOCK_DOMAIN_HIERARCHY_PARENT, LANDLOCK_DOMAIN_HIERARCHY_SELF, and LANDLOCK_DOMAIN_HIERARCHY_CHILD. This could be used by extending the landlock_ruleset_attr type and adding a new landlock_domain_hierarchy_attr type:

struct landlock_ruleset_attr ruleset_attr = {
.handled_access_dom = LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE | \
LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
}

// Allows sending data to and receiving data from processes in the same // domain or a child domain, through abstract unix sockets. struct landlock_domain_hierarchy_attr dom_attr = {
.allowed_access = LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE | \
LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
.relationship = LANDLOCK_DOMAIN_HIERARCHY_SELF | \
LANDLOCK_DOMAIN_HIERARCHY_CHILD,
};

It should also work with other kind of IPCs:
* LANDLOCK_ACCESS_DOM_UNIX_PATHNAME_RECEIVE/SEND (signal)
* LANDLOCK_ACCESS_DOM_SIGNAL_RECEIVE/SEND (signal)
* LANDLOCK_ACCESS_DOM_XSI_RECEIVE/SEND (XSI message queue)
* LANDLOCK_ACCESS_DOM_MQ_RECEIVE/SEND (POSIX message queue)
* LANDLOCK_ACCESS_DOM_PTRACE_RECEIVE/SEND (ptrace, which would be limited)

Quoted 1 line

What do you think?

I was wondering if you expand your idea on the following example.

Considering P1 with the rights that you mentioned in your email, forks a new process (P2). Now both P1 and P2 are on the same domain and are allowed to send data to and receive data from processes in the same domain or a child domain.
/*
* Same domain (inherited)
* .-------------.

 * | P1----.     |      P1 -> P2 : allow
 * |        \    |      P2 -> P1 : allow
 * |         '   |
 * |         P2  |
 * '-------------'
 */
(P1 domain) = (P2 domain) = {
		.allowed_access =
			LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE | 
			LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
		.relationship = 
			LANDLOCK_DOMAIN_HIERARCHY_SELF | 
			LANDLOCK_DOMAIN_HIERARCHY_CHILD,
		}

In another example, if P1 has the same domain as before but P2 has LANDLOCK_DOMAIN_HIERARCHY_PARENT in their domain, so P1 still can connect to P2.
/*
* Parent domain
* .------.
* | P1 --. P1 -> P2 : allow
* '------' \ P2 -> P1 : allow
* '
* P2
*/

(P1 domain) = {
                .allowed_access =
                        LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE |
                        LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
                .relationship = 
                        LANDLOCK_DOMAIN_HIERARCHY_SELF |
                        LANDLOCK_DOMAIN_HIERARCHY_CHILD,
                }
(P2 domain) = {
                .allowed_access =
                        LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE |
                        LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
                .relationship = 
                        LANDLOCK_DOMAIN_HIERARCHY_SELF |
                        LANDLOCK_DOMAIN_HIERARCHY_CHILD |
			LANDLOCK_DOMAIN_HIERARCHY_PARENT,
		}
maintainer
#6 lore raw
Quoted 94 lines · Tahera Fahimi
Quoted 78 lines · Mickaël Salaün
Quoted 31 lines · Tahera Fahimi
Quoted 22 lines · Mickaël Salaün

Thanks for this patch. Please CC the netdev mailing list too, they may be interested by this feature. I also added a few folks that previously showed their interest for this feature.

Quoted 5 lines · TaheraFahimi

Abstract unix sockets are used for local interprocess communication without relying on filesystem. Since landlock has no restriction for connecting to a UNIX socket in the abstract namespace, a sandboxed process can connect to a socket outside the sandboxed environment. Access to such sockets should be scoped the same way ptrace access is limited.

This is good but it would be better to explain that Landlock doesn't currently control abstract unix sockets and that it would make sense for a sandbox.

Quoted 5 lines

For a landlocked process to be allowed to connect to a target process, it must have a subset of the target process’s rules (the connecting socket must be in a sub-domain of the listening socket). This patch adds a new LSM hook for connect function in unix socket with the related access rights.

Quoted 7 lines

Because of compatibility reasons, and because Landlock should be flexible, we need to extend the user space interface. As explained in the GitHub issue, we need to add a new "scoped" field to the landlock_ruleset_attr struct. This field will optionally contain a LANDLOCK_RULESET_SCOPED_ABSTRACT_UNIX_SOCKET flag to specify that this ruleset will deny any connection from within the sandbox to its parents (i.e. any parent sandbox or not-sandboxed processes).

Quoted 5 lines

Thanks for the feedback. Here is what I understood, please correct me if I am wrong. First, I should add another field to the landlock_ruleset_attr (a field like handled_access_net, but for the unix sockets) with a flag LANDLOCK_ACCESS_UNIX_CONNECT (it is a flag like LANDLOCK_ACCESS_NET_CONNECT_TCP but fot the unix sockets connect).

That was the initial idea, but after thinking more about it and talking with some users, I now think we can get a more generic interface.

Because unix sockets, signals, and other IPCs are fully controlled by the kernel (contrary to inet sockets that get out of the system), we can add ingress and egress control according to the source and the destination.

To control the direction we could add an LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE and a LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND rights (these names are a bit long but at least explicit). To control the source and destination, it makes sense to use Landlock domain (i.e. sandboxes):
LANDLOCK_DOMAIN_HIERARCHY_PARENT, LANDLOCK_DOMAIN_HIERARCHY_SELF, and LANDLOCK_DOMAIN_HIERARCHY_CHILD. This could be used by extending the landlock_ruleset_attr type and adding a new landlock_domain_hierarchy_attr type:

struct landlock_ruleset_attr ruleset_attr = {
.handled_access_dom = LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE | \
LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
}

// Allows sending data to and receiving data from processes in the same // domain or a child domain, through abstract unix sockets. struct landlock_domain_hierarchy_attr dom_attr = {
.allowed_access = LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE | \
LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
.relationship = LANDLOCK_DOMAIN_HIERARCHY_SELF | \
LANDLOCK_DOMAIN_HIERARCHY_CHILD,
};

It should also work with other kind of IPCs:
* LANDLOCK_ACCESS_DOM_UNIX_PATHNAME_RECEIVE/SEND (signal)
* LANDLOCK_ACCESS_DOM_SIGNAL_RECEIVE/SEND (signal)
* LANDLOCK_ACCESS_DOM_XSI_RECEIVE/SEND (XSI message queue)
* LANDLOCK_ACCESS_DOM_MQ_RECEIVE/SEND (POSIX message queue)
* LANDLOCK_ACCESS_DOM_PTRACE_RECEIVE/SEND (ptrace, which would be limited)

Quoted 1 line

What do you think?

I was wondering if you expand your idea on the following example.

Considering P1 with the rights that you mentioned in your email, forks a new process (P2). Now both P1 and P2 are on the same domain and are allowed to send data to and receive data from processes in the same domain or a child domain.
/*
* Same domain (inherited)
* .-------------.

 * | P1----.     |      P1 -> P2 : allow
 * |        \    |      P2 -> P1 : allow
 * |         '   |
 * |         P2  |
Quoted 9 lines

* '-------------'
*/
(P1 domain) = (P2 domain) = {
.allowed_access =
LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE | LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
.relationship =
LANDLOCK_DOMAIN_HIERARCHY_SELF | LANDLOCK_DOMAIN_HIERARCHY_CHILD,

In this case LANDLOCK_DOMAIN_HIERARCHY_CHILD would not be required because P1 and P2 are on the same domain.

Quoted 14 lines
		}

In another example, if P1 has the same domain as before but P2 has LANDLOCK_DOMAIN_HIERARCHY_PARENT in their domain, so P1 still can connect to P2.
/*
* Parent domain
* .------.
* | P1 --. P1 -> P2 : allow
* '------' \ P2 -> P1 : allow
* '
* P2
*/

Quoted 7 lines

(P1 domain) = {
.allowed_access =
LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE | LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
.relationship =
LANDLOCK_DOMAIN_HIERARCHY_SELF | LANDLOCK_DOMAIN_HIERARCHY_CHILD,

Hmm, in this case P2 doesn't have a domain, so LANDLOCK_DOMAIN_HIERARCHY_CHILD doesn't make sense.

Quoted 10 lines
                }
(P2 domain) = {
                .allowed_access =
                        LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE |
                        LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
                .relationship = 
                        LANDLOCK_DOMAIN_HIERARCHY_SELF |
                        LANDLOCK_DOMAIN_HIERARCHY_CHILD |
			LANDLOCK_DOMAIN_HIERARCHY_PARENT,
		}

I think you wanted to use the "Inherited + child domain" example here, in which case the domain policies make sense.

I was maybe too enthusiastic with the "relationship" field. Let's rename landlock_domain_hierarchy_attr to landlock_domain_attr and remove the "relationship" field. We'll always consider that LANDLOCK_DOMAIN_HIERARCHY_SELF is set as well as LANDLOCK_DOMAIN_HIERARCHY_CHILD (i.e. no restriction to send/received to/from a child domain or our own domain). In a nutshell, please only keep the LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_{RECEIVE,SEND} rights and follow the same logic as with ptrace restrictions. It will be easier to reason about and will be useful for most cases. We could later extend that with more features.

LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE will then translates to "allow to receive from the parent domain". LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND will then translates to "allow to send to the parent domain".

As for other Landlock access rights, the restrictions of domains should only be changed if LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_* is "handled" by the ruleset/domain.

#7 lore raw
Quoted 158 lines · Mickaël Salaün
Quoted 94 lines · Tahera Fahimi
Quoted 78 lines · Mickaël Salaün
Quoted 31 lines · Tahera Fahimi
Quoted 22 lines · Mickaël Salaün

Thanks for this patch. Please CC the netdev mailing list too, they may be interested by this feature. I also added a few folks that previously showed their interest for this feature.

Quoted 5 lines · TaheraFahimi

Abstract unix sockets are used for local interprocess communication without relying on filesystem. Since landlock has no restriction for connecting to a UNIX socket in the abstract namespace, a sandboxed process can connect to a socket outside the sandboxed environment. Access to such sockets should be scoped the same way ptrace access is limited.

This is good but it would be better to explain that Landlock doesn't currently control abstract unix sockets and that it would make sense for a sandbox.

Quoted 5 lines

For a landlocked process to be allowed to connect to a target process, it must have a subset of the target process’s rules (the connecting socket must be in a sub-domain of the listening socket). This patch adds a new LSM hook for connect function in unix socket with the related access rights.

Quoted 7 lines

Because of compatibility reasons, and because Landlock should be flexible, we need to extend the user space interface. As explained in the GitHub issue, we need to add a new "scoped" field to the landlock_ruleset_attr struct. This field will optionally contain a LANDLOCK_RULESET_SCOPED_ABSTRACT_UNIX_SOCKET flag to specify that this ruleset will deny any connection from within the sandbox to its parents (i.e. any parent sandbox or not-sandboxed processes).

Quoted 5 lines

Thanks for the feedback. Here is what I understood, please correct me if I am wrong. First, I should add another field to the landlock_ruleset_attr (a field like handled_access_net, but for the unix sockets) with a flag LANDLOCK_ACCESS_UNIX_CONNECT (it is a flag like LANDLOCK_ACCESS_NET_CONNECT_TCP but fot the unix sockets connect).

That was the initial idea, but after thinking more about it and talking with some users, I now think we can get a more generic interface.

Because unix sockets, signals, and other IPCs are fully controlled by the kernel (contrary to inet sockets that get out of the system), we can add ingress and egress control according to the source and the destination.

To control the direction we could add an LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE and a LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND rights (these names are a bit long but at least explicit). To control the source and destination, it makes sense to use Landlock domain (i.e. sandboxes):
LANDLOCK_DOMAIN_HIERARCHY_PARENT, LANDLOCK_DOMAIN_HIERARCHY_SELF, and LANDLOCK_DOMAIN_HIERARCHY_CHILD. This could be used by extending the landlock_ruleset_attr type and adding a new landlock_domain_hierarchy_attr type:

struct landlock_ruleset_attr ruleset_attr = {
.handled_access_dom = LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE | \
LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
}

// Allows sending data to and receiving data from processes in the same // domain or a child domain, through abstract unix sockets. struct landlock_domain_hierarchy_attr dom_attr = {
.allowed_access = LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE | \
LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
.relationship = LANDLOCK_DOMAIN_HIERARCHY_SELF | \
LANDLOCK_DOMAIN_HIERARCHY_CHILD,
};

It should also work with other kind of IPCs:
* LANDLOCK_ACCESS_DOM_UNIX_PATHNAME_RECEIVE/SEND (signal)
* LANDLOCK_ACCESS_DOM_SIGNAL_RECEIVE/SEND (signal)
* LANDLOCK_ACCESS_DOM_XSI_RECEIVE/SEND (XSI message queue)
* LANDLOCK_ACCESS_DOM_MQ_RECEIVE/SEND (POSIX message queue)
* LANDLOCK_ACCESS_DOM_PTRACE_RECEIVE/SEND (ptrace, which would be limited)

Quoted 1 line

What do you think?

I was wondering if you expand your idea on the following example.

Considering P1 with the rights that you mentioned in your email, forks a new process (P2). Now both P1 and P2 are on the same domain and are allowed to send data to and receive data from processes in the same domain or a child domain.
/*
* Same domain (inherited)
* .-------------.

 * | P1----.     |      P1 -> P2 : allow
 * |        \    |      P2 -> P1 : allow
 * |         '   |
 * |         P2  |
Quoted 9 lines

* '-------------'
*/
(P1 domain) = (P2 domain) = {
.allowed_access =
LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE | LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
.relationship =
LANDLOCK_DOMAIN_HIERARCHY_SELF | LANDLOCK_DOMAIN_HIERARCHY_CHILD,

In this case LANDLOCK_DOMAIN_HIERARCHY_CHILD would not be required because P1 and P2 are on the same domain.

Quoted 14 lines
		}

In another example, if P1 has the same domain as before but P2 has LANDLOCK_DOMAIN_HIERARCHY_PARENT in their domain, so P1 still can connect to P2.
/*
* Parent domain
* .------.
* | P1 --. P1 -> P2 : allow
* '------' \ P2 -> P1 : allow
* '
* P2
*/

Quoted 7 lines

(P1 domain) = {
.allowed_access =
LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE | LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
.relationship =
LANDLOCK_DOMAIN_HIERARCHY_SELF | LANDLOCK_DOMAIN_HIERARCHY_CHILD,

Hmm, in this case P2 doesn't have a domain, so LANDLOCK_DOMAIN_HIERARCHY_CHILD doesn't make sense.

Quoted 10 lines
                }
(P2 domain) = {
                .allowed_access =
                        LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE |
                        LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND,
                .relationship = 
                        LANDLOCK_DOMAIN_HIERARCHY_SELF |
                        LANDLOCK_DOMAIN_HIERARCHY_CHILD |
			LANDLOCK_DOMAIN_HIERARCHY_PARENT,
		}

I think you wanted to use the "Inherited + child domain" example here, in which case the domain policies make sense.

I was maybe too enthusiastic with the "relationship" field. Let's rename landlock_domain_hierarchy_attr to landlock_domain_attr and remove the "relationship" field. We'll always consider that LANDLOCK_DOMAIN_HIERARCHY_SELF is set as well as LANDLOCK_DOMAIN_HIERARCHY_CHILD (i.e. no restriction to send/received to/from a child domain or our own domain). In a nutshell, please only keep the LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_{RECEIVE,SEND} rights and follow the same logic as with ptrace restrictions. It will be easier to reason about and will be useful for most cases. We could later extend that with more features.

Quoted 4 lines

LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_RECEIVE will then translates to "allow to receive from the parent domain". LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_SEND will then translates to "allow to send to the parent domain".

If we consider LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_* shows the ability to send/recieve data to/from the parent domain, different scenarios would be as follow(again using your drawings from the ptrace_test):

/*
* No domain
*
* P1-. P1 -> P2 : allow
* \ P2 -> P1 : allow
* 'P2
*/

(Child domain): Since child can not send/recieve data to/from parent,the connection of both direction is banned.
/*
* Child domain:
*
* P1--. P1 -> P2 : deny

 *        \             P2 -> P1 : deny
 *        .'-----.
 *        |  P2  |
 *        '------'

*/

(Parent domain): The parent's access to its parent is restricted, so the child and parent can establish connection.
/*
* Parent domain
* .------.
* | P1 --. P1 -> P2 : allow
* '------' \ P2 -> P1 : allow
* '
* P2
*/

(Parent + child domain): Same as (child domain) scenario /*
* Parent + child domain(inherited)
* .------.
* | P1 ---. P1 -> P2 : deny
* '------' \ P2 -> P1 : deny

 *         .---'--.
 *         |  P2  |
 *         '------'

*/

(Same domain): An example is when a process fork two child processes and they inherit the parent's access. In this case, children proccess can send/recieve data to/from each other since they are in the same domain. /*
* Same domain (sibling)
* .-------------.

 * | P1----.     |      P1 -> P2 : allow
 * |        \    |      P2 -> P1 : allow
 * |         '   |
 * |         P2  |

* '-------------'
*/

/*
* Inherited + child domain
* .-----------------.

 * |  P1----.        |  P1 -> P2 : deny
 * |         \       |  P2 -> P1 : deny
 * |        .-'----. |
 * |        |  P2  | |
 * |        '------' |

* '-----------------'
*/

/*
* Inherited + parent domain
* .-----------------.

 * |.------.         |  P1 -> P2 : allow
 * ||  P1  ----.     |  P2 -> P1 : allow
 * |'------'    \    |
 * |             '   |
 * |             P2  |

* '-----------------'
*/

/*
* Inherited + parent and child domain
* .-----------------.

 * | .------.        |  P1 -> P2 : deny
 * | |  P1  .        |  P2 -> P1 : deny
 * | '------'\       |
 * |          \      |
 * |        .--'---. |
 * |        |  P2  | |
 * |        '------' |

* '-----------------'
*/
Any feedback on this logic is appreciated.

Quoted 3 lines

As for other Landlock access rights, the restrictions of domains should only be changed if LANDLOCK_ACCESS_DOM_UNIX_ABSTRACT_* is "handled" by the ruleset/domain.

maintainer
#8 lore raw

OK, thanks to your examples I found some issues with this "send/recv" design. A sandboxed process should not be able to block actions on its own socket from a higher privileged domain (or a process without domain). One issue is that if a domain D2 denies access (to its abstract unix sockets) to its parent D1, processes without domains (e.g. parent of D1) should not be restricted in any way. Furthermore, it should not be possible for a process to enforce such restriction if it is not already sandboxed in a domain. Implementing such mechanism would require to add exceptions, which makes this design inconsistent.

Let's get back to the initial "scope" design, which is simpler and consistent with the ptrace restrictions. Sorry for the back and forth. This discussions will be useful for the rationale though. ;) I kept the relevant parts:

Quoted 5 lines · Tahera Fahimi
Quoted 4 lines · Mickaël Salaün
Quoted 3 lines · Tahera Fahimi
Quoted 2 lines · Mickaël Salaün
Quoted 1 line · Tahera Fahimi

On Tue, Apr 02, 2024 at 11:53:09AM +0200, Mickaël Salaün wrote:

[...]

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines

Because of compatibility reasons, and because Landlock should be flexible, we need to extend the user space interface. As explained in the GitHub issue, we need to add a new "scoped" field to the landlock_ruleset_attr struct. This field will optionally contain a LANDLOCK_RULESET_SCOPED_ABSTRACT_UNIX_SOCKET flag to specify that this ruleset will deny any connection from within the sandbox to its parents (i.e. any parent sandbox or not-sandboxed processes).

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Thanks for the feedback. Here is what I understood, please correct me if I am wrong. First, I should add another field to the landlock_ruleset_attr (a field like handled_access_net, but for the unix sockets) with a flag LANDLOCK_ACCESS_UNIX_CONNECT (it is a flag like LANDLOCK_ACCESS_NET_CONNECT_TCP but fot the unix sockets connect).

Yes, but the field's name should be "scoped", and it will only accept a LANDLOCK_RULESET_SCOPED_ABSTRACT_UNIX_SOCKET flag.

This is a bit different than handled_access_net because there is no rule that would accept LANDLOCK_RULESET_SCOPED_ABSTRACT_UNIX_SOCKET (i.e. it is a restriction-only).

Without LANDLOCK_RULESET_SCOPED_ABSTRACT_UNIX_SOCKET, the current behavior should not be changed. This should be covered with appropriate tests.

Taking the following examples for domains with LANDLOCK_RULESET_SCOPED_ABSTRACT_UNIX_SOCKET, we get the same restrictions as with ptrace:

[...]

Quoted 7 lines

/*
* No domain
*
* P1-. P1 -> P2 : allow
* \ P2 -> P1 : allow
* 'P2
*/

This is still correct.

Quoted 9 lines

/*
* Child domain:
*
* P1--. P1 -> P2 : deny

 *        \             P2 -> P1 : deny
 *        .'-----.
 *        |  P2  |
 *        '------'

*/

With the "scoped" approach:
P1 -> P2: allow
P2 -> P1: deny

Quoted 8 lines

/*
* Parent domain
* .------.
* | P1 --. P1 -> P2 : allow
* '------' \ P2 -> P1 : allow
* '
* P2
*/

With the "scoped" approach:
P1 -> P2: deny
P2 -> P1: allow

Indeed, only the domain hierarchy matters, not the process hierarchy. This works the same way with ptrace restrictions.

Quoted 9 lines

/*
* Parent + child domain(inherited)
* .------.
* | P1 ---. P1 -> P2 : deny
* '------' \ P2 -> P1 : deny

 *         .---'--.
 *         |  P2  |
 *         '------'

*/

This is still correct.

Quoted 9 lines

/*
* Same domain (sibling)
* .-------------.

 * | P1----.     |      P1 -> P2 : allow
 * |        \    |      P2 -> P1 : allow
 * |         '   |
 * |         P2  |

* '-------------'
*/

This is still correct.

Quoted 10 lines

/*
* Inherited + child domain
* .-----------------.

 * |  P1----.        |  P1 -> P2 : deny
 * |         \       |  P2 -> P1 : deny
 * |        .-'----. |
 * |        |  P2  | |
 * |        '------' |

* '-----------------'
*/

With the "scoped" approach:
P1 -> P2: allow
P2 -> P1: deny

Quoted 10 lines

/*
* Inherited + parent domain
* .-----------------.

 * |.------.         |  P1 -> P2 : allow
 * ||  P1  ----.     |  P2 -> P1 : allow
 * |'------'    \    |
 * |             '   |
 * |             P2  |

* '-----------------'
*/

With the "scoped" approach:
P1 -> P2: deny
P2 -> P1: allow

Quoted 10 lines

/*
* Inherited + parent and child domain
* .-----------------.

 * | .------.        |  P1 -> P2 : deny
 * | |  P1  .        |  P2 -> P1 : deny
 * | '------'\       |
 * |          \      |
 * |        .--'---. |
 * |        |  P2  | |
 * |        '------' |
Quoted 2 lines

* '-----------------'
*/

This is still correct.