Commit 547d9bf9 authored by Ruslan Kuprieiev's avatar Ruslan Kuprieiev Committed by Pavel Emelyanov

v2 security: set suid flag on crtools and check real uid on dump/restore

v2: remove redundant functions and variables.
Signed-off-by: 's avatarRuslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 398705d4
...@@ -1957,6 +1957,9 @@ static int prepare_creds(int pid, struct task_restore_core_args *args) ...@@ -1957,6 +1957,9 @@ static int prepare_creds(int pid, struct task_restore_core_args *args)
return -1; return -1;
} }
if (!may_restore_uid(ce->uid))
return -1;
args->creds = *ce; args->creds = *ce;
args->creds.cap_inh = args->cap_inh; args->creds.cap_inh = args->cap_inh;
memcpy(args->cap_inh, ce->cap_inh, sizeof(args->cap_inh)); memcpy(args->cap_inh, ce->cap_inh, sizeof(args->cap_inh));
......
...@@ -72,6 +72,7 @@ int main(int argc, char *argv[]) ...@@ -72,6 +72,7 @@ int main(int argc, char *argv[])
BUILD_BUG_ON(PAGE_SIZE != PAGE_IMAGE_SIZE); BUILD_BUG_ON(PAGE_SIZE != PAGE_IMAGE_SIZE);
cr_pb_init(); cr_pb_init();
restrict_uid(getuid());
if (argc < 2) if (argc < 2)
goto usage; goto usage;
......
...@@ -210,5 +210,6 @@ static inline bool pid_rst_prio(unsigned pid_a, unsigned pid_b) ...@@ -210,5 +210,6 @@ static inline bool pid_rst_prio(unsigned pid_a, unsigned pid_b)
void restrict_uid(unsigned int uid); void restrict_uid(unsigned int uid);
bool may_dump_uid(unsigned int uid); bool may_dump_uid(unsigned int uid);
bool may_restore_uid(unsigned int uid);
#endif /* __CR_CRTOOLS_H__ */ #endif /* __CR_CRTOOLS_H__ */
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "crtools.h" #include "crtools.h"
#include "log.h" #include "log.h"
static unsigned int dumper_uid = 0; static unsigned int cr_uid; /* UID which user can C/R */
/* /*
* Setup what user is requesting for dump (via rpc or using * Setup what user is requesting for dump (via rpc or using
...@@ -14,16 +14,33 @@ static unsigned int dumper_uid = 0; ...@@ -14,16 +14,33 @@ static unsigned int dumper_uid = 0;
void restrict_uid(unsigned int uid) void restrict_uid(unsigned int uid)
{ {
pr_info("Restrict C/R with %u uid\n", uid); pr_info("Restrict C/R with %u uid\n", uid);
dumper_uid = uid; cr_uid = uid;
}
static bool check_uid(unsigned int uid)
{
if (cr_uid == 0)
return true;
if (cr_uid == uid)
return true;
return false;
} }
bool may_dump_uid(unsigned int uid) bool may_dump_uid(unsigned int uid)
{ {
if (dumper_uid == 0) if (check_uid(uid))
return true; return true;
if (dumper_uid == uid)
pr_err("UID (%u) != dumper's UID(%u)\n", uid, cr_uid);
return false;
}
bool may_restore_uid(unsigned int uid)
{
if (check_uid(uid))
return true; return true;
pr_err("UID (%u) != dumper's UID(%u)\n", uid, dumper_uid); pr_err("UID (%u) != restorer's UID(%u)\n", uid, cr_uid);
return false; return false;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment