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 169DB42901C; Thu, 16 Jul 2026 14:15:51 +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=1784211353; cv=none; b=KaV3stOnuCP2xF3AlteTr+ha89SByKtsGbVbs2pAxjRj68JJupyyYFlGFMDRRq8C3MGoWVqL6go/Uq6Tw1wcVEhdIZm80aJgwJfhS9nZPQq4o0IQcoYSVAz89bngRSb4G+/OSjhBzu3jEXDHRg/yfaqs7rTILH0vvW2OmV4h2Mw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784211353; c=relaxed/simple; bh=0ox8QGQLU/ZaDKherwHTlDQzBHfcbEYObPi5G5XP44I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mpMlBVfnge+eJunJErEGK2N9aHSXp+x4iii4at8bDh9V66g3uSGjQtKN/9bUM91bd/AoUWVUoxLkx/CBio1h0+NnpfR6QUMl56SWRa9wUPL2r5zw/RjPlIehBpCe3oUAsBZBSYTd35Axqpy8yX9rE+lAelaE0V7mokupMpwcJgA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=l9SCJ+yB; 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="l9SCJ+yB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33B081F000E9; Thu, 16 Jul 2026 14:15:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784211351; bh=uOGIK0lKuNFeYE4mdRZXex7WX5YsSLKcDHG+hNxeDlU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=l9SCJ+yBsDv32VA+s9yk0uPq9Udxe4beTHQbW5bM7jL+23+EiqR6UhWQMSwrPskVt Xs45WfzUfDvff/WFowOztHZAOJ+zuoPhPe4/kRpQuK/KHpoUuUg8Ranf+hgk6hIQyK yITt5YmhNl6fjZ9fbVK4EfLZcHWl/JXEVsokOgVE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dmitry Torokhov , Luis Chamberlain , Andrii Kuchmenko , "Christophe Leroy (CS GROUP)" , Sami Tolvanen Subject: [PATCH 6.18 395/480] module: decompress: check return value of module_extend_max_pages() Date: Thu, 16 Jul 2026 15:32:22 +0200 Message-ID: <20260716133053.345941518@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260716133044.672218725@linuxfoundation.org> References: <20260716133044.672218725@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-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrii Kuchmenko commit 786d2d84416a9a1c1a47b71a68d679d886284be2 upstream. module_extend_max_pages() calls kvrealloc() internally and returns -ENOMEM on allocation failure. The return value is never checked. If the initial allocation fails, info->pages remains NULL and info->max_pages remains 0. Subsequent calls to module_get_next_page() will attempt to dynamically grow the array by calling module_extend_max_pages(info, 0) since info->used_pages is 0. This results in kvrealloc(NULL, 0) returning ZERO_SIZE_PTR, which is treated as a success, leading to a dereference of ZERO_SIZE_PTR and a kernel oops. Fix: add the missing error check after module_extend_max_pages() and return immediately on failure. This matches the pattern used by every other kvrealloc() caller in the module loading path. Fixes: b1ae6dc41eaa ("module: add in-kernel support for decompressing") Cc: Dmitry Torokhov Cc: Luis Chamberlain Cc: stable@vger.kernel.org Signed-off-by: Andrii Kuchmenko Reviewed-by: Christophe Leroy (CS GROUP) [Sami: Corrected the analysis in the commit message.] Signed-off-by: Sami Tolvanen Signed-off-by: Greg Kroah-Hartman --- kernel/module/decompress.c | 2 ++ 1 file changed, 2 insertions(+) --- a/kernel/module/decompress.c +++ b/kernel/module/decompress.c @@ -307,6 +307,8 @@ int module_decompress(struct load_info * */ n_pages = DIV_ROUND_UP(size, PAGE_SIZE) * 2; error = module_extend_max_pages(info, n_pages); + if (error) + return error; data_size = MODULE_DECOMPRESS_FN(info, buf, size); if (data_size < 0) {