]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
swapon: do not run execvp() calls when swapon is setuid binary
authorSami Kerola <kerolasa@iki.fi>
Tue, 2 Feb 2016 13:40:10 +0000 (13:40 +0000)
committerKarel Zak <kzak@redhat.com>
Thu, 11 Feb 2016 09:52:18 +0000 (10:52 +0100)
swapon(8) is not expected to be setuid binary, but if it is try to avoid
obvious security vulnerability of executing user preferred mkswap file as
someone else, such as root.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/swapon.c

index 5ad5cd1f3b6a835e06024d4d77a2d6199077e3f8..be8f7718bbf1f34f55eb700603eeeeccf4fc1669 100644 (file)
@@ -297,6 +297,10 @@ static int swap_reinitialize(struct swapon_ctl *ctl)
        char const *cmd[7];
        int idx=0;
 
+       if (geteuid() != getuid()) {
+               warnx(_("will not execute mkswap when swapon is setuid binary"));
+               return -1;
+       }
        warnx(_("%s: reinitializing the swap."), ctl->device);
 
        switch((pid=fork())) {