Skip to contentSkip to conversation

Add Landlock UDP support documentation

PATCH Superseded Matthieu Buffet 5 participants 27 messages Sep 17 – Nov 18 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

cover Add Landlock UDP support documentation

Hi Alejandro, Mickaël, Günther,

Here is a small update to landlock.7 and landlock_add_rule.2 to add missing TCP info, and add UDP specifics introduced in kernels 7.2+. With the benefit of hindsight, re-reading UAPI header changes, I actually did a bit more than copy-pasting from them (see patch 3/3):
- explicitly state in the access right description that sending datagrams without a destination does not require any access right
- more importantly: clarify the description of the most non-trivial behaviour (auto-bind denials when emitting, which can occur even if CONNECT_SEND_UDP is not handled)
Mickaël, if you are okay with these additions, would you like them in a UAPI header patch to sync the two?

Have a nice day!

Matthieu Buffet (3):
man/man2/landlock_add_rule.2: Clarify ephemeral port range man/man7/landlock.7: Document AF_UNSPEC behaviour and error codes man/man7/landlock.7, man/man2/landlock_add_rule.2: Document UDP
support

 man/man2/landlock_add_rule.2 | 23 +++++++---
 man/man7/landlock.7          | 88 ++++++++++++++++++++++++++++++++++--
 2 files changed, 102 insertions(+), 9 deletions(-)

base-commit: dbc7211e1e52dcd485bd3e081cfa761506edc4e9

Signature · 1 line
2.47.3
#1 lore raw

PATCH 1/3 man/man2/landlock_add_rule.2: Clarify ephemeral port range

Clarify that ephemeral port range can differ from system to system, and that a compromised application can choose (without any randomness) exactly which ephemeral port will be chosen next (as long as it is within the kernel-wide ip_local_port_range)

---
 man/man2/landlock_add_rule.2 | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
man/man2/landlock_add_rule.2 +6 -2
index fe01a98d99ea..633d89824373 100644
@@ -109,9 +109,13 @@ is the network port in host endianness.
 It should be noted that port 0 passed to
 .BR bind (2)
 will bind to an available port from the ephemeral port range.
-This can be configured in the
+The range is configured globally in the
 .I /proc/sys/net/ipv4/ip_local_port_range
-sysctl (also used for IPv6).
+sysctl (also used for IPv6),
+and can be further restricted per-socket using
+.BR setsockopt (2)
+with
+.BR IP_LOCAL_PORT_RANGE (2const).
 .IP
 A Landlock rule with port 0
 and the
Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH 1/3] man/man2/landlock_add_rule.2: Clarify ephemeral port range

Quoted 15 lines · Matthieu Buffet

Clarify that ephemeral port range can differ from system to system, and that a compromised application can choose (without any randomness) exactly which ephemeral port will be chosen next (as long as it is within the kernel-wide ip_local_port_range)

---
 man/man2/landlock_add_rule.2 | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
man/man2/landlock_add_rule.2 +0 -0
index fe01a98d99ea..633d89824373 100644

man/man2/landlock_add_rule.2 is the network port in host endianness. · line 115

Quoted 9 lines
man/man2/landlock_add_rule.2 +3 -2
@@ -109,9 +109,13 @@ is the network port in host endianness.
 It should be noted that port 0 passed to
 .BR bind (2)
 will bind to an available port from the ephemeral port range.
-This can be configured in the
+The range is configured globally in the
 .I /proc/sys/net/ipv4/ip_local_port_range
-sysctl (also used for IPv6).
+sysctl (also used for IPv6),
+and can be further restricted per-socket using

Grammar nit: I believe this should be "per socket".

Quoted 9 lines
man/man2/landlock_add_rule.2 +3 -0
+.BR setsockopt (2)
+with
+.BR IP_LOCAL_PORT_RANGE (2const).
 .IP
 A Landlock rule with port 0
 and the
Signature · 1 line
2.47.3

High level remark: The kernel-side documentation has slightly different phrasing, saying:

It should be noted that port 0 passed to bind(2) will bind to an available port from the ephemeral port range. This can be configured with the /proc/sys/net/ipv4/ip_local_port_range sysctl (also used for IPv6), and within that range, on a per-socket basis with setsockopt(IP_LOCAL_PORT_RANGE).

But I think your variant is slightly clearer. Do you plan to update the kernel-side documentation as well?

Thanks,
–Günther

Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] man/man2/landlock_add_rule.2: Clarify ephemeral port range

In reply to Matthieu Buffet
Quoted 6 lines · Matthieu Buffet

Clarify that ephemeral port range can differ from system to system, and that a compromised application can choose (without any randomness) exactly which ephemeral port will be chosen next (as long as it is within the kernel-wide ip_local_port_range)

With Günther's nits:

Quoted 27 lines
---
 man/man2/landlock_add_rule.2 | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
man/man2/landlock_add_rule.2 +6 -2
index fe01a98d99ea..633d89824373 100644
@@ -109,9 +109,13 @@ is the network port in host endianness.
 It should be noted that port 0 passed to
 .BR bind (2)
 will bind to an available port from the ephemeral port range.
-This can be configured in the
+The range is configured globally in the
 .I /proc/sys/net/ipv4/ip_local_port_range
-sysctl (also used for IPv6).
+sysctl (also used for IPv6),
+and can be further restricted per-socket using
+.BR setsockopt (2)
+with
+.BR IP_LOCAL_PORT_RANGE (2const).
 .IP
 A Landlock rule with port 0
 and the
Signature · 1 line
2.47.3
#4 lore raw

PATCH 2/3 man/man7/landlock.7: Document AF_UNSPEC behaviour and error codes

In reply to Matthieu Buffet

Current TCP documentation is missing a description of how AF_UNSPEC is mapped (depending on operation and address contents) to AF_INET, and the error codes synthesized by Landlock.

---
 man/man7/landlock.7 | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
man/man7/landlock.7 +18 -0
index 880dd50582f3..51e63f40052c 100644
@@ -276,6 +276,24 @@ Bind a TCP socket to a local port.
 .TP
 .BR LANDLOCK_ACCESS_NET_CONNECT_TCP "  (since Landlock ABI version 4)"
 Connect an active TCP socket to a remote port.
+.P
+Note on
+.BR AF_UNSPEC :
+Calling
+.BR connect (2)
+with that address family
+can only dissolve existing associations,
+and as such is always allowed.
+Calling
+.BR bind (2)
+with that address family
+is treated the same way the network stack treats it:
+for IPv4 and
+.B INADDR_ANY
+it is treated as
+.BR AF_INET .
+All other uses of that address family result in the same error codes
+as when Landlock is not in use.
 .\"
 .SS Scope flags
 These flags enable isolating a sandboxed process from a set of IPC actions.
Signature · 1 line
2.47.3
#5 lore raw

Re: [PATCH 2/3] man/man7/landlock.7: Document AF_UNSPEC behaviour and error codes

Nit in patch subject: "behavior" (man pages use US English)

Quoted 14 lines · Matthieu Buffet

Current TCP documentation is missing a description of how AF_UNSPEC is mapped (depending on operation and address contents) to AF_INET, and the error codes synthesized by Landlock.

---
 man/man7/landlock.7 | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
man/man7/landlock.7 +0 -0
index 880dd50582f3..51e63f40052c 100644

man/man7/landlock.7 Bind a TCP socket to a local port. · line 284

Quoted 9 lines
man/man7/landlock.7 +6 -0
@@ -276,6 +276,24 @@ Bind a TCP socket to a local port.
 .TP
 .BR LANDLOCK_ACCESS_NET_CONNECT_TCP "  (since Landlock ABI version 4)"
 Connect an active TCP socket to a remote port.
+.P
+Note on
+.BR AF_UNSPEC :
+Calling
+.BR connect (2)
+with that address family

I realize this is technically correct, but to a reader who does not remember the nomenclature of the socket() call in detail, it is possible to misinterpret "that address family" as referring to TCP, rather than to "AF_UNSPEC".

connect(AF_UNSPEC) also does not work universally on all socket families and types (see connect(2)), so the socket that it's being used with also has an address family that plays a role here.

Maybe simpler to just say "AF_UNSPEC" instead of "that address family"?

Quoted 4 lines
man/man7/landlock.7 +2 -0
+can only dissolve existing associations,
+and as such is always allowed.
 
 

man/man7/landlock.7 Bind a TCP socket to a local port. · line 296

