* [PATCH RESEND] apparmor: Replace memcpy + NUL termination with kmemdup_nul in do_setattr
@ 2026-03-09 22:41 Thorsten Blum
2026-03-18 6:31 ` John Johansen
0 siblings, 1 reply; 5+ messages in thread
From: Thorsten Blum @ 2026-03-09 22:41 UTC (permalink / raw)
To: John Johansen, Paul Moore, James Morris, Serge E. Hallyn
Cc: Thorsten Blum, apparmor, linux-security-module, linux-kernel
Use kmemdup_nul() to copy 'value' instead of using memcpy() followed by
a manual NUL termination. No functional changes.
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
security/apparmor/lsm.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index c1d42fc72fdb..49aa6ad68838 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -858,12 +858,9 @@ static int do_setattr(u64 attr, void *value, size_t size)
/* AppArmor requires that the buffer must be null terminated atm */
if (args[size - 1] != '\0') {
- /* null terminate */
- largs = args = kmalloc(size + 1, GFP_KERNEL);
+ largs = args = kmemdup_nul(value, size, GFP_KERNEL);
if (!args)
return -ENOMEM;
- memcpy(args, value, size);
- args[size] = '\0';
}
error = -EINVAL;
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH RESEND] apparmor: Replace memcpy + NUL termination with kmemdup_nul in do_setattr
2026-03-09 22:41 [PATCH RESEND] apparmor: Replace memcpy + NUL termination with kmemdup_nul in do_setattr Thorsten Blum
@ 2026-03-18 6:31 ` John Johansen
0 siblings, 0 replies; 5+ messages in thread
From: John Johansen @ 2026-03-18 6:31 UTC (permalink / raw)
To: Thorsten Blum, Paul Moore, James Morris, Serge E. Hallyn
Cc: apparmor, linux-security-module, linux-kernel
On 3/9/26 15:41, Thorsten Blum wrote:
> Use kmemdup_nul() to copy 'value' instead of using memcpy() followed by
> a manual NUL termination. No functional changes.
>
> Reviewed-by: Serge Hallyn <serge@hallyn.com>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
sorry this got lost in the mess of the last month, this has
now been pulled into my tree
> ---
> security/apparmor/lsm.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
> index c1d42fc72fdb..49aa6ad68838 100644
> --- a/security/apparmor/lsm.c
> +++ b/security/apparmor/lsm.c
> @@ -858,12 +858,9 @@ static int do_setattr(u64 attr, void *value, size_t size)
>
> /* AppArmor requires that the buffer must be null terminated atm */
> if (args[size - 1] != '\0') {
> - /* null terminate */
> - largs = args = kmalloc(size + 1, GFP_KERNEL);
> + largs = args = kmemdup_nul(value, size, GFP_KERNEL);
> if (!args)
> return -ENOMEM;
> - memcpy(args, value, size);
> - args[size] = '\0';
> }
>
> error = -EINVAL;
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH RESEND] apparmor: Replace memcpy + NUL termination with kmemdup_nul in do_setattr
@ 2026-02-22 20:46 Thorsten Blum
2026-02-22 20:53 ` Serge E. Hallyn
2026-03-18 6:26 ` John Johansen
0 siblings, 2 replies; 5+ messages in thread
From: Thorsten Blum @ 2026-02-22 20:46 UTC (permalink / raw)
To: John Johansen, Paul Moore, James Morris, Serge E. Hallyn
Cc: Thorsten Blum, apparmor, linux-security-module, linux-kernel
Use kmemdup_nul() to copy 'value' instead of using memcpy() followed by
a manual NUL termination. No functional changes.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
security/apparmor/lsm.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
index c1d42fc72fdb..49aa6ad68838 100644
--- a/security/apparmor/lsm.c
+++ b/security/apparmor/lsm.c
@@ -858,12 +858,9 @@ static int do_setattr(u64 attr, void *value, size_t size)
/* AppArmor requires that the buffer must be null terminated atm */
if (args[size - 1] != '\0') {
- /* null terminate */
- largs = args = kmalloc(size + 1, GFP_KERNEL);
+ largs = args = kmemdup_nul(value, size, GFP_KERNEL);
if (!args)
return -ENOMEM;
- memcpy(args, value, size);
- args[size] = '\0';
}
error = -EINVAL;
--
Thorsten Blum <thorsten.blum@linux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH RESEND] apparmor: Replace memcpy + NUL termination with kmemdup_nul in do_setattr
2026-02-22 20:46 Thorsten Blum
@ 2026-02-22 20:53 ` Serge E. Hallyn
2026-03-18 6:26 ` John Johansen
1 sibling, 0 replies; 5+ messages in thread
From: Serge E. Hallyn @ 2026-02-22 20:53 UTC (permalink / raw)
To: Thorsten Blum
Cc: John Johansen, Paul Moore, James Morris, Serge E. Hallyn,
apparmor, linux-security-module, linux-kernel
On Sun, Feb 22, 2026 at 09:46:44PM +0100, Thorsten Blum wrote:
> Use kmemdup_nul() to copy 'value' instead of using memcpy() followed by
> a manual NUL termination. No functional changes.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Looks correct, thanks.
Reviewed-by: Serge Hallyn <serge@hallyn.com>
> ---
> security/apparmor/lsm.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
> index c1d42fc72fdb..49aa6ad68838 100644
> --- a/security/apparmor/lsm.c
> +++ b/security/apparmor/lsm.c
> @@ -858,12 +858,9 @@ static int do_setattr(u64 attr, void *value, size_t size)
>
> /* AppArmor requires that the buffer must be null terminated atm */
> if (args[size - 1] != '\0') {
> - /* null terminate */
> - largs = args = kmalloc(size + 1, GFP_KERNEL);
> + largs = args = kmemdup_nul(value, size, GFP_KERNEL);
> if (!args)
> return -ENOMEM;
> - memcpy(args, value, size);
> - args[size] = '\0';
> }
>
> error = -EINVAL;
> --
> Thorsten Blum <thorsten.blum@linux.dev>
> GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH RESEND] apparmor: Replace memcpy + NUL termination with kmemdup_nul in do_setattr
2026-02-22 20:46 Thorsten Blum
2026-02-22 20:53 ` Serge E. Hallyn
@ 2026-03-18 6:26 ` John Johansen
1 sibling, 0 replies; 5+ messages in thread
From: John Johansen @ 2026-03-18 6:26 UTC (permalink / raw)
To: Thorsten Blum, Paul Moore, James Morris, Serge E. Hallyn
Cc: apparmor, linux-security-module, linux-kernel
On 2/22/26 12:46, Thorsten Blum wrote:
> Use kmemdup_nul() to copy 'value' instead of using memcpy() followed by
> a manual NUL termination. No functional changes.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
sorry this got dropped. It has been now pulled into my tree
> ---
> security/apparmor/lsm.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
> index c1d42fc72fdb..49aa6ad68838 100644
> --- a/security/apparmor/lsm.c
> +++ b/security/apparmor/lsm.c
> @@ -858,12 +858,9 @@ static int do_setattr(u64 attr, void *value, size_t size)
>
> /* AppArmor requires that the buffer must be null terminated atm */
> if (args[size - 1] != '\0') {
> - /* null terminate */
> - largs = args = kmalloc(size + 1, GFP_KERNEL);
> + largs = args = kmemdup_nul(value, size, GFP_KERNEL);
> if (!args)
> return -ENOMEM;
> - memcpy(args, value, size);
> - args[size] = '\0';
> }
>
> error = -EINVAL;
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-03-18 6:31 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-09 22:41 [PATCH RESEND] apparmor: Replace memcpy + NUL termination with kmemdup_nul in do_setattr Thorsten Blum
2026-03-18 6:31 ` John Johansen
-- strict thread matches above, loose matches on Subject: below --
2026-02-22 20:46 Thorsten Blum
2026-02-22 20:53 ` Serge E. Hallyn
2026-03-18 6:26 ` John Johansen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox