From 53d37ba23f4805dc81849595d18160eac7e75439 Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Thu, 9 Nov 2017 17:41:09 -0700 Subject: [PATCH] Better, consistent definition of AID_SHARED_GID. AID_SHARED_GID is a GID shared by a specific app across all users on the same device. Bring the UserHandle and multiuser.c implementations into agreement, and copy/paste the unit tests that verify that both behave identically. This fixes a regression where multiuser_get_shared_gid() was applying per-user isolation when it shouldn't have. Test: adb shell /data/nativetest64/libcutils_test/libcutils_test64 Bug: 34151068, 64548938 Change-Id: I491dd79d23a214425a68865d1d0f8269916aad4c --- libcutils/Android.bp | 2 +- libcutils/{multiuser.c => multiuser.cpp} | 6 ++++-- libcutils/tests/multiuser_test.cpp | 12 +++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) rename libcutils/{multiuser.c => multiuser.cpp} (90%) diff --git a/libcutils/Android.bp b/libcutils/Android.bp index d7413d16c..9cba109a4 100644 --- a/libcutils/Android.bp +++ b/libcutils/Android.bp @@ -20,7 +20,7 @@ libcutils_nonwindows_sources = [ "android_get_control_file.cpp", "fs.cpp", - "multiuser.c", + "multiuser.cpp", "socket_inaddr_any_server_unix.cpp", "socket_local_client_unix.cpp", "socket_local_server_unix.cpp", diff --git a/libcutils/multiuser.c b/libcutils/multiuser.cpp similarity index 90% rename from libcutils/multiuser.c rename to libcutils/multiuser.cpp index 61403f4f1..0fd3d0c52 100644 --- a/libcutils/multiuser.c +++ b/libcutils/multiuser.cpp @@ -53,9 +53,11 @@ gid_t multiuser_get_ext_cache_gid(userid_t user_id, appid_t app_id) { } } -gid_t multiuser_get_shared_gid(userid_t user_id, appid_t app_id) { +gid_t multiuser_get_shared_gid(userid_t, appid_t app_id) { if (app_id >= AID_APP_START && app_id <= AID_APP_END) { - return multiuser_get_uid(user_id, (app_id - AID_APP_START) + AID_SHARED_GID_START); + return (app_id - AID_APP_START) + AID_SHARED_GID_START; + } else if (app_id >= AID_ROOT && app_id <= AID_APP_START) { + return app_id; } else { return -1; } diff --git a/libcutils/tests/multiuser_test.cpp b/libcutils/tests/multiuser_test.cpp index 2f9d854b3..4b0fd130f 100644 --- a/libcutils/tests/multiuser_test.cpp +++ b/libcutils/tests/multiuser_test.cpp @@ -57,7 +57,10 @@ TEST(MultiuserTest, TestCache) { EXPECT_EQ(ERR_GID, multiuser_get_cache_gid(0, 1000)); EXPECT_EQ(20000U, multiuser_get_cache_gid(0, 10000)); EXPECT_EQ(ERR_GID, multiuser_get_cache_gid(0, 50000)); + EXPECT_EQ(ERR_GID, multiuser_get_cache_gid(10, 0)); + EXPECT_EQ(ERR_GID, multiuser_get_cache_gid(10, 1000)); EXPECT_EQ(1020000U, multiuser_get_cache_gid(10, 10000)); + EXPECT_EQ(ERR_GID, multiuser_get_cache_gid(10, 50000)); } TEST(MultiuserTest, TestExt) { @@ -77,9 +80,12 @@ TEST(MultiuserTest, TestExtCache) { } TEST(MultiuserTest, TestShared) { - EXPECT_EQ(ERR_GID, multiuser_get_shared_gid(0, 0)); - EXPECT_EQ(ERR_GID, multiuser_get_shared_gid(0, 1000)); + EXPECT_EQ(0U, multiuser_get_shared_gid(0, 0)); + EXPECT_EQ(1000U, multiuser_get_shared_gid(0, 1000)); EXPECT_EQ(50000U, multiuser_get_shared_gid(0, 10000)); EXPECT_EQ(ERR_GID, multiuser_get_shared_gid(0, 50000)); - EXPECT_EQ(1050000U, multiuser_get_shared_gid(10, 10000)); + EXPECT_EQ(0U, multiuser_get_shared_gid(10, 0)); + EXPECT_EQ(1000U, multiuser_get_shared_gid(10, 1000)); + EXPECT_EQ(50000U, multiuser_get_shared_gid(10, 10000)); + EXPECT_EQ(ERR_GID, multiuser_get_shared_gid(10, 50000)); }