From patchwork Wed Oct 19 08:34:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4914 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp225744wrs; Wed, 19 Oct 2022 02:43:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4SW+rdCpzlU9FdqV0PaMIzcK5/XIDa8LgHMO22c1YmKd0ogq8ZM8/DnnoTtuamRemKv84x X-Received: by 2002:a17:906:8a61:b0:78d:9d00:c906 with SMTP id hy1-20020a1709068a6100b0078d9d00c906mr5978566ejc.321.1666172635141; Wed, 19 Oct 2022 02:43:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666172635; cv=none; d=google.com; s=arc-20160816; b=RJR7rsj0IhYrwaDIziigrKzGNfqW581SWUtrgHmU8d4M29QZfkWgybn4+KeDOYGmdE d2pyrj5jeEAGN7rLhONCsVEmT3wrJsHUgRgx8JHyla5Q2r0z2teePC/O8fCmZX0S9wl+ jXZOLDrXU/pHTl04WoyjhvDKLxs2slhfmEvcN39vn5z5q63mSwdfm06X8/PmU2mja6T/ HCEvLcsccIteDJQj64jbRXCXmY7thjtxNQ5bAlYxrCJZ/vWki82lW5PvMPNR70L5aMk3 7iq53ioOvaT+wuqG5JX8M6xAEL8Zzkrp7tNagTUN+suApqaRHooiah7E/cmexNTiH6pG 9Kkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=B4G7M8JKZn6dY9zXOIh+E6Zcjzi8GQVa+pilD8KJgvQ=; b=aZYlgswI3c7zzv1HdMO5uEXS9sQ8AxTB/tLJS0ETaedQKbR0/wB7QChyhmtE7GrWwd ngKDqcPNtBKIwYuB/ciNiAazqHh0vFZehlEtXffoj9gwICOLnomAkTW5k8S84f6a805z AfeiRF3XP5wnEHUmoQFmwjJLqvxU5xhrGmIfT4dy9KDvffRn149IKSKmKyotv75MKWK8 WXv94Fix26iwsVjDcsCmajKhewWgrCWcMrMhfMxR0KJySaECxYYvzcmx5/wwHeRNc+sV olebw0XaLmqOwFmnkkEuFAfJzRamk9QeVPwcCmJ6e/c+HJQgW1bE/PlFShvrcTo17X6K QA2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=N72xUiT8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l17-20020aa7c311000000b00458b6dd954dsi12423086edq.200.2022.10.19.02.43.22; Wed, 19 Oct 2022 02:43:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=N72xUiT8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233912AbiJSJgV (ORCPT + 99 others); Wed, 19 Oct 2022 05:36:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233921AbiJSJ3w (ORCPT ); Wed, 19 Oct 2022 05:29:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22A82C354F; Wed, 19 Oct 2022 02:13:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 581D3617EA; Wed, 19 Oct 2022 09:13:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A3B5C433D7; Wed, 19 Oct 2022 09:13:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666170798; bh=zx+NsFJM2HlrPk63IXXZIbC844ngJf0rvo8h74tKeLo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N72xUiT8OZk4c8NSRuN+/Pxn92eQcDactv98sAG4yuqFffxi14+UWq59cZa0u2Bij y1kL+AEMaYT+t+mdF/eJsPh996idi72wxuPWnKDFn+TnddBdSXZqsgc5MJoCidJRuO PqFKIgPrZUXIqEIg6NooO+gwB1YJulwgjfDIpfsA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Walleij , Alexander Sverdlin , "Russell King (Oracle)" , Sasha Levin Subject: [PATCH 6.0 791/862] ARM: 9242/1: kasan: Only map modules if CONFIG_KASAN_VMALLOC=n Date: Wed, 19 Oct 2022 10:34:38 +0200 Message-Id: <20221019083324.863655777@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747108636906494958?= X-GMAIL-MSGID: =?utf-8?q?1747108636906494958?= From: Alex Sverdlin [ Upstream commit 823f606ab6b4759a1faf0388abcf4fb0776710d2 ] In case CONFIG_KASAN_VMALLOC=y kasan_populate_vmalloc() allocates the shadow pages dynamically. But even worse is that kasan_release_vmalloc() releases them, which is not compatible with create_mapping() of MODULES_VADDR..MODULES_END range: BUG: Bad page state in process kworker/9:1 pfn:2068b page:e5e06160 refcount:0 mapcount:0 mapping:00000000 index:0x0 flags: 0x1000(reserved) raw: 00001000 e5e06164 e5e06164 00000000 00000000 00000000 ffffffff 00000000 page dumped because: PAGE_FLAGS_CHECK_AT_FREE flag(s) set bad because of flags: 0x1000(reserved) Modules linked in: ip_tables CPU: 9 PID: 154 Comm: kworker/9:1 Not tainted 5.4.188-... #1 Hardware name: LSI Axxia AXM55XX Workqueue: events do_free_init unwind_backtrace show_stack dump_stack bad_page free_pcp_prepare free_unref_page kasan_depopulate_vmalloc_pte __apply_to_page_range apply_to_existing_page_range kasan_release_vmalloc __purge_vmap_area_lazy _vm_unmap_aliases.part.0 __vunmap do_free_init process_one_work worker_thread kthread Reviewed-by: Linus Walleij Signed-off-by: Alexander Sverdlin Signed-off-by: Russell King (Oracle) Signed-off-by: Sasha Levin --- arch/arm/mm/kasan_init.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/arm/mm/kasan_init.c b/arch/arm/mm/kasan_init.c index 29caee9c79ce..46d9f4a622cb 100644 --- a/arch/arm/mm/kasan_init.c +++ b/arch/arm/mm/kasan_init.c @@ -268,12 +268,17 @@ void __init kasan_init(void) /* * 1. The module global variables are in MODULES_VADDR ~ MODULES_END, - * so we need to map this area. + * so we need to map this area if CONFIG_KASAN_VMALLOC=n. With + * VMALLOC support KASAN will manage this region dynamically, + * refer to kasan_populate_vmalloc() and ARM's implementation of + * module_alloc(). * 2. PKMAP_BASE ~ PKMAP_BASE+PMD_SIZE's shadow and MODULES_VADDR * ~ MODULES_END's shadow is in the same PMD_SIZE, so we can't * use kasan_populate_zero_shadow. */ - create_mapping((void *)MODULES_VADDR, (void *)(PKMAP_BASE + PMD_SIZE)); + if (!IS_ENABLED(CONFIG_KASAN_VMALLOC) && IS_ENABLED(CONFIG_MODULES)) + create_mapping((void *)MODULES_VADDR, (void *)(MODULES_END)); + create_mapping((void *)PKMAP_BASE, (void *)(PKMAP_BASE + PMD_SIZE)); /* * KAsan may reuse the contents of kasan_early_shadow_pte directly, so