ANDROID: sdcardfs: Fix gid issue
authorDaniel Rosenberg <drosen@google.com>
Mon, 13 Mar 2017 22:34:03 +0000 (15:34 -0700)
committerAmit Pundir <amit.pundir@linaro.org>
Mon, 10 Apr 2017 07:42:16 +0000 (13:12 +0530)
We were already calculating most of these values,
and erroring out because the check was confused by this.
Instead of recalculating, adjust it as needed.

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Bug: 36160015
Change-Id: I9caf3e2fd32ca2e37ff8ed71b1d392f1761bc9a9

fs/sdcardfs/derived_perm.c
fs/sdcardfs/multiuser.h

index 763f10340487bde32bcb36b9fefd88b84b9d0037..28e9b8d42f9eb38607d7fd6639d727402de1768c 100644 (file)
@@ -205,13 +205,13 @@ void fixup_lower_ownership(struct dentry* dentry, const char *name) {
                        break;
                case PERM_ANDROID_PACKAGE:
                        if (info->d_uid != 0)
-                               gid = multiuser_get_ext_gid(info->userid, info->d_uid);
+                               gid = multiuser_get_ext_gid(info->d_uid);
                        else
                                gid = multiuser_get_uid(info->userid, uid);
                        break;
                case PERM_ANDROID_PACKAGE_CACHE:
                        if (info->d_uid != 0)
-                               gid = multiuser_get_cache_gid(info->userid, info->d_uid);
+                               gid = multiuser_get_cache_gid(info->d_uid);
                        else
                                gid = multiuser_get_uid(info->userid, uid);
                        break;
index ca141ff40b4914acda36bda27c1ab26a348ce50a..2e89b587231402a459bd86e0623856ead76cf339 100644 (file)
 typedef uid_t userid_t;
 typedef uid_t appid_t;
 
-static inline uid_t multiuser_get_uid(userid_t user_id, appid_t app_id) {
+static inline uid_t multiuser_get_uid(userid_t user_id, appid_t app_id)
+{
        return (user_id * AID_USER_OFFSET) + (app_id % AID_USER_OFFSET);
 }
 
-static inline gid_t multiuser_get_cache_gid(userid_t user_id, 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_CACHE_GID_START);
-       } else {
-               return -1;
-       }
+static inline gid_t multiuser_get_cache_gid(uid_t uid)
+{
+       return uid - AID_APP_START + AID_CACHE_GID_START;
 }
 
-static inline gid_t multiuser_get_ext_gid(userid_t user_id, 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_EXT_GID_START);
-       } else {
-               return -1;
-       }
+static inline gid_t multiuser_get_ext_gid(uid_t uid)
+{
+       return uid - AID_APP_START + AID_EXT_GID_START;
 }