-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add syscall filtering to xrdp systemd unit #2697
Conversation
Hi @iskunk This looks like a good idea to me. As you say, it's Linux only for now, and systemd at that. While it's bedding in however, having something which can be changed by a developer or user to work around an issue seems like a good compromise. In the longer term, we could target Linux in general and FreeBSD (Capsicum?) provided our architectures are up to it. That's a big step however, compared to this one. I'll need to do a bit of testing before I merge this:-
@metalefty, @jsorg71, @Nexarian - I'd appreciate your thoughts on this PR. |
Sounds good. A common theme between seccomp, AppArmor, SELinux, and other such security layers is that they can break the application, often in subtle ways, if they are not properly vetted. (When they are, then their effect will be unnoticeable to the user.) It would be helpful to have some kind of automated coverage test suite that exercises the various features and operating modes, so that this kind of thing can be validated/iterated without needing manual intervention. Xrdp definitely has some odd nooks and crannies (e.g. the FUSE drive-sharing stuff) that I've had a hard time getting to work for the purpose of proofing my AppArmor profiles. |
We've got automated tests which we're building up for the libraries. A lot of the application however just isn't suited to this at the moment sadly. |
Overall, I like the idea to make xrdp secure. The same idea can be applied to FreeBSD using Capsicum but unfortunately I'm not familiar with Capsicum. |
I've had a test of this on a few more configurations using Ubuntu 22.04:-
So I had to add Alternatively we could just use @System-service instead of the existing list, I believe. I'm out of time today, but I also need to look at CentOS 7. That doesn't support |
I figured there were a couple edge cases still hiding in there. Thanks for testing this out. I considered It would be so helpful to be able to run through those configurations automatically. Would it improve the testing situation much to have a headless, scriptable RDP testing client based on rdpy? |
Agreed about the narrower filter. I'll have a look at CentOS 7 (which is still taking updates) and see what happens there. Also agreed about the automated testing. However, it's a massive amount of effort to not only set up, but also to maintain. I can't see the project in its current state being able to bear that kind of cost. |
Following command works well to display the audit messages (Ubuntu 22.04):-
I'm also wondering if in the main xrdp process (not the forked one) we can catch the SIGCHLD and see if the process was terminated with SIGSYS. If so, we could at least log that the seccomp filter had been triggered. I'll have a play around. |
Out of time today (and I haven't looked at CentOS 7 yet), but here's a log from a modified xrdp instance tripping the filter:-
then, feeding the PID into
which gives the syscall of 28 (madvise) I'll post my patch later. |
Well, so much for CentOS 7 testing:- https://bugzilla.redhat.com/show_bug.cgi?id=1546063 In other words, this change has no effect on CentOS 7 as systemd doesn't support SECCOMP. |
Bummer. If there is a way to to minimize the time needed to set up and run the tests you've been doing, then that would also be good. The AppArmor profiles will need the same sort of vetting. Good to hear that the new directives don't cause breakage on CentOS 7. Folks who want the protection there could use Bubblewrap ( I've updated and rebased the PR commit for freshness. |
I think we're good to merge this now. We're logging SECCOMP failures causing xrdp to exit (see #2719), so any problems with existing systems should be relatively easy to find. |
This makes use of systemd's system-call filtering facility to add (Linux) seccomp support to the
xrdp
daemon in a non-invasive way. This implicitly also enables NoNewPrivileges. (SeeSystemCallFilter=
insystemd.exec(5)
)This marks wide swaths of the Linux kernel API as off-limits, significantly reducing the attack surface of the system available to a baddie who manages to compromise the program. If a prohibited syscall is used, the program is immediately killed with SIGSYS.
I've put together this syscall filter through some trial and error, and am able to perform a full login/logout cycle without issue. If there are any unusual codepaths used by
xrdp
, then those should be tested to ensure the filter covers everything needed.Some notes on testing the filter:
syscall=99
bit is salient. The syscall number can be looked up using thescmp_sys_resolver(1)
utility:systemd-analyze syscall-filter
. (I generally made use of the sets to keep things simple, save for a couple oddball cases.)SystemCallLog=
. Comment outSystemCallFilter=
, and append its arguments toSystemCallLog=~@default
. Then watch syslog for messages like the one above (only they will showsig=0
).Note: This approach to adding seccomp support is easy, but of course it is limited not only to systemd, but also to Linux. It should be considered a stopgap solution at best. A better one would be to add support in the code, making use of seccomp on Linux, pledge on OpenBSD, and similar facilities on other systems. That is what OpenSSH does (see the
sandbox-*.c
source files).