Blame slurm_salloc_privileges.patch
|
Philip Kovacs |
9be8f2 |
--- slurm-17.02.7/src/salloc/salloc.c 2017-08-14 13:48:43.000000000 -0400
|
|
Philip Kovacs |
9be8f2 |
+++ slurm-17.02.7/src/salloc/salloc.c.new 2017-08-23 00:07:22.759099425 -0400
|
|
Philip Kovacs |
9be8f2 |
@@ -42,6 +42,7 @@
|
|
Philip Kovacs |
9be8f2 |
|
|
Philip Kovacs |
9be8f2 |
#include <dirent.h>
|
|
Philip Kovacs |
9be8f2 |
#include <fcntl.h>
|
|
Philip Kovacs |
9be8f2 |
+#include <grp.h>
|
|
Philip Kovacs |
9be8f2 |
#include <pwd.h>
|
|
Philip Kovacs |
9be8f2 |
#include <stdbool.h>
|
|
Philip Kovacs |
9be8f2 |
#include <stdio.h>
|
|
Philip Kovacs |
9be8f2 |
@@ -298,13 +299,27 @@
|
|
Philip Kovacs |
9be8f2 |
if (_fill_job_desc_from_opts(&desc) == -1) {
|
|
Philip Kovacs |
9be8f2 |
exit(error_exit);
|
|
Philip Kovacs |
9be8f2 |
}
|
|
Philip Kovacs |
9be8f2 |
- if (opt.gid != (gid_t) -1) {
|
|
Philip Kovacs |
9be8f2 |
+
|
|
Philip Kovacs |
9be8f2 |
+ /* If the requested gid is different than ours, become that gid */
|
|
Philip Kovacs |
9be8f2 |
+ if ((getgid() != opt.gid) && (opt.gid != (gid_t) -1)) {
|
|
Philip Kovacs |
9be8f2 |
if (setgid(opt.gid) < 0) {
|
|
Philip Kovacs |
9be8f2 |
error("setgid: %m");
|
|
Philip Kovacs |
9be8f2 |
exit(error_exit);
|
|
Philip Kovacs |
9be8f2 |
}
|
|
Philip Kovacs |
9be8f2 |
}
|
|
Philip Kovacs |
9be8f2 |
|
|
Philip Kovacs |
9be8f2 |
+ /* If the requested uid is different than ours, become that uid */
|
|
Philip Kovacs |
9be8f2 |
+ if ((getuid() != opt.uid) && (opt.uid != (uid_t) -1)) {
|
|
Philip Kovacs |
9be8f2 |
+ if (setgroups(0, NULL) < 0) {
|
|
Philip Kovacs |
9be8f2 |
+ error("setgroups: %m");
|
|
Philip Kovacs |
9be8f2 |
+ exit(error_exit);
|
|
Philip Kovacs |
9be8f2 |
+ }
|
|
Philip Kovacs |
9be8f2 |
+ if (setuid(opt.uid) < 0) {
|
|
Philip Kovacs |
9be8f2 |
+ error("setuid: %m");
|
|
Philip Kovacs |
9be8f2 |
+ exit(error_exit);
|
|
Philip Kovacs |
9be8f2 |
+ }
|
|
Philip Kovacs |
9be8f2 |
+ }
|
|
Philip Kovacs |
9be8f2 |
+
|
|
Philip Kovacs |
9be8f2 |
callbacks.ping = _ping_handler;
|
|
Philip Kovacs |
9be8f2 |
callbacks.timeout = _timeout_handler;
|
|
Philip Kovacs |
9be8f2 |
callbacks.job_complete = _job_complete_handler;
|
|
Philip Kovacs |
9be8f2 |
@@ -333,13 +348,6 @@
|
|
Philip Kovacs |
9be8f2 |
sleep (++retries);
|
|
Philip Kovacs |
9be8f2 |
}
|
|
Philip Kovacs |
9be8f2 |
|
|
Philip Kovacs |
9be8f2 |
- /* become the user after the allocation has been requested. */
|
|
Philip Kovacs |
9be8f2 |
- if (opt.uid != (uid_t) -1) {
|
|
Philip Kovacs |
9be8f2 |
- if (setuid(opt.uid) < 0) {
|
|
Philip Kovacs |
9be8f2 |
- error("setuid: %m");
|
|
Philip Kovacs |
9be8f2 |
- exit(error_exit);
|
|
Philip Kovacs |
9be8f2 |
- }
|
|
Philip Kovacs |
9be8f2 |
- }
|
|
Philip Kovacs |
9be8f2 |
if (alloc == NULL) {
|
|
Philip Kovacs |
9be8f2 |
if (allocation_interrupted) {
|
|
Philip Kovacs |
9be8f2 |
/* cancelled by signal */
|