From nobody Fri Apr 3 16:14:08 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 3813F3E0241 for ; Tue, 24 Mar 2026 10:00:33 +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=1774346433; cv=none; b=ccng7Eexet2ap3wTfX31hmoNzqz4LZY2+0MFdEWfpaJBMHGiuZ8Bq3SgfOKNPo8T2OUT+8cvorpdxGgZtgsyDCmdTTriV8RTpK9wtLasz4dOefyRaqQP8+3km+j9kXcK3V+INX6XtwqxX4eos7oDd7/nNOuvqU/DFvW/4ipXFjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774346433; c=relaxed/simple; bh=HUOngOFoyGHQgaZ85Xk/jo93b+mIJRl7GJuKRuvWg48=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QLOwrJE/WOh0GR+UPypqyXp2CMSGhz0nW04a48ZEwburG7CB6sT1QE1XCImYalCuLPjWvEEsGIOAHp3uFyI5Zlls7xkPuQyLPcp8iyXBmYhrTjAwI8SJw4s4mRW6f/0hnDuTZYoDXEQg0VNOPgdYSt/lS1FWT+KaBU7Ku0TBjG4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CmtA77oh; 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="CmtA77oh" Received: by smtp.kernel.org (Postfix) with ESMTPS id C45D7C2BCB5; Tue, 24 Mar 2026 10:00:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774346432; bh=HUOngOFoyGHQgaZ85Xk/jo93b+mIJRl7GJuKRuvWg48=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=CmtA77ohefRx7XW6oLVK6YckpgUjIQ9mBCd9cRe05GAn/fLi8dYPU7tFrxUl9Zg4Z xsYfVQYUr1L1gS/7t7usl8Oa/QxEGRVWuLFNcHZ0vaLiMvf+f3f933eXifK2gcu/F4 PnFsmApMZXOkojdPjAMpzf6kkUG5x7w5zNJBOIW04Mybay7iVRsb8kjB8bjPF8rv0D 33DceFVCzfRjWGXkwJ4ZkDTsL9iLqbBd7w0Cv+XNDX4zEJoynxu3sXDG9W/mWWRgbQ 45sn6LSOC5VdsnXvF/1i3oFEJVykqMxQoyDWMuWsRoelnPBebINulo1GbxzIDdf2lf d6P+JGLMtbYUw== 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 BAF8EE9A75C; Tue, 24 Mar 2026 10:00:32 +0000 (UTC) From: Shivam Kalra via B4 Relay Date: Tue, 24 Mar 2026 15:30:28 +0530 Subject: [PATCH v7 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: <20260324-vmalloc-shrink-v7-3-c0e62b8e5d83@zohomail.in> References: <20260324-vmalloc-shrink-v7-0-c0e62b8e5d83@zohomail.in> In-Reply-To: <20260324-vmalloc-shrink-v7-0-c0e62b8e5d83@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=1774346430; l=1805; i=shivamkalra98@zohomail.in; s=20260212; h=from:subject:message-id; bh=LSUYWjYOjJYKYliRO3bYLhKxcMuMIBGaVN2tymO6+ew=; b=rnj4cYZkzkJ86bsOX6qnSlWl5dROAsN7ly5d6iDcEQPVC7kXfPVNp2+aT/Y+JklM8mQ3ukx5Y aizhMbSd8BvDTD8JdpVEUyF3RLaOHctT575Mvr0Wj0aLjsC/fSjn72S 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