Quoted 10 lines
man/man7/landlock.7 +10 -0
+Calling
+.BR bind (2)
+with that address family
+is treated the same way the network stack treats it:
+for IPv4 and
+.B INADDR_ANY
+it is treated as
+.BR AF_INET .
+All other uses of that address family result in the same error codes
+as when Landlock is not in use.

It's unclear to me how bind() with an AF_UNSPEC family address is relevant to Landlock sandboxing? Is this relevant to include?

Quoted 6 lines
man/man7/landlock.7 +0 -0
 .\"

.SS Scope flags
These flags enable isolating a sandboxed process from a set of IPC actions.

Signature · 1 line
2.47.3

I also could not find this change in the kernel documentation, I assume you plan to copy it there as well?

–Günther

#6 lore raw

PATCH 3/3 man/man7/landlock.7, man/man2/landlock_add_rule.2: Document UDP support

In reply to Matthieu Buffet

Landlock support for UDP-specific policy was merged in 7.2 in linux.git 9a8ed15ce224 ("landlock: Add UDP bind() access control") and
linux.git e61247a2e694 ("landlock: Add UDP send+connect access control")

Update the example to account for ABI v10, and add documentation for new access rights taken from the UAPI header, plus:
- explicitly state in the access right description that sending datagrams without a destination does not require any access right
- more importantly: clarify the description of the most non-trivial behaviour (auto-bind denials when emitting, which can occur even if CONNECT_SEND_UDP is not handled)

---
 man/man2/landlock_add_rule.2 | 15 +++++---
 man/man7/landlock.7          | 70 ++++++++++++++++++++++++++++++++++--
 2 files changed, 78 insertions(+), 7 deletions(-)
man/man2/landlock_add_rule.2 +11 -4
index 633d89824373..2b2b28147de0 100644
@@ -82,7 +82,7 @@ just a file.
 .TP
 .BR LANDLOCK_RULE_NET_PORT "  (since Landlock ABI version 4)"
 For these rules,
-the object is a TCP port,
+the object is a TCP or UDP port,
 and the related actions are defined with
 .IR "network access rights" .
 .IP
@@ -120,8 +120,14 @@ with
 A Landlock rule with port 0
 and the
 .B LANDLOCK_ACCESS_NET_BIND_TCP
-right means that requesting to bind on port 0 is allowed
-and it will automatically translate to binding on the related port range.
+or
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+right means that requesting to bind on port 0
+(explicitly, or implicitly
+by e.g.\& sending a datagram on an unbound UDP socket)
+is allowed
+and it will automatically translate to
+binding on a kernel-assigned ephemeral port.
 .P
 .I flags
 must be 0.
@@ -141,7 +147,8 @@ can fail for the following reasons:
 .I rule_type
 is
 .BR LANDLOCK_RULE_NET_PORT ,
-but TCP is not supported by the running kernel.
+but the kernel was built without
+.BR CONFIG_INET .
 .TP
 .B EBADF
 .I ruleset_fd
man/man7/landlock.7 +67 -3

106 lines not on this page · raw message

Signature · 1 line
2.47.3
Reviewed-by on v1 3/3
#7 lore raw

Re: [PATCH 3/3] man/man7/landlock.7, man/man2/landlock_add_rule.2: Document UDP support

Nit: On subject line: You can use "man/man?/landlock*.?", similar to Tingmao's commit bd51589f (2026-09-11; "man/man?/landlock*.?: Document LANDLOCK_ADD_RULE_QUIET")

High level remark: This patch does not apply cleanly, can you please rebase? I think it might be conflicting with Tingmao's recent "quiet flag" changes.

Quoted 34 lines · Matthieu Buffet

Landlock support for UDP-specific policy was merged in 7.2 in linux.git 9a8ed15ce224 ("landlock: Add UDP bind() access control") and
linux.git e61247a2e694 ("landlock: Add UDP send+connect access control")

Update the example to account for ABI v10, and add documentation for new access rights taken from the UAPI header, plus:
- explicitly state in the access right description that sending datagrams without a destination does not require any access right
- more importantly: clarify the description of the most non-trivial behaviour (auto-bind denials when emitting, which can occur even if CONNECT_SEND_UDP is not handled)

---
 man/man2/landlock_add_rule.2 | 15 +++++---
 man/man7/landlock.7          | 70 ++++++++++++++++++++++++++++++++++--
 2 files changed, 78 insertions(+), 7 deletions(-)
man/man2/landlock_add_rule.2 +1 -1
index 633d89824373..2b2b28147de0 100644
@@ -82,7 +82,7 @@ just a file.
 .TP
 .BR LANDLOCK_RULE_NET_PORT "  (since Landlock ABI version 4)"
 For these rules,
-the object is a TCP port,
+the object is a TCP or UDP port,
 and the related actions are defined with
 .IR "network access rights" .
 .IP

man/man2/landlock_add_rule.2 with · line 127

Quoted 10 lines
man/man2/landlock_add_rule.2 +5 -2
@@ -120,8 +120,14 @@ with
 A Landlock rule with port 0
 and the
 .B LANDLOCK_ACCESS_NET_BIND_TCP
-right means that requesting to bind on port 0 is allowed
-and it will automatically translate to binding on the related port range.
+or
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+right means that requesting to bind on port 0
+(explicitly, or implicitly
+by e.g.\& sending a datagram on an unbound UDP socket)
      ^^^^^^

Per man-pages(7) style guide, "e.g." is followed by a comma and should be avoided except in short parenthetical asides (e.g., like this one).

man/man2/landlock_add_rule.2 can fail for the following reasons: · line 151

Quoted 13 lines
man/man2/landlock_add_rule.2 +5 -1
+is allowed
+and it will automatically translate to
+binding on a kernel-assigned ephemeral port.
 .P
 .I flags
 must be 0.
@@ -141,7 +147,8 @@ can fail for the following reasons:
 .I rule_type
 is
 .BR LANDLOCK_RULE_NET_PORT ,
-but TCP is not supported by the running kernel.
+but the kernel was built without
+.BR CONFIG_INET .

Good catch, this should be adapted in the kernel documentation as well.

Quoted 23 lines
man/man2/landlock_add_rule.2 +0 -0
 .TP
 .B EBADF
 .I ruleset_fd
man/man7/landlock.7 +3 -2
index 51e63f40052c..884e1d49feb0 100644
@@ -53,8 +53,8 @@ For these rules, the object is a file hierarchy,
 and the related filesystem actions are defined with
 .IR "filesystem access rights" .
 .TP
-.BR "Network rules" " (since ABI v4)"
-For these rules, the object is a TCP port,
+.BR "Network rules" " (since ABI v4 for TCP, v10 for UDP)"
+For these rules, the object is a TCP or UDP port,
 and the related actions are defined with
 .IR "network access rights" .
 .\"
@@ -277,6 +277,55 @@ Bind a TCP socket to a local port.
 .BR LANDLOCK_ACCESS_NET_CONNECT_TCP "  (since Landlock ABI version 4)"
 Connect an active TCP socket to a remote port.
 .P
+And similarly for UDP port numbers:

man/man7/landlock.7 Bind a TCP socket to a local port. · line 290

Quoted 10 lines
man/man7/landlock.7 +10 -0
+.TP
+.BR LANDLOCK_ACCESS_NET_BIND_UDP "  (since Landlock ABI version 10)"
+Bind a UDP socket to the given local port.
+.TP
+.BR LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP "  (since Landlock ABI version 10)"
+Set the remote port of a UDP socket to the given port,
+or send datagrams to the given remote port
+taking precedence over any destination pre-set on a socket.
+Sending without an explicit destination
+(i.e.\& on a socket already connected)

Same for "i.e." as for "e.g.".

Quoted 89 lines
man/man7/landlock.7 +54 -1
+is never restricted.
+.P
+Note on auto-binding:
+Setting a remote address
+or sending a first datagram
+on UDP sockets
+performs an implicit
+.BR bind (2)
+to an ephemeral local source port
+if not already bound.
+If
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+is handled,
+to avoid an
+.B EACCES
+error when sending outbound datagrams
+(even if
+.B LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP
+is not handled),
+either:
+.IP \[bu] 3
+use a socket already bound to a port
+before the ruleset started being enforced;
+.IP \[bu] 3
+grant
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+on port 0, meaning
+\[lq]any port in the ephemeral port range\[rq];
+.IP \[bu] 3
+grant
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+on a specific port,
+and call
+.BR bind (2)
+on that port before trying to
+.BR connect (2)
+or send datagrams.
+.P
 Note on
 .BR AF_UNSPEC :
 Calling
