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

libutil: EPERM from kill(-1, ...) is fine #4530

Merged
merged 1 commit into from
Feb 26, 2021
Merged

Conversation

alyssais
Copy link
Member

@alyssais alyssais commented Feb 7, 2021

I tested a trivial program that called kill(-1, SIGKILL), which was
run as the only process for an unpriveleged user, on Linux and
FreeBSD. On Linux, kill reported success, while on FreeBSD it failed
with EPERM.

POSIX says:

If pid is -1, sig shall be sent to all processes (excluding an
unspecified set of system processes) for which the process has
permission to send that signal.

and

The kill() function is successful if the process has permission to
send sig to any of the processes specified by pid. If kill() fails,
no signal shall be sent.

and

[EPERM]
The process does not have permission to send the signal to any
receiving process.

My reading of this is that kill(-1, ...) may fail with EPERM when
there are no other processes to kill (since the current process is
ignored). Since kill(-1, ...) only attempts to kill processes the
user has permission to kill, it can't mean that we tried to do
something we didn't have permission to kill, so it should be fine to
interpret EPERM the same as success here for any POSIX-compliant
system.

This fixes an issue that @Mic92 encountered1 when he tried to review a
Nixpkgs PR on FreeBSD.

I tested a trivial program that called kill(-1, SIGKILL), which was
run as the only process for an unpriveleged user, on Linux and
FreeBSD.  On Linux, kill reported success, while on FreeBSD it failed
with EPERM.

POSIX says:

> If pid is -1, sig shall be sent to all processes (excluding an
> unspecified set of system processes) for which the process has
> permission to send that signal.

and

> The kill() function is successful if the process has permission to
> send sig to any of the processes specified by pid.  If kill() fails,
> no signal shall be sent.

and

> [EPERM]
>     The process does not have permission to send the signal to any
>     receiving process.

My reading of this is that kill(-1, ...) may fail with EPERM when
there are no other processes to kill (since the current process is
ignored).  Since kill(-1, ...) only attempts to kill processes the
user has permission to kill, it can't mean that we tried to do
something we didn't have permission to kill, so it should be fine to
interpret EPERM the same as success here for any POSIX-compliant
system.

This fixes an issue that Mic92 encountered[1] when he tried to review a
Nixpkgs PR on FreeBSD.

[1]: NixOS/nixpkgs#81459 (comment)
@alyssais alyssais mentioned this pull request Feb 7, 2021
10 tasks
uqs pushed a commit to freebsd/freebsd-ports that referenced this pull request Feb 8, 2021
Related upstream PR:
NixOS/nix#4530

PR:		253322
Submitted by:	hi@alyssa.is
MFH:		2021Q1


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@564693 35697150-7ecd-e111-bb59-0022644237b5
uqs pushed a commit to freebsd/freebsd-ports that referenced this pull request Feb 8, 2021
Related upstream PR:
NixOS/nix#4530

PR:		253322
Submitted by:	hi@alyssa.is
MFH:		2021Q1
Jehops pushed a commit to Jehops/freebsd-ports-legacy that referenced this pull request Feb 8, 2021
Related upstream PR:
NixOS/nix#4530

PR:		253322
Submitted by:	hi@alyssa.is
MFH:		2021Q1


git-svn-id: svn+ssh://svn.freebsd.org/ports/head@564693 35697150-7ecd-e111-bb59-0022644237b5
uqs pushed a commit to freebsd/freebsd-ports that referenced this pull request Feb 8, 2021
Update to 2.3.10

PR:		251897
Submitted by:	nc
Differential Revision:	https://reviews.freebsd.org/D27996

Fix a runtime issue causing Nix to die when it builds packages

Related upstream PR:
NixOS/nix#4530

PR:		253322
Submitted by:	hi@alyssa.is
dch pushed a commit to skunkwerks/ports that referenced this pull request Feb 9, 2021
Related upstream PR:
NixOS/nix#4530

PR:		253322
Submitted by:	hi@alyssa.is
MFH:		2021Q1
@edolstra edolstra merged commit 5edab77 into NixOS:master Feb 26, 2021
uqs pushed a commit to freebsd/freebsd-ports that referenced this pull request Apr 1, 2021
Update to 2.3.10

PR:		251897
Submitted by:	nc
Differential Revision:	https://reviews.freebsd.org/D27996

Fix a runtime issue causing Nix to die when it builds packages

Related upstream PR:
NixOS/nix#4530

PR:		253322
Submitted by:	hi@alyssa.is
svmhdvn pushed a commit to svmhdvn/freebsd-ports that referenced this pull request Jan 10, 2024
Related upstream PR:
NixOS/nix#4530

PR:		253322
Submitted by:	hi@alyssa.is
MFH:		2021Q1
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

2 participants