setpriv: More Landlock improvements - #4551
Conversation
65cf01a to
1fe8170
Compare
464778d to
1029514
Compare
masatake
left a comment
There was a problem hiding this comment.
I reviewed the code extending test_mkfds and the test case using test_mkfds. LGTM.
|
@Skyb0rg007 what do you think of moving the network specific Landlock tests to a dedicated script ? I fear that overtime the current script that we have will bloat with the addition of more Landlock features. |
I'm fine with that, though this test files probably don't need to grow that much because future net and scope restrictions don't really need corresponding tests (since we're testing that Testing the audit integration (the last missing Landlock feature in |
Signed-off-by: Skye Soss <skye@soss.website>
The ability to connect and listen via two different invocations is important for testing Landlock functionality. Signed-off-by: Skye Soss <skye@soss.website>
Each access right is tested against the ABI version. If a right is not supported, immediately raise an error that includes the name of the right that is not supported, rather than waiting for the syscall to fail with a generic "invalid argument" error. Signed-off-by: Skye Soss <skye@soss.website>
Support the Landlock TCP bind and connect rights together with net-port rules. These were added in ABI 4. Signed-off-by: Skye Soss <skye@soss.website>
Support Landlock scope restrictions for signals and abstract Unix sockets. These were added in ABI version 6. Signed-off-by: Skye Soss <skye@soss.website>
43af5b3 to
6672fa9
Compare
|
All the I think keeping the tests in one file for now is fine; I'll split it up as needed in the future. |
7919999 to
5040a66
Compare
5040a66 to
a811c9a
Compare
| compopt -o nospace | ||
| _setpriv_landlock_rights "$1" fs 'path-beneath:' "${cur#path-beneath:}" | ||
| ;; | ||
| net-port:*:*) |
There was a problem hiding this comment.
Is this really needed ? Tested the completion without this fallthrough case and it seems to work just fine.
There was a problem hiding this comment.
I think removing that causes the completion to call setpriv --list-landlock-rights net:, which errors and thus returns no completions
There was a problem hiding this comment.
I tested this, and it doesn't error out, but without that pattern setpriv --list-landlock-rights net is called every time tab completion is asked for, even after the second colon is entered. This pattern saves that call.
There was a problem hiding this comment.
Ok, thanks for clarifying :)
| --apparmor-profile | ||
| --landlock-access | ||
| --landlock-rule | ||
| --landlock-support |
There was a problem hiding this comment.
Just these two missing.
| --landlock-support | |
| --list-landlock-access | |
| --list-landlock-rights |
Normally this should've been caught by tools/checkcompletion.sh, I'll investigate on my end.
There was a problem hiding this comment.
--landlock-support is already there. The --list-* options aren't there for the same reason --list-caps isn't: they're used to implement bash completion so aren't really public APIs
There was a problem hiding this comment.
Yes, --landlock-support can be ignored, that was a formatting error. However, the --list* would be nice to have still, we try to maintain a solid coherence between the available long options and the bash completions.
But if you really don't want these in the completion spec, you can annotate the lines where the long options are defined with IGNORECHECK=yes, tools/get-options.sh will ignore them so tools/checkcompletion.sh doesn't annoy us with false positives in the future (since I found the cause of the detection bug).
There was a problem hiding this comment.
So in setpriv.c
{ "list-landlock-access", no_argument, NULL, LIST_LANDLOCK_ACCESS }, /* IGNORECHECK=yes */
{ "list-landlock-rights", required_argument, NULL, LIST_LANDLOCK_RIGHTS },, /* IGNORECHECK=yes */There was a problem hiding this comment.
I'm okay with adding completion for them, my original PR just copied what was done for --list-caps
There was a problem hiding this comment.
Completion added
This includes --list-landlock-access, --list-landlock-rights, and --list-caps.
cgoesche
left a comment
There was a problem hiding this comment.
All the points I have raised have been properly addressed. LGTM
This PR adds support to setpriv for handling network access rights and the scope restrictions.
Kernel documentation can be found here, but the new features are:
--landlock-access net:connect-tcp--landlock-access net:bind-tcp--landlock-rule net-port:connect-tcp,bind-tcp:80--landlock-access scope:signal--landlock-access scope:abstract-unix-socketThere are also features added to the
test_mkfdscommand to allow just binding or just connecting to a TCP or abstract unix socket, to test the corresponding Landlock restrictions.I also improved the error message for unsupported Landlock rights.
Notes
When parsing
fsrights, thelandlock_fs_access_to_maskfunction doesn't ensure that the user provided the name of a filesystem right, but instead works with the first matching prefix.This is "fixed" for the
netandscoperights, especially since it resulted in weird situations (ex.path-beneath:read:/only givesread-file, notread-dir). The next Linux release is addingnet:bind-udp, so it's a good idea to require full qualification now, and it is hopefully not as much of a pain to type out the rights now that shell completion is working.The scope rights are technically not access rights, and I try to make sure the error messages and other output are clear on that. The
--landlock-accessoption is just poorly named; not much anyone can do about that now.--list-landlock-accesswould previously printfs, even if the kernel didn't support Landlock at all. This behavior is changed to now produce an error if Landlock isn't supported at all.ABI 10 is currently merged into Linus's tree, which includes
net:bind-udpandnet:connect-send-udp. I didn't add those in this PR since I couldn't test it but they're likely safe to add in early. Just say the word -- it's a 4 line change.I added myself to the copyright comments on the Landlock files, as my name is >50% of the git blame. I have no clue if there's a different criteria for that.