From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 342C6376A19; Tue, 16 Jun 2026 17:05:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781629529; cv=none; b=Td2TRwbrIZOUCMkk9sFwPkv0DkD7DtjWtxJv+kmcvyq1ag049p32uIe0E4z9bRS2NKQOYAHlIwh4nObnBluDkfq1OPp3cSrw/17y2bmywu1Z1VMu3JpzoRJn7/5s6YO6qeyEwdTiqcmcp+irEHHviqpXAAkjeUcCft84JZUN1EE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781629529; c=relaxed/simple; bh=uMDRdUrFuDpBZDgX94KNaVsVmbvTlsQCgzlbYH77E34=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VDUDaqB9ApRx2usSPFrsl693FDi12uQnCW3rUjRhsOmmlLvmNya7/YZty3N7sp+N+OF8HFYGIDJpFDgVHPDY/4G1utyhlFeQr8YA6X/1MLC5bnaL6V3BPyR2aJBOCrr/3RUi7ifuiO7NES16BN1zPryzQACOFXFRiAB/jz8Ldf0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=i5/S4Nhy; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="i5/S4Nhy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF4A51F000E9; Tue, 16 Jun 2026 17:05:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781629527; bh=LQSNFgaXg3c0zkD0ja3EKMRdgNHA/qlGPLE0qvEIC+8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=i5/S4NhyH+9a3s/I/mflzekytf9F2bJU6N22eiSozR8fixzwp/HHiUIvr5RLTkLDZ /9cG6HbPveV47TI9Cp8j+vvlT9dGKafRxSN79hGWhxTJYGyi30T45lnIt7nYs7HV21 9nijzp7cyWtL2ok9+SGV0sCo0JNesgaW606/DG6M= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Alexander A. Klimov" , =?UTF-8?q?Ma=C3=ADra=20Canal?= , Sasha Levin Subject: [PATCH 6.6 290/452] drm/vc4: fix krealloc() memory leak Date: Tue, 16 Jun 2026 20:28:37 +0530 Message-ID: <20260616145132.803475565@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616145117.796205997@linuxfoundation.org> References: <20260616145117.796205997@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexander A. Klimov [ Upstream commit 5d563a5da8717629ae72f9eadf1e0e340bd1658b ] 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 Signed-off-by: MaĆ­ra Canal Link: https://patch.msgid.link/20260606123817.37222-1-grandmaster@al2klimov.de Signed-off-by: Sasha Levin --- drivers/gpu/drm/vc4/vc4_validate_shaders.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_validate_shaders.c b/drivers/gpu/drm/vc4/vc4_validate_shaders.c index 9745f8810eca6d..c2c6767ae55862 100644 --- a/drivers/gpu/drm/vc4/vc4_validate_shaders.c +++ b/drivers/gpu/drm/vc4/vc4_validate_shaders.c @@ -288,15 +288,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++; -- 2.53.0