From 63c3b5d2ca96b4a2a88ae01bea94021e874ce8fe Mon Sep 17 00:00:00 2001 From: "GONG, Ruiqi" Date: Mon, 6 Jun 2022 16:17:14 +0800 Subject: smack: Replace kzalloc + strncpy with kstrndup 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 Signed-off-by: Casey Schaufler --- security/smack/smack_access.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'security') 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; } -- cgit v1.2.3 From aa16fb4b9e7e1057008d999138e7ae68a40bf167 Mon Sep 17 00:00:00 2001 From: Xiu Jianfeng Date: Fri, 10 Jun 2022 17:23:07 +0800 Subject: smack: Remove the redundant lsm_inode_alloc It's not possible for inode->i_security to be NULL here because every inode will call inode_init_always and then lsm_inode_alloc to alloc memory for inode->security, this is what LSM infrastructure management do, so remove this redundant code. Signed-off-by: Xiu Jianfeng Signed-off-by: Casey Schaufler --- security/smack/smack_lsm.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'security') diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c index 6207762dbdb1..001831458fa2 100644 --- a/security/smack/smack_lsm.c +++ b/security/smack/smack_lsm.c @@ -766,13 +766,6 @@ static int smack_set_mnt_opts(struct super_block *sb, if (sp->smk_flags & SMK_SB_INITIALIZED) return 0; - if (inode->i_security == NULL) { - int rc = lsm_inode_alloc(inode); - - if (rc) - return rc; - } - if (!smack_privileged(CAP_MAC_ADMIN)) { /* * Unprivileged mounts don't get to specify Smack values. -- cgit v1.2.3