public inbox for linux-security-module@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] apparmor: replace strcpy with strscpy
@ 2026-01-20 14:50 Ryan Foster
  2026-02-05  7:52 ` John Johansen
  0 siblings, 1 reply; 2+ messages in thread
From: Ryan Foster @ 2026-01-20 14:50 UTC (permalink / raw)
  To: john.johansen
  Cc: paul, jmorris, serge, apparmor, linux-security-module,
	linux-kernel, Ryan Foster

Found by checkpatch. Replace strcpy() with strscpy() for safer
string handling per KSPP recommendations.

Two changes:
- apparmorfs.c: gen_symlink_name() uses tracked buffer size
- lib.c: aa_policy_init() uses exact allocation size

Link: https://github.com/KSPP/linux/issues/88
Signed-off-by: Ryan Foster <foster.ryan.r@gmail.com>
---
 security/apparmor/apparmorfs.c | 2 +-
 security/apparmor/lib.c        | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
index 907bd2667e28..f38974231df2 100644
--- a/security/apparmor/apparmorfs.c
+++ b/security/apparmor/apparmorfs.c
@@ -1614,7 +1614,7 @@ static char *gen_symlink_name(int depth, const char *dirname, const char *fname)
 		return ERR_PTR(-ENOMEM);
 
 	for (; depth > 0; depth--) {
-		strcpy(s, "../../");
+		strscpy(s, "../../", size);
 		s += 6;
 		size -= 6;
 	}
diff --git a/security/apparmor/lib.c b/security/apparmor/lib.c
index 82dbb97ad406..7cb393f91a10 100644
--- a/security/apparmor/lib.c
+++ b/security/apparmor/lib.c
@@ -487,7 +487,7 @@ bool aa_policy_init(struct aa_policy *policy, const char *prefix,
 	} else {
 		hname = aa_str_alloc(strlen(name) + 1, gfp);
 		if (hname)
-			strcpy(hname, name);
+			strscpy(hname, name, strlen(name) + 1);
 	}
 	if (!hname)
 		return false;
-- 
2.52.0


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

end of thread, other threads:[~2026-02-05  7:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-20 14:50 [PATCH] apparmor: replace strcpy with strscpy Ryan Foster
2026-02-05  7:52 ` John Johansen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox