Commit 229e4e50 authored by Pavel Emelyanov's avatar Pavel Emelyanov

security: Check not only real user ID

When dumping/restoring for unpriveledged user, check for all
sets of IDs to match, just like ptrace-may-attach in the kernel.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent b4c8c5ae
...@@ -22,34 +22,25 @@ void restrict_uid(unsigned int uid, unsigned int gid) ...@@ -22,34 +22,25 @@ void restrict_uid(unsigned int uid, unsigned int gid)
cr_gid = gid; cr_gid = gid;
} }
static bool check_uid(unsigned int uid) static bool check_ids(unsigned int crid, unsigned int rid, unsigned int eid, unsigned int sid)
{ {
if (cr_uid == 0) if (crid == 0)
return true; return true;
if (cr_uid == uid) if (crid == rid && crid == eid && crid == sid)
return true; return true;
pr_err("UID/GID mismatch %u != (%u,%u,%u)\n", crid, rid, eid, sid);
return false; return false;
} }
bool may_dump(struct proc_status_creds *creds) bool may_dump(struct proc_status_creds *creds)
{ {
unsigned int uid = creds->uids[0]; return check_ids(cr_uid, creds->uids[0], creds->uids[1], creds->uids[2]) &&
check_ids(cr_gid, creds->gids[0], creds->gids[1], creds->gids[2]);
if (check_uid(uid))
return true;
pr_err("UID (%u) != dumper's UID(%u)\n", uid, cr_uid);
return false;
} }
bool may_restore(CredsEntry *creds) bool may_restore(CredsEntry *creds)
{ {
unsigned int uid = creds->uid; return check_ids(cr_uid, creds->uid, creds->euid, creds->suid) &&
check_ids(cr_gid, creds->gid, creds->egid, creds->sgid);
if (check_uid(uid))
return true;
pr_err("UID (%u) != restorer's UID(%u)\n", uid, cr_uid);
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