From patchwork Wed Feb 2 08:44:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12732713 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5DDDC433F5 for ; Wed, 2 Feb 2022 08:45:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245072AbiBBIpA convert rfc822-to-8bit (ORCPT ); Wed, 2 Feb 2022 03:45:00 -0500 Received: from mail-eopbgr90075.outbound.protection.outlook.com ([40.107.9.75]:30800 "EHLO FRA01-MR2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S245069AbiBBIo7 (ORCPT ); Wed, 2 Feb 2022 03:44:59 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZtWBDizEa3lVP3uv9WAv8CS5f31WEYVjTGyxcv5za7wmyLb06sE/Tv9Y7jZ8W6uqet6JWYPSRxRfaWd9EP6YspLGp00W5bj3STAvntgt6DTWXcoFAIVu3ofAolZpUDAxLBjloIWOFtA1K+L4gMB1j/m/B5a+t370FmN3m5U+ljLN4nj+sd4TrBeFdgYtZu5SkJFC47uACb69Z8ZOlClNMaQuaGt7P49sEss0d3rjuhZqu2e7W2y1BbQ0Lmp71UDM76ZL3Z9WTqcHTZ0ndz4Xetsnpe8vdPdDuMZ9tOz2aVbL4Mckz1ffsBy9aYiUWAQIsbMr6KgbLN/5dESt+ps1cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6Ind7o++C36YYMkSVPYnPhsPIiTzLjg06hyjBauGJi4=; b=C3xyyVHfWq/80P3EjUofILeccSpcRbwVjg/kingmrQta/v7qn+bVPqYxEMn5Mhz+NbfLK8apwbdp0RF6Uv0HmWSFElQBrbInFuvSPYsbbYQAWeG2ZNX94JaLI/OnItLPmPoxOv8jC0OQgcTb/EPWriOHeju/HwjB5JVDuhYEOpMnMomum/jpcdKYzHkjdxDlSbM9K1vkrKfBcZx/NKnx23lwFgVVw089iQBL2MqqIcOB/6TEJlIaEEnR/m9mBdj1bMA7xVwlt/+ESS2bzfgoDdIrt+CxCM/k/gX0ofLeSaXRKIRByDowyjjXZwmkzMgfwNoKqRWqZ4JKl5iNAVOazw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:31::15) by PAZP264MB2894.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:1f6::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11; Wed, 2 Feb 2022 08:44:56 +0000 Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::c9a2:1db0:5469:54e1]) by MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::c9a2:1db0:5469:54e1%9]) with mapi id 15.20.4951.012; Wed, 2 Feb 2022 08:44:56 +0000 From: Christophe Leroy To: Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Andrew Morton CC: Christophe Leroy , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "linux-hardening@vger.kernel.org" , "kasan-dev@googlegroups.com" Subject: [PATCH 1/4] mm/kasan: Add CONFIG_KASAN_SOFTWARE Thread-Topic: [PATCH 1/4] mm/kasan: Add CONFIG_KASAN_SOFTWARE Thread-Index: AQHYGBEnAwJzYYWGn0e5XkqoRz5SsA== Date: Wed, 2 Feb 2022 08:44:56 +0000 Message-ID: Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=csgroup.eu; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1105e9be-ae1c-483d-a81b-08d9e6284a0a x-ms-traffictypediagnostic: PAZP264MB2894:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6108; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: HfRPigFKtSv9p0/jCRTAQywNrKV8x6hixhRgNqmiFNZAZMjXAe9NVc/KCEm0tRn6QA5fl7xq/0sjiDLcPyz+MzJ/+KoCfgFo/yDPmlvWhR5aO+EOHsReEqKiD0CwOlUQfNCPkNoUSxD/fV0p8io3hHEwG4M9yC1Fr7XY4gYXym84nQJEhWf1mhgSRXvkl8mXUr1I1OynT/OuvkEKGtOadPVcD/Vv1Vr/rptBh4Vmj4wMB8acWfCZ85SzcRAyew0KlacQoPdWX9dX44ANiSOnDk2NMksYuF0jDIAVngY+0hY1PFHeK7706Wfq12ZdbLw0h6Vg3qoM1tsoRCvkHs3qmXMAcW81zQ9iW8Go/BcI/+O977m285Oox6EXVk6V9EXaDNw7iciGcdaRWQNiK2P2MgTSverOflsuK9yKRlqKc2ptVml2OQajTmMZJ2SZuzBVaWKiPrwIhiOOyILkZ/TwWX3sgU8nHmJHlCoAYXrxMraHAkgPUJTjp71VVV1LNi8Mws6zFIB0avoUeJo2kuT/KgvfRbWhx7nwoXKBXzBZGYLnpSMx2RBr7OgJbJXKbFKl7YhPIsYfc7VwbdnkYzWHbudDdP/R8kpEOj/MSwa0SQX5eu/I+D8dnaDDvyLoCgBxcoZRDwRwTrgvijLsQHzePpMmxfFQNIPgDY3S4S7ygNTyZtl4mCafMg1PaLpS1+qtZImWzSdHnIM0AMkzkoAx8A== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(66446008)(2906002)(122000001)(6512007)(44832011)(36756003)(83380400001)(5660300002)(30864003)(2616005)(8936002)(38100700002)(66946007)(66556008)(66476007)(4326008)(8676002)(316002)(64756008)(86362001)(186003)(91956017)(76116006)(54906003)(26005)(38070700005)(71200400001)(6506007)(110136005)(6486002)(508600001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?IrHmp00xJV4L+F3wMdEHMCZ?= =?iso-8859-1?q?pLNWhQp3kIIk5f65IIi5za9Xc9C0n/yFYgXxJtlgi0i3IazZ9yb9lgib9dQY?= =?iso-8859-1?q?PiSBHFazu6RlKn7e/SoCeSh0fcegI6uPsxXQDw6Eu5/TWH2Tm+MS2eRu72Mi?= =?iso-8859-1?q?oxEoX6AkfD22hRO+i9zhARFLLwWAZnkFXRZ2SPbM8RPoBo0vKA046t1zMOJq?= =?iso-8859-1?q?I80kmsVkZNLYQ0WdiYoQa6E5PaorR41xyvle7ctD63uTsKADocnDhl5je7rL?= =?iso-8859-1?q?HZ48ntumeKvMp0X/KqDz9tzz+NfTgByRvPVtqdQeaSpxuRqhzbSC07rSuEo6?= =?iso-8859-1?q?sUk6aPxcNyX9SJoHDplAwLEcZE3I6C/DP+MZ+jI/JsnAW6eUuBnHoXRJEGcJ?= =?iso-8859-1?q?kciy3B3+E49GjfyUQpF8qHz/7OlTy/C+lh2pgfEOrOVLWJqWbtb0ERmUSiwe?= =?iso-8859-1?q?Ei6O2GcW8eyDAITUnZr8/fCr1LUF6p28TMDJ3ZABJqA2GFaUMTK7JCfOHX5/?= =?iso-8859-1?q?nOmhKgbAC1qs436KZThAlxgqzqsFI4PWxW4GJhViaPtDDQlfqlegOMEqFSjQ?= =?iso-8859-1?q?PKQmNIyCBeDjORg2EVCoX7QpUS1ChUwFTdztHpPQ4LkZ2ZlBJYhWPudQ2vIL?= =?iso-8859-1?q?iGO4EZdfDEhe2FijqU/TzMRiS0eJMS0l9ZFHK3HJT7pCPzCbw+ujEH1rKZDc?= =?iso-8859-1?q?kh0A4jgPb2zcOLESrAgRJVFNCkFbUjfVOY8lkLc3ww4gHh9otJHcs01Lz4IL?= =?iso-8859-1?q?eyQ54jTLmkt0EeVpbsEfQtU22ssZ0issjaFPCr5IHzl7C+6RGRfOitkXCaJv?= =?iso-8859-1?q?LL0UUPeOttNjx7dtzhgNfos659BxFgvFERXyXjb42PXbI/eelqRNQSymZIj5?= =?iso-8859-1?q?irD/ZjE8vcCAUkFHSWLhiJ7bie1uLa8sjkhYkH5BAwlJ/LhdZJuVbwECFinN?= =?iso-8859-1?q?nm7GB0vpyFznRpgNfB8iZBl/ZbAdNXh05Ft5sTo2vw4ViV0o6mtT0K3GYXkb?= =?iso-8859-1?q?QbIIqg5PIbAzRgCg/TBElmj6EUs3JGZCMqlqW53YUilPQFwu85jr4q9Uq1/Y?= =?iso-8859-1?q?Dji10O1dAz67RqSBaerTeeLD37NCtrM94z8m0q3qfLF6fIxxF3+/jgvgMbTu?= =?iso-8859-1?q?F5xaG/nD27/fk5oRCV3ZFKVayxuCTmlcnF9iLy8SXc7jw3GqrQf6G2nTaPjp?= =?iso-8859-1?q?eXp+uFEzgVdg3icCV1o1WcYeRtVWSVE4K2ncywrqoblGzyubaX1Xvy9vTOU3?= =?iso-8859-1?q?3ewK0QJOxtKhknTHgJ2idCERtufK6AWACRSjw7GDu/ytDAQnFgLCQHW4NduZ?= =?iso-8859-1?q?a0eNF7wFXtRb1e7OW3LyRfNvuhqjVQ/d7eHdgICiGH3+1ZEg8F3XOVIHroFh?= =?iso-8859-1?q?sUG9runH4MC9xrK552EVQf11C7lptSspcovcsrXicQkC3paVl9jHB8+pAdYY?= =?iso-8859-1?q?3l7x3PBcEK01oWGqubAlceibZbqF1XGf3PA9I6l4Gy7V8NHSw5vDN8SANMfN?= =?iso-8859-1?q?qsDXDaGsKxrK9ODMJXC9kEQyBDC0O6VLoKVQbQBs+ibGBHdGeTNG4rl590tW?= =?iso-8859-1?q?AFMlJJiS4Ad9e9T+2YdD4mkUfguwIEvGYb5KZKYE6FyyIYm19YJinphn8koz?= =?iso-8859-1?q?RkNif7WcheyKkccMTA9XVpQnpCtSaETUBnLiAh1D0TLjGfn/lv22IGL5LYUn?= =?iso-8859-1?q?3wpxXE/MZt+TVa0RidK+XS/wVJ6sz7Do6Qucr4J6bfM/UNqfV5YhfUc9tfWY?= =?iso-8859-1?q?qQ3M=3D?= MIME-Version: 1.0 X-OriginatorOrg: csgroup.eu X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 1105e9be-ae1c-483d-a81b-08d9e6284a0a X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Feb 2022 08:44:56.3991 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 9914def7-b676-4fda-8815-5d49fb3b45c8 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ObWeQ6nmhXlOHeuhBN0SZX2HXVERFslKaLACTDbeKqC+E/M53izbmaCMc06sTNGTabWQinJoYcc3JPodnwWkSWHoaWJratjplIr4EU/tv+4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAZP264MB2894 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Many many places check whether there is one of CONFIG_KASAN_GENERIC or CONFIG_KASAN_SW_TAGS In order to avoid adding more places with such a awful check, add CONFIG_KASAN_SOFTWARE which is selected by both CONFIG_KASAN_GENERIC and CONFIG_KASAN_SW_TAGS. This patch only modifies core part. Arch specific parts can be upgraded one by one in a second step. Don't change mm/ptdump.c as those #ifdefs go away in the patch after the next. Signed-off-by: Christophe Leroy Reported-by: kernel test robot --- include/linux/fortify-string.h | 2 +- include/linux/kasan-checks.h | 2 +- include/linux/kasan.h | 13 ++++++------- include/linux/moduleloader.h | 3 +-- include/linux/sched.h | 2 +- include/linux/vmalloc.h | 3 +-- init/init_task.c | 2 +- lib/Kconfig.kasan | 9 +++++++-- mm/kasan/Makefile | 5 +++-- mm/kasan/common.c | 4 ++-- mm/kasan/kasan.h | 8 ++++---- mm/kasan/report.c | 2 +- 12 files changed, 29 insertions(+), 26 deletions(-) diff --git a/include/linux/fortify-string.h b/include/linux/fortify-string.h index a6cd6815f249..65c06e30fc6b 100644 --- a/include/linux/fortify-string.h +++ b/include/linux/fortify-string.h @@ -24,7 +24,7 @@ void __write_overflow(void) __compiletime_error("detected write beyond size of o __ret; \ }) -#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) +#ifdef CONFIG_KASAN_SOFTWARE extern void *__underlying_memchr(const void *p, int c, __kernel_size_t size) __RENAME(memchr); extern int __underlying_memcmp(const void *p, const void *q, __kernel_size_t size) __RENAME(memcmp); extern void *__underlying_memcpy(void *p, const void *q, __kernel_size_t size) __RENAME(memcpy); diff --git a/include/linux/kasan-checks.h b/include/linux/kasan-checks.h index 3d6d22a25bdc..7ad385c4b2fc 100644 --- a/include/linux/kasan-checks.h +++ b/include/linux/kasan-checks.h @@ -15,7 +15,7 @@ * even in compilation units that selectively disable KASAN, but must use KASAN * to validate access to an address. Never use these in header files! */ -#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) +#ifdef CONFIG_KASAN_SOFTWARE bool __kasan_check_read(const volatile void *p, unsigned int size); bool __kasan_check_write(const volatile void *p, unsigned int size); #else diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 4a45562d8893..c29778b25d8a 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -25,7 +25,7 @@ struct kunit_kasan_expectation { #endif -#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) +#ifdef CONFIG_KASAN_SOFTWARE #include @@ -66,7 +66,7 @@ extern void kasan_enable_current(void); /* Disable reporting bugs for current task */ extern void kasan_disable_current(void); -#else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ +#else /* CONFIG_KASAN_SOFTWARE */ static inline int kasan_add_zero_shadow(void *start, unsigned long size) { @@ -79,7 +79,7 @@ static inline void kasan_remove_zero_shadow(void *start, static inline void kasan_enable_current(void) {} static inline void kasan_disable_current(void) {} -#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ +#endif /* CONFIG_KASAN_SOFTWARE */ #ifdef CONFIG_KASAN_HW_TAGS @@ -467,8 +467,7 @@ static inline void kasan_populate_early_vm_area_shadow(void *start, #endif /* CONFIG_KASAN_VMALLOC */ -#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ - !defined(CONFIG_KASAN_VMALLOC) +#if defined(CONFIG_KASAN_SOFTWARE) && !defined(CONFIG_KASAN_VMALLOC) /* * These functions provide a special case to support backing module @@ -478,12 +477,12 @@ static inline void kasan_populate_early_vm_area_shadow(void *start, int kasan_module_alloc(void *addr, size_t size, gfp_t gfp_mask); void kasan_free_shadow(const struct vm_struct *vm); -#else /* (CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) && !CONFIG_KASAN_VMALLOC */ +#else /* CONFIG_KASAN_SOFTWARE && !CONFIG_KASAN_VMALLOC */ static inline int kasan_module_alloc(void *addr, size_t size, gfp_t gfp_mask) { return 0; } static inline void kasan_free_shadow(const struct vm_struct *vm) {} -#endif /* (CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) && !CONFIG_KASAN_VMALLOC */ +#endif /* CONFIG_KASAN_SOFTWARE && !CONFIG_KASAN_VMALLOC */ #ifdef CONFIG_KASAN_INLINE void kasan_non_canonical_hook(unsigned long addr); diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h index 9e09d11ffe5b..232687e315b3 100644 --- a/include/linux/moduleloader.h +++ b/include/linux/moduleloader.h @@ -96,8 +96,7 @@ void module_arch_cleanup(struct module *mod); /* Any cleanup before freeing mod->module_init */ void module_arch_freeing_init(struct module *mod); -#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ - !defined(CONFIG_KASAN_VMALLOC) +#if defined(CONFIG_KASAN_SOFTWARE) && !defined(CONFIG_KASAN_VMALLOC) #include #define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT) #else diff --git a/include/linux/sched.h b/include/linux/sched.h index f5b2be39a78c..8d815aea1009 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1335,7 +1335,7 @@ struct task_struct { u64 timer_slack_ns; u64 default_timer_slack_ns; -#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) +#ifdef CONFIG_KASAN_SOFTWARE unsigned int kasan_depth; #endif diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h index 880227b9f044..83d870b16a31 100644 --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -28,8 +28,7 @@ struct notifier_block; /* in notifier.h */ #define VM_MAP_PUT_PAGES 0x00000200 /* put pages and free array in vfree */ #define VM_NO_HUGE_VMAP 0x00000400 /* force PAGE_SIZE pte mapping */ -#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ - !defined(CONFIG_KASAN_VMALLOC) +#if defined(CONFIG_KASAN_SOFTWARE) && !defined(CONFIG_KASAN_VMALLOC) #define VM_DEFER_KMEMLEAK 0x00000800 /* defer kmemleak object creation */ #else #define VM_DEFER_KMEMLEAK 0 diff --git a/init/init_task.c b/init/init_task.c index 73cc8f03511a..fa924e5ae173 100644 --- a/init/init_task.c +++ b/init/init_task.c @@ -177,7 +177,7 @@ struct task_struct init_task .numa_group = NULL, .numa_faults = NULL, #endif -#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) +#ifdef CONFIG_KASAN_SOFTWARE .kasan_depth = 1, #endif #ifdef CONFIG_KCSAN diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan index 879757b6dd14..4b2de3bd188a 100644 --- a/lib/Kconfig.kasan +++ b/lib/Kconfig.kasan @@ -46,6 +46,9 @@ menuconfig KASAN if KASAN +config KASAN_SOFTWARE + bool + choice prompt "KASAN mode" default KASAN_GENERIC @@ -69,6 +72,7 @@ config KASAN_GENERIC depends on CC_HAS_WORKING_NOSANITIZE_ADDRESS select SLUB_DEBUG if SLUB select CONSTRUCTORS + select KASAN_SOFTWARE help Enables generic KASAN mode. @@ -90,6 +94,7 @@ config KASAN_SW_TAGS depends on CC_HAS_WORKING_NOSANITIZE_ADDRESS select SLUB_DEBUG if SLUB select CONSTRUCTORS + select KASAN_SOFTWARE help Enables software tag-based KASAN mode. @@ -125,7 +130,7 @@ endchoice choice prompt "Instrumentation type" - depends on KASAN_GENERIC || KASAN_SW_TAGS + depends on KASAN_SOFTWARE default KASAN_OUTLINE config KASAN_OUTLINE @@ -150,7 +155,7 @@ endchoice config KASAN_STACK bool "Enable stack instrumentation (unsafe)" if CC_IS_CLANG && !COMPILE_TEST - depends on KASAN_GENERIC || KASAN_SW_TAGS + depends on KASAN_SOFTWARE depends on !ARCH_DISABLE_KASAN_INLINE default y if CC_IS_GCC help diff --git a/mm/kasan/Makefile b/mm/kasan/Makefile index adcd9acaef61..5f22899b3b2b 100644 --- a/mm/kasan/Makefile +++ b/mm/kasan/Makefile @@ -36,6 +36,7 @@ CFLAGS_hw_tags.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_sw_tags.o := $(CC_FLAGS_KASAN_RUNTIME) obj-$(CONFIG_KASAN) := common.o report.o -obj-$(CONFIG_KASAN_GENERIC) += init.o generic.o report_generic.o shadow.o quarantine.o +obj-$(CONFIG_KASAN_SOFTWARE) += init.o shadow.o +obj-$(CONFIG_KASAN_GENERIC) += generic.o report_generic.o quarantine.o obj-$(CONFIG_KASAN_HW_TAGS) += hw_tags.o report_hw_tags.o tags.o report_tags.o -obj-$(CONFIG_KASAN_SW_TAGS) += init.o report_sw_tags.o shadow.o sw_tags.o tags.o report_tags.o +obj-$(CONFIG_KASAN_SW_TAGS) += sw_tags.o report_sw_tags.o tags.o report_tags.o diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 92196562687b..5693fe2c176f 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -45,7 +45,7 @@ void kasan_set_track(struct kasan_track *track, gfp_t flags) track->stack = kasan_save_stack(flags, true); } -#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) +#ifdef CONFIG_KASAN_SOFTWARE void kasan_enable_current(void) { current->kasan_depth++; @@ -58,7 +58,7 @@ void kasan_disable_current(void) } EXPORT_SYMBOL(kasan_disable_current); -#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ +#endif /* CONFIG_KASAN_SOFTWARE */ void __kasan_unpoison_range(const void *address, size_t size) { diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index c17fa8d26ffe..57d96714bc1b 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -55,7 +55,7 @@ static inline bool kasan_sync_fault_possible(void) #endif -#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) +#ifdef CONFIG_KASAN_SOFTWARE #define KASAN_GRANULE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT) #else #include @@ -211,7 +211,7 @@ struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache, const void *object); #endif -#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) +#ifdef CONFIG_KASAN_SOFTWARE static inline const void *kasan_shadow_to_mem(const void *shadow_addr) { @@ -235,14 +235,14 @@ static inline bool addr_has_metadata(const void *addr) bool kasan_check_range(unsigned long addr, size_t size, bool write, unsigned long ret_ip); -#else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ +#else /* CONFIG_KASAN_SOFTWARE */ static inline bool addr_has_metadata(const void *addr) { return (is_vmalloc_addr(addr) || virt_addr_valid(addr)); } -#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ +#endif /* CONFIG_KASAN_SOFTWARE */ #if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) void kasan_print_tags(u8 addr_tag, const void *addr); diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 3ad9624dcc56..bce57bbd1baa 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -334,7 +334,7 @@ static void print_memory_metadata(const void *addr) static bool report_enabled(void) { -#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) +#ifdef CONFIG_KASAN_SOFTWARE if (current->kasan_depth) return false; #endif From patchwork Wed Feb 2 08:44:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12732714 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4D8EC433FE for ; Wed, 2 Feb 2022 08:45:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245085AbiBBIpA convert rfc822-to-8bit (ORCPT ); Wed, 2 Feb 2022 03:45:00 -0500 Received: from mail-eopbgr90048.outbound.protection.outlook.com ([40.107.9.48]:8736 "EHLO FRA01-MR2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S245070AbiBBIpA (ORCPT ); Wed, 2 Feb 2022 03:45:00 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WZWMOumrTSJJGQVmUz6mtthZO+BX2keaEIdhstOQUgcxc/x3oX3TozTUuC4Ft8dWLdI+l1RaYGHAYCKHxzI5imXrCm0sOU9fvNJGRmuykD+tLycAhKWfgUvctrSNCU+4kp+jnoyDzK5wnPMfp3awpVtjkgqNax96uWMqsN6UsrDgKnUlUglP/K8P2+Z+5INO0XN306claqKyoXGFn+M9lhMsWT8KCqdDpLUDqssTuSnUSeuknu7uHUav/GaXx8jqTHwC5U/LAbELC9yYc12120+k6CIG6GP6Y/+61c67OO2WB2diIaYl+I4Wfb2ac1P6DW2v/WuoeruWQ77HcoDu9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=8wBo4nIdN2RFAwFq84yvv3HNVVFCq353gnyFKfCn4EQ=; b=OOWd6OZTkR5Yd7vzcx/VT/U7Xw9rFVIgnGiSdpSGaIPZ/gE19hfS9douJYv4JoNmYuIUoi0xEPT3UVibPbGL5MLud8TgAY6HMjkhFi91bFXY2vFWku/jy6pivuMeGqnhHpPUFJuN5fLWWk3tjE3DsgJt+kge2XLnaPIwIBBLn+S1Q3Ve8xtjQ/x0vXhveovKEq03HLlBoo4pchl3LZZaUoG8nSFQA85rUMlD286udJ4zNldVqpaG8+PDbH7hF5tdhLZxI6LrOXzwMpOxn+D2pEuyzzwWuLrFVQ/TcqCt5WzjsPi4RweDbq3nZuiBFFQg9fEk3swWDqAsT9eZXmnDBw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:31::15) by MR1P264MB4276.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:42::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11; Wed, 2 Feb 2022 08:44:58 +0000 Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::c9a2:1db0:5469:54e1]) by MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::c9a2:1db0:5469:54e1%9]) with mapi id 15.20.4951.012; Wed, 2 Feb 2022 08:44:58 +0000 From: Christophe Leroy To: Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Andrew Morton CC: Christophe Leroy , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "linux-hardening@vger.kernel.org" , "kasan-dev@googlegroups.com" Subject: [PATCH 2/4] mm/kasan: Move kasan_pXX_table() and kasan_early_shadow_page_entry() Thread-Topic: [PATCH 2/4] mm/kasan: Move kasan_pXX_table() and kasan_early_shadow_page_entry() Thread-Index: AQHYGBEobYxXe/WLd0imaMeHUpNeig== Date: Wed, 2 Feb 2022 08:44:58 +0000 Message-ID: <3fe9bf0867b2ffc7cd43fe7040ee18d245641ec1.1643791473.git.christophe.leroy@csgroup.eu> References: In-Reply-To: Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=csgroup.eu; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 22de4de2-d2b5-478a-b76a-08d9e6284b28 x-ms-traffictypediagnostic: MR1P264MB4276:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6430; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: uI8b/v92ssuNqCBoj7rr9TnkNw653L/5dLA4aiJUCxM3ZwIEoU/t0TVeiUMseVVNRp8Xt8xfHW2Zs8/3cmHQ9iKlM7gTAF6NC5+LQkXUQjgfSg2uY4bubQVpUYTXmE2FFHRjpfSfHlNVfe+oIRqtubwpF1EdKc4xAjrX8I//MMPGPuXUEhNN1ZCgIA75Mo+lrWK8JsYrdTqG/LoS31+er+FowE0fm6ITuoZJB8aC2CMEzoLxfSi8jBb6I3V+wB41Q8ADlEHwC0LKUAeZ+RH4n5cph6S5IUt/aI/7EfIcV1l/AyhktmtCB3ZGbi4ClzqaTZRSuwZW7zYk63IYqRsrofPcbtydnLfPj60s9RG175w0ECH8YlBBVbM74z7JPRBJUNVikZrzP3tx9E1rPQa7PKAgmBuCzVq2lzF/L09uD30VgFZ7IuqxdW949Fijrh1yjlzvpkMZbOt7g3JhHPz4vW5AfAS9aaJmO0pwGfBVIl4Y4aIUdNfjbsiKFZa/48+Z3PfNe7KI3/LZkPFftFbrhPX3bxGMclSZQKUGx5tIyG28cLyV3wcbmfD2YZmuZG59qVCGZCZKQyKIj/x++a9fntIyaeF9mVGf1aF64qFSg9TqTVbq2wVDh/AMLNs85L56nluHUHvYYT4abCCiEECnSfOi2jtjmrzYbrbGyIt4AFSUIAtQS3MvMSHmJ6GLxFoKDQwDt382+MqucoGO7D1/vg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(6486002)(2616005)(26005)(186003)(508600001)(76116006)(66946007)(66446008)(71200400001)(91956017)(5660300002)(36756003)(66556008)(66476007)(8936002)(64756008)(8676002)(2906002)(4326008)(122000001)(38100700002)(86362001)(316002)(110136005)(44832011)(54906003)(6512007)(6506007)(83380400001)(38070700005);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?dqgUGT6Qod7qf1SE6nAmUjd?= =?iso-8859-1?q?4G8yGctp6SqIXypebggRqPmQPFQFIr2yb6GJZE6A0N1Kp1HmEZAu7qMQuGzz?= =?iso-8859-1?q?2ObbGuK5UbYnECJzk1LXS6QEGy8o5/UJhDX7Y1/QkpE4O8hHRFlutdE6wVDt?= =?iso-8859-1?q?xJNZJzMIdxiPuB9gkSW8N0nP7AaoZwHxwO/EAUigFd/l9DNTknOwB6PsbXVR?= =?iso-8859-1?q?UZ/39d7cu6AwF5jmENSEQf5WQ0keeHJzDYz5dneKXdYGEnJWZIeggfSehOIw?= =?iso-8859-1?q?a9p7Zrs1r2uVM8hh1FQQDrI3QdRnh3h7SDYvdL52r8z9SyflnKJeqBrzmzj8?= =?iso-8859-1?q?yJtLyY02VXSyn41xSZ5lNH6RMu1cb0oBPhvWcgO5gF8d+cIxkT6rU4t3ag15?= =?iso-8859-1?q?UaWShOn1OAxIw8wklQnAGyvkXYD7vnOZnNoBikMaQMebH/AOWrHUzPG2t8Cb?= =?iso-8859-1?q?f9DkUtrPp7Eb3ak7pw/9GRtaW4hna8g1d5kaIKla2vtIugSJHZ8bE+vbqmoK?= =?iso-8859-1?q?Mn7K3q7H2e7GVv2JswhdguVbELHpjE1to2PgtGe+fW2mzS6CQ8I6QhDDwMeY?= =?iso-8859-1?q?bIMrCIqdKuAcTq1u8Wc67lF5HspfBy3yS086TF3wR7+zUlVup8zMWrPyzv8M?= =?iso-8859-1?q?Pj1D0rOCjbvopQze4B1X3OotwWkCAmkfByiu/lG2wYRM2WxcQNbldHmtBv7q?= =?iso-8859-1?q?oiA/hPiCUE/hTWmWtESx0cY8K/P1mZ8+2ZpkFet7tG5duxd4eJ1wpA7K7IM4?= =?iso-8859-1?q?bhzaLdmzChr5Hi0FPCV7v7wTE/Q9fKVFXjfhphid1gZh4MpyLt8BKPcvjqO/?= =?iso-8859-1?q?pwfl1ftI8YMQfqhHQO3zq3jIZNW6TAbV6Blcbm5vg6iRY3iP9oYyu//sLqqv?= =?iso-8859-1?q?RFL70yQag103NaLiz7d4w2LiRAZ9kaKnWTIUckj8Sf4O+Ey7FDw1oAwbKP9V?= =?iso-8859-1?q?vYk3qQHZakzbSeanjUejMmFOGw+6+7fiNYRWwpC2Msr7TkLsdYiTd78lZEhk?= =?iso-8859-1?q?Y/HtbtR/OoGTGZyFzHmj3BC4RdTdj3Tu4wdwwzXNoHPIxanQa9qNbvIcu/XC?= =?iso-8859-1?q?6ykIAkFGI+dGdVfl6DFfAtimKlst8l3kafWnxL69ex8gwRTlB0DD244umHZu?= =?iso-8859-1?q?vhKclBX91s2KmbcaMd1AtpmepqwnwlM3TnyubABnbQQkLTHAaTBVZlQZRkxo?= =?iso-8859-1?q?DUSHVp3rbGbHewsajtwZQ5oCBE4KU3focGu/GizlSz7DpOVOwpz7xfhdGj5f?= =?iso-8859-1?q?T0e8e4n+FfmOCS1r3nbLIh/bmuREDVQlHYvnQgs/mUIj1wbZFnenWUAEJUw+?= =?iso-8859-1?q?Aus8zxDj4PydF9l4l32tOP3oSIs14zpQX24McUevnclWZrB8+9zd6h12fuHW?= =?iso-8859-1?q?lnf1JMSe24Y3ge4EgP8PhM4A1FLYiDQrVgEiQSn8ARCC0/S15FKi50LsxcFW?= =?iso-8859-1?q?2QY0ZgvLP1zAVRxPN2M8A+aIq4LXJO0HFwZGZt6aRT0+gclT6s02YbElJxXo?= =?iso-8859-1?q?tGUhT1a/QRh1D/us2qCBnSzwG/HikkWM6Jg+yzUFRKeMLf/XjZki4frrcXwJ?= =?iso-8859-1?q?mw1C5JLdfODGBrVxtJVXi+e61zFXlr76rgFYgJBpNFiNKipnXOY+ONiEmyE5?= =?iso-8859-1?q?FkbT5SkQwRQy13MVyGM79b4LhXYg4QtrAZmqMzakudkmWSgIcNK8MoSf45ds?= =?iso-8859-1?q?0+nPlXeExpjj6pLz3l1hjwX0UPYhkNHfLrEwml9z0ClHd9H9gM/+LrT1Iboo?= =?iso-8859-1?q?9VlM=3D?= MIME-Version: 1.0 X-OriginatorOrg: csgroup.eu X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 22de4de2-d2b5-478a-b76a-08d9e6284b28 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Feb 2022 08:44:58.3050 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 9914def7-b676-4fda-8815-5d49fb3b45c8 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 5jqpnrEHw8N6wfhiQbsud8slVsQPpsED+BePjXS5fcdSsIR+gXpVlLM4i1zDSsurSuZ7Yj/4X4GFRSj/AMAvPhU5tOnX+Hq/1bUbVNcN72I= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MR1P264MB4276 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org In order to reuse them outside of mm/kasan/init.c, move the following helpers outside of init.c: kasan_p4d_table() kasan_pud_table() kasan_pmd_table() kasan_pte_table() kasan_early_shadow_page_entry() And make them available when KASAN is not selected. Inclusion of kasan.h in mm.h needs to be moved down a bit in order to get lm_alias() definition. Signed-off-by: Christophe Leroy Reported-by: kernel test robot Reported-by: kernel test robot --- include/linux/kasan.h | 57 +++++++++++++++++++++++++++++++++++++++++++ include/linux/mm.h | 3 ++- mm/kasan/init.c | 37 ---------------------------- 3 files changed, 59 insertions(+), 38 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index c29778b25d8a..1629797198ec 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -28,6 +28,7 @@ struct kunit_kasan_expectation { #ifdef CONFIG_KASAN_SOFTWARE #include +#include /* Software KASAN implementations use shadow memory. */ @@ -81,6 +82,62 @@ static inline void kasan_disable_current(void) {} #endif /* CONFIG_KASAN_SOFTWARE */ +#if defined(CONFIG_KASAN_SOFTWARE) && CONFIG_PGTABLE_LEVELS > 4 +static inline bool kasan_p4d_table(pgd_t pgd) +{ + return pgd_page(pgd) == virt_to_page(lm_alias(kasan_early_shadow_p4d)); +} +#else +static inline bool kasan_p4d_table(pgd_t pgd) +{ + return false; +} +#endif +#if defined(CONFIG_KASAN_SOFTWARE) && CONFIG_PGTABLE_LEVELS > 3 +static inline bool kasan_pud_table(p4d_t p4d) +{ + return p4d_page(p4d) == virt_to_page(lm_alias(kasan_early_shadow_pud)); +} +#else +static inline bool kasan_pud_table(p4d_t p4d) +{ + return false; +} +#endif +#if defined(CONFIG_KASAN_SOFTWARE) && CONFIG_PGTABLE_LEVELS > 2 +static inline bool kasan_pmd_table(pud_t pud) +{ + return pud_page(pud) == virt_to_page(lm_alias(kasan_early_shadow_pmd)); +} +#else +static inline bool kasan_pmd_table(pud_t pud) +{ + return false; +} +#endif + +#ifdef CONFIG_KASAN_SOFTWARE +static inline bool kasan_pte_table(pmd_t pmd) +{ + return pmd_page(pmd) == virt_to_page(lm_alias(kasan_early_shadow_pte)); +} + +static inline bool kasan_early_shadow_page_entry(pte_t pte) +{ + return pte_page(pte) == virt_to_page(lm_alias(kasan_early_shadow_page)); +} +#else +static inline bool kasan_pte_table(pmd_t pmd) +{ + return false; +} + +static inline bool kasan_early_shadow_page_entry(pte_t pte) +{ + return false; +} +#endif + #ifdef CONFIG_KASAN_HW_TAGS DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled); diff --git a/include/linux/mm.h b/include/linux/mm.h index e1a84b1e6787..b06ee84b3717 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -31,7 +31,6 @@ #include #include #include -#include struct mempolicy; struct anon_vma; @@ -121,6 +120,8 @@ extern int mmap_rnd_compat_bits __read_mostly; #define lm_alias(x) __va(__pa_symbol(x)) #endif +#include + /* * To prevent common memory management code establishing * a zero page mapping on a read fault. diff --git a/mm/kasan/init.c b/mm/kasan/init.c index cc64ed6858c6..e863071a49ef 100644 --- a/mm/kasan/init.c +++ b/mm/kasan/init.c @@ -30,53 +30,16 @@ unsigned char kasan_early_shadow_page[PAGE_SIZE] __page_aligned_bss; #if CONFIG_PGTABLE_LEVELS > 4 p4d_t kasan_early_shadow_p4d[MAX_PTRS_PER_P4D] __page_aligned_bss; -static inline bool kasan_p4d_table(pgd_t pgd) -{ - return pgd_page(pgd) == virt_to_page(lm_alias(kasan_early_shadow_p4d)); -} -#else -static inline bool kasan_p4d_table(pgd_t pgd) -{ - return false; -} #endif #if CONFIG_PGTABLE_LEVELS > 3 pud_t kasan_early_shadow_pud[MAX_PTRS_PER_PUD] __page_aligned_bss; -static inline bool kasan_pud_table(p4d_t p4d) -{ - return p4d_page(p4d) == virt_to_page(lm_alias(kasan_early_shadow_pud)); -} -#else -static inline bool kasan_pud_table(p4d_t p4d) -{ - return false; -} #endif #if CONFIG_PGTABLE_LEVELS > 2 pmd_t kasan_early_shadow_pmd[MAX_PTRS_PER_PMD] __page_aligned_bss; -static inline bool kasan_pmd_table(pud_t pud) -{ - return pud_page(pud) == virt_to_page(lm_alias(kasan_early_shadow_pmd)); -} -#else -static inline bool kasan_pmd_table(pud_t pud) -{ - return false; -} #endif pte_t kasan_early_shadow_pte[MAX_PTRS_PER_PTE + PTE_HWTABLE_PTRS] __page_aligned_bss; -static inline bool kasan_pte_table(pmd_t pmd) -{ - return pmd_page(pmd) == virt_to_page(lm_alias(kasan_early_shadow_pte)); -} - -static inline bool kasan_early_shadow_page_entry(pte_t pte) -{ - return pte_page(pte) == virt_to_page(lm_alias(kasan_early_shadow_page)); -} - static __init void *early_alloc(size_t size, int node) { void *ptr = memblock_alloc_try_nid(size, size, __pa(MAX_DMA_ADDRESS), From patchwork Wed Feb 2 08:45:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12732715 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DEF8C433EF for ; Wed, 2 Feb 2022 08:45:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245097AbiBBIpJ convert rfc822-to-8bit (ORCPT ); Wed, 2 Feb 2022 03:45:09 -0500 Received: from mail-eopbgr90077.outbound.protection.outlook.com ([40.107.9.77]:6180 "EHLO FRA01-MR2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S245094AbiBBIpC (ORCPT ); Wed, 2 Feb 2022 03:45:02 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iiIl7g7LGIKvIAlzXpBc86Xg2w8mGn8WHt7bjSDNLN1tfbvhSAmTNFPmttTja4malMfufV5CLos83wAUImpKgYursPI8lT/rV0Bh7LIS5chnpQFkFhnksPg9rn8ts0a+T9jFduDyDbPhWcoJWekwIe6MkEX+eDErJPafaGXlt+eiF9pimWj4CXzhH9DXMkBNTB290Da0vpm+F+siMXb+B/vzpWF51RuscNX5aZ3yP7B2R1RUqLh4DKffJNpIYVXdOOUYuPVNXQfPbxINQ3kfOpSbdOZUkFFUrWTna2Yy7mm8W3/wPPdbMFE/COXLm4fxzJOtA+P+mieY5o+WJMqVJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=V5HZpJSMefTe1BknEmToruAT0+zCkQH76HIrX9oj8dk=; b=XaaoJU1+naNIhEpapL851xHOp/d5j5AHQLLPj10FR7qNCPjBKmqeMOrgLdCZ/2AYHvzC+90nCs5yNQP3HxXLLwnPy98thE3r+urGC4VcjT19g6hPYjONAe8jk6zmKK9+hPC7Damp3o0qjBy5/5owlezN/6OBEyr2IwU2WVj+G9sPkHSdsZZnU01S4hW53gQtPw8MWO/5l6FMteUk7TtJNjGa3KcE8aHDtnuc2aR09ZC9Ch7Mp8z1g/VawZ5IKBxvaD4/2xB3OYaiCVNjR4KuZvjEfXrpYKWwz4Y8d5NtOdO8RiBlUPk+J5C76+u3I0wHlaWbkFETBcVsjRXMaTo3iA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:31::15) by MR1P264MB4276.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:42::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.11; Wed, 2 Feb 2022 08:45:01 +0000 Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::c9a2:1db0:5469:54e1]) by MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::c9a2:1db0:5469:54e1%9]) with mapi id 15.20.4951.012; Wed, 2 Feb 2022 08:45:00 +0000 From: Christophe Leroy To: Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Andrew Morton CC: Christophe Leroy , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "linux-hardening@vger.kernel.org" , "kasan-dev@googlegroups.com" Subject: [PATCH 3/4] powerpc/ptdump: Use kasan_pXX_table() Thread-Topic: [PATCH 3/4] powerpc/ptdump: Use kasan_pXX_table() Thread-Index: AQHYGBEqqckPpaTFM0exPARyP+NQmw== Date: Wed, 2 Feb 2022 08:45:00 +0000 Message-ID: <976e4678182a5e47311d6200ad8c93bb20c85f64.1643791473.git.christophe.leroy@csgroup.eu> References: In-Reply-To: Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=csgroup.eu; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1b3eafa6-bf37-41ac-fb6f-08d9e6284cb6 x-ms-traffictypediagnostic: MR1P264MB4276:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5516; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: E6FRJOEuOEjUES9MLd01MlGvCM/vE7amPAQcuk05qxrYNwo2HKfp/8GcQA//y1eqSY8nJRbuNpHGFtqVQ1avLgWSGZ+fhm3xPebblK5kSVpLDHiFWEl7GJK07po+m7vNHVFxHgJdmYEYZN5t8faFIZ1TDGcGyYx8Pop/mkWUQ0aJAuTmBsqpnLxC+N4mamCkbvKvu/zp1DqrToZLI6VdZlroYklqEoDIhXtjUgByxgPn5CN3Fd7jJmPMut6IPEQg8KuGbcM014hAH62ZhZSBDCzQ6xK0U2j+R8VPu1yxgHuylb38g5cwBNCGPZR1tUmLuFAXJMkeinUPwYvWnr59UKqFWhK/97Jsn1mcJdAaj7bA5ry/jN3LwA9QLQbAx55L/mhFM7Aq9nz3Eb1TJ4SzJ6G2TCU4a2IcTRXl1VphpflL/F4EAZYLXXx2IZ/oDTv2NSuq7+rVExq6abw12TLAg7cCviNJRgv2JDpjPyFTWfWs9Qc7RXiRGrLm1nytLbT1RJFFuO0aeydC1sYyFWjB54rLZqyvfCP7TUBsPw1BVuntUdlErFU8X+vSkPmzvPdEPCKuzQXl30wBNcqP1kOsouv4XEzT/LjdL1c9O0bpyspajI4NQRMg25pvyZ8CVs/18qL/E7st+iZBrlmwxcy8+tssQAzLCwASYWlNlkCDvMp2PDReX5bAkLt4mhx3oqTy34wI+S8qvwzXL1xb4mW8+g== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(54906003)(38100700002)(86362001)(122000001)(110136005)(44832011)(316002)(38070700005)(83380400001)(6512007)(6506007)(76116006)(66946007)(66446008)(71200400001)(26005)(6486002)(2616005)(508600001)(186003)(2906002)(4326008)(8676002)(5660300002)(91956017)(66476007)(8936002)(64756008)(36756003)(66556008);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?OwPGI3hMnsa5tPcA1C5LzIf?= =?iso-8859-1?q?qVM9LmpPIfw+Kkkddsqmyju1gWjjuJDbAYNPRRrIGz8kR46KAyqG2DEBVuyj?= =?iso-8859-1?q?e1SSDleDbWZeeIWnsVvnFq83QJXhpfBmqQq1d85z49Kw5wcDPHdxD5jjy+LN?= =?iso-8859-1?q?P/IGpwGnD77qwHhfRvrTBG6uTbO7fZwqTlZ3Af3jW22JkKbfQAvsWZO6qc/g?= =?iso-8859-1?q?eBDkaETQWiei8/vRf20RP1zyGTVnAFPirZPuDoK3dzrKD0LMy0RGK8yn83zP?= =?iso-8859-1?q?mZY2n7Q7ukG4VQ8aFo5NP4iRuiLcTye9m58iVFnn0wXCxGKgFGf/UNj6wTVE?= =?iso-8859-1?q?KNhFSopAQpRgD4m8uzjoMoE25bYiEi1lux/A26rE1covCwy8gbKzA/ATHX9+?= =?iso-8859-1?q?xVuyZOjYgl4O3xKGLdNXlupZng4Z1+2VR8OxxVk74Sbo1M7Fbvb9xyfmlGWH?= =?iso-8859-1?q?m8pjbv80bac/IfZVRK5VUa3gwVF1ZHRJrR52pcuh78HTja7YK2GOB6cAVTjD?= =?iso-8859-1?q?pWRXNYDlckmDjmPUQIS4MlxNC2qX06Ul2kI12Hut+dhWLXN/j1DfrAbu3far?= =?iso-8859-1?q?sOuG8l5bX9EeWJXtGN2RHKyPFqKAfcGPQCbOP0K+LDrRshGilWFOI5Gw4DCQ?= =?iso-8859-1?q?GxdHm2Xcs7/AQZUAG5BVT3Yla99sWlQbWLI0bLVVv6FrcFVVArZw9dP8Wwu/?= =?iso-8859-1?q?hyfHlPN5onmLnvlGKHtk+a7S48dGw2AH4mwMcLylDf3pSJ2srQg/0/r5PRqo?= =?iso-8859-1?q?x7cERmbguQBG8cKwGkA2gLcGl9Du+ZjRm/jP+J8c8TAWNOrmFCFvHvkvSoNi?= =?iso-8859-1?q?DKB+QDBsLEKM13NYjDO9x98e78JE3izZZ2qGvUUtaJhq32V4JABaWI+S54/i?= =?iso-8859-1?q?ZCAUCsMMHs7aacAfP2+9tWMts387n4kWvrF7cAt8iFfW9r4ZoYjZuwjSolIW?= =?iso-8859-1?q?7CY4ZSqi8yg80x0qWeRkRku8FW01ov53BJEvg45aN5u8e7YBWKgIuyKMOL1z?= =?iso-8859-1?q?D6RsWWUELkSr/GZgSO8GLHd0Ij4j0lkBGHkj4e8tS8Ljex/IGdRI+FKR13QX?= =?iso-8859-1?q?8HBznfQSH6rRl811NzMIGKMrL/lXQVTfrAIyxQiJn1wlKeicS0yeEcSqPvy2?= =?iso-8859-1?q?gCCzYxUpcFfaywuZfrtyq7r67MJ6zQ7Iev++oe1tF84o8vrL2TwwocyOtLt8?= =?iso-8859-1?q?KwCtsdw5vaJU/dXEBLUOm5HunehxFSi5vk9GCvOr48GJm8dofd0lJzaOmTdq?= =?iso-8859-1?q?z2ytXFYvYrSmxOntdDvU6e1AXVja9IhvSgOR0daK8jZqp+u8LV3fG2lWGOpS?= =?iso-8859-1?q?WwA14yZ1rMRLVvdZGGzxBFcADsom2gT3fjd/VpwVL+Yyj5FcwxPUDOtA+gpq?= =?iso-8859-1?q?XpHTwuqWcOQ96kE20bthNgJ9MSk0HMYPjArRufzfr4yTrqi1KHJ10zC1FNv/?= =?iso-8859-1?q?ByjxlVC4cx1g9j+X7bzax3e4WJL47gO4JdDprZwv7lWYwA3GCNCqwDiWps4s?= =?iso-8859-1?q?RuOMiZRdx/+C+61n6epG8soBFpk3NSueSuV5u+0wZ8xxNsqbWU4FFRZv+fLk?= =?iso-8859-1?q?kurruoYyOxjrjniWDri3nTMFuJc5z/60OZaakJR7y1APhp4RW78mgZFuTLDU?= =?iso-8859-1?q?5wR5USaArVnVL7h91XwzXYiVUiBmYKPPKOUQtjbCH+4HgUE+uo82Bn1jz4aQ?= =?iso-8859-1?q?y5hTt5odR910rm1rLENSQMUVHHZoEK9KTHDcsQE+GNwc268oyDDBL+T9lhAP?= =?iso-8859-1?q?oiWg=3D?= MIME-Version: 1.0 X-OriginatorOrg: csgroup.eu X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 1b3eafa6-bf37-41ac-fb6f-08d9e6284cb6 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Feb 2022 08:45:00.8995 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 9914def7-b676-4fda-8815-5d49fb3b45c8 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: wICNpzSWfgL3v5YZGctUQ0j4c1YaIkBLpA+5hZyK8y/uvowCvzmLFvjrC+OSRPWzR0ECNpIiP0GJHh7ji4VZxdCyBGNftcOhS3b9vAxSZ0k= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MR1P264MB4276 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Instead of opencoding, use the new kasan_pXX_table() helpers. Signed-off-by: Christophe Leroy --- mm/ptdump.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/mm/ptdump.c b/mm/ptdump.c index da751448d0e4..bb6782de8203 100644 --- a/mm/ptdump.c +++ b/mm/ptdump.c @@ -4,7 +4,6 @@ #include #include -#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) /* * This is an optimization for KASAN=y case. Since all kasan page tables * eventually point to the kasan_early_shadow_page we could call note_page() @@ -15,15 +14,16 @@ static inline int note_kasan_page_table(struct mm_walk *walk, unsigned long addr) { +#ifdef CONFIG_KASAN_SOFTWARE struct ptdump_state *st = walk->private; st->note_page(st, addr, 4, pte_val(kasan_early_shadow_pte[0])); walk->action = ACTION_CONTINUE; +#endif return 0; } -#endif static int ptdump_pgd_entry(pgd_t *pgd, unsigned long addr, unsigned long next, struct mm_walk *walk) @@ -31,11 +31,8 @@ static int ptdump_pgd_entry(pgd_t *pgd, unsigned long addr, struct ptdump_state *st = walk->private; pgd_t val = READ_ONCE(*pgd); -#if CONFIG_PGTABLE_LEVELS > 4 && \ - (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) - if (pgd_page(val) == virt_to_page(lm_alias(kasan_early_shadow_p4d))) + if (kasan_p4d_table(val)) return note_kasan_page_table(walk, addr); -#endif if (st->effective_prot) st->effective_prot(st, 0, pgd_val(val)); @@ -52,11 +49,8 @@ static int ptdump_p4d_entry(p4d_t *p4d, unsigned long addr, struct ptdump_state *st = walk->private; p4d_t val = READ_ONCE(*p4d); -#if CONFIG_PGTABLE_LEVELS > 3 && \ - (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) - if (p4d_page(val) == virt_to_page(lm_alias(kasan_early_shadow_pud))) + if (kasan_pud_table(val)) return note_kasan_page_table(walk, addr); -#endif if (st->effective_prot) st->effective_prot(st, 1, p4d_val(val)); @@ -73,11 +67,8 @@ static int ptdump_pud_entry(pud_t *pud, unsigned long addr, struct ptdump_state *st = walk->private; pud_t val = READ_ONCE(*pud); -#if CONFIG_PGTABLE_LEVELS > 2 && \ - (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) - if (pud_page(val) == virt_to_page(lm_alias(kasan_early_shadow_pmd))) + if (kasan_pmd_table(val)) return note_kasan_page_table(walk, addr); -#endif if (st->effective_prot) st->effective_prot(st, 2, pud_val(val)); @@ -94,10 +85,8 @@ static int ptdump_pmd_entry(pmd_t *pmd, unsigned long addr, struct ptdump_state *st = walk->private; pmd_t val = READ_ONCE(*pmd); -#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) - if (pmd_page(val) == virt_to_page(lm_alias(kasan_early_shadow_pte))) + if (kasan_pte_table(val)) return note_kasan_page_table(walk, addr); -#endif if (st->effective_prot) st->effective_prot(st, 3, pmd_val(val)); From patchwork Wed Feb 2 08:45:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 12732716 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A81CC433F5 for ; Wed, 2 Feb 2022 08:45:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245124AbiBBIpL convert rfc822-to-8bit (ORCPT ); Wed, 2 Feb 2022 03:45:11 -0500 Received: from mail-eopbgr90074.outbound.protection.outlook.com ([40.107.9.74]:23472 "EHLO FRA01-MR2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S245122AbiBBIpI (ORCPT ); Wed, 2 Feb 2022 03:45:08 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hguDEE+NBXdcyPFFzb1mLGthJrIPbWO2736/inkZtOYcJO3riOMekimiHyfxMMczBu4gCZ0vUJ9SR3yl5WLhTZbCEia3aBgRfTeJhcI8e1WwfqJCo4446q/ceBi9IKfMagiRGU+CdPckxO+uCGojIHjGJaD5/XOuTOo43Lc5DEHEuihdEqhO2viDV8v77asUbYlTwmBoBOPW8xAe9oSm+CE7fZiBTRbRbbmSxTw4FtA7KAUjMxEVgmCz2WjEfUpazfdZXqwmTUSqclymo3owePfUFfewwSZppqiBqD7ebDC8bjv8q6VirzfjflPjswGygJEfispn7wIBLsjlVlTy9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dHXMQs7YgD3Yni5ZkwlbHjK3NnL1xtKJYyaAF37axAM=; b=Nwhc9D1o3NSsLT+diQRgH4sMHDA/1SvZssW5OJsDdNQE4UFxxuFlAfYvO0s6gfs1AYqqE7e8xHBXuXdKFanZNze4qdFHryODFQCT2qXRugeoxl83tIWcwea+I9EgbxiLdgTI1e4/Ts5UV4azYp5+2wzAgSG3TO1vEQ5f46NjgYIBpqwProK+/CwKL7rC78INBW5LVOHD36wgjOXmzlWXtegdHeD+3LwkObA8dRHm5Zh4e+NJuRFrnzrD7T1VJfXlR8fgrBNAXFRFTRNZD+t9lb4NAhauPg9EnL9kpaaOxu970/DZN2msjZLCDUY8Kh5LskFLLpc0WU7uPykfS5jZsg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:31::15) by PAZP264MB2847.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:1e7::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Wed, 2 Feb 2022 08:45:06 +0000 Received: from MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::c9a2:1db0:5469:54e1]) by MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM ([fe80::c9a2:1db0:5469:54e1%9]) with mapi id 15.20.4951.012; Wed, 2 Feb 2022 08:45:06 +0000 From: Christophe Leroy To: Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Andrew Morton CC: Christophe Leroy , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "linux-hardening@vger.kernel.org" , "kasan-dev@googlegroups.com" , Paul Walmsley , Palmer Dabbelt , Albert Ou Subject: [PATCH 4/4] [RFC] risc/kasan: Use kasan_pXX_table() Thread-Topic: [PATCH 4/4] [RFC] risc/kasan: Use kasan_pXX_table() Thread-Index: AQHYGBEtLm+UnIWHmE22p3QOjbJy3A== Date: Wed, 2 Feb 2022 08:45:06 +0000 Message-ID: <1f88cb32e438f9f29f45ae56849ac3fd94ec8a54.1643791473.git.christophe.leroy@csgroup.eu> References: In-Reply-To: Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=csgroup.eu; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 8abdb104-f1be-40e2-ac9c-08d9e6285011 x-ms-traffictypediagnostic: PAZP264MB2847:EE_ x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1060; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 7UMAg4phz99NXiCxFdFCNZQ0UP8jTsRbYId8UMRzwIr0vnmCDToHiDgP+2/S6+1k51Oh8m78PyvftHYLNjyilGdQfHyEiqfxZBJBK3dp6HcdkX2Hy8VB6ajx3rfxszUTe3c4eRhWJmNFOtLoFwR4/wP6ZwgZSijtuMJgnHeVYtspPJFBOgYjr7i92H2QnGp3D6LvGEtidUmoqEx9vHrJ+hdb/oiz4JyvaNWT6Gekl33DsPRlM8I9OB8JlJL8eaEustkQt88bfA/IiW5bABRKVwccrSbhp+s+6NbWiYsZcOij7TvqEgj0IF9ljujBgldwa3ujZd8T5PLYjWBqg724oN5fVrGhDg+k/odtEZUtoV/prmU7tO8G9Wqt5ZexRu8Ud/fBA3Ch6FXgx8uwl/Nn6kweKcy7UKuvvB5qb3BdQwms2GzooXP3uCjiCXvsvVIFrDFFMEfIKw8PNCf8Pj6B7MWUJ3H/szn1UZCK+u+w0nZw8BsTBAsm1e3HhqqRmyQCfHLubbmw9m0DB/y1BlYlAvX8FIgRFI9bKCOFjbg/n9b1bdECeMnTDZjd30ljKAvc4ZiysHGmiDgmsyIWbthYHOAg7MYNU9a3f7rsp8JyqBvNaLdCnr11JmD6DF6cPfNOQSdH17hdeQYVF6sv3bu7oFqgsh+tHcgfDFOCnwra5bXbBYYqPYDpYmDKRjHB8iM7yOyQiA4sbZHlMDx4Bpb0Ew== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(71200400001)(122000001)(6486002)(508600001)(110136005)(316002)(38100700002)(38070700005)(54906003)(2906002)(36756003)(91956017)(86362001)(66946007)(8936002)(186003)(44832011)(76116006)(4326008)(26005)(8676002)(83380400001)(7416002)(66446008)(66556008)(64756008)(66476007)(6506007)(6512007)(5660300002)(2616005);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?mjSK8srJ0AIT8N6GgQdIXJ4?= =?iso-8859-1?q?Jkf6F/GdAbS+jeXMKvlB7qaGuZT3fvEXrNzT7bBHnez+dpM1Y6zWC0EgvPUC?= =?iso-8859-1?q?Zj86pcRiH6E49rwipKp3oUcQP+izehIwSSe844yqPKKcxVONQgnsLirWWPHz?= =?iso-8859-1?q?eT72B3FmrYP/lJyRx2RxtUPOFqgWImQ26XTjeT9gwbPgzV0cBMfB+NfaqfDa?= =?iso-8859-1?q?DD7SPoNc5OG6opbdEg/P6MKqeRn2otPXCVULUjKmH7o0hH67CzTfGJrWKOH/?= =?iso-8859-1?q?+eTsaz2jNbFACu8LixzWtsMMEOv7vQVKcwQJpLnOVGpD8h4QDQWi6Bx3M9fX?= =?iso-8859-1?q?GxTgbi1ndMJeUyfG7b2ImAQFhAKtrWeoIQpd+t6Kyo0c8x0v26i1tate2diu?= =?iso-8859-1?q?TFhutI9E/2IJVJfZYDNyJS/aSUH8eS4t2XLS0/v/T9EYCLZ4Nm1WUdw7oyir?= =?iso-8859-1?q?82EVIC0fThvy7rijB1Mh4tWhvPg898/RvVZSnz0CIjDCct5N9Qn/RhqU/dNt?= =?iso-8859-1?q?3rHSiCKbBzkyiAZgtDKEQNhyw6NLlaXBfzQzbYkVf61y88onDnrQwei2pG0J?= =?iso-8859-1?q?L/ITtd8Uqwy2H+84LP3UZ1E/cWpUcfALutHQnI3OT2kHwy4dji0DaSjNkj+i?= =?iso-8859-1?q?P5nG240iRzdhNWxTn7QZwqLWhu4vdEF4m0eQWf94Qa0EAv24n+ggMlTezTwA?= =?iso-8859-1?q?kb0q2jZO1edGKQ2mU16JJNwEFCoGid0NPkCElplV7/0FuWJlfU1r6DctuvV4?= =?iso-8859-1?q?q5KMF//jsxsQDfoYiD+pw7v2TQSal9mXu5d22LE8oARcEUaINtK1tne65BuD?= =?iso-8859-1?q?xo9eNMaR2t01CYM1rlC0/Bm6mwo6Vy0IitLEFn1QGOIoa88QSNDjScpqVnru?= =?iso-8859-1?q?ADp/miHMZ/9QZ8yk/8mTzsMCcMeSEECflCjqahmWwhO7FOjqu14clDlif2jv?= =?iso-8859-1?q?qYv65NissGGh0dnknyqHH7pCKvjVKHax4NbTAwC2iorNAKS0Eld2UIWtr8rr?= =?iso-8859-1?q?d1EVqVNdO2P9PFEzqg6cUlJPTF9xy5kkJqnD9ajyVZMyGJBq9uI5nd67Asiv?= =?iso-8859-1?q?L6u2HjNC9Cli89edAky9l+ZXr9ZnjRPM2eV2IZI00p03n054QVJCH0fUwOW4?= =?iso-8859-1?q?kIZGa3VWaEk3q61vfaXxkxsZWxpbccJguw2zmjFGm+kPmPxaGYVzrhMcRdk6?= =?iso-8859-1?q?3mjK6cE3GR01s6LzSCoTgR9PU4mhZPKXGQ82XsiGkXjle7ueGuT1yO9M4LtG?= =?iso-8859-1?q?3k+Oi6+p2eMepoP4GnqxZsDKL8LPFkVHea5E384l9kXImGklO3X/P0wWMr6m?= =?iso-8859-1?q?J3sz+mGO1ThYvAo8GJt3XX7DHPWnPapsDueLwMm/lkt8YR2jsFznNCGgyOWr?= =?iso-8859-1?q?Ni9GaFdYPXRPToeVAh561aFgZ2ccN/mfHdxiVAl7Om7/w10klCxx4aIoraZo?= =?iso-8859-1?q?997vOSeq7SIunYxrL4E8k2zZntgkMmOGkQ2fZwUCqapMYiC0/NJZuqjTazrG?= =?iso-8859-1?q?eOxT1Rlme4auSRj65Krr2diSuyu/hg5Slvo4AAqSSWL6skU2hlthrJ/Bclv8?= =?iso-8859-1?q?8nu2OARaGBi14kAFuGHnFa7REL2BdDllJb3HSv98TqmL7K3FfvaL5tMA2uGt?= =?iso-8859-1?q?IgajyHjIrfF3xut6/fq6tj/9DNQZOJ7Q54iyuLRZS8U5DIBgUFknVGYstxjj?= =?iso-8859-1?q?sXh2YioNTY/HXWkPQmbtlTz0pb2VtNTUpU68MgXmpXDee7YoHw6jB0V+gppu?= =?iso-8859-1?q?EzzI=3D?= MIME-Version: 1.0 X-OriginatorOrg: csgroup.eu X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MRZP264MB2988.FRAP264.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 8abdb104-f1be-40e2-ac9c-08d9e6285011 X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Feb 2022 08:45:06.5583 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 9914def7-b676-4fda-8815-5d49fb3b45c8 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: P0GK3+tjOPSeDDsCpCjgY1LTh99wdJ21CbYbSKxHfQb6o9zJrr5DLPJpdt1Ktx1UZKBBYG/BcWD9t3yTJvTanV1KhfpPlkI1CZeVLDn33L0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAZP264MB2847 Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Instead of opencoding, use the new kasan_pXX_table() helpers. Add kasan_pgd_next_table() to make things similar to other levels. Signed-off-by: Christophe Leroy Cc: Paul Walmsley Cc: Palmer Dabbelt Cc: Albert Ou --- Sent as an RFC as I don't have any risc setup to test it. --- arch/riscv/mm/kasan_init.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/arch/riscv/mm/kasan_init.c b/arch/riscv/mm/kasan_init.c index f61f7ca6fe0f..f82d8b73f518 100644 --- a/arch/riscv/mm/kasan_init.c +++ b/arch/riscv/mm/kasan_init.c @@ -61,13 +61,10 @@ static void __init kasan_populate_pmd(pud_t *pud, unsigned long vaddr, unsigned pmd_t *pmdp, *base_pmd; unsigned long next; - if (pud_none(*pud)) { + if (pud_none(*pud) || kasan_pmd_table(*pud)) base_pmd = memblock_alloc(PTRS_PER_PMD * sizeof(pmd_t), PAGE_SIZE); - } else { + else base_pmd = (pmd_t *)pud_pgtable(*pud); - if (base_pmd == lm_alias(kasan_early_shadow_pmd)) - base_pmd = memblock_alloc(PTRS_PER_PMD * sizeof(pmd_t), PAGE_SIZE); - } pmdp = base_pmd + pmd_index(vaddr); @@ -112,9 +109,10 @@ static void __init kasan_populate_pud(pgd_t *pgd, */ base_pud = pt_ops.get_pud_virt(pfn_to_phys(_pgd_pfn(*pgd))); } else { - base_pud = (pud_t *)pgd_page_vaddr(*pgd); - if (base_pud == lm_alias(kasan_early_shadow_pud)) + if (kasan_pud_table(*pgd)) base_pud = memblock_alloc(PTRS_PER_PUD * sizeof(pud_t), PAGE_SIZE); + else + base_pud = (pud_t *)pgd_page_vaddr(*pgd); } pudp = base_pud + pud_index(vaddr); @@ -157,6 +155,11 @@ static void __init kasan_populate_pud(pgd_t *pgd, kasan_populate_pud(pgdp, vaddr, next, early) : \ kasan_populate_pmd((pud_t *)pgdp, vaddr, next)) +static inline bool kasan_pgd_next_table(pgd_t pgd) +{ + return pgd_page(pgd) == virt_to_page(lm_alias(kasan_early_shadow_pgd_next)); +} + static void __init kasan_populate_pgd(pgd_t *pgdp, unsigned long vaddr, unsigned long end, bool early) @@ -172,8 +175,7 @@ static void __init kasan_populate_pgd(pgd_t *pgdp, phys_addr = __pa((uintptr_t)kasan_early_shadow_pgd_next); set_pgd(pgdp, pfn_pgd(PFN_DOWN(phys_addr), PAGE_TABLE)); continue; - } else if (pgd_page_vaddr(*pgdp) == - (unsigned long)lm_alias(kasan_early_shadow_pgd_next)) { + } else if (kasan_pgd_next_table(*pgdp)) { /* * pgdp can't be none since kasan_early_init * initialized all KASAN shadow region with @@ -251,7 +253,6 @@ static void __init kasan_shallow_populate_pud(pgd_t *pgdp, unsigned long next; pud_t *pudp, *base_pud; pmd_t *base_pmd; - bool is_kasan_pmd; base_pud = (pud_t *)pgd_page_vaddr(*pgdp); pudp = base_pud + pud_index(vaddr); @@ -262,9 +263,8 @@ static void __init kasan_shallow_populate_pud(pgd_t *pgdp, do { next = pud_addr_end(vaddr, end); - is_kasan_pmd = (pud_pgtable(*pudp) == lm_alias(kasan_early_shadow_pmd)); - if (is_kasan_pmd) { + if (kasan_pmd_table(*pudp)) { base_pmd = memblock_alloc(PAGE_SIZE, PAGE_SIZE); set_pud(pudp, pfn_pud(PFN_DOWN(__pa(base_pmd)), PAGE_TABLE)); } @@ -280,8 +280,7 @@ static void __init kasan_shallow_populate_pgd(unsigned long vaddr, unsigned long do { next = pgd_addr_end(vaddr, end); - is_kasan_pgd_next = (pgd_page_vaddr(*pgd_k) == - (unsigned long)lm_alias(kasan_early_shadow_pgd_next)); + is_kasan_pgd_next = kasan_pgd_next_table(*pgd_k); if (is_kasan_pgd_next) { p = memblock_alloc(PAGE_SIZE, PAGE_SIZE);