linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND PATCH] smack: Replace kzalloc + strncpy with kstrndup
@ 2022-06-07  9:36 GONG, Ruiqi
  2022-06-07 19:18 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: GONG, Ruiqi @ 2022-06-07  9:36 UTC (permalink / raw)
  To: Casey Schaufler, James Morris, Serge E . Hallyn
  Cc: Kees Cook, linux-security-module, linux-kernel, Wang Weiyang,
	Xiu Jianfeng, Gong Ruiqi

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(-)

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;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [RESEND PATCH] smack: Replace kzalloc + strncpy with kstrndup
  2022-06-07  9:36 [RESEND PATCH] smack: Replace kzalloc + strncpy with kstrndup GONG, Ruiqi
@ 2022-06-07 19:18 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2022-06-07 19:18 UTC (permalink / raw)
  To: GONG, Ruiqi
  Cc: Casey Schaufler, James Morris, Serge E . Hallyn,
	linux-security-module, linux-kernel, Wang Weiyang, Xiu Jianfeng

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>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-06-08  0:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-07  9:36 [RESEND PATCH] smack: Replace kzalloc + strncpy with kstrndup GONG, Ruiqi
2022-06-07 19:18 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).