kdbus: use u64 capability for v6.3 or later version 86/306886/1
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Tue, 27 Feb 2024 07:24:12 +0000 (16:24 +0900)
committerJaehoon Chung <jh80.chung@samsung.com>
Thu, 29 Feb 2024 00:53:35 +0000 (09:53 +0900)
Since the commit f122a08b197d ("capability: just use a 'u64' instead of a 'u32[2]' array")
of v6.3, not anymore u32[2] array capability. Use u64 capability
for v6.3 or later kernel version.

Change-Id: Ibb1dbdeafade0489c6c546ff1cace78e76add2bd
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
kernel/kdbus/metadata.c

index 1b12bba6505582e3dc54bd2e612fc7092ff9e363..30471cbc9b0cbdd2029cd77f070e76aec17e110c 100644 (file)
@@ -131,9 +131,13 @@ struct kdbus_meta_conn {
 /* fixed size equivalent of "kdbus_caps" */
 struct kdbus_meta_caps {
        u32 last_cap;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
+       kernel_cap_t cap_sets[4];
+#else
        struct {
                u32 caps[_KERNEL_CAPABILITY_U32S];
        } set[4];
+#endif
 };
 
 /**
@@ -765,6 +769,28 @@ static void kdbus_meta_export_caps(struct kdbus_meta_caps *out,
 
        out->last_cap = CAP_LAST_CAP;
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 3, 0)
+       if (parent) {
+               out->cap_sets[0] = cred->cap_inheritable;
+               out->cap_sets[1] = cred->cap_permitted;
+               out->cap_sets[2] = cred->cap_effective;
+               out->cap_sets[3] = cred->cap_bset;
+       } else if (owner) {
+               out->cap_sets[0] = CAP_EMPTY_SET;
+               out->cap_sets[1] = CAP_FULL_SET;
+               out->cap_sets[2] = CAP_FULL_SET;
+               out->cap_sets[3] = CAP_FULL_SET;
+       } else {
+               out->cap_sets[0] = CAP_EMPTY_SET;
+               out->cap_sets[1] = CAP_EMPTY_SET;
+               out->cap_sets[2] = CAP_EMPTY_SET;
+               out->cap_sets[3] = CAP_EMPTY_SET;
+       }
+
+       /* clear unused bits */
+       for (i = 0; i < 4; i++)
+               out->cap_sets[i].val &= CAP_VALID_MASK;
+#else
        CAP_FOR_EACH_U32(i) {
                if (parent) {
                        out->set[0].caps[i] = cred->cap_inheritable.cap[i];
@@ -788,6 +814,7 @@ static void kdbus_meta_export_caps(struct kdbus_meta_caps *out,
        for (i = 0; i < 4; i++)
                out->set[i].caps[CAP_TO_INDEX(CAP_LAST_CAP)] &=
                                        CAP_LAST_U32_VALID_MASK;
+#endif
 }
 
 /* This is equivalent to from_kuid_munged(), but maps INVALID_UID to itself */