Skip to content
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

ntpd: Add patch to allow getpid syscall in seccomp filter. #24573

Merged
merged 1 commit into from Apr 6, 2017

Conversation

ambrop72
Copy link
Contributor

@ambrop72 ambrop72 commented Apr 2, 2017

Fixes issue #21136.

The problem is that the seccomp system call filter configured by ntpd did not
include getpid, but the program then called getpid which hanged. This could be
seen with strace:

prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) = 0
seccomp(SECCOMP_SET_MODE_STRICT, 1, NULL) = -1 EINVAL (Invalid argument)
seccomp(SECCOMP_SET_MODE_FILTER, 0, {len=41, filter=0x5620d7f0bd90}) = 0
getpid() = ?

I do not know exactly why this is a problem on NixOS only, perhaps we have getpid
caching disabled.

Motivation for this change

Ntpd was broken.

Things done
  • Tested using sandboxing
    (nix.useSandbox on NixOS,
    or option build-use-sandbox in nix.conf
    on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • Linux
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@mention-bot
Copy link

@ambrop72, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @fpletz and @dezgeg to be potential reviewers.

@ambrop72
Copy link
Contributor Author

ambrop72 commented Apr 2, 2017

Please don't merge yet, I found that it does not completely solve the problem. It works when I restart the ntpd service or from command line but it doesn't work when auto-starting on boot. There must be more system calls missing on the list.

Fixes issue NixOS#21136.

The problem is that the seccomp system call filter configured by ntpd did not
include some system calls that were apparently needed. For example the
program hanged in getpid just after the filter was installed:

prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)  = 0
seccomp(SECCOMP_SET_MODE_STRICT, 1, NULL) = -1 EINVAL (Invalid argument)
seccomp(SECCOMP_SET_MODE_FILTER, 0, {len=41, filter=0x5620d7f0bd90}) = 0
getpid()                                = ?

I do not know exactly why this is a problem on NixOS only, perhaps we have getpid
caching disabled.

The fcntl and setsockopt system calls also had to be added.
@ambrop72
Copy link
Contributor Author

ambrop72 commented Apr 2, 2017

I had to also add fcntl and setsockopt, it works for me. I didn't test on i686 though only x86_64.

@@ -15,6 +15,10 @@ stdenv.mkDerivation rec {
sha256 = "0whbyf82lrczbri4adbsa4hg1ppfa6c7qcj7nhjwdfp1g1vjh95p";
};

# The hardcoded list of allowed system calls for seccomp is
# insufficient for NixOS, add more to make it work (issue #21136).
patches = [ ./seccomp.patch ];
Copy link
Member

@Mic92 Mic92 Apr 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also send this patch upstream?

Copy link
Member

@Mic92 Mic92 Apr 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does any other linux distribution enable this? It might be that seccomp in ntp is slightly unmaintained.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it also fails due to the use of the openat syscall when it tries to update the drift file

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think a blacklist is better. There is a whole class of *at system calls that might be used instead of their pendants by libc.

@dezgeg
Copy link
Contributor

dezgeg commented Apr 2, 2017

Can't you anyways nowadays have systemd doing the seccomp thing instead of each app reimplementing the same thing (and poorly, as seems to be the case).

@Mic92
Copy link
Member

Mic92 commented Apr 2, 2017

This would be the alternative, we could set a blacklist like this within the service unit

SystemCallFilter=~@cpu-emulation @debug @keyring @module @mount @obsolete @raw-io

@joachifm
Copy link
Contributor

joachifm commented Apr 6, 2017

Merging as it seems like this fixes a problem right now; I guess we can talk about how to do it better later.

@joachifm joachifm merged commit bb771e0 into NixOS:master Apr 6, 2017
@NeQuissimus
Copy link
Member

Would it be OK to bring this into 17.03 despite the seemingly temporary nature of the fix?

@Mic92
Copy link
Member

Mic92 commented Apr 16, 2017

yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants