From patchwork Tue Nov 26 00:52:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrii Nakryiko X-Patchwork-Id: 13885376 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6FCED59D80 for ; Tue, 26 Nov 2024 00:52:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 47A766B0082; Mon, 25 Nov 2024 19:52:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42A4C6B0085; Mon, 25 Nov 2024 19:52:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3198A6B0088; Mon, 25 Nov 2024 19:52:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 149836B0082 for ; Mon, 25 Nov 2024 19:52:22 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8743FA0676 for ; Tue, 26 Nov 2024 00:52:21 +0000 (UTC) X-FDA: 82826419956.22.8296E47 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf10.hostedemail.com (Postfix) with ESMTP id 4BCBAC0004 for ; Tue, 26 Nov 2024 00:52:18 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=umgQduCH; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf10.hostedemail.com: domain of andrii@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=andrii@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732582337; a=rsa-sha256; cv=none; b=ZVrbx6TuAv5RIlNIPISLJdlEXvUPERCeq9ImxvzMwPOW3/P0nWEqZIuH+TINjqhuaM/ACD D84UfxD9fVobR3fEP3WqasvV1e/TefQxh3PYXKgTXteCz2sdImVsmAcAVWV2Ev919XerQm BkN42/wTo0MWypwQdudoud/YvmXz6xg= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=umgQduCH; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf10.hostedemail.com: domain of andrii@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=andrii@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732582337; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=mmb5o5S0XZrtE0inlJhfYMR+o4jzKUG1gvFGfESAZ34=; b=tcyR+4lPH6QFXT5XbhhELnAxv78lCv5XxgUBQnKtMZm68k9PW7xGSrckcvQ2fOIFwgnZeZ tvSMeaBGt/8vimQiI8wpoDLCHBBbKSU1hf1d8iNHSVlVIW0aUwlcfC74pxQaEDSKEe/KRm b/FiHHrPC5xRPHk2cBG6b+K3V/y4I3E= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 636F45C2770; Tue, 26 Nov 2024 00:51:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68BCAC4CECE; Tue, 26 Nov 2024 00:52:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732582338; bh=B1+ggchJb8GusZDAY26niU/dmeqT4DRum6Nh2NFx7AM=; h=From:To:Cc:Subject:Date:From; b=umgQduCHCBujzvVdlYa68l6rdolQMJYXalMOc7Xv+z/Sr924eEOb3KoG3E9Xl93hF uLm1/E2fyvuVI87zwJ7KAbOddh9mPFXyF3NjpLfGQ2GhbjinV9EhFX1QwqFel0dMTO +o2gaOroUjMS1vGqt9dI9YoZC4M14s4iGrwyrajKCpLXCXQvG+BIlhYkTVrlJB8mA8 w4C1T0pSYFSU0mRtXcqT3btE1q/HZx54umah3cc9BfYT7zHNk60n3nZ9rEIjiTXcie idSvDMIq3EYXpkE7uEsPRrKoFCgUQBbc9mxN+8oLPnMxFrEHcjQuaggxcxD6Lq+fcx 508+bPYJr3J/g== From: Andrii Nakryiko To: linux-mm@kvack.org, akpm@linux-foundation.org, urezki@gmail.com, hch@infradead.org Cc: vbabka@suse.cz, dakr@kernel.org, mhocko@suse.com, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, ast@kernel.org, Andrii Nakryiko Subject: [PATCH mm/stable] mm: fix vrealloc()'s KASAN poisoning logic Date: Mon, 25 Nov 2024 16:52:06 -0800 Message-ID: <20241126005206.3457974-1-andrii@kernel.org> X-Mailer: git-send-email 2.43.5 MIME-Version: 1.0 X-Rspamd-Queue-Id: 4BCBAC0004 X-Stat-Signature: 38aimztte6oq3hgq66g48wjwqh4hc1ha X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1732582338-863373 X-HE-Meta: U2FsdGVkX18I+8aTa2g6Tbb6TPRh7vlGbOrc+BL8toaElhsISeMVkz5x/LTD+f9WZh4Wt/ghpbT8zQ5BrT6S1Od3clxp1JloWQX7jkAw8YjJ7vL5GoqLT8Dd2TJdADZCZvtvwFfdq60QaJZqy3JmMxhYXAKCKpGXPC4P1IFrj4TUsIhPGuwksnrOOKcoeVffV8yMKUMkWaXMwNN1L/vwx099QeR2NX8SVCJRqYTQvzmKDJFWabcANZ8GBNm4UqI3FAAE5H5yaFn8Q6XCeDDW4sJOzJvUIlx6s6/CizbBCYuhEy5wjpTgj/pV3Dj0RH1lsj7AcMivln6wsGnBVnnn9xUD4jZj56hNSrkmdIP6GiWmx/U6+v9isacFOgfElpDKHl6Ibb5+m0ipRtDuoS8zMSV8FhGAGNaD9Ux8YEfwjDpj/kPQo6OtIvtEjSApBLON9nxRYT52ncIKET5vO2/J617kp7zpZSZYn4ltaFXqpFKbt5dS4Z0217G1ixQlJVCUqjh6FoWQaSfSGMUkmLcGQ+AGEhwJde1mEBmWHKr5QaaziwVhYQl3pIMUOo1pTRyBMutVhdug3JCJDr/XQ9A/mp22saSlDxP6tG13B4MSnkoY71CViNwVSDWmYcrw0ShQoTtnH5xZ8g8409X8URUSQQXBU+S1hJQ7+fGYWHoa/Ha6wLPzP2xQWCTxDp1M8CHVQBWenzZOyunp27UFDu5qvas5k+S5UnVHxUz/SG8YJAL2/GHOUsmBfSidqB4NfQfF0jAPRpRBtc3Y2cEbqcphg9n4rXLDB7JmOd2s+M9FlwmGkXL0STtjNKN7rbptrkkJGGfAqVHbdqB0qQtyO+pWQXvLStilhKAjo+xbLqQgm1JRpMr++ijLmI4gnMU5gpN/PJvXGP0j6mfn7sxec1dfsHt0LzNetWfAgWyH03e6egr+bMZ1vibQJgQsWLTI1UaZaEYnD5Y26vj3yWNkoOH 1SZLzodT aha04ac6JPrT7rqeo1Pdkj97gSkmdvzhCUYbbOMX10GpSi/TNf09yf29OZAAwSCrP6l0B8XwDFiPSujw7FrB7viCEeVUnya8kXUn0eEkdGR0Ut8IiiyfXFXog0PZgW7U1QkgnxlbMhJoCWlmTSvkut0hiVWg9pUZNFZcXdDwCpVSGRrE89woxHZ8K+PXAazzd+hSfhFToEl9idofzLT9f6m8Oie4OluLwpZ6C3WVyJoa43bA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When vrealloc() reuses already allocated vmap_area, we need to re-annotate poisoned and unpoisoned portions of underlying memory according to the new size. Note, hard-coding KASAN_VMALLOC_PROT_NORMAL might not be exactly correct, but KASAN flag logic is pretty involved and spread out throughout __vmalloc_node_range_noprof(), so I'm using the bare minimum flag here and leaving the rest to mm people to refactor this logic and reuse it here. Fixes: 3ddc2fefe6f3 ("mm: vmalloc: implement vrealloc()") Signed-off-by: Andrii Nakryiko --- mm/vmalloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 7ed39d104201..f009b21705c1 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4093,7 +4093,8 @@ void *vrealloc_noprof(const void *p, size_t size, gfp_t flags) /* Zero out spare memory. */ if (want_init_on_alloc(flags)) memset((void *)p + size, 0, old_size - size); - + kasan_poison_vmalloc(p + size, old_size - size); + kasan_unpoison_vmalloc(p, size, KASAN_VMALLOC_PROT_NORMAL); return (void *)p; }