]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
keys: use kmalloc_flex in user_preparse
authorThorsten Blum <thorsten.blum@linux.dev>
Mon, 4 May 2026 09:31:00 +0000 (11:31 +0200)
committerJarkko Sakkinen <jarkko@kernel.org>
Mon, 15 Jun 2026 12:19:12 +0000 (15:19 +0300)
Use kmalloc_flex() when allocating a new struct user_key_payload in
user_preparse() to replace the open-coded size arithmetic and to keep
the size type-safe.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://lore.kernel.org/r/20260504093058.49720-3-thorsten.blum@linux.dev
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
security/keys/user_defined.c

index 686d56e4cc85096dcdb4947de6e602d5e906cc7b..6f88b507f92791bd9569673c5d6534d76c58a978 100644 (file)
@@ -64,7 +64,7 @@ int user_preparse(struct key_preparsed_payload *prep)
        if (datalen == 0 || datalen > 32767 || !prep->data)
                return -EINVAL;
 
-       upayload = kmalloc(sizeof(*upayload) + datalen, GFP_KERNEL);
+       upayload = kmalloc_flex(*upayload, data, datalen);
        if (!upayload)
                return -ENOMEM;