From e1663eeae46b3765a4e369e1fe70f1c1ef03cb0b Mon Sep 17 00:00:00 2001 From: Chirantan Ekbote Date: Fri, 3 Sep 2021 18:31:25 +0900 Subject: [PATCH] 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 Tested-by: kokoro Reviewed-by: Fergus Dall Reviewed-by: Daniel Verkamp Commit-Queue: Daniel Verkamp --- src/linux.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/linux.rs b/src/linux.rs index 03f4a91dbe..cd10673c53 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -1692,8 +1692,12 @@ fn add_current_user_to_jail(jail: &mut Minijail) -> Result { 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,