landlock.7: Code example improvements
cover landlock.7: Code example improvements
Various improvements as pointed out by Mickaël Salaün in
https://lore.kernel.org/linux-man/[email protected]/
* Checking system call results differently, for consistency
* Use constants for the compatibility table
(I'm not very attached to the other solution)
* Better wording for error message if Landlock unusable
* Return instead of exit() if Landlock unusable
Regarding the EOPNOTSUPP/ENOTSUP discussion, the consensus seems to be that EOPNOTSUPP is preferable, because that is the only of the two error codes that the kernel knows about.
Günther Noack (4):
landlock.7: Check syscall result with == -1 instead of <= 0 landlock.7: Use LANDLOCK_* constants for compatibility table landlock.7: wfix: Error message wording in code example landlock.7: Return instead of exit() if Landlock is unusable
man7/landlock.7 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
base-commit: 6693a21cf73c502f2429b4ec07698130a2be9a93
Signature · 1 line
2.40.0
PATCH 1/4 landlock.7: Check syscall result with == -1 instead of <= 0
As pointed out by Mickaël Salaün in
https://lore.kernel.org/linux-man/[email protected]/
--- man7/landlock.7 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
man7/landlock.7 +1 -1
@@ -445,7 +445,7 @@ __u64 landlock_fs_access_rights[] = { int abi = landlock_create_ruleset(NULL, 0, LANDLOCK_CREATE_RULESET_VERSION); -if (abi <= 0) { +if (abi == \-1) { /* * Kernel too old, not compiled with Landlock, * or Landlock was not enabled at boot time.
Signature · 1 line
2.40.0
PATCH 2/4 landlock.7: Use LANDLOCK_* constants for compatibility table
In reply to Günther NoackAs discussed in
https://lore.kernel.org/linux-man/[email protected]/
--- man7/landlock.7 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
man7/landlock.7 +3 -3
@@ -438,9 +438,9 @@ and only use the available subset of access rights: * numbers hardcoded to keep the example short. */ __u64 landlock_fs_access_rights[] = { - (1ULL << 13) \- 1, /* ABI v1 */ - (1ULL << 14) \- 1, /* ABI v2: add "refer" */ - (1ULL << 15) \- 1, /* ABI v3: add "truncate" */ + (LANDLOCK_ACCESS_FS_MAKE_SYM << 1) \- 1, /* v1 */ + (LANDLOCK_ACCESS_FS_REFER << 1) \- 1, /* v2: add "refer" */ + (LANDLOCK_ACCESS_FS_TRUNCATE << 1) \- 1, /* v3: add "truncate" */ }; int abi = landlock_create_ruleset(NULL, 0,
Signature · 1 line
2.40.0
PATCH 3/4 landlock.7: wfix: Error message wording in code example
In reply to Günther NoackAs suggested by Mickaël Salaün in
https://lore.kernel.org/linux-man/[email protected]/
--- man7/landlock.7 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
man7/landlock.7 +1 -1
@@ -450,7 +450,7 @@ if (abi == \-1) { * Kernel too old, not compiled with Landlock, * or Landlock was not enabled at boot time. */ - perror("Giving up \- No Landlock support"); + perror("Unable to use Landlock"); exit(EXIT_FAILURE); } abi = MIN(abi, 3);
Signature · 1 line
2.40.0
PATCH 4/4 landlock.7: Return instead of exit() if Landlock is unusable
In reply to Günther NoackWhen following a best effort approach,
we should not fail when Landlock is unusable,
but we should fall back to doing nothing.
As discussed in
https://lore.kernel.org/linux-man/[email protected]/
--- man7/landlock.7 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
man7/landlock.7 +1 -1
@@ -451,7 +451,7 @@ if (abi == \-1) { * or Landlock was not enabled at boot time. */ perror("Unable to use Landlock"); - exit(EXIT_FAILURE); + return; /* Graceful fallback: Do nothing. */ } abi = MIN(abi, 3);
Signature · 1 line
2.40.0
Hi Günther!
Quoted 13 lines · Günther Noack
Various improvements as pointed out by Mickaël Salaün in
https://lore.kernel.org/linux-man/[email protected]/* Checking system call results differently, for consistency
* Use constants for the compatibility table
(I'm not very attached to the other solution)
* Better wording for error message if Landlock unusable
* Return instead ofexit()if Landlock unusableRegarding the EOPNOTSUPP/ENOTSUP discussion, the consensus seems to be that EOPNOTSUPP is preferable, because that is the only of the two error codes that the kernel knows about.
Quoted 5 lines
Günther Noack (4):
landlock.7: Check syscall result with == -1 instead of <= 0 landlock.7: Use LANDLOCK_* constants for compatibility table landlock.7: wfix: Error message wording in code example landlock.7: Return instead ofexit()if Landlock is unusable
Thanks! Patch set applied. (I tweaked the commit messages a little bit.)
Cheers,
Alex
Quoted 6 lines
man7/landlock.7 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)base-commit:
6693a21cf73c502f2429b4ec07698130a2be9a93
Signature · 2 lines
<http://www.alejandro-colomar.es/> GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5
Quoted 16 lines · Alejandro Colomar
Hi Günther!
Quoted 13 lines · Günther Noack
Various improvements as pointed out by Mickaël Salaün in
https://lore.kernel.org/linux-man/[email protected]/* Checking system call results differently, for consistency
* Use constants for the compatibility table
(I'm not very attached to the other solution)
* Better wording for error message if Landlock unusable
* Return instead ofexit()if Landlock unusableRegarding the EOPNOTSUPP/ENOTSUP discussion, the consensus seems to be that EOPNOTSUPP is preferable, because that is the only of the two error codes that the kernel knows about.
Quoted 8 lines
Quoted 5 lines
Günther Noack (4):
landlock.7: Check syscall result with == -1 instead of <= 0 landlock.7: Use LANDLOCK_* constants for compatibility table landlock.7: wfix: Error message wording in code example landlock.7: Return instead ofexit()if Landlock is unusableThanks! Patch set applied. (I tweaked the commit messages a little bit.)
Thanks Günther and Alex!
Quoted 11 lines
Cheers,
AlexQuoted 6 lines
man7/landlock.7 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)base-commit:
6693a21cf73c502f2429b4ec07698130a2be9a93