Only change uid/gid when it's not 0

Only change the device uid/gid in the sandbox when it is not 0.
Otherwise, running crosvm as root makes minijail complain:

   libminijail[16370]: useless change to uid 0

BUG=none
TEST=run crosvm as root

Change-Id: Ida4b0e772ed000d3e42f77012af9d2505f64d92a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3141297
Auto-Submit: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Fergus Dall <sidereal@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Chirantan Ekbote 2021-09-03 18:31:25 +09:00 committed by Commit Bot
parent 3eeaf6a339
commit e1663eeae4

View file

@ -1692,8 +1692,12 @@ fn add_current_user_to_jail(jail: &mut Minijail) -> Result<Ids> {
jail.gidmap(&format!("{0} {0} 1", crosvm_gid))
.map_err(Error::SettingGidMap)?;
jail.change_uid(crosvm_uid);
jail.change_gid(crosvm_gid);
if crosvm_uid != 0 {
jail.change_uid(crosvm_uid);
}
if crosvm_gid != 0 {
jail.change_gid(crosvm_gid);
}
Ok(Ids {
uid: crosvm_uid,