Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp870637rwi; Wed, 19 Oct 2022 04:07:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6XK6AIOja7bUhd5+Gqno3JTwrGnbzUyo+1Y2RnZDU/Ee6zLOUPP/G5dhbDCfGCE9NBzCNb X-Received: by 2002:a17:907:72cb:b0:793:30b3:7f89 with SMTP id du11-20020a17090772cb00b0079330b37f89mr1202619ejc.259.1666177679210; Wed, 19 Oct 2022 04:07:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666177679; cv=none; d=google.com; s=arc-20160816; b=KoGGl37SLFMa6crigJekeNBKZjYP3YFKT9ediiFKVGhJI4ZRCoRcz/brgl5CMVUPOr 60EVWe4goRkYbzm3obrUYLP9OCZnQLG3dsJKkH5NpT2Zu1Z4DwD0hMipF+wWYiQVrNhF rJZYzO1rFteuXOvcmJjM5b5d1G/ewCCJQTVwtDQu+tWgBfXqnzaRqYbug6QRouqB1419 33ikjwSJqPjpBQ8jLgtDWu2CQLfJ3UJqjlKOwj/v3IPZr4D2sgiwUz5pGPnUXIqzqaqj UqLfxifw3NRBpKUwHvCUjlZJgW0UEnWK2Ik/xG9zZOUkLE4Toqp74ocpmMzSutsoGOf+ jcaw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gn41-20020a1709070d2900b00781c9c3b6f5si13890745ejc.474.2022.10.19.04.07.22; Wed, 19 Oct 2022 04:07:59 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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 -- 2.35.1