-
Notifications
You must be signed in to change notification settings - Fork 3.9k
openssh: allow cryptodev ioctls #29116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hurrian
wants to merge
1
commit into
openwrt:master
Choose a base branch
from
hurrian:openssh_cryptodev_fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+67
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| From 275730c69326cefeb62aedc3a08cec88ff9c295e Mon Sep 17 00:00:00 2001 | ||
| From: Kenneth Kasilag <kenneth@kasilag.me> | ||
| Date: Sat, 11 Apr 2026 03:29:42 +0000 | ||
| Subject: [PATCH] openssh: allow cryptodev ioctls | ||
|
|
||
| When OpenSSL is built with the devcrypto engine, crypto | ||
| operations are serviced via ioctl() calls on /dev/crypto. | ||
|
|
||
| The pre-auth child inherits the open fd from the monitor | ||
| but the seccomp filter only whitelists FIONREAD and | ||
| TIOCGWINSZ, causing any cryptodev ioctl to trigger SIGSYS. | ||
|
|
||
| The child is killed immediately after authentication | ||
| succeeds, during the keystate transfer phase where it | ||
| first attempts to perform a cipher or MAC operation | ||
| through the devcrypto engine: | ||
| ``` | ||
| monitor_child_preauth: preauth child terminated | ||
| by signal 31 | ||
| ``` | ||
|
|
||
| As this was tested on the Airoha AN7581 with Cortex-A53 | ||
| cores, signal 31 on aarch64 is SIGSYS, confirming seccomp | ||
| violation rather than a code defect. | ||
|
|
||
| Add a BPF rule that allows ioctl commands with type byte | ||
| 'c' (0x63), which is the ioctl type used by all cryptodev | ||
| operations (CIOCGSESSION, CIOCCRYPT, CIOCFSESSION, etc.). | ||
|
|
||
| The rule matches on the type byte rather than the exact | ||
| ioctl command values because cryptodev is an out-of-tree | ||
| kernel module and its header is not available at OpenSSH | ||
| build time. | ||
|
|
||
| The rule is gated on ALLOW_CRYPTODEV_IOCTL, defined by | ||
| the build system only when libopenssl-devcrypto is enabled. | ||
|
|
||
| Signed-off-by: Kenneth Kasilag <kenneth@kasilag.me> | ||
| --- | ||
| sandbox-seccomp-filter.c | 11 +++++++++++ | ||
| 1 files changed, 11 insertions(+) | ||
|
|
||
| --- a/sandbox-seccomp-filter.c | ||
| +++ b/sandbox-seccomp-filter.c | ||
| @@ -452,6 +452,17 @@ static const struct sock_filter preauth_ | ||
| SC_ALLOW_ARG(__NR_socketcall, 0, SYS_SHUTDOWN), | ||
| SC_DENY(__NR_socketcall, EACCES), | ||
| #endif | ||
| +#if defined(__NR_ioctl) && defined(ALLOW_CRYPTODEV_IOCTL) | ||
| + /* Allow ioctls with type 'c' for /dev/crypto */ | ||
| + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, __NR_ioctl, 0, 6), | ||
| + BPF_STMT(BPF_LD+BPF_W+BPF_ABS, | ||
| + offsetof(struct seccomp_data, args[1])), | ||
| + BPF_STMT(BPF_ALU+BPF_AND+BPF_K, 0x0000FF00), | ||
| + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x00006300, 0, 1), | ||
| + BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ALLOW), | ||
| + BPF_STMT(BPF_LD+BPF_W+BPF_ABS, | ||
| + offsetof(struct seccomp_data, nr)), | ||
| +#endif | ||
| #if defined(__NR_ioctl) && defined(__s390__) | ||
| /* Allow ioctls for ICA crypto card on s390 */ | ||
| SC_ALLOW_ARG(__NR_ioctl, 1, Z90STAT_STATUS_MASK), | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No matter how hard I look, I don't see this patch in the upstream repository, nor do I see it pending in the pull requests - https://github.com/openssh/openssh-portable/pulls
I think it would be better if it were part of the upstream project, rather than us keeping the patch to ourselves and having to rebase and maintain it with every update.