ksmbd: remove unnecessary conditions
Subsystems (3)
PATCH 1/1 ksmbd: remove unnecessary conditions
uid_t are unsigned so they can't be less than zero. Remove the conditions since they are always true.
--- fs/ksmbd/smbacl.c | 48 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 26 deletions(-)
fs/ksmbd/smbacl.c +22 -26
@@ -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 ; } }
Signature · 1 line
2.20.1
Sergey Senozhatsky
reviewerQuoted 10 lines · Dan Carpenter
fs/ksmbd/smbacl.c +0
-8id =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. */
fs/ksmbd/smbacl.c static int sid_to_id(struct user_namespace *user_ns, · line 281
Quoted 10 lines
fs/ksmbd/smbacl.c +5
-5- 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);
Can make_kuid() return INVALID_UID? IOW, uid_valid(uid) here as well?
Quoted 7 lines
fs/ksmbd/smbacl.c +6
-0+ +/* 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 ; }
[..]
fs/ksmbd/smbacl.c static int sid_to_id(struct user_namespace *user_ns, · line 298
Quoted 5 lines
fs/ksmbd/smbacl.c +5
-0+/* +* Translate raw sid into kgid in the server's user +* namespace. +*/ + gid =make_kgid (&init_user_ns, id);
Ditto.
Quoted 5 lines
fs/ksmbd/smbacl.c +5
-0+/* 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 ;
Quoted 15 lines · Sergey Senozhatsky
Quoted 14 lines · Dan Carpenter
fs/ksmbd/smbacl.c +0
-12id =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 ;
Quoted 8 lines
fs/ksmbd/smbacl.c static int sid_to_id(struct user_namespace *user_ns, · line 281
Quoted 6 lines
fs/ksmbd/smbacl.c +5
-1- } +/* +* Translate raw sid into kuid in the server's user +* namespace. +*/ + uid =make_kuid (&init_user_ns, id);Can
make_kuid()returnINVALID_UID? IOW,uid_valid(uid)here as well?
No need to check twice. We're going to check at the end.
Quoted 5 lines
fs/ksmbd/smbacl.c static int sid_to_id(struct user_namespace *user_ns, · line 285
Quoted 5 lines
fs/ksmbd/smbacl.c +4
-0+ +/* If this is an idmapped mount, apply the idmapping. */ + uid =kuid_from_mnt (user_ns, uid); +if (uid_valid (uid)) {
^^^^^^^^^^^^^^
The check here is sufficient.
regards,
dan carpenter
Sergey Senozhatsky
reviewerQuoted 28 lines · Dan Carpenter
Quoted 15 lines · Sergey Senozhatsky
Quoted 14 lines · Dan Carpenter
fs/ksmbd/smbacl.c +0
-12id =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 ;Quoted 8 lines
fs/ksmbd/smbacl.c static int sid_to_id(struct user_namespace *user_ns, · line 281
Quoted 6 lines
fs/ksmbd/smbacl.c +5
-1- } +/* +* Translate raw sid into kuid in the server's user +* namespace. +*/ + uid =make_kuid (&init_user_ns, id);Can
make_kuid()returnINVALID_UID? IOW,uid_valid(uid)here as well?No need to check twice. We're going to check at the end.
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
fs/ksmbd/smbacl.c static int sid_to_id(struct user_namespace *user_ns, · line 285
Quoted 4 lines
fs/ksmbd/smbacl.c +4
-0+ +/* If this is an idmapped mount, apply the idmapping. */ + uid =kuid_from_mnt (user_ns, uid); +if (uid_valid (uid)) {^^^^^^^^^^^^^^The check here is sufficient.
My point was more that a potentially invalid UID is passed to kuid_from_mnt() and kgid_from_mnt(). I don't see map_id_up(), for example, checking that passed UID is valid. So decided to double check.
Quoted 36 lines · Sergey Senozhatsky
Quoted 28 lines · Dan Carpenter
Quoted 15 lines · Sergey Senozhatsky
Quoted 14 lines · Dan Carpenter
fs/ksmbd/smbacl.c +0
-12id =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 ;Quoted 8 lines
fs/ksmbd/smbacl.c static int sid_to_id(struct user_namespace *user_ns, · line 281
Quoted 6 lines
fs/ksmbd/smbacl.c +5
-1- } +/* +* Translate raw sid into kuid in the server's user +* namespace. +*/ + uid =make_kuid (&init_user_ns, id);Can
make_kuid()returnINVALID_UID? IOW,uid_valid(uid)here as well?No need to check twice. We're going to check at the end.
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
fs/ksmbd/smbacl.c static int sid_to_id(struct user_namespace *user_ns, · line 285
Quoted 4 lines
fs/ksmbd/smbacl.c +4
-0+ +/* If this is an idmapped mount, apply the idmapping. */ + uid =kuid_from_mnt (user_ns, uid); +if (uid_valid (uid)) {^^^^^^^^^^^^^^The check here is sufficient.
Quoted 3 lines
My point was more that a potentially invalid UID is passed to
kuid_from_mnt()andkgid_from_mnt(). I don't seemap_id_up(), for example, checking that passed UID is valid. So decided to double check.
But you've seen it now, right? The kuid_from_mnt() will return INVALID_UID if you pass it any unknown uid (including INVALID_UID).
regards,
dan carpenter
Sergey Senozhatsky
reviewerOn (21/09/07 12:14), Dan Carpenter wrote:
[..]
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 2 lines
Can
make_kuid()returnINVALID_UID? IOW,uid_valid(uid)here as well?No need to check twice. We're going to check at the end.
Quoted 5 lines
fs/ksmbd/smbacl.c static int sid_to_id(struct user_namespace *user_ns, · line 285
Quoted 5 lines
fs/ksmbd/smbacl.c +4
-0+ +/* If this is an idmapped mount, apply the idmapping. */ + uid =kuid_from_mnt (user_ns, uid); +if (uid_valid (uid)) {^^^^^^^^^^^^^^The check here is sufficient.
Quoted 5 lines
Quoted 3 lines
My point was more that a potentially invalid UID is passed to
kuid_from_mnt()andkgid_from_mnt(). I don't seemap_id_up(), for example, checking that passed UID is valid. So decided to double check.But you've seen it now, right?
A linear search in array of 5 elements or a binary search in array of 340 elements? Yea, I saw it. I'd prefer one extra uid_valid(), if you'd ask me - why call the function if we already know that it'll fail.
Quoted 19 lines · Sergey Senozhatsky
On (21/09/07 12:14), Dan Carpenter wrote:
[..]Quoted 17 lines
Quoted 16 lines
Quoted 6 lines
Quoted 2 lines
Can
make_kuid()returnINVALID_UID? IOW,uid_valid(uid)here as well?No need to check twice. We're going to check at the end.
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
fs/ksmbd/smbacl.c static int sid_to_id(struct user_namespace *user_ns, · line 285
Quoted 4 lines
fs/ksmbd/smbacl.c +4
-0+ +/* If this is an idmapped mount, apply the idmapping. */ + uid =kuid_from_mnt (user_ns, uid); +if (uid_valid (uid)) {^^^^^^^^^^^^^^The check here is sufficient.
My point was more that a potentially invalid UID is passed to
kuid_from_mnt()andkgid_from_mnt(). I don't seemap_id_up(), for example, checking that passed UID is valid. So decided to double check.
Quoted 5 lines
Quoted 1 line
But you've seen it now, right?
A linear search in array of 5 elements or a binary search in array of 340 elements? Yea, I saw it. I'd prefer one extra
uid_valid(), if you'd ask me - why call the function if we already know that it'll fail.
It's a failure path. Hopefully people will only give us valid data.
We would normally only optimize the failure path if we thought that it could be used as a DoS vector.
regards,
dan carpenter
Sergey Senozhatsky
reviewerQuoted 9 lines · Dan Carpenter
Quoted 6 lines
Quoted 2 lines
But you've seen it now, right?
A linear search in array of 5 elements or a binary search in array of 340 elements? Yea, I saw it. I'd prefer one extra
uid_valid(), if you'd ask me - why call the function if we already know that it'll fail.It's a failure path. Hopefully people will only give us valid data.
I usually prefer to assume that remote clients are _not exactly_ nice folks. Can this be a DoS vector - probably not. cmp; je; is several thousand times cheaper that a bsearch, and this is a remote user request servicing path. So. Just my 5 cents.
I'll leave it to you and Namjae to decide.