From patchwork Wed Dec 4 07:52:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hao Ge X-Patchwork-Id: 13893341 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 EB9C0E7716D for ; Wed, 4 Dec 2024 07:53:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C0D06B007B; Wed, 4 Dec 2024 02:53:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 571336B0082; Wed, 4 Dec 2024 02:53:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 45FC16B0083; Wed, 4 Dec 2024 02:53:39 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 27B236B007B for ; Wed, 4 Dec 2024 02:53:39 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C06B81A0E51 for ; Wed, 4 Dec 2024 07:53:38 +0000 (UTC) X-FDA: 82856511486.27.579ACF1 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) by imf28.hostedemail.com (Postfix) with ESMTP id C0FBEC0007 for ; Wed, 4 Dec 2024 07:53:19 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=kkR+U3JD; spf=pass (imf28.hostedemail.com: domain of hao.ge@linux.dev designates 95.215.58.174 as permitted sender) smtp.mailfrom=hao.ge@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733298807; 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=kI9iBLCys+xSu5BTxCbQwH4kUk1hhRaGf+nDlT0SiTE=; b=XsZ+wSsHzK4hhMGW/EItLvrMA67yEP70/sJ8zxgWMQmtuKa/+7gd6WmEk4QT97C+GQl0HW ClYiY6txn7E4z3BIGvrtoe6VREQx8YjF0yXI7hgAjBKvTvmtg+ZKc6ApA/O2ncnAZh9v1i deF1EzRzf1JY3qE8lr18EhJqt/93LDo= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=kkR+U3JD; spf=pass (imf28.hostedemail.com: domain of hao.ge@linux.dev designates 95.215.58.174 as permitted sender) smtp.mailfrom=hao.ge@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733298807; a=rsa-sha256; cv=none; b=YOC4q3m0sVFt7xnL26RDx/dB2DBr8ix7IRDaCe2IuTFdt/kz4x/jym+smb1C8nTGwpjuYg wTJr6cLzz4g5WIuS04HqUVOeGORMUxPpoOfWu0jfQI4TgKGxx+sitFMgRtEWQaPXg8oLe4 SiUVxyM1bY01OGh/Q+oKP24k7qAJCUc= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1733298815; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=kI9iBLCys+xSu5BTxCbQwH4kUk1hhRaGf+nDlT0SiTE=; b=kkR+U3JDTgvqgd4UTSUljJmsPRHoGJxPrl70tGxP37hiWNfyp0NInJFVrNFIITU8paV6ji qNilzrNdfOHAuOvUVRZt3d4xZoho1r6w6GPBA0Br5UmLYlSjBysjOBFKsYAdg7W6rk53nz HdeoDrxY49B5dsEpJdidxKKDHkdzekg= From: Hao Ge To: surenb@google.com, kent.overstreet@linux.dev, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, hao.ge@linux.dev, Hao Ge Subject: [PATCH] mm/alloc_tag: fix vm_module_tags_populate's KASAN poisoning logic Date: Wed, 4 Dec 2024 15:52:48 +0800 Message-Id: <20241204075248.384215-1-hao.ge@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam05 X-Stat-Signature: fokgirbkqbc1nuzm43zo3tsqmezwn1jx X-Rspamd-Queue-Id: C0FBEC0007 X-Rspam-User: X-HE-Tag: 1733298799-337031 X-HE-Meta: U2FsdGVkX19p0ubXkUoo5cfuLTjq7/f8rsxjzkNHUbfaye1CiMO5hLop2RMkT8p8it92mppM6otVTBfR6tikgcYE1rO0Kt7/W8gR4gpJ1Do2jLc2i4B3o8MwhDoWVxI5I9y/wW5rsvffMkUHJ8Wj2AmH3mTmH/FEKVIV4i2xCJ3k8F65SOlqvJOg8FDnlSx2vSxmvz1Tx7ZrhXXFrgT/bw4hUCUNVXOMKwX1tjtgJU/rQbKj3yqQwMw/y3H+NdXlEpnXK3UvfJiMr2pi6Ugav7kpgC/KtMX28AIuKqljh6sfowOwMsd1MqiB9MgpcEF+hHbzlcDGU9scNGhio6o7cDYYq5y44CiX3tROZcuy0MBFh79By3cLhNiid+mX4qb+Z9U40+u24eC3FIdaGvVEzIMOE5op1YEIPzgP5lGWKJlEWIn61k7KKDaSlCDYrZEK362e9S+ZuqdN6+2f2CWK3bb6Mou6+vQ7J9DjoTS654UvbQOz4hWgALDlhbOikX2ImfDC3ecIJaZGoDSsCZq1abMTD5JUikN8bH6Km0HtbagFSQ4w0VRi+a5PA+NxJhljxkz9cWuGQt0iQwJaBGoDmcAbQNp1V9usPxTBrNXIytsGMNZ57CfdPHVrYYU2gJKvyOn5tYZyUBd9ZOaNGYeJUNrFKwRP488o2sD9umvul/TPPBopIT4fLXJH/5ZOBb1fQq0WYEv+E3x3rdFpr9hemoU3yA6FsmRGSBJRJBfNKsK89aQ+6O947h6YvUxSG6r2trzsXC1HErdkaDknm+gKhWZ8YXIH1r776Qun1+x1IP0A6eHIvyEgxcWXso/RoB7Lt2onFarFDtfq1lO+uEIvOSRzYTYsEImtHI23wZ1erRDlkxPD0us2C1gzXWRzqF9Tf3kGnUHERZ+WzxvZ/FXJTy7BwMKTV1UZ967WVXGEzVaKTr4GZFXmbY/e5Pk05zdyxCd4IPFsaKl4qE16CC/ vrvMiPLT Bo57xEmCYZhKaKgvAacxQ2FTzA3YfdrPnEltVRSsxbFx+Yu31rSzEPaGoVTUAb78YIewtnMfXS97YfrH2eB/8cqGKwRTK/Hvgv39sUTEHXPVxpyac5VDdmyeJCHdyg6RgGOV99orOD/MuLINgrPf/L7OID1wKmvdcyy0O2VL576munckU8AN1rX8zuA== 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: From: Hao Ge After merge commit 233e89322cbe ("alloc_tag: fix module allocation tags populated area calculation"), We still encountered a KASAN bug. This is because we have only actually performed page allocation and address mapping here. we need to unpoisoned portions of underlying memory. Because we have a change in the size here,we need to re-annotate poisoned and unpoisoned portions of underlying memory according to the new size. Here is the log for KASAN: [ 5.041171][ T1] ================================================================== [ 5.042047][ T1] BUG: KASAN: vmalloc-out-of-bounds in move_module+0x2c0/0x708 [ 5.042723][ T1] Write of size 240 at addr ffff80007e510000 by task systemd/1 [ 5.043412][ T1] [ 5.043523][ T72] input: QEMU QEMU USB Tablet as /devices/pci0000:00/0000:00:01.1/0000:02:001 [ 5.043614][ T1] CPU: 0 UID: 0 PID: 1 Comm: systemd Not tainted 6.13.0-rc1+ #28 [ 5.045560][ T1] Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015 [ 5.046328][ T1] Call trace: [ 5.046670][ T1] show_stack+0x20/0x38 (C) [ 5.047127][ T1] dump_stack_lvl+0x80/0xf8 [ 5.047533][ T1] print_address_description.constprop.0+0x58/0x358 [ 5.048092][ T72] hid-generic 0003:0627:0001.0001: input,hidraw0: USB HID v0.01 Mouse [QEMU 0 [ 5.048126][ T1] print_report+0xb0/0x280 [ 5.049682][ T1] kasan_report+0xb8/0x108 [ 5.050170][ T1] kasan_check_range+0xe8/0x190 [ 5.050685][ T1] memcpy+0x58/0xa0 [ 5.051135][ T1] move_module+0x2c0/0x708 [ 5.051586][ T1] layout_and_allocate.constprop.0+0x308/0x5b8 [ 5.052219][ T1] load_module+0x134/0x16c8 [ 5.052671][ T1] init_module_from_file+0xdc/0x138 [ 5.053193][ T1] idempotent_init_module+0x344/0x600 [ 5.053742][ T1] __arm64_sys_finit_module+0xbc/0x150 [ 5.054289][ T1] invoke_syscall+0xd4/0x258 [ 5.054749][ T1] el0_svc_common.constprop.0+0xb4/0x240 [ 5.055319][ T1] do_el0_svc+0x48/0x68 [ 5.055743][ T1] el0_svc+0x40/0xe0 [ 5.056142][ T1] el0t_64_sync_handler+0x10c/0x138 [ 5.056658][ T1] el0t_64_sync+0x1ac/0x1b0 Fixes: 233e89322cbe ("alloc_tag: fix module allocation tags populated area calculation") Signed-off-by: Hao Ge --- commit 233e89322cbe ("alloc_tag: fix module allocation tags populated area calculation") is currently in the mm-hotfixes-unstable branch, so this patch is developed based on the mm-hotfixes-unstable branch. --- lib/alloc_tag.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/alloc_tag.c b/lib/alloc_tag.c index 4ee6caa6d2da..ad31acb1279a 100644 --- a/lib/alloc_tag.c +++ b/lib/alloc_tag.c @@ -421,7 +421,15 @@ static int vm_module_tags_populate(void) __free_page(next_page[i]); return -ENOMEM; } + + kasan_poison_vmalloc((void *)module_tags.start_addr, + vm_module_tags->nr_pages << PAGE_SHIFT); + vm_module_tags->nr_pages += nr; + + kasan_unpoison_vmalloc((void *)module_tags.start_addr, + vm_module_tags->nr_pages << PAGE_SHIFT, + KASAN_VMALLOC_PROT_NORMAL); } return 0;