2022-04-30 11:33:54

by Xin Xiong

[permalink] [raw]
Subject: [PATCH] ksmbd: fix reference count leak in smb_check_perm_dacl()

The issue happens in a specific path in smb_check_perm_dacl(). When
"id" and "uid" have the same value, the function simply jumps out of
the loop without decrementing the reference count of the object
"posix_acls", which is increased by get_acl() earlier. This may
result in memory leaks.

Fix it by decreasing the reference count of "posix_acls" before
jumping to label "check_access_bits".

Fixes: 777cad1604d6 ("ksmbd: remove select FS_POSIX_ACL in Kconfig")
Signed-off-by: Xin Xiong <[email protected]>
Signed-off-by: Xin Tan <[email protected]>
---
fs/ksmbd/smbacl.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/fs/ksmbd/smbacl.c b/fs/ksmbd/smbacl.c
index 6ecf55ea1fed..38f23bf981ac 100644
--- a/fs/ksmbd/smbacl.c
+++ b/fs/ksmbd/smbacl.c
@@ -1261,6 +1261,7 @@ int smb_check_perm_dacl(struct ksmbd_conn *conn, struct path *path,
if (!access_bits)
access_bits =
SET_MINIMUM_RIGHTS;
+ posix_acl_release(posix_acls);
goto check_access_bits;
}
}
--
2.25.1


2022-05-02 22:46:55

by Namjae Jeon

[permalink] [raw]
Subject: Re: [PATCH] ksmbd: fix reference count leak in smb_check_perm_dacl()

2022-04-29 17:11 GMT+09:00, Xin Xiong <[email protected]>:
> The issue happens in a specific path in smb_check_perm_dacl(). When
> "id" and "uid" have the same value, the function simply jumps out of
> the loop without decrementing the reference count of the object
> "posix_acls", which is increased by get_acl() earlier. This may
> result in memory leaks.
>
> Fix it by decreasing the reference count of "posix_acls" before
> jumping to label "check_access_bits".
>
> Fixes: 777cad1604d6 ("ksmbd: remove select FS_POSIX_ACL in Kconfig")
> Signed-off-by: Xin Xiong <[email protected]>
> Signed-off-by: Xin Tan <[email protected]>
Acked-by: Namjae Jeon <[email protected]>

Thanks!