]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/vc4: fix krealloc() memory leak
authorAlexander A. Klimov <grandmaster@al2klimov.de>
Sat, 6 Jun 2026 12:38:10 +0000 (14:38 +0200)
committerMaíra Canal <mcanal@igalia.com>
Tue, 9 Jun 2026 18:29:57 +0000 (15:29 -0300)
Don't just overwrite the original pointer passed to krealloc()
with its return value without checking latter:

    MEM = krealloc(MEM, SZ, GFP);

If krealloc() returns NULL, that erases the pointer
to the still allocated memory, hence leaks this memory.
Instead, use a temporary variable, check it's not NULL
and only then assign it to the original pointer:

    TMP = krealloc(MEM, SZ, GFP);
    if (!TMP) return;
    MEM = TMP;

While on it, use krealloc_array().

Fixes: 6d45c81d229d ("drm/vc4: Add support for branching in shader validation.")
Signed-off-by: Alexander A. Klimov <grandmaster@al2klimov.de>
Signed-off-by: Maíra Canal <mcanal@igalia.com>
Link: https://patch.msgid.link/20260606123817.37222-1-grandmaster@al2klimov.de
drivers/gpu/drm/vc4/vc4_validate_shaders.c

index d48cf76983c09ba28586bc731e8f6fbba5eb8ad4..66502a6a4a8e7b54ef42524484f896607892f38e 100644 (file)
@@ -290,15 +290,16 @@ static bool require_uniform_address_uniform(struct vc4_validated_shader_info *va
 {
        uint32_t o = validated_shader->num_uniform_addr_offsets;
        uint32_t num_uniforms = validated_shader->uniforms_size / 4;
+       u32 *offsets;
 
-       validated_shader->uniform_addr_offsets =
-               krealloc(validated_shader->uniform_addr_offsets,
-                        (o + 1) *
-                        sizeof(*validated_shader->uniform_addr_offsets),
-                        GFP_KERNEL);
-       if (!validated_shader->uniform_addr_offsets)
+       offsets = krealloc_array(validated_shader->uniform_addr_offsets,
+                                o + 1,
+                                sizeof(*validated_shader->uniform_addr_offsets),
+                                GFP_KERNEL);
+       if (!offsets)
                return false;
 
+       validated_shader->uniform_addr_offsets = offsets;
        validated_shader->uniform_addr_offsets[o] = num_uniforms;
        validated_shader->num_uniform_addr_offsets++;