diff mbox series

[RESEND] smack: Replace kzalloc + strncpy with kstrndup

Message ID 20220607093649.928131-1-gongruiqi1@huawei.com (mailing list archive)
State Handled Elsewhere
Headers show
Series [RESEND] smack: Replace kzalloc + strncpy with kstrndup | expand

Commit Message

Gong Ruiqi June 7, 2022, 9:36 a.m. UTC
Simplify the code by using kstrndup instead of kzalloc and strncpy in
smk_parse_smack(), which meanwhile remove strncpy as [1] suggests.

[1]: https://github.com/KSPP/linux/issues/90

Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>
---

Resend: fix email issue to make it acceptable by the mailing list

 security/smack/smack_access.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Kees Cook June 7, 2022, 7:18 p.m. UTC | #1
On Tue, Jun 07, 2022 at 05:36:49PM +0800, GONG, Ruiqi wrote:
> Simplify the code by using kstrndup instead of kzalloc and strncpy in
> smk_parse_smack(), which meanwhile remove strncpy as [1] suggests.
> 
> [1]: https://github.com/KSPP/linux/issues/90
> 
> Signed-off-by: GONG, Ruiqi <gongruiqi1@huawei.com>

Reviewed-by: Kees Cook <keescook@chromium.org>
diff mbox series

Patch

diff --git a/security/smack/smack_access.c b/security/smack/smack_access.c
index d2186e2757be..585e5e35710b 100644
--- a/security/smack/smack_access.c
+++ b/security/smack/smack_access.c
@@ -465,12 +465,9 @@  char *smk_parse_smack(const char *string, int len)
 	if (i == 0 || i >= SMK_LONGLABEL)
 		return ERR_PTR(-EINVAL);
 
-	smack = kzalloc(i + 1, GFP_NOFS);
-	if (smack == NULL)
+	smack = kstrndup(string, i, GFP_NOFS);
+	if (!smack)
 		return ERR_PTR(-ENOMEM);
-
-	strncpy(smack, string, i);
-
 	return smack;
 }