@@ -292,6 +341,17 @@ for IPv4 and
 .B INADDR_ANY
 it is treated as
 .BR AF_INET .
+Sending datagrams to that address family
+on IPv4 UDP sockets
+will similarly be treated as
+.BR AF_INET .
+On IPv6 UDP sockets,
+such use is not supported
+and will always result in a denial as if the policy rejected it:
+use a
+.I NULL
+address instead to get the same semantics
+inside and outside a Landlock domain.
 All other uses of that address family result in the same error codes
 as when Landlock is not in use.
 .\"
@@ -518,6 +578,9 @@ _	_	_
 8	7.0	LANDLOCK_RESTRICT_SELF_TSYNC
 _	_	_
 9	7.1	LANDLOCK_ACCESS_FS_RESOLVE_UNIX
+_	_	_
+10	7.2	LANDLOCK_ACCESS_NET_BIND_UDP
+\^	\^	LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP
 .TE
 .P
 Users should use the Landlock ABI version rather than the kernel version
@@ -628,6 +691,7 @@ __u64 landlock_fs_access_rights[] = {
     (LANDLOCK_ACCESS_FS_IOCTL_DEV    << 1) \- 1,  // v7: same
     (LANDLOCK_ACCESS_FS_IOCTL_DEV    << 1) \- 1,  // v8: same
     (LANDLOCK_ACCESS_FS_RESOLVE_UNIX << 1) \- 1,  // v9: add "resolve_unix"
+    (LANDLOCK_ACCESS_FS_RESOLVE_UNIX << 1) \- 1,  // v10: UDP support
 };
 \&
 int abi = landlock_create_ruleset(NULL, 0,
@@ -640,7 +704,7 @@ if (abi == \-1) {
     perror("Unable to use Landlock");
     return;  /* Graceful fallback: Do nothing.  */
 }
-abi = MIN(abi, 9);
+abi = MIN(abi, 10);
 \&
 /* Only use the available rights in the ruleset.  */
 attr.handled_access_fs &= landlock_fs_access_rights[abi \- 1];
Signature · 1 line
2.47.3

Documentation seems correct.

I notcied that the original kernel documentation was rephrased in multiple places. I think these rephrases are largely good and help to explain the subject, but I'm a bit worried that the two documentation places might drift apart. Are you planning on sending a follow-up on the kernel side to keep both sides in sync?

In some cases, we might need to balance conciseness and detail (e.g., you might want to see how this looks rendered (man -l) to see that the descriptions of the UDP rights are not significantly longer than the ones for TCP.)

Thanks,
-Günther

Reviewed-by
#8 lore raw

Re: [PATCH 3/3] man/man7/landlock.7, man/man2/landlock_add_rule.2: Document UDP support

Quoted 204 lines · Günther Noack

Nit: On subject line: You can use "man/man?/landlock*.?", similar to Tingmao's commit bd51589f (2026-09-11; "man/man?/landlock*.?: Document LANDLOCK_ADD_RULE_QUIET")

High level remark: This patch does not apply cleanly, can you please rebase? I think it might be conflicting with Tingmao's recent "quiet flag" changes.

Quoted 34 lines · Matthieu Buffet

Landlock support for UDP-specific policy was merged in 7.2 in linux.git 9a8ed15ce224 ("landlock: Add UDP bind() access control") and
linux.git e61247a2e694 ("landlock: Add UDP send+connect access control")

Update the example to account for ABI v10, and add documentation for new access rights taken from the UAPI header, plus:
- explicitly state in the access right description that sending datagrams without a destination does not require any access right
- more importantly: clarify the description of the most non-trivial behaviour (auto-bind denials when emitting, which can occur even if CONNECT_SEND_UDP is not handled)

---
 man/man2/landlock_add_rule.2 | 15 +++++---
 man/man7/landlock.7          | 70 ++++++++++++++++++++++++++++++++++--
 2 files changed, 78 insertions(+), 7 deletions(-)
man/man2/landlock_add_rule.2 +1 -1
index 633d89824373..2b2b28147de0 100644
@@ -82,7 +82,7 @@ just a file.
 .TP
 .BR LANDLOCK_RULE_NET_PORT "  (since Landlock ABI version 4)"
 For these rules,
-the object is a TCP port,
+the object is a TCP or UDP port,
 and the related actions are defined with
 .IR "network access rights" .
 .IP

man/man2/landlock_add_rule.2 with · line 127

Quoted 10 lines
man/man2/landlock_add_rule.2 +5 -2
@@ -120,8 +120,14 @@ with
 A Landlock rule with port 0
 and the
 .B LANDLOCK_ACCESS_NET_BIND_TCP
-right means that requesting to bind on port 0 is allowed
-and it will automatically translate to binding on the related port range.
+or
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+right means that requesting to bind on port 0
+(explicitly, or implicitly
+by e.g.\& sending a datagram on an unbound UDP socket)
      ^^^^^^

Per man-pages(7) style guide, "e.g." is followed by a comma and should be avoided except in short parenthetical asides (e.g., like this one).

man/man2/landlock_add_rule.2 can fail for the following reasons: · line 151

Quoted 13 lines
man/man2/landlock_add_rule.2 +5 -1
+is allowed
+and it will automatically translate to
+binding on a kernel-assigned ephemeral port.
 .P
 .I flags
 must be 0.
@@ -141,7 +147,8 @@ can fail for the following reasons:
 .I rule_type
 is
 .BR LANDLOCK_RULE_NET_PORT ,
-but TCP is not supported by the running kernel.
+but the kernel was built without
+.BR CONFIG_INET .

Good catch, this should be adapted in the kernel documentation as well.

Quoted 23 lines
man/man2/landlock_add_rule.2 +0 -0
 .TP
 .B EBADF
 .I ruleset_fd
man/man7/landlock.7 +3 -2
index 51e63f40052c..884e1d49feb0 100644
@@ -53,8 +53,8 @@ For these rules, the object is a file hierarchy,
 and the related filesystem actions are defined with
 .IR "filesystem access rights" .
 .TP
-.BR "Network rules" " (since ABI v4)"
-For these rules, the object is a TCP port,
+.BR "Network rules" " (since ABI v4 for TCP, v10 for UDP)"
+For these rules, the object is a TCP or UDP port,
 and the related actions are defined with
 .IR "network access rights" .
 .\"
@@ -277,6 +277,55 @@ Bind a TCP socket to a local port.
 .BR LANDLOCK_ACCESS_NET_CONNECT_TCP "  (since Landlock ABI version 4)"
 Connect an active TCP socket to a remote port.
 .P
+And similarly for UDP port numbers:

man/man7/landlock.7 Bind a TCP socket to a local port. · line 290

Quoted 10 lines
man/man7/landlock.7 +10 -0
+.TP
+.BR LANDLOCK_ACCESS_NET_BIND_UDP "  (since Landlock ABI version 10)"
+Bind a UDP socket to the given local port.
+.TP
+.BR LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP "  (since Landlock ABI version 10)"
+Set the remote port of a UDP socket to the given port,
+or send datagrams to the given remote port
+taking precedence over any destination pre-set on a socket.
+Sending without an explicit destination
+(i.e.\& on a socket already connected)

Same for "i.e." as for "e.g.".

Quoted 89 lines
man/man7/landlock.7 +54 -1
+is never restricted.
+.P
+Note on auto-binding:
+Setting a remote address
+or sending a first datagram
+on UDP sockets
+performs an implicit
+.BR bind (2)
+to an ephemeral local source port
+if not already bound.
+If
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+is handled,
+to avoid an
+.B EACCES
+error when sending outbound datagrams
+(even if
+.B LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP
+is not handled),
+either:
+.IP \[bu] 3
+use a socket already bound to a port
+before the ruleset started being enforced;
+.IP \[bu] 3
+grant
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+on port 0, meaning
+\[lq]any port in the ephemeral port range\[rq];
+.IP \[bu] 3
+grant
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+on a specific port,
+and call
+.BR bind (2)
+on that port before trying to
+.BR connect (2)
+or send datagrams.
+.P
 Note on
 .BR AF_UNSPEC :
 Calling
@@ -292,6 +341,17 @@ for IPv4 and
 .B INADDR_ANY
 it is treated as
 .BR AF_INET .
+Sending datagrams to that address family
+on IPv4 UDP sockets
+will similarly be treated as
+.BR AF_INET .
+On IPv6 UDP sockets,
+such use is not supported
+and will always result in a denial as if the policy rejected it:
+use a
+.I NULL
+address instead to get the same semantics
+inside and outside a Landlock domain.
 All other uses of that address family result in the same error codes
 as when Landlock is not in use.
 .\"
@@ -518,6 +578,9 @@ _	_	_
 8	7.0	LANDLOCK_RESTRICT_SELF_TSYNC
 _	_	_
 9	7.1	LANDLOCK_ACCESS_FS_RESOLVE_UNIX
+_	_	_
+10	7.2	LANDLOCK_ACCESS_NET_BIND_UDP
+\^	\^	LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP
 .TE
 .P
 Users should use the Landlock ABI version rather than the kernel version
@@ -628,6 +691,7 @@ __u64 landlock_fs_access_rights[] = {
     (LANDLOCK_ACCESS_FS_IOCTL_DEV    << 1) \- 1,  // v7: same
     (LANDLOCK_ACCESS_FS_IOCTL_DEV    << 1) \- 1,  // v8: same
     (LANDLOCK_ACCESS_FS_RESOLVE_UNIX << 1) \- 1,  // v9: add "resolve_unix"
+    (LANDLOCK_ACCESS_FS_RESOLVE_UNIX << 1) \- 1,  // v10: UDP support
 };
 \&
 int abi = landlock_create_ruleset(NULL, 0,
@@ -640,7 +704,7 @@ if (abi == \-1) {
     perror("Unable to use Landlock");
     return;  /* Graceful fallback: Do nothing.  */
 }
-abi = MIN(abi, 9);
+abi = MIN(abi, 10);
 \&
 /* Only use the available rights in the ruleset.  */
 attr.handled_access_fs &= landlock_fs_access_rights[abi \- 1];
Signature · 1 line
2.47.3

Documentation seems correct.

Quoted 5 lines

I notcied that the original kernel documentation was rephrased in multiple places. I think these rephrases are largely good and help to explain the subject, but I'm a bit worried that the two documentation places might drift apart. Are you planning on sending a follow-up on the kernel side to keep both sides in sync?

As Matthieu proposed in the cover letter, yes that would definitely be appreciated.

Quoted 7 lines

In some cases, we might need to balance conciseness and detail (e.g., you might want to see how this looks rendered (man -l) to see that the descriptions of the UDP rights are not significantly longer than the ones for TCP.)

Quoted 3 lines

Thanks,
-Günther

#9 lore raw
In reply to Matthieu Buffet
Quoted 11 lines · Matthieu Buffet

Hi Alejandro, Mickaël, Günther,

Here is a small update to landlock.7 and landlock_add_rule.2 to add missing TCP info, and add UDP specifics introduced in kernels 7.2+. With the benefit of hindsight, re-reading UAPI header changes, I actually did a bit more than copy-pasting from them (see patch 3/3):
- explicitly state in the access right description that sending datagrams without a destination does not require any access right
- more importantly: clarify the description of the most non-trivial behaviour (auto-bind denials when emitting, which can occur even if CONNECT_SEND_UDP is not handled)

Thanks for the patches!

Quoted 2 lines

Mickaël, if you are okay with these additions, would you like them in a UAPI header patch to sync the two?

Yes please.

Quoted 20 lines

Have a nice day!

Matthieu Buffet (3):
man/man2/landlock_add_rule.2: Clarify ephemeral port range man/man7/landlock.7: Document AF_UNSPEC behaviour and error codes man/man7/landlock.7, man/man2/landlock_add_rule.2: Document UDP
support

 man/man2/landlock_add_rule.2 | 23 +++++++---
 man/man7/landlock.7          | 88 ++++++++++++++++++++++++++++++++++--
 2 files changed, 102 insertions(+), 9 deletions(-)

base-commit: dbc7211e1e52dcd485bd3e081cfa761506edc4e9

Signature · 1 line
2.47.3
#10 lore raw
Quoted 13 lines · Mickaël Salaün
Quoted 11 lines · Matthieu Buffet

Hi Alejandro, Mickaël, Günther,

Here is a small update to landlock.7 and landlock_add_rule.2 to add missing TCP info, and add UDP specifics introduced in kernels 7.2+. With the benefit of hindsight, re-reading UAPI header changes, I actually did a bit more than copy-pasting from them (see patch 3/3):
- explicitly state in the access right description that sending datagrams without a destination does not require any access right
- more importantly: clarify the description of the most non-trivial behaviour (auto-bind denials when emitting, which can occur even if CONNECT_SEND_UDP is not handled)

Quoted 1 line

Thanks for the patches!

Hello Matthieu!

Friendly ping on this, to make sure we don't forget it -- do you think you could find the time to send a small follow-up to this?

Thanks,
–Günther

#11 lore raw

Hi Günther,

Quoted 2 lines · Günther Noack

Friendly ping on this, to make sure we don't forget it -- do you think you could find the time to send a small follow-up to this?

Sorry, busy days. Here are the patches with your comments taken into account and fixed, and I have a patch ready to sync the UAPI header if these look ok.

Have a nice day,

Matthieu

#12 lore raw

PATCH v2 1/2 man/man2/landlock_add_rule.2: Clarify ephemeral port range

Clarify that ephemeral port range can differ from system to system, and that an application can choose exactly which ephemeral port will be chosen next (as long as it is within the kernel-wide ip_local_port_range).

---
 man/man2/landlock_add_rule.2 | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
man/man2/landlock_add_rule.2 +6 -2
index 94bc63068935..253498bfa2cf 100644
@@ -109,9 +109,13 @@ is the network port in host endianness.
 It should be noted that port 0 passed to
 .BR bind (2)
 will bind to an available port from the ephemeral port range.
-This can be configured in the
+The range is configured globally in the
 .I /proc/sys/net/ipv4/ip_local_port_range
-sysctl (also used for IPv6).
+sysctl (also used for IPv6),
+and can be further restricted per socket using
+.BR setsockopt (2)
+with
+.BR IP_LOCAL_PORT_RANGE (2const).
 .IP
 A Landlock rule with port 0
 and the

base-commit: c189a6b2e4dd2e74f3b360b24e489e27f4e45bad

Signature · 1 line
2.47.3
#13 lore raw

PATCH v2 2/2 man/man?/landlock*.?: Document UDP support

Landlock support for UDP-specific policy was merged in 7.2 in linux.git 9a8ed15ce224 ("landlock: Add UDP bind() access control") and
linux.git e61247a2e694 ("landlock: Add UDP send+connect access control")

Add documentation for new access rights taken from the UAPI header, plus:
- clarify the description of the most non-trivial behavior (auto-bind denials when emitting, which can occur even if CONNECT_SEND_UDP is not handled)
- improve AF_UNSPEC behavior description in both connect() and IPv6-send cases
- minor wording fixes to be backported in the UAPI header

---
 man/man2/landlock_add_rule.2 | 14 +++++--
 man/man7/landlock.7          | 74 +++++++++++++++++++++++++++++++++++-
 2 files changed, 82 insertions(+), 6 deletions(-)
man/man2/landlock_add_rule.2 +10 -4
index 253498bfa2cf..337ff4150f2c 100644
@@ -82,7 +82,7 @@ just a file.
 .TP
 .BR LANDLOCK_RULE_NET_PORT "  (since Landlock ABI version 4)"
 For these rules,
-the object is a TCP port,
+the object is a TCP or UDP port,
 and the related actions are defined with
 .IR "network access rights" .
 .IP
@@ -120,8 +120,13 @@ with
 A Landlock rule with port 0
 and the
 .B LANDLOCK_ACCESS_NET_BIND_TCP
-right means that requesting to bind on port 0 is allowed
-and it will automatically translate to binding on the related port range.
+or
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+right means that requesting to bind on port 0
+(explicitly, or implicitly
+for instance by sending a datagram on an unbound UDP socket)
+is allowed
+and it will automatically translate to binding on a kernel-assigned ephemeral port.
 .P
 .I flags
 is a bit mask of the following optional flags:
@@ -181,7 +186,8 @@ can fail for the following reasons:
 .I rule_type
 is
 .BR LANDLOCK_RULE_NET_PORT ,
-but TCP is not supported by the running kernel.
+but the kernel was built without
+.BR CONFIG_INET .
 .TP
 .B EBADF
 .I ruleset_fd
man/man7/landlock.7 +72 -2

92 lines not on this page · raw message

Signature · 1 line
2.47.3
#14 lore raw

Re: [PATCH v2 2/2] man/man?/landlock*.?: Document UDP support

Quoted 36 lines · Matthieu Buffet

Landlock support for UDP-specific policy was merged in 7.2 in linux.git 9a8ed15ce224 ("landlock: Add UDP bind() access control") and
linux.git e61247a2e694 ("landlock: Add UDP send+connect access control")

Add documentation for new access rights taken from the UAPI header, plus:
- clarify the description of the most non-trivial behavior (auto-bind denials when emitting, which can occur even if CONNECT_SEND_UDP is not handled)
- improve AF_UNSPEC behavior description in both connect() and IPv6-send cases
- minor wording fixes to be backported in the UAPI header

---
 man/man2/landlock_add_rule.2 | 14 +++++--
 man/man7/landlock.7          | 74 +++++++++++++++++++++++++++++++++++-
 2 files changed, 82 insertions(+), 6 deletions(-)
man/man2/landlock_add_rule.2 +1 -1
index 253498bfa2cf..337ff4150f2c 100644
@@ -82,7 +82,7 @@ just a file.
 .TP
 .BR LANDLOCK_RULE_NET_PORT "  (since Landlock ABI version 4)"
 For these rules,
-the object is a TCP port,
+the object is a TCP or UDP port,
 and the related actions are defined with
 .IR "network access rights" .
 .IP
@@ -120,8 +120,13 @@ with
 A Landlock rule with port 0
 and the

man/man2/landlock_add_rule.2 with · line 129

Quoted 10 lines
man/man2/landlock_add_rule.2 +7 -2
 .B LANDLOCK_ACCESS_NET_BIND_TCP
-right means that requesting to bind on port 0 is allowed
-and it will automatically translate to binding on the related port range.
+or
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+right means that requesting to bind on port 0
+(explicitly, or implicitly
+for instance by sending a datagram on an unbound UDP socket)
+is allowed
+and it will automatically translate to binding on a kernel-assigned ephemeral port.

With the caveat of not being a native speaker either, the commas in this sentence feel wrong to me.

Suggestion:

A Landlock rule with port 0 and the LANDLOCK_ACCESS_NET_BIND_TCP or

LANDLOCK_ACCESS_NET_BIND_UDP right means that requesting to bind to

                                                                   ^^
  port 0 (explicitly or implicitly, for instance, by sending a datagram
                   ^^^           ^^^           ^^^
  on an unbound socket) is allowed, and it will automatically
                                 ^^^

translate to binding on a kernel-assigned ephemeral port.

(You might also use the shorter "e.g.," instead of "for instance,".) I'm happy to stand corrected, Alejandro has a better grip on correct grammar than me. :)

Quoted 46 lines
man/man2/landlock_add_rule.2 +2 -1
 .P
 .I flags
 is a bit mask of the following optional flags:
@@ -181,7 +186,8 @@ can fail for the following reasons:
 .I rule_type
 is
 .BR LANDLOCK_RULE_NET_PORT ,
-but TCP is not supported by the running kernel.
+but the kernel was built without
+.BR CONFIG_INET .
 .TP
 .B EBADF
 .I ruleset_fd
man/man7/landlock.7 +16 -2
index ad63826da84f..296c4d74a22f 100644
@@ -53,8 +53,8 @@ For these rules, the object is a file hierarchy,
 and the related filesystem actions are defined with
 .IR "filesystem access rights" .
 .TP
-.BR "Network rules" " (since ABI v4)"
-For these rules, the object is a TCP port,
+.BR "Network rules" " (since ABI v4 for TCP, v10 for UDP)"
+For these rules, the object is a TCP or UDP port,
 and the related actions are defined with
 .IR "network access rights" .
 .\"
@@ -276,6 +276,74 @@ Bind a TCP socket to a local port.
 .TP
 .BR LANDLOCK_ACCESS_NET_CONNECT_TCP "  (since Landlock ABI version 4)"
 Connect an active TCP socket to a remote port.
+.P
+And similarly for UDP port numbers:
+.TP
+.BR LANDLOCK_ACCESS_NET_BIND_UDP "  (since Landlock ABI version 10)"
+Bind UDP sockets to the given local port.
+.TP
+.BR LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP "  (since Landlock ABI version 10)"
+Set the remote port of UDP sockets to the given port,
+or send datagrams to the given remote port
+ignoring any destination pre-set on a socket.
+.P
+Note on auto-binding:
+Setting a remote address
+or sending a first datagram

man/man7/landlock.7 Bind a TCP socket to a local port. · line 302

Quoted 10 lines
man/man7/landlock.7 +10 -0
+auto-binds
+UDP sockets
+to an ephemeral local source port
+if not already bound.
+To allow this if
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+is handled
+(even if
+.B LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP
+is not),

This phrasing is different to the kernel documentation, where it says:

To allow this if both LANDLOCK_ACCESS_NET_BIND_UDP and LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP are handled, [...]

(see https://docs.kernel.org/userspace-api/landlock.html)

Is this intentional?

Quoted 36 lines
man/man7/landlock.7 +34 -0
+either:
+.IP \[bu] 3
+use a socket already bound to a port
+before the ruleset started being enforced;
+.IP \[bu] 3
+grant
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+on port 0, meaning
+\[lq]any port in the ephemeral port range\[rq];
+.IP \[bu] 3
+grant
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+on a specific port,
+and call
+.BR bind (2)
+on that port before trying to
+.BR connect (2)
+or send datagrams.
 
 
+.P
+Note on
+.BR AF_UNSPEC :
+Calling
+.BR connect (2)
+on a TCP or UDP socket
+with an address of the
+.B AF_UNSPEC
+family
+can only dissolve existing associations,
+and as such is always allowed.
+On IPv6 UDP sockets, if
+.B LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP
+is handled,
+sending datagrams to
+.B AF_UNSPEC

man/man7/landlock.7 Bind a TCP socket to a local port. · line 346

Quoted 10 lines
man/man7/landlock.7 +10 -0
+addresses is not supported
+and will always result in a denial,
+as if the policy rejected it:
+use a
+.I NULL
+address instead to get the same semantics
+inside and outside a Landlock domain.
+Other uses of the
+.B AF_UNSPEC
+family have unchanged semantics.

This second "note" discussion seems to deviate in its meaning from what the second "note" box said in the kernel documentation.

https://docs.kernel.org/userspace-api/landlock.html#network-flags

Is this intentional?

I admittedly have trouble following the documentation in this rewritten note (and also the kernel documentation). What does "sending datagrams to AF_UNSPEC" mean in the context of IPv6? The connect(2) to AF_UNSPEC is a different matter - that one does not set up a default remote address as other UDP connects go, but it dissolves a pre-existing TCP connection, or in the UDP case, it likely removes the remote address that was configured with a previous connect(2) call with an actual address.

Quoted 15 lines
man/man7/landlock.7 +0 -0
 .\"

.SS Scope flags
These flags enable isolating a sandboxed process from a set of IPC actions.

man/man7/landlock.7 +2 -0
@@ -531,6 +599,8 @@ _	_	_
 9	7.1	LANDLOCK_ACCESS_FS_RESOLVE_UNIX
 _	_	_
 10	7.2	LANDLOCK_ADD_RULE_QUIET
+\^	\^	LANDLOCK_ACCESS_NET_BIND_UDP
+\^	\^	LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP
 .TE
 .P
 Users should use the Landlock ABI version rather than the kernel version
Signature · 1 line
2.47.3

Is the new man page phrasing one that you'd also like to carry over into the kernel documentation?

–Günther

#15 lore raw

Re: [PATCH v2 2/2] man/man?/landlock*.?: Document UDP support

Hi Günther, Matthieu,

Quoted 3 lines

Date: 2026-11-06 23:02:40+0100
From: Günther Noack <[email protected]>

[...]

Quoted 27 lines

man/man2/landlock_add_rule.2 with · line 129

Quoted 13 lines
man/man2/landlock_add_rule.2 +7 -2
@@ -120,8 +120,13 @@ with
 A Landlock rule with port 0
 and the
 .B LANDLOCK_ACCESS_NET_BIND_TCP
-right means that requesting to bind on port 0 is allowed
-and it will automatically translate to binding on the related port range.
+or
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+right means that requesting to bind on port 0
+(explicitly, or implicitly
+for instance by sending a datagram on an unbound UDP socket)
+is allowed
+and it will automatically translate to binding on a kernel-assigned ephemeral port.

With the caveat of not being a native speaker either, the commas in this sentence feel wrong to me.

Suggestion:

A Landlock rule with port 0 and the LANDLOCK_ACCESS_NET_BIND_TCP or

LANDLOCK_ACCESS_NET_BIND_UDP right means that requesting to bind to

                                                                   ^^
  port 0 (explicitly or implicitly, for instance, by sending a datagram
                   ^^^           ^^^           ^^^
  on an unbound socket) is allowed, and it will automatically
                                 ^^^
Quoted 6 lines

translate to binding on a kernel-assigned ephemeral port.

(You might also use the shorter "e.g.," instead of "for instance,".) I'm happy to stand corrected, Alejandro has a better grip on correct grammar than me. :)

Not a native speaker either, but I agree with Günther.

Have a lovely day!
Alex

Signature · 1 line
<https://www.alejandro-colomar.es>
#16 lore raw

Re: [PATCH v2 2/2] man/man?/landlock*.?: Document UDP support

Hi Günther, Alejandro,

Quoted 16 lines · Günther Noack

man/man2/landlock_add_rule.2 with · line 129

Quoted 12 lines · Matthieu Buffet

A Landlock rule with port 0
and the
.B LANDLOCK_ACCESS_NET_BIND_TCP

man/man2/landlock_add_rule.2 +7 -2
-right means that requesting to bind on port 0 is allowed
-and it will automatically translate to binding on the related port range.
+or
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+right means that requesting to bind on port 0
+(explicitly, or implicitly
+for instance by sending a datagram on an unbound UDP socket)
+is allowed
+and it will automatically translate to binding on a kernel-assigned ephemeral port.

With the caveat of not being a native speaker either, the commas in this sentence feel wrong to me.

I was trying to make the comma match the fact that the example only applies to the implicit case, but if it sounds wrong let's use your suggestion.

Quoted 9 lines

man/man7/landlock.7 Bind a TCP socket to a local port. · line 302

Quoted 6 lines
man/man7/landlock.7 +6 -0
+To allow this if
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+is handled
+(even if
+.B LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP
+is not),

This phrasing is different to the kernel documentation, where it says:

Quoted 6 lines

To allow this if both LANDLOCK_ACCESS_NET_BIND_UDP and LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP are handled, [...]

(see https://docs.kernel.org/userspace-api/landlock.html)

Is this intentional?

Absolutely, it's bullet point #1 (the most important imho) in the three divergences I listed in the patch description. My current text in the kernel docs is not technically wrong, but it does not highlight the most non-trivial case (connect+send not handled, but bind handled, causing connect+send denials).

Quoted 29 lines
Quoted 15 lines
man/man7/landlock.7 +15 -0
+Note on
+.BR AF_UNSPEC :
+Calling
+.BR connect (2)
+on a TCP or UDP socket
+with an address of the
+.B AF_UNSPEC
+family
+can only dissolve existing associations,
+and as such is always allowed.
+On IPv6 UDP sockets, if
+.B LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP
+is handled,
+sending datagrams to
+.B AF_UNSPEC

man/man7/landlock.7 Bind a TCP socket to a local port. · line 346

Quoted 10 lines
man/man7/landlock.7 +10 -0
+addresses is not supported
+and will always result in a denial,
+as if the policy rejected it:
+use a
+.I NULL
+address instead to get the same semantics
+inside and outside a Landlock domain.
+Other uses of the
+.B AF_UNSPEC
+family have unchanged semantics.

This second "note" discussion seems to deviate in its meaning from what the second "note" box said in the kernel documentation.

Quoted 3 lines

https://docs.kernel.org/userspace-api/landlock.html#network-flags

Is this intentional?

Yes that's bullet point #2, a better description ("always result in a denial, as if the policy rejected it" instead of just "not supported") of this deviation from normal network stack behavior.

Quoted 3 lines

I admittedly have trouble following the documentation in this rewritten note (and also the kernel documentation). What does "sending datagrams to AF_UNSPEC" mean in the context of IPv6?

You are correct about connect(AF_UNSPEC) semantics, and here I meant sendto()/sendmsg()/etc. on an IPv6 UDP socket with a msg_name whose family is AF_UNSPEC (which is interpreted as "no address" by the network stack). I changed this to a hopefully more explicit wording in v3.

Quoted 2 lines

Is the new man page phrasing one that you'd also like to carry over into the kernel documentation?

Absolutely, tell me what you think about v3, and once we agree on the changes I will send a patch to sync them into the docs.

Have a nice day!

Matthieu

#17 lore raw

PATCH v3 1/1 man/man?/landlock*.?: Document UDP support

Landlock support for UDP-specific policy was merged in 7.2 in linux.git 9a8ed15ce224 ("landlock: Add UDP bind() access control") and
linux.git e61247a2e694 ("landlock: Add UDP send+connect access control")

Add documentation for new access rights, taken from the UAPI header with minor deviations to be backported into it:
- clarify the most non-trivial behavior (auto-bind denials when sending if BIND_UDP is handled) without restricting to the case where CONNECT_SEND_UDP is handled
- improve description of how AF_UNSPEC destination addresses behave:
connect() is always allowed, sending is always denied (instead of just "not supported") on IPv6 UDP sockets
- minor wording improvements, nothing else semantically different

---
Changes v1->v2:
- Remove bind(AF_UNSPEC) behavior note, connect(AF_UNSPEC) note is reduced to a few words merged into a single patch
- Phrasing clarification
- Man formatting and etiquette

Changes v2->v3:
- Minor ephemeral port range rewording patch has already been merged, only one patch left
- Reword the sendto/sendmsg(AF_UNSPEC) note: we are talking about explicit addresses of AF_UNSPEC family on a domain=IPv6&type=UDP socket
- Punctuation+phrasing

 man/man2/landlock_add_rule.2 | 15 ++++++--
 man/man7/landlock.7          | 75 +++++++++++++++++++++++++++++++++++-
 2 files changed, 84 insertions(+), 6 deletions(-)
man/man2/landlock_add_rule.2 +11 -4
index 253498bfa2cf..9ff470a988d2 100644
@@ -82,7 +82,7 @@ just a file.
 .TP
 .BR LANDLOCK_RULE_NET_PORT "  (since Landlock ABI version 4)"
 For these rules,
-the object is a TCP port,
+the object is a TCP or UDP port,
 and the related actions are defined with
 .IR "network access rights" .
 .IP
@@ -120,8 +120,14 @@ with
 A Landlock rule with port 0
 and the
 .B LANDLOCK_ACCESS_NET_BIND_TCP
-right means that requesting to bind on port 0 is allowed
-and it will automatically translate to binding on the related port range.
+or
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+right means that requesting to bind to port 0
+(explicitly or implicitly,
+e.g., by sending a datagram on an unbound UDP socket)
+is allowed,
+and it will automatically translate to
+binding on a kernel-assigned ephemeral port.
 .P
 .I flags
 is a bit mask of the following optional flags:
@@ -181,7 +187,8 @@ can fail for the following reasons:
 .I rule_type
 is
 .BR LANDLOCK_RULE_NET_PORT ,
-but TCP is not supported by the running kernel.
+but the kernel was built without
+.BR CONFIG_INET .
 .TP
 .B EBADF
 .I ruleset_fd
man/man7/landlock.7 +73 -2

93 lines not on this page · raw message

base-commit: 9dc90054e92357bbe4c44f9c2a38c111f8ed7374

Signature · 1 line
2.47.3
#18 lore raw

Re: [PATCH v2 2/2] man/man?/landlock*.?: Document UDP support

In reply to Matthieu Buffet

[CC += Branden]

Hi Matthieu,

Quoted 22 lines

Date: 2026-11-15 21:55:50+0100
From: Matthieu Buffet <[email protected]>

Hi Günther, Alejandro,

Quoted 6 lines · Günther Noack

Review

Quoted 5 lines · Matthieu Buffet

A Landlock rule with port 0
and the
.B LANDLOCK_ACCESS_NET_BIND_TCP

(quoted diff) +0 -2
-right means that requesting to bind on port 0 is allowed
-and it will automatically translate to binding on the related port

range.

Quoted 7 lines

man/man2/landlock_add_rule.2 with

Quoted 7 lines
man/man2/landlock_add_rule.2 +7 -0
+or
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+right means that requesting to bind on port 0
+(explicitly, or implicitly
+for instance by sending a datagram on an unbound UDP socket)
+is allowed
+and it will automatically translate to binding on a kernel-assigned

ephemeral port.

Quoted 1 line
Quoted 5 lines
Quoted 2 lines

With the caveat of not being a native speaker either, the commas in this sentence feel wrong to me.

I was trying to make the comma match the fact that the example only applies to the implicit case, but if it sounds wrong let's use your suggestion.

Perhaps you could use two levels of separation, with ';':

	(explicitly;
	or implicitly,
	for instance, by sending a datagram ...)

But this is a bit beyond my expertise. I've CCd Branden, which will surely be able to help.

Have a lovely night!
Alex

Quoted 78 lines
Quoted 10 lines

man/man7/landlock.7 Bind a TCP socket to a local port. · line 302

Quoted 7 lines
man/man7/landlock.7 +6 -0
+To allow this if
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+is handled
+(even if
+.B LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP
+is not),

This phrasing is different to the kernel documentation, where it says:

Quoted 6 lines

To allow this if both LANDLOCK_ACCESS_NET_BIND_UDP and LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP are handled, [...]

(see https://docs.kernel.org/userspace-api/landlock.html)

Is this intentional?

Absolutely, it's bullet point #1 (the most important imho) in the three divergences I listed in the patch description. My current text in the kernel docs is not technically wrong, but it does not highlight the most non-trivial case (connect+send not handled, but bind handled, causing connect+send denials).

Quoted 29 lines
Quoted 15 lines
man/man7/landlock.7 +15 -0
+Note on
+.BR AF_UNSPEC :
+Calling
+.BR connect (2)
+on a TCP or UDP socket
+with an address of the
+.B AF_UNSPEC
+family
+can only dissolve existing associations,
+and as such is always allowed.
+On IPv6 UDP sockets, if
+.B LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP
+is handled,
+sending datagrams to
+.B AF_UNSPEC

man/man7/landlock.7 Bind a TCP socket to a local port. · line 346

Quoted 10 lines
man/man7/landlock.7 +10 -0
+addresses is not supported
+and will always result in a denial,
+as if the policy rejected it:
+use a
+.I NULL
+address instead to get the same semantics
+inside and outside a Landlock domain.
+Other uses of the
+.B AF_UNSPEC
+family have unchanged semantics.

This second "note" discussion seems to deviate in its meaning from what the second "note" box said in the kernel documentation.

Quoted 3 lines

https://docs.kernel.org/userspace-api/landlock.html#network-flags

Is this intentional?

Yes that's bullet point #2, a better description ("always result in a denial, as if the policy rejected it" instead of just "not supported") of this deviation from normal network stack behavior.

Quoted 3 lines

I admittedly have trouble following the documentation in this rewritten note (and also the kernel documentation). What does "sending datagrams to AF_UNSPEC" mean in the context of IPv6?

You are correct about connect(AF_UNSPEC) semantics, and here I meant sendto()/sendmsg()/etc. on an IPv6 UDP socket with a msg_name whose family is AF_UNSPEC (which is interpreted as "no address" by the network stack). I changed this to a hopefully more explicit wording in v3.

Quoted 2 lines

Is the new man page phrasing one that you'd also like to carry over into the kernel documentation?

Absolutely, tell me what you think about v3, and once we agree on the changes I will send a patch to sync them into the docs.

Have a nice day!

Matthieu

Signature · 1 line
<https://www.alejandro-colomar.es>
#19 lore raw

Re: [PATCH v2 2/2] man/man?/landlock*.?: Document UDP support

Hi Alex,

Quoted 25 lines · Alejandro Colomar
Quoted 19 lines

Date: 2026-11-15 21:55:50+0100
From: Matthieu Buffet <[email protected]>

Quoted 6 lines · Günther Noack

Review

Quoted 5 lines · Matthieu Buffet

A Landlock rule with port 0
and the
.B LANDLOCK_ACCESS_NET_BIND_TCP

(quoted diff) +0 -2
-right means that requesting to bind on port 0 is allowed
-and it will automatically translate to binding on the related port

range.

Quoted 7 lines

man/man2/landlock_add_rule.2 with

Quoted 7 lines
man/man2/landlock_add_rule.2 +7 -0
+or
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+right means that requesting to bind on port 0
+(explicitly, or implicitly
+for instance by sending a datagram on an unbound UDP socket)
+is allowed
+and it will automatically translate to binding on a kernel-assigned

ephemeral port.

Quoted 1 line
Quoted 5 lines
Quoted 2 lines

With the caveat of not being a native speaker either, the commas in this sentence feel wrong to me.

I was trying to make the comma match the fact that the example only applies to the implicit case, but if it sounds wrong let's use your suggestion.

Quoted 8 lines

Perhaps you could use two levels of separation, with ';':

	(explicitly;
	or implicitly,
	for instance, by sending a datagram ...)

But this is a bit beyond my expertise. I've CCd Branden, which will surely be able to help.

Well, maybe.

I don't know of hard rules governing this sort of construction, but use of a semicolon here "feels" wrong, as you're not joining independent clauses nor are you separating list items, at least some of which contain commas.

I might use an em dash here. But, trying to interpret this language for myself, I think the best solution might be to recast to break up this long sentence into shorter ones.

Thus:

A Landlock rule with port 0
and the
.B LANDLOCK_ACCESS_NET_BIND_TCP
or
.B LANDLOCK_ACCESS_NET_BIND_UDP
right means that a port 0 binding request is allowed, automatically translating
to a binding on a kernel-assigned ephemeral port.
Such binding can be done explicitly or implicitly. Sending a datagram on an unbound UDP socket is one implicit means.

I also recast the text to tighten wording, to reduce use of passive voice, and to favor present tense over future.

Does this help?

Regards,
Branden

#20 lore raw

Re: [PATCH v2 2/2] man/man?/landlock*.?: Document UDP support

Hi Branden,

Quoted 53 lines

Date: 2026-11-15 15:53:59-0600
From: "G. Branden Robinson" <[email protected]>

Hi Alex,

Quoted 25 lines · Alejandro Colomar
Quoted 19 lines

Date: 2026-11-15 21:55:50+0100
From: Matthieu Buffet <[email protected]>

Quoted 6 lines · Günther Noack

Review

Quoted 5 lines · Matthieu Buffet

A Landlock rule with port 0
and the
.B LANDLOCK_ACCESS_NET_BIND_TCP

(quoted diff) +0 -2
-right means that requesting to bind on port 0 is allowed
-and it will automatically translate to binding on the related port

range.

Quoted 7 lines

man/man2/landlock_add_rule.2 with

Quoted 7 lines
man/man2/landlock_add_rule.2 +7 -0
+or
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+right means that requesting to bind on port 0
+(explicitly, or implicitly
+for instance by sending a datagram on an unbound UDP socket)
+is allowed
+and it will automatically translate to binding on a kernel-assigned

ephemeral port.

Quoted 1 line
Quoted 5 lines
Quoted 2 lines

With the caveat of not being a native speaker either, the commas in this sentence feel wrong to me.

I was trying to make the comma match the fact that the example only applies to the implicit case, but if it sounds wrong let's use your suggestion.

Quoted 8 lines

Perhaps you could use two levels of separation, with ';':

	(explicitly;
	or implicitly,
	for instance, by sending a datagram ...)

But this is a bit beyond my expertise. I've CCd Branden, which will surely be able to help.

Well, maybe.

I don't know of hard rules governing this sort of construction, but use of a semicolon here "feels" wrong, as you're not joining independent clauses nor are you separating list items, at least some of which contain commas.

I might use an em dash here. But, trying to interpret this language for myself, I think the best solution might be to recast to break up this long sentence into shorter ones.

Thus:

Quoted 10 lines

A Landlock rule with port 0
and the
.B LANDLOCK_ACCESS_NET_BIND_TCP
or
.B LANDLOCK_ACCESS_NET_BIND_UDP
right means that a port 0 binding request is allowed, automatically translating
to a binding on a kernel-assigned ephemeral port.
Such binding can be done explicitly or implicitly. Sending a datagram on an unbound UDP socket is one implicit means.

Thanks! That sounds good. Perhaps we could put the last sentence in parentheses, as it's not part of the specification.

A Landlock rule with port 0
and the
.B LANDLOCK_ACCESS_NET_BIND_TCP
or
.B LANDLOCK_ACCESS_NET_BIND_UDP
right means that a port 0 binding request is allowed, automatically translating
to a binding on a kernel-assigned ephemeral port.
Such binding can be done explicitly or implicitly (sending a datagram on an unbound UDP socket is one implicit means).

Have a lovely day!
Alex

Quoted 8 lines

I also recast the text to tighten wording, to reduce use of passive voice, and to favor present tense over future.

Does this help?

Regards,
Branden

Signature · 1 line
<https://www.alejandro-colomar.es>
#21 lore raw

Re: [PATCH v2 2/2] man/man?/landlock*.?: Document UDP support

Hi Alejandro, Branden,

Quoted 2 lines · Alejandro Colomar

Thanks! That sounds good. Perhaps we could put the last sentence in parentheses, as it's not part of the specification.

Here is a version with the fix. I also fixed a bad copy-paste of bullet points in the AF_UNSPEC note (unordered list of alternatives).

Quoted 2 lines · G. Branden Robinson

I also recast the text to tighten wording, to reduce use of passive voice, and to favor present tense over future.

A way into my prose is always found by passive voice. That is much better, thank you both! Matthieu

#22 lore raw

PATCH v4 1/1 man/man?/landlock*.?: Document UDP support

Landlock support for UDP-specific policy was merged in 7.2 in linux.git 9a8ed15ce224 ("landlock: Add UDP bind() access control") and
linux.git e61247a2e694 ("landlock: Add UDP send+connect access control")

Add documentation for new access rights, taken from the UAPI header with minor improvements to be backported into it:
- clarify the most non-trivial behavior (auto-bind denials when sending if BIND_UDP is handled) without restricting to the case where CONNECT_SEND_UDP is handled
- improve description of how AF_UNSPEC destination addresses behave:
connect() is always allowed, sending is always denied (instead of just "not supported") on IPv6 UDP sockets
- minor wording improvements, nothing else semantically different

---
 man/man2/landlock_add_rule.2 | 14 +++++--
 man/man7/landlock.7          | 75 +++++++++++++++++++++++++++++++++++-
 2 files changed, 83 insertions(+), 6 deletions(-)
man/man2/landlock_add_rule.2 +10 -4
index 253498bfa2cf..d48a27292987 100644
@@ -82,7 +82,7 @@ just a file.
 .TP
 .BR LANDLOCK_RULE_NET_PORT "  (since Landlock ABI version 4)"
 For these rules,
-the object is a TCP port,
+the object is a TCP or UDP port,
 and the related actions are defined with
 .IR "network access rights" .
 .IP
@@ -120,8 +120,13 @@ with
 A Landlock rule with port 0
 and the
 .B LANDLOCK_ACCESS_NET_BIND_TCP
-right means that requesting to bind on port 0 is allowed
-and it will automatically translate to binding on the related port range.
+or
+.B LANDLOCK_ACCESS_NET_BIND_UDP
+right means that a port 0 binding request is allowed,
+automatically translating
+to a binding on a kernel-assigned ephemeral port.
+Such binding can be done explicitly or implicitly
+(sending a datagram on an unbound UDP socket is one implicit means).
 .P
 .I flags
 is a bit mask of the following optional flags:
@@ -181,7 +186,8 @@ can fail for the following reasons:
 .I rule_type
 is
 .BR LANDLOCK_RULE_NET_PORT ,
-but TCP is not supported by the running kernel.
+but the kernel was built without
+.BR CONFIG_INET .
 .TP
 .B EBADF
 .I ruleset_fd
man/man7/landlock.7 +73 -2

93 lines not on this page · raw message

base-commit: 7b4329e4945b1506f75c67c18730ad0191e09fb0

Signature · 1 line
2.47.3
Reviewed-by on v2 1/2
#23 lore raw

Re: [PATCH v2 1/2] man/man2/landlock_add_rule.2: Clarify ephemeral port range

In reply to Matthieu Buffet
Quoted 31 lines · Matthieu Buffet

Clarify that ephemeral port range can differ from system to system, and that an application can choose exactly which ephemeral port will be chosen next (as long as it is within the kernel-wide ip_local_port_range).

---
 man/man2/landlock_add_rule.2 | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
man/man2/landlock_add_rule.2 +6 -2
index 94bc63068935..253498bfa2cf 100644
@@ -109,9 +109,13 @@ is the network port in host endianness.
 It should be noted that port 0 passed to
 .BR bind (2)
 will bind to an available port from the ephemeral port range.
-This can be configured in the
+The range is configured globally in the
 .I /proc/sys/net/ipv4/ip_local_port_range
-sysctl (also used for IPv6).
+sysctl (also used for IPv6),
+and can be further restricted per socket using
+.BR setsockopt (2)
+with
+.BR IP_LOCAL_PORT_RANGE (2const).
 .IP
 A Landlock rule with port 0
 and the
Quoted 4 lines

base-commit: c189a6b2e4dd2e74f3b360b24e489e27f4e45bad

Signature · 1 line
2.47.3

I think Mickaël's Reviewed-by from [1] should also count since you addressed the grammar nit from [2].

The high level remark from [2] still stands, please don't forget to ideally update the kernel documentation in line with these changes, so that it uses the same wording on both sides.

Thanks,
–Günther

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

#24 lore raw

Re: [PATCH v2 1/2] man/man2/landlock_add_rule.2: Clarify ephemeral port range

Hi!

Quoted 42 lines

Date: 2026-11-06 22:24:11+0100
From: Günther Noack <[email protected]>

Quoted 31 lines · Matthieu Buffet

Clarify that ephemeral port range can differ from system to system, and that an application can choose exactly which ephemeral port will be chosen next (as long as it is within the kernel-wide ip_local_port_range).

---
 man/man2/landlock_add_rule.2 | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
man/man2/landlock_add_rule.2 +6 -2
index 94bc63068935..253498bfa2cf 100644
@@ -109,9 +109,13 @@ is the network port in host endianness.
 It should be noted that port 0 passed to
 .BR bind (2)
 will bind to an available port from the ephemeral port range.
-This can be configured in the
+The range is configured globally in the
 .I /proc/sys/net/ipv4/ip_local_port_range
-sysctl (also used for IPv6).
+sysctl (also used for IPv6),
+and can be further restricted per socket using
+.BR setsockopt (2)
+with
+.BR IP_LOCAL_PORT_RANGE (2const).
 .IP
 A Landlock rule with port 0
 and the
Quoted 4 lines

base-commit: c189a6b2e4dd2e74f3b360b24e489e27f4e45bad

Signature · 1 line
2.47.3
Quoted 2 lines

I think Mickaël's Reviewed-by from [1] should also count since you addressed the grammar nit from [2].

Thanks! I've applied the patch with both Reviewed-by tags.

Have a lovely day!
Alex

Quoted 10 lines

The high level remark from [2] still stands, please don't forget to ideally update the kernel documentation in line with these changes, so that it uses the same wording on both sides.

Thanks,
–Günther

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

Signature · 1 line
<https://www.alejandro-colomar.es>
#25 lore raw
In reply to Matthieu Buffet

Hi Matthieu,

Quoted 11 lines

Date: 2026-11-03 00:37:34+0100
From: Matthieu Buffet <[email protected]>

Hi Günther,

Quoted 2 lines · Günther Noack

Friendly ping on this, to make sure we don't forget it -- do you think you could find the time to send a small follow-up to this?

Sorry, busy days. Here are the patches with your comments taken into account and fixed, and I have a patch ready to sync the UAPI header if these look ok.

I see v2 has 2 patches instead of 3. What happened to patch 2/3?

Have a lovely night!
Alex

Quoted 4 lines

Have a nice day,

Matthieu

Signature · 1 line
<https://www.alejandro-colomar.es>
#26 lore raw

Hi Alejandro,

Quoted 1 line · Alejandro Colomar

I see v2 has 2 patches instead of 3. What happened to patch 2/3?

Patch 2/3 was for AF_UNSPEC behavior, which, as Günther pointed out, did not need to be as precise (e.g. no need to document the bind() specifics, just "everything else works as-is"), so it became a silly one-liner and I merged it into 3/3. Sorry, I should have mentioned that in my reply.

Signature · 1 line
Matthieu