ksmbd: fix control flow issues in sid_to_id()
authorNamjae Jeon <linkinjeon@kernel.org>
Mon, 6 Sep 2021 23:16:26 +0000 (08:16 +0900)
committerSteve French <stfrench@microsoft.com>
Wed, 8 Sep 2021 22:16:13 +0000 (17:16 -0500)
Addresses-Coverity reported Control flow issues in sid_to_id()
/fs/ksmbd/smbacl.c: 277 in sid_to_id()
271
272 if (sidtype == SIDOWNER) {
273 kuid_t uid;
274 uid_t id;
275
276 id = le32_to_cpu(psid->sub_auth[psid->num_subauth - 1]);
>>> CID 1506810:  Control flow issues  (NO_EFFECT)
>>> This greater-than-or-equal-to-zero comparison of an unsigned value
>>> is always true. "id >= 0U".
277 if (id >= 0) {
278 /*
279  * Translate raw sid into kuid in the server's user
280  * namespace.
281  */
282 uid = make_kuid(&init_user_ns, id);

Addresses-Coverity: ("Control flow issues")
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/ksmbd/smbacl.c

index 16da99a..0a95cde 100644 (file)
@@ -274,38 +274,34 @@ static int sid_to_id(struct user_namespace *user_ns,
                uid_t id;
 
                id = le32_to_cpu(psid->sub_auth[psid->num_subauth - 1]);
-               if (id >= 0) {
-                       /*
-                        * Translate raw sid into kuid in the server's user
-                        * namespace.
-                        */
-                       uid = make_kuid(&init_user_ns, id);
-
-                       /* If this is an idmapped mount, apply the idmapping. */
-                       uid = kuid_from_mnt(user_ns, uid);
-                       if (uid_valid(uid)) {
-                               fattr->cf_uid = uid;
-                               rc = 0;
-                       }
+               /*
+                * Translate raw sid into kuid in the server's user
+                * namespace.
+                */
+               uid = make_kuid(&init_user_ns, id);
+
+               /* If this is an idmapped mount, apply the idmapping. */
+               uid = kuid_from_mnt(user_ns, uid);
+               if (uid_valid(uid)) {
+                       fattr->cf_uid = uid;
+                       rc = 0;
                }
        } else {
                kgid_t gid;
                gid_t id;
 
                id = le32_to_cpu(psid->sub_auth[psid->num_subauth - 1]);
-               if (id >= 0) {
-                       /*
-                        * Translate raw sid into kgid in the server's user
-                        * namespace.
-                        */
-                       gid = make_kgid(&init_user_ns, id);
-
-                       /* If this is an idmapped mount, apply the idmapping. */
-                       gid = kgid_from_mnt(user_ns, gid);
-                       if (gid_valid(gid)) {
-                               fattr->cf_gid = gid;
-                               rc = 0;
-                       }
+               /*
+                * Translate raw sid into kgid in the server's user
+                * namespace.
+                */
+               gid = make_kgid(&init_user_ns, id);
+
+               /* If this is an idmapped mount, apply the idmapping. */
+               gid = kgid_from_mnt(user_ns, gid);
+               if (gid_valid(gid)) {
+                       fattr->cf_gid = gid;
+                       rc = 0;
                }
        }