From nobody Thu Apr 2 18:47:47 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8E40F3DA5AE for ; Fri, 27 Mar 2026 09:48:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774604920; cv=none; b=TuN+0cf4RjKP7zz+lAL6xP0VPspPE+/ktGSTMShIKfVdcC8fTqebIrSunmC1y7wuWVXjKuvprkpe8VgB7b8NWREUE712A9AhIxmUkByYpRW4oaql0UIFhHrWpCWmyGUpitEwmF90yaER/GnZ78kkj6+LhuQmFiAq0lSL4MMJJtg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774604920; c=relaxed/simple; bh=HUOngOFoyGHQgaZ85Xk/jo93b+mIJRl7GJuKRuvWg48=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jbYJrJtM86b2ILr1wUZcAGKtQGik3aACkBSYNxyjihuK4NWHAmoJlLN0tJXXxJtMk+n4W2hdH4ToZddpC0TOSNlP9RZkVrdkhvetdWlEmEwhPqmYGSLk6eb4MbTAyM3d3+ZhOZzhUE92tBkMwNj4SBHHMeD2YjZ5Fd9mn37cVWk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KuZ/XKC9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KuZ/XKC9" Received: by smtp.kernel.org (Postfix) with ESMTPS id 538A5C2BCB3; Fri, 27 Mar 2026 09:48:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774604920; bh=HUOngOFoyGHQgaZ85Xk/jo93b+mIJRl7GJuKRuvWg48=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=KuZ/XKC9Nae+tDa7pw4bitE/mfl5R+qU585u315/GoxdAS1eBAhe/pyLwISgIbp/x 712A6r1i0XL5BLc4b/zm9HUGSGVn4cc0WOhZmzsa02y/HTkgXVBKuRYaGppcoguzSr VTDYnIJbm0nSC6rcQDqyldT+NgjCapR80C/E2YNdDkBkEOUReadsQ2pf0pw/I3GVFR 3E8FbqRiDJ5KSssR3ZLU+s/+lqgDFJFghEbu3O/FVpwq2xfgOZ4UhtUWDOKto5M0ii 8cG5XhjVXSh0yzdHG1hPZFCZt//nHhlie0P+T53Uqp+UqcOk+/Dp0X3H+24a748I+E rbBAfJGLKppBw== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 474F010ED643; Fri, 27 Mar 2026 09:48:40 +0000 (UTC) From: Shivam Kalra via B4 Relay Date: Fri, 27 Mar 2026 15:18:39 +0530 Subject: [PATCH v8 3/6] mm/vmalloc: zero newly exposed memory on vrealloc() grow Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260327-vmalloc-shrink-v8-3-cc6b57059ed7@zohomail.in> References: <20260327-vmalloc-shrink-v8-0-cc6b57059ed7@zohomail.in> In-Reply-To: <20260327-vmalloc-shrink-v8-0-cc6b57059ed7@zohomail.in> To: Andrew Morton , Uladzislau Rezki Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alice Ryhl , Danilo Krummrich , Shivam Kalra X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1774604917; l=1805; i=shivamkalra98@zohomail.in; s=20260212; h=from:subject:message-id; bh=LSUYWjYOjJYKYliRO3bYLhKxcMuMIBGaVN2tymO6+ew=; b=rhThTDLnB57E/DBczd8HBXwMc5oEaaeJggo8YDeT6Y5MrRyp+O/EQh7sxM1hZvm1pvxDVce7R Zy3ihFALKZ+BT2UKkAd+06tqJ3RxfEKcdMJTVjTZPZTwIrL3lutscSU X-Developer-Key: i=shivamkalra98@zohomail.in; a=ed25519; pk=9Q+S1LD/xjbjL7bEaLIlwRADBwU/6LJq7lYm8LFrkQE= X-Endpoint-Received: by B4 Relay for shivamkalra98@zohomail.in/20260212 with auth_id=633 X-Original-From: Shivam Kalra Reply-To: shivamkalra98@zohomail.in From: Shivam Kalra When growing an existing vmalloc allocation in-place, zero the newly exposed memory region [old_size, size) if the caller requested it via __GFP_ZERO (checked via want_init_on_alloc(flags)). Previously, the code assumed that the unused capacity in the vm_struct was already zeroed either at initial allocation time or during a prior shrink. However, if an intermediate shrink operation occurred without __GFP_ZERO and without init_on_free enabled, the "freed" portion of the allocation would retain its old data. If a subsequent grow-in-place operation then explicitly requests __GFP_ZERO, failing to zero the memory here would violate the allocation flags and leak the previously discarded, potentially sensitive data. Signed-off-by: Shivam Kalra --- mm/vmalloc.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 133c3b0418fe..ddb689bf9ba5 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4368,13 +4368,16 @@ void *vrealloc_node_align_noprof(const void *p, siz= e_t size, unsigned long align * We already have the bytes available in the allocation; use them. */ if (size <=3D (size_t)vm->nr_pages << PAGE_SHIFT) { - /* - * No need to zero memory here, as unused memory will have - * already been zeroed at initial allocation time or during - * realloc shrink time. - */ vm->requested_size =3D size; kasan_vrealloc(p, old_size, size); + + /* + * Zero the newly exposed bytes if requested. + * The region [old_size, size) may contain stale data from + * a previous shrink that did not use __GFP_ZERO. + */ + if (want_init_on_alloc(flags)) + memset((void *)p + old_size, 0, size - old_size); return (void *)p; } =20 --=20 2.43.0