Skip to content

Commit f4b89d8

Browse files
gnoackl0kod
authored andcommitted
landlock: Various documentation improvements
* Fix some typos, incomplete or confusing phrases. * Split paragraphs where appropriate. * List the same error code multiple times, if it has multiple possible causes. * Bring wording closer to the man page wording, which has undergone more thorough review (esp. for LANDLOCK_ACCESS_FS_WRITE_FILE). * Small semantic clarifications * Call the ephemeral port range "ephemeral" * Clarify reasons for EFAULT in landlock_add_rule() * Clarify @rule_type doc for landlock_add_rule() This is a collection of small fixes which I collected when preparing the corresponding man pages [1]. Cc: Alejandro Colomar <alx@kernel.org> Cc: Konstantin Meskhidze <konstantin.meskhidze@huawei.com> Link: https://lore.kernel.org/r/20240715155554.2791018-1-gnoack@google.com [1] Signed-off-by: Günther Noack <gnoack@google.com> Link: https://lore.kernel.org/r/20240715160328.2792835-2-gnoack@google.com [mic: Add label to link, fix formatting spotted by make htmldocs, synchronize userspace-api documentation's date] Signed-off-by: Mickaël Salaün <mic@digikod.net>
1 parent 33c97e7 commit f4b89d8

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

Documentation/userspace-api/landlock.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Landlock: unprivileged access control
88
=====================================
99

1010
:Author: Mickaël Salaün
11-
:Date: April 2024
11+
:Date: July 2024
1212

1313
The goal of Landlock is to enable to restrict ambient rights (e.g. global
1414
filesystem or network access) for a set of processes. Because Landlock

include/uapi/linux/landlock.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,21 @@ struct landlock_path_beneath_attr {
104104
*/
105105
struct landlock_net_port_attr {
106106
/**
107-
* @allowed_access: Bitmask of allowed access network for a port
107+
* @allowed_access: Bitmask of allowed network actions for a port
108108
* (cf. `Network flags`_).
109109
*/
110110
__u64 allowed_access;
111111
/**
112112
* @port: Network port in host endianness.
113113
*
114-
* It should be noted that port 0 passed to :manpage:`bind(2)` will
115-
* bind to an available port from a specific port range. This can be
116-
* configured thanks to the ``/proc/sys/net/ipv4/ip_local_port_range``
117-
* sysctl (also used for IPv6). A Landlock rule with port 0 and the
118-
* ``LANDLOCK_ACCESS_NET_BIND_TCP`` right means that requesting to bind
119-
* on port 0 is allowed and it will automatically translate to binding
120-
* on the related port range.
114+
* It should be noted that port 0 passed to :manpage:`bind(2)` will bind
115+
* to an available port from the ephemeral port range. This can be
116+
* configured with the ``/proc/sys/net/ipv4/ip_local_port_range`` sysctl
117+
* (also used for IPv6).
118+
*
119+
* A Landlock rule with port 0 and the ``LANDLOCK_ACCESS_NET_BIND_TCP``
120+
* right means that requesting to bind on port 0 is allowed and it will
121+
* automatically translate to binding on the related port range.
121122
*/
122123
__u64 port;
123124
};
@@ -138,10 +139,10 @@ struct landlock_net_port_attr {
138139
* The following access rights apply only to files:
139140
*
140141
* - %LANDLOCK_ACCESS_FS_EXECUTE: Execute a file.
141-
* - %LANDLOCK_ACCESS_FS_WRITE_FILE: Open a file with write access. Note that
142-
* you might additionally need the %LANDLOCK_ACCESS_FS_TRUNCATE right in order
143-
* to overwrite files with :manpage:`open(2)` using ``O_TRUNC`` or
144-
* :manpage:`creat(2)`.
142+
* - %LANDLOCK_ACCESS_FS_WRITE_FILE: Open a file with write access. When
143+
* opening files for writing, you will often additionally need the
144+
* %LANDLOCK_ACCESS_FS_TRUNCATE right. In many cases, these system calls
145+
* truncate existing files when overwriting them (e.g., :manpage:`creat(2)`).
145146
* - %LANDLOCK_ACCESS_FS_READ_FILE: Open a file with read access.
146147
* - %LANDLOCK_ACCESS_FS_TRUNCATE: Truncate a file with :manpage:`truncate(2)`,
147148
* :manpage:`ftruncate(2)`, :manpage:`creat(2)`, or :manpage:`open(2)` with
@@ -263,7 +264,7 @@ struct landlock_net_port_attr {
263264
* These flags enable to restrict a sandboxed process to a set of network
264265
* actions. This is supported since the Landlock ABI version 4.
265266
*
266-
* TCP sockets with allowed actions:
267+
* The following access rights apply to TCP port numbers:
267268
*
268269
* - %LANDLOCK_ACCESS_NET_BIND_TCP: Bind a TCP socket to a local port.
269270
* - %LANDLOCK_ACCESS_NET_CONNECT_TCP: Connect an active TCP socket to

security/landlock/syscalls.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,7 @@ static int add_rule_net_port(struct landlock_ruleset *ruleset,
378378
* with the new rule.
379379
* @rule_type: Identify the structure type pointed to by @rule_attr:
380380
* %LANDLOCK_RULE_PATH_BENEATH or %LANDLOCK_RULE_NET_PORT.
381-
* @rule_attr: Pointer to a rule (only of type &struct
382-
* landlock_path_beneath_attr for now).
381+
* @rule_attr: Pointer to a rule (matching the @rule_type).
383382
* @flags: Must be 0.
384383
*
385384
* This system call enables to define a new rule and add it to an existing
@@ -390,18 +389,20 @@ static int add_rule_net_port(struct landlock_ruleset *ruleset,
390389
* - %EOPNOTSUPP: Landlock is supported by the kernel but disabled at boot time;
391390
* - %EAFNOSUPPORT: @rule_type is %LANDLOCK_RULE_NET_PORT but TCP/IP is not
392391
* supported by the running kernel;
393-
* - %EINVAL: @flags is not 0, or inconsistent access in the rule (i.e.
392+
* - %EINVAL: @flags is not 0;
393+
* - %EINVAL: The rule accesses are inconsistent (i.e.
394394
* &landlock_path_beneath_attr.allowed_access or
395-
* &landlock_net_port_attr.allowed_access is not a subset of the
396-
* ruleset handled accesses), or &landlock_net_port_attr.port is
397-
* greater than 65535;
398-
* - %ENOMSG: Empty accesses (e.g. &landlock_path_beneath_attr.allowed_access);
395+
* &landlock_net_port_attr.allowed_access is not a subset of the ruleset
396+
* handled accesses)
397+
* - %EINVAL: &landlock_net_port_attr.port is greater than 65535;
398+
* - %ENOMSG: Empty accesses (e.g. &landlock_path_beneath_attr.allowed_access is
399+
* 0);
399400
* - %EBADF: @ruleset_fd is not a file descriptor for the current thread, or a
400401
* member of @rule_attr is not a file descriptor as expected;
401402
* - %EBADFD: @ruleset_fd is not a ruleset file descriptor, or a member of
402403
* @rule_attr is not the expected file descriptor type;
403404
* - %EPERM: @ruleset_fd has no write access to the underlying ruleset;
404-
* - %EFAULT: @rule_attr inconsistency.
405+
* - %EFAULT: @rule_attr was not a valid address.
405406
*/
406407
SYSCALL_DEFINE4(landlock_add_rule, const int, ruleset_fd,
407408
const enum landlock_rule_type, rule_type,

0 commit comments

Comments
 (0)