diff options
author | Karel Zak | 2016-02-11 12:07:34 +0100 |
---|---|---|
committer | Karel Zak | 2016-02-11 12:07:34 +0100 |
commit | eac478dcfd6ab8f3eb1ed1acbcb872573da02a0f (patch) | |
tree | 6a6a04c25f48551d208900555b5c3e43e33d5432 /sys-utils/swapon.c | |
parent | Merge branch 'colcrt' of git://github.com/kerolasa/lelux-utiliteetit (diff) | |
download | kernel-qcow2-util-linux-eac478dcfd6ab8f3eb1ed1acbcb872573da02a0f.tar.gz kernel-qcow2-util-linux-eac478dcfd6ab8f3eb1ed1acbcb872573da02a0f.tar.xz kernel-qcow2-util-linux-eac478dcfd6ab8f3eb1ed1acbcb872573da02a0f.zip |
swapon: drop perms if setuid before call mkswap
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/swapon.c')
-rw-r--r-- | sys-utils/swapon.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/sys-utils/swapon.c b/sys-utils/swapon.c index 7d68c42d7..914e69ad4 100644 --- a/sys-utils/swapon.c +++ b/sys-utils/swapon.c @@ -295,10 +295,6 @@ 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())) { @@ -307,6 +303,14 @@ static int swap_reinitialize(struct swapon_ctl *ctl) return -1; case 0: /* child */ + if (geteuid() != getuid()) { + /* in case someone uses swapon as setuid binary */ + if (setgid(getgid()) < 0) + exit(EXIT_FAILURE); + if (setuid(getuid()) < 0) + exit(EXIT_FAILURE); + } + cmd[idx++] = "mkswap"; if (ctl->label) { cmd[idx++] = "-L"; |