From patchwork Tue Sep 15 21:15:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777715 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D33959D for ; Tue, 15 Sep 2020 21:16:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1B61020795 for ; Tue, 15 Sep 2020 21:16:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="hdJRfah2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B61020795 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 08A95900069; Tue, 15 Sep 2020 17:16:28 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 06351900012; Tue, 15 Sep 2020 17:16:28 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB843900069; Tue, 15 Sep 2020 17:16:27 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0136.hostedemail.com [216.40.44.136]) by kanga.kvack.org (Postfix) with ESMTP id D71DE900012 for ; Tue, 15 Sep 2020 17:16:27 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 946278249980 for ; Tue, 15 Sep 2020 21:16:27 +0000 (UTC) X-FDA: 77266554414.18.fact76_3e0a89327114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 6347A100EC683 for ; Tue, 15 Sep 2020 21:16:27 +0000 (UTC) X-Spam-Summary: 1,0,0,8266b483f14eb019,d41d8cd98f00b204,3ks9hxwokca4o1r5scy19zu22uzs.q20zw18b-00y9oqy.25u@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1534:1540:1593:1594:1711:1714:1730:1747:1777:1792:1978:1981:2194:2199:2393:2559:2562:3138:3139:3140:3141:3142:3152:3350:3608:3865:3870:3871:3874:4250:4321:5007:6261:6653:6742:9969:10004:10400:11026:11232:11473:11658:11914:12043:12048:12296:12297:12438:12555:12895:12986:13069:13311:13357:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:30054,0,RBL:209.85.221.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yfrsf3uhko31oqi34xropc3zywxycsq51cedx7uoxkbnti17ixj31we31tao9.wawfuz9wankszadn9ksd7fg6w9mx9pz4qbdu14yhjr6rw9ai43trbe7aitydm84.q-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0 :0,LFtim X-HE-Tag: fact76_3e0a89327114 X-Filterd-Recvd-Size: 4283 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:16:26 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id a10so1679750wrw.22 for ; Tue, 15 Sep 2020 14:16:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=ssmRcE1kYrAL6ZSKtgqrQSJk1HXoJcRhQCNgYvB5iuc=; b=hdJRfah27omL2Icwf/rxTkSFi5BnYgCVvskJ11E2UfIrsn1Mb/F7yTQcD06APh0cwH /PQM+iEq1I9X1SVCRt7GsbyaBFZ08nXIez8Ee31J+csXHA5G+18bpBS5Ki1z1hmKdAKU 6aSiakRBh6ZFQ4FZoVBwXy53lbVrt3vVsusrJZHcUrT4kmDelLNgmQKyMb1LPB7Eyp/0 9hxtjgFINQ+sYWtGquoG4hX7la9aJEm/9GWxIbMuRVtwFTKa9VItfgPlTwxd87Khgpfv /i9M6iSRPhprO4Ku7DQa5UReY8WpiUcbvMSF5+/rPjX3hDZ/4BKLyTMacs7ztFqkbKV6 GPHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ssmRcE1kYrAL6ZSKtgqrQSJk1HXoJcRhQCNgYvB5iuc=; b=JSNGjrAdFclp3OKluTdAGh3gyaZRSmOWKN58tywiVbpBJFbGajdkl/KR77Xb3PcR6u 89fWP38kdwCytTXpYvA6jJtgV/sJtqwPs5Xkw/Ys+hyZCDxxjNOQ7zER04BErYSru1kY nzct5IU9vuxD2N1OgrMmJDOm2/okriOevcOeY4P/quS1eTpPQ2jbB0iSjkaBG71i8vqC XnDWgm5HVGE+qhwxUonOXE+CgUfs+hD7QfZmbW70ShXsDxjeRCynopzwlNF9sN+nTkDc 4HNJTDqAr2xm7HkjyqhYWZT18fOolcVRYNVL+z9EM496P9J2FxPr7dKxNWWta29bVkq1 lldQ== X-Gm-Message-State: AOAM531k1jCsmRnGXUbWG7oxGbEaeRv69suAAzj2JWnM5YL16c5c1Rv0 P9eLr5pKRNQVf4RhhBzJxYUiJzLocF0AW55Z X-Google-Smtp-Source: ABdhPJxK3f6kOYACU+1LPYljRJxMyomUs5lqQAssZQ0ReoMmGpVcJpTajmnKJKzKQyrcVQ3n/6jTySujdqs9K7LP X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:adf:ffca:: with SMTP id x10mr15472756wrs.342.1600204585311; Tue, 15 Sep 2020 14:16:25 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:43 +0200 In-Reply-To: Message-Id: <2de958570c5bccf438cde8eb8c2fce7e5a37deed.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 01/37] kasan: KASAN_VMALLOC depends on KASAN_GENERIC From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 6347A100EC683 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: Currently only generic KASAN mode supports vmalloc, reflect that in the config. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: I1889e5b3bed28cc5d607802fb6ae43ba461c0dc1 --- lib/Kconfig.kasan | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan index 047b53dbfd58..e1d55331b618 100644 --- a/lib/Kconfig.kasan +++ b/lib/Kconfig.kasan @@ -156,7 +156,7 @@ config KASAN_SW_TAGS_IDENTIFY config KASAN_VMALLOC bool "Back mappings in vmalloc space with real shadow memory" - depends on HAVE_ARCH_KASAN_VMALLOC + depends on KASAN_GENERIC && HAVE_ARCH_KASAN_VMALLOC help By default, the shadow region for vmalloc space is the read-only zero page. This means that KASAN cannot detect errors involving From patchwork Tue Sep 15 21:15:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777719 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E5834746 for ; Tue, 15 Sep 2020 21:16:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8539C2078E for ; Tue, 15 Sep 2020 21:16:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="PNOD7wmZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8539C2078E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5206490006D; Tue, 15 Sep 2020 17:16:34 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4CE12900012; Tue, 15 Sep 2020 17:16:34 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3BD8B90006D; Tue, 15 Sep 2020 17:16:34 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0227.hostedemail.com [216.40.44.227]) by kanga.kvack.org (Postfix) with ESMTP id 26F88900012 for ; Tue, 15 Sep 2020 17:16:34 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id D99CB180AD807 for ; Tue, 15 Sep 2020 21:16:33 +0000 (UTC) X-FDA: 77266554666.22.bean83_1c1863a27114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id A527118038E72 for ; Tue, 15 Sep 2020 21:16:29 +0000 (UTC) X-Spam-Summary: 1,0,0,ad9fd9082827f415,d41d8cd98f00b204,3ky9hxwokcbaq3t7ue03b1w44w1u.s421y3ad-220bqs0.47w@flex--andreyknvl.bounces.google.com,,RULES_HIT:2:41:69:152:355:379:541:800:960:966:968:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1593:1594:1605:1730:1747:1777:1792:1981:2194:2196:2199:2200:2393:2559:2562:2693:3138:3139:3140:3141:3142:3152:3865:3866:3867:3868:3870:3871:4049:4120:4250:4321:4385:4605:5007:6261:6653:6742:7903:8603:9036:9592:9969:10004:11026:11232:11473:11658:11914:12043:12048:12291:12296:12297:12438:12555:12683:12895:12986:14096:14097:14394:14659:21080:21324:21365:21444:21451:21627:21740:21987:21990:30012:30054,0,RBL:209.85.128.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yr8ggj1ce14dt7fdhkb4ofcpcg8yc1d6ysfbki6ud1zarpea8qxnec4s8rcwj.cuig84ojm6a5s5osnocridsauea3ynbic86597dnmz7gxjyher7ghcy13hfu3bz.4-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache: 0,MSF:no X-HE-Tag: bean83_1c1863a27114 X-Filterd-Recvd-Size: 9527 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf28.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:16:29 +0000 (UTC) Received: by mail-wm1-f73.google.com with SMTP id b20so391792wmj.1 for ; Tue, 15 Sep 2020 14:16:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=4h8AUAED/J4coJrwCCrtoX8os6dI9SXh1HX4PoZIciE=; b=PNOD7wmZmgwat0w8m+zelUVNjscKBzL4KMvNSFfTXEZPR1DKQKcNjvE+gBhe6x4Qee Qv65LdmRhOQDXqceE66KRGIbSQ3hsEWQDyxTs4GIc+szsagGW1SuoSsIC/OXiPFdpBQj XaHgoErKOrVZxi96WIQ6ZpDOPQENXz0xEvmDGyG4G8wf/x8iAeS8aoF6puuYrwFQ4KKM 0TZo4X1bllxpnxySVaAiskAeWtb/XCLz6QHgr6y/sTzEyI3Is425kj8ASw9KBngLTAmF kO7aelyB0m96ptmxdoI1ecmRvGeO5+QzxHFJZnMMerRMfKra6aJPUwZkT12iChYb9g+5 pM8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=4h8AUAED/J4coJrwCCrtoX8os6dI9SXh1HX4PoZIciE=; b=OOkc0xXF65ns57bLMe5IBDYwtT0yq974AcN0yiYu/w7t0SKmYIwPW9Kx/eBfQlMd44 P+VROpiYlUjWpJcZfZlpyQP+qTA/5a868UN8k7zjvCs/CZ7n0Mu9jRcO6/azf1BFDFss f10a3vX7WXUsnzG+f+WAOFm+BHX//+aGOs1aETt1A39cQQOqanWU94yjN1wlUbrfpPpw sMzR9+fxYa4xUmLIwYoXtBhes087JVYUPLqmiybwRu5LgEm4aknyQl5gtzI7QWeGxVwJ 7bcDReu0XXUh/OsLbyMJnrvSOY0zKM3Vt/9Db/Ximlk4rymQj3ysB9T7uGyZJICVKm/N 2OFQ== X-Gm-Message-State: AOAM530qpfTeOVq+ItCYmEdFa0zRWZXXL/rOcvRZ16nBiiV6InHyzNXj zyA8uzQ7nv/O/h7NHCOF6c9oyh02kEYDPNJo X-Google-Smtp-Source: ABdhPJzJ3YcrQa2Zxum+n99IaW5x7IglkoaJwGBH3mwIS4l9LxxFEf93e8R6mpnNY+eU+2GpjaToVlCy8bmEbRTu X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:cc84:: with SMTP id p4mr1290068wma.58.1600204587590; Tue, 15 Sep 2020 14:16:27 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:44 +0200 In-Reply-To: Message-Id: <34bc63b581b206b914919c7371cf021bcf26294e.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 02/37] kasan: group vmalloc code From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: A527118038E72 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Group all vmalloc-related function declarations in include/linux/kasan.h, and their implementations in mm/kasan/common.c. No functional changes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: Ie20b6c689203cd6de4fd7f2c465ec081c00c5f15 --- include/linux/kasan.h | 41 +++++++++++++---------- mm/kasan/common.c | 78 ++++++++++++++++++++++--------------------- 2 files changed, 63 insertions(+), 56 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 087fba34b209..bd5b4965a269 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -69,19 +69,6 @@ struct kasan_cache { int free_meta_offset; }; -/* - * These functions provide a special case to support backing module - * allocations with real shadow memory. With KASAN vmalloc, the special - * case is unnecessary, as the work is handled in the generic case. - */ -#ifndef CONFIG_KASAN_VMALLOC -int kasan_module_alloc(void *addr, size_t size); -void kasan_free_shadow(const struct vm_struct *vm); -#else -static inline int kasan_module_alloc(void *addr, size_t size) { return 0; } -static inline void kasan_free_shadow(const struct vm_struct *vm) {} -#endif - int kasan_add_zero_shadow(void *start, unsigned long size); void kasan_remove_zero_shadow(void *start, unsigned long size); @@ -150,9 +137,6 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, return false; } -static inline int kasan_module_alloc(void *addr, size_t size) { return 0; } -static inline void kasan_free_shadow(const struct vm_struct *vm) {} - static inline int kasan_add_zero_shadow(void *start, unsigned long size) { return 0; @@ -205,13 +189,16 @@ static inline void *kasan_reset_tag(const void *addr) #endif /* CONFIG_KASAN_SW_TAGS */ #ifdef CONFIG_KASAN_VMALLOC + int kasan_populate_vmalloc(unsigned long addr, unsigned long size); void kasan_poison_vmalloc(const void *start, unsigned long size); void kasan_unpoison_vmalloc(const void *start, unsigned long size); void kasan_release_vmalloc(unsigned long start, unsigned long end, unsigned long free_region_start, unsigned long free_region_end); -#else + +#else /* CONFIG_KASAN_VMALLOC */ + static inline int kasan_populate_vmalloc(unsigned long start, unsigned long size) { @@ -226,7 +213,25 @@ static inline void kasan_release_vmalloc(unsigned long start, unsigned long end, unsigned long free_region_start, unsigned long free_region_end) {} -#endif + +#endif /* CONFIG_KASAN_VMALLOC */ + +#if defined(CONFIG_KASAN) && !defined(CONFIG_KASAN_VMALLOC) + +/* + * These functions provide a special case to support backing module + * allocations with real shadow memory. With KASAN vmalloc, the special + * case is unnecessary, as the work is handled in the generic case. + */ +int kasan_module_alloc(void *addr, size_t size); +void kasan_free_shadow(const struct vm_struct *vm); + +#else /* CONFIG_KASAN && !CONFIG_KASAN_VMALLOC */ + +static inline int kasan_module_alloc(void *addr, size_t size) { return 0; } +static inline void kasan_free_shadow(const struct vm_struct *vm) {} + +#endif /* CONFIG_KASAN && !CONFIG_KASAN_VMALLOC */ #ifdef CONFIG_KASAN_INLINE void kasan_non_canonical_hook(unsigned long addr); diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 950fd372a07e..d1c987f324cd 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -541,44 +541,6 @@ void kasan_kfree_large(void *ptr, unsigned long ip) /* The object will be poisoned by page_alloc. */ } -#ifndef CONFIG_KASAN_VMALLOC -int kasan_module_alloc(void *addr, size_t size) -{ - void *ret; - size_t scaled_size; - size_t shadow_size; - unsigned long shadow_start; - - shadow_start = (unsigned long)kasan_mem_to_shadow(addr); - scaled_size = (size + KASAN_SHADOW_MASK) >> KASAN_SHADOW_SCALE_SHIFT; - shadow_size = round_up(scaled_size, PAGE_SIZE); - - if (WARN_ON(!PAGE_ALIGNED(shadow_start))) - return -EINVAL; - - ret = __vmalloc_node_range(shadow_size, 1, shadow_start, - shadow_start + shadow_size, - GFP_KERNEL, - PAGE_KERNEL, VM_NO_GUARD, NUMA_NO_NODE, - __builtin_return_address(0)); - - if (ret) { - __memset(ret, KASAN_SHADOW_INIT, shadow_size); - find_vm_area(addr)->flags |= VM_KASAN; - kmemleak_ignore(ret); - return 0; - } - - return -ENOMEM; -} - -void kasan_free_shadow(const struct vm_struct *vm) -{ - if (vm->flags & VM_KASAN) - vfree(kasan_mem_to_shadow(vm->addr)); -} -#endif - #ifdef CONFIG_MEMORY_HOTPLUG static bool shadow_mapped(unsigned long addr) { @@ -690,6 +652,7 @@ core_initcall(kasan_memhotplug_init); #endif #ifdef CONFIG_KASAN_VMALLOC + static int kasan_populate_vmalloc_pte(pte_t *ptep, unsigned long addr, void *unused) { @@ -928,4 +891,43 @@ void kasan_release_vmalloc(unsigned long start, unsigned long end, (unsigned long)shadow_end); } } + +#else /* CONFIG_KASAN_VMALLOC */ + +int kasan_module_alloc(void *addr, size_t size) +{ + void *ret; + size_t scaled_size; + size_t shadow_size; + unsigned long shadow_start; + + shadow_start = (unsigned long)kasan_mem_to_shadow(addr); + scaled_size = (size + KASAN_SHADOW_MASK) >> KASAN_SHADOW_SCALE_SHIFT; + shadow_size = round_up(scaled_size, PAGE_SIZE); + + if (WARN_ON(!PAGE_ALIGNED(shadow_start))) + return -EINVAL; + + ret = __vmalloc_node_range(shadow_size, 1, shadow_start, + shadow_start + shadow_size, + GFP_KERNEL, + PAGE_KERNEL, VM_NO_GUARD, NUMA_NO_NODE, + __builtin_return_address(0)); + + if (ret) { + __memset(ret, KASAN_SHADOW_INIT, shadow_size); + find_vm_area(addr)->flags |= VM_KASAN; + kmemleak_ignore(ret); + return 0; + } + + return -ENOMEM; +} + +void kasan_free_shadow(const struct vm_struct *vm) +{ + if (vm->flags & VM_KASAN) + vfree(kasan_mem_to_shadow(vm->addr)); +} + #endif From patchwork Tue Sep 15 21:15:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777717 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E76D26CA for ; Tue, 15 Sep 2020 21:16:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9913520770 for ; Tue, 15 Sep 2020 21:16:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="hMw9RQ1d" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9913520770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BAC8590006B; Tue, 15 Sep 2020 17:16:31 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B5CEA900012; Tue, 15 Sep 2020 17:16:31 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A72DE90006B; Tue, 15 Sep 2020 17:16:31 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0086.hostedemail.com [216.40.44.86]) by kanga.kvack.org (Postfix) with ESMTP id 92BD0900012 for ; Tue, 15 Sep 2020 17:16:31 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 49FBC3489 for ; Tue, 15 Sep 2020 21:16:31 +0000 (UTC) X-FDA: 77266554582.02.man81_1d11c1227114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 21B7F1005DE99 for ; Tue, 15 Sep 2020 21:16:31 +0000 (UTC) X-Spam-Summary: 1,0,0,fec48826970cb842,d41d8cd98f00b204,3ls9hxwokcbis5v9wg25d3y66y3w.u64305cf-442dsu2.69y@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:69:152:355:379:541:800:960:966:968:973:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:1981:2194:2196:2199:2200:2393:2559:2562:3138:3139:3140:3141:3142:3152:3354:3865:3866:3868:3871:4117:4250:4321:4385:5007:6261:6653:6742:8603:9592:9969:10004:10400:11026:11232:11473:11658:11914:12043:12048:12291:12296:12297:12438:12555:12683:12895:12986:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:21772:21990:30054,0,RBL:209.85.160.202:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04ygprzoscj7au4faxd7gikgbrghcyce6baku5ec4rwrh3orq1dee6b4sk4ro5q.ngwtfyaxfqju6zgs4ry4x3mzyc1ichocjadxwji6w4xp5zbqd7ztca753fce66j.a-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp ,MSBL:0, X-HE-Tag: man81_1d11c1227114 X-Filterd-Recvd-Size: 6762 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:16:30 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id f12so4020115qtq.5 for ; Tue, 15 Sep 2020 14:16:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=CRuZK+9yjNiKO3/D2O90q00ovcGW/0GaRtF/oaFCa6M=; b=hMw9RQ1dm2tX2wxDoS+iGFKc6VjnZ0XSq5Et2xcn9Si1ATKtqSzmGft3iR27ujVutM 6Pmv9Ouek8j/oMRKz9BmvZ7pHOYOe6Lqj7XAOJ+IVmxsC1pGbjA11jnsHJo+2P3BeD7U ssDvbd51P7yEcYy2VrkEPQOC1NGoueMpaJQ5NMWy/P26Q+4Eur2f8WwuoSAjAISHRjgs 4RFp88PAKRndNiG30G5JrdImqqcM8yXxseTQ3P3rk5mKHk51srzaCdnLOHyzHH11eFdB Z56rbIIDpE49gN6dYAIcfwB4B6ezKY9w/+af2eDNmCwV76JcqLbQzvBbSbEiYiI9oDjM YJVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=CRuZK+9yjNiKO3/D2O90q00ovcGW/0GaRtF/oaFCa6M=; b=QBVQNgpBcHpbElWl4ipluFIiiLPuwyrXqB1PWY70fvhJ48ZFtpQ435uuP14lXidFAI vvbGE4VzfItx3JaSovXA3ljmjY5091WlMBmazBlREHxtHNh7q/hdRYB+y+zx2VltPyI7 J8btzzVTxqHadsrDe4SxfJxbz0ZDQ0Fsa6Evc1Nt+MntiJ/6vTo5MlDJzEHq/Fy7l2QO fI5S+uWQ7Bl4N+uZHdpsQI9CKVBl7VWaCjOMeGyT5fhfW7bjY4K6U4tNEjeQ1x1TlJp/ twcrX8DjNCXZNaIFKor4G1ISEXm8/o7yUBvOt+qhjaRrrmHqaMGShnQfLPy147kSxY1Q Bz3w== X-Gm-Message-State: AOAM532TzhEDsvQIM3MSHuYm3wPn7Pw+H46AO41BbNHYwNl+TI1ubja7 SzOZkBKWO7IEZ9SvLrmimQMOg0QuheQ8dD98 X-Google-Smtp-Source: ABdhPJyN5unj5rLtoXzfox4mXS2M3S/SaZl+8R1nGGjQ6/HS4oOUtG9N8+ab9YhNGQBGWUztUka8v9nB9tQGSTvy X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:4527:: with SMTP id l7mr20524343qvu.2.1600204589991; Tue, 15 Sep 2020 14:16:29 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:45 +0200 In-Reply-To: Message-Id: <6ad13f9f94e1a2f84f603e0e374582b89a44a75e.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 03/37] kasan: shadow declarations only for software modes From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 21B7F1005DE99 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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: This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Group shadow-related KASAN function declarations and only define them for the two existing software modes. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: I864be75a88b91b443c55e9c2042865e15703e164 --- include/linux/kasan.h | 44 ++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index bd5b4965a269..44a9aae44138 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -3,16 +3,24 @@ #define _LINUX_KASAN_H #include +#include struct kmem_cache; struct page; struct vm_struct; struct task_struct; -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) #include -#include + +/* Software KASAN implementations use shadow memory. */ + +#ifdef CONFIG_KASAN_SW_TAGS +#define KASAN_SHADOW_INIT 0xFF +#else +#define KASAN_SHADOW_INIT 0 +#endif extern unsigned char kasan_early_shadow_page[PAGE_SIZE]; extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE]; @@ -29,6 +37,23 @@ static inline void *kasan_mem_to_shadow(const void *addr) + KASAN_SHADOW_OFFSET; } +int kasan_add_zero_shadow(void *start, unsigned long size); +void kasan_remove_zero_shadow(void *start, unsigned long size); + +#else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ + +static inline int kasan_add_zero_shadow(void *start, unsigned long size) +{ + return 0; +} +static inline void kasan_remove_zero_shadow(void *start, + unsigned long size) +{} + +#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ + +#ifdef CONFIG_KASAN + /* Enable reporting bugs after kasan_disable_current() */ extern void kasan_enable_current(void); @@ -69,9 +94,6 @@ struct kasan_cache { int free_meta_offset; }; -int kasan_add_zero_shadow(void *start, unsigned long size); -void kasan_remove_zero_shadow(void *start, unsigned long size); - size_t __ksize(const void *); static inline void kasan_unpoison_slab(const void *ptr) { @@ -137,14 +159,6 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, return false; } -static inline int kasan_add_zero_shadow(void *start, unsigned long size) -{ - return 0; -} -static inline void kasan_remove_zero_shadow(void *start, - unsigned long size) -{} - static inline void kasan_unpoison_slab(const void *ptr) { } static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } @@ -152,8 +166,6 @@ static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } #ifdef CONFIG_KASAN_GENERIC -#define KASAN_SHADOW_INIT 0 - void kasan_cache_shrink(struct kmem_cache *cache); void kasan_cache_shutdown(struct kmem_cache *cache); void kasan_record_aux_stack(void *ptr); @@ -168,8 +180,6 @@ static inline void kasan_record_aux_stack(void *ptr) {} #ifdef CONFIG_KASAN_SW_TAGS -#define KASAN_SHADOW_INIT 0xFF - void kasan_init_tags(void); void *kasan_reset_tag(const void *addr); From patchwork Tue Sep 15 21:15:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777721 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 141C56CA for ; Tue, 15 Sep 2020 21:16:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A85872078E for ; Tue, 15 Sep 2020 21:16:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="uRtKhim4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A85872078E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2B150900070; Tue, 15 Sep 2020 17:16:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 261FE900012; Tue, 15 Sep 2020 17:16:35 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 101F3900070; Tue, 15 Sep 2020 17:16:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0066.hostedemail.com [216.40.44.66]) by kanga.kvack.org (Postfix) with ESMTP id EB9AA900012 for ; Tue, 15 Sep 2020 17:16:34 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A62CA180AD807 for ; Tue, 15 Sep 2020 21:16:34 +0000 (UTC) X-FDA: 77266554708.20.swing34_591428c27114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id AA2DF180C0623 for ; Tue, 15 Sep 2020 21:16:33 +0000 (UTC) X-Spam-Summary: 1,0,0,69dfc5cb5c95b232,d41d8cd98f00b204,3mc9hxwokcbuv8yczj58g619916z.x97638fi-775gvx5.9c1@flex--andreyknvl.bounces.google.com,,RULES_HIT:1:41:69:152:355:379:541:800:960:966:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1593:1594:1605:1730:1747:1777:1792:1981:2194:2196:2198:2199:2200:2201:2393:2559:2562:2637:2693:2731:2898:2901:3138:3139:3140:3141:3142:3152:3865:3866:3867:3868:3870:3871:3874:4250:4321:4385:4605:5007:6119:6261:6653:6742:7875:7903:8603:8660:8957:9969:10004:11026:11232:11473:11658:11914:12043:12048:12295:12296:12297:12438:12555:12683:12895:12986:13148:13161:13229:13230:13972:14096:14097:14394:14659:14877:21080:21365:21444:21451:21627:21939:21990:30003:30054:30070,0,RBL:209.85.219.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04y8enffs7hhggdkgxy3id5pcqgf7ypexe9kuqrhew1nj3j9cmbwt91xaf15xix.gwjfebnf3c1yyf6u1zgorip5cf8ibecqh35rkdhp5kn4rs366dgqw4whw7bje5y.n-lbl8.mailshell.net-223.238.255.100,Cach eIP:none X-HE-Tag: swing34_591428c27114 X-Filterd-Recvd-Size: 14753 Received: from mail-qv1-f74.google.com (mail-qv1-f74.google.com [209.85.219.74]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:16:33 +0000 (UTC) Received: by mail-qv1-f74.google.com with SMTP id ct11so3063042qvb.16 for ; Tue, 15 Sep 2020 14:16:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=7fRB9Iij7agHmnAb8fbKN2e178BCIXlUxdNq0r2bkng=; b=uRtKhim4j+aOgU6zmmJT+G7/XfPkk2HgXmIbUAGmkJ8sSJl4FknfU2mUjQVYz8v9V4 kCLnMgdTToHZGPXAaNhcukeFtUiMJPZ50Zc3g4+ofwds6pkg2fG4PB26kH2kP+cketWZ X1o9QZ4xFY9qDFoQl3jL3ixNfpBnikMxNeOdeCdnaNuE+WJDIv+YYAHtEdRL31m171lU qbCO91INIUiZwipbSHY8lV6B6Y6sz98itP8IAa+G59dn9bht0aEn86z4QivzvA1sLP1g PBQRxFBVr8HIOwDAXgO6k292VFZJZlGZinPsoJCLg56yN+ugaDwSPXe8cfzCLmo9V0Bb yi9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=7fRB9Iij7agHmnAb8fbKN2e178BCIXlUxdNq0r2bkng=; b=tQYZ1UUqH/gAZ90OJrB33H21hjDNUvT5yUInVT54KfqL5MLj7Lxv4d8MfGI+TvtP8l QHP9OXmyOueqcgUxGxFwh8eHN/tdXXN2tVM1h2/lc4tEBFn2BWdESGnDeMUXcVFlRszp cD3RA775sOgVBm261j18ThGv6kcOWy2zQRFVaWBlCze/0jrSWvh0D1KPx4fgRpN6+lLG zgm3GYMszWrs96YHGKh86dE+a7XVKdMKHZRuZRdx6Ev4wgA/7efhq8Y0406M4mkgBC6h DzVryP91D5bR/tjyZhmHwJOGSxmM481nX6BUC05M6cLECF5nzpFse1Y5kwh+juZP1mtR 5CTg== X-Gm-Message-State: AOAM530sNPJvBkhLcNLHtZNpyPOsW2JWGAey3devw88bdgTXQ5rS5QSd LrKdZwqruK+Sx2YI7k7oukPgfGiG+KCBv6/8 X-Google-Smtp-Source: ABdhPJw+zjobUk3bsZsNBHz5f8KYQ09CDmEVT8AEnlfKTWcvZ1vGTGkZoiQvT9AnLAC/QGg5Jm6xphhWjAYSLguq X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:e348:: with SMTP id a8mr3829329qvm.49.1600204592242; Tue, 15 Sep 2020 14:16:32 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:46 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 04/37] kasan: rename (un)poison_shadow to (un)poison_memory From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: AA2DF180C0623 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. The new mode won't be using shadow memory, but will reuse the same functions. Rename kasan_unpoison_shadow to kasan_unpoison_memory, and kasan_poison_shadow to kasan_poison_memory. No functional changes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: Ia359f32815242c4704e49a5f1639ca2d2f8cba69 --- include/linux/kasan.h | 6 +++--- kernel/fork.c | 4 ++-- mm/kasan/common.c | 38 +++++++++++++++++++------------------- mm/kasan/generic.c | 12 ++++++------ mm/kasan/kasan.h | 2 +- mm/kasan/tags.c | 2 +- mm/slab_common.c | 2 +- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 44a9aae44138..18617d5c4cd7 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -60,7 +60,7 @@ extern void kasan_enable_current(void); /* Disable reporting bugs for current task */ extern void kasan_disable_current(void); -void kasan_unpoison_shadow(const void *address, size_t size); +void kasan_unpoison_memory(const void *address, size_t size); void kasan_unpoison_task_stack(struct task_struct *task); @@ -97,7 +97,7 @@ struct kasan_cache { size_t __ksize(const void *); static inline void kasan_unpoison_slab(const void *ptr) { - kasan_unpoison_shadow(ptr, __ksize(ptr)); + kasan_unpoison_memory(ptr, __ksize(ptr)); } size_t kasan_metadata_size(struct kmem_cache *cache); @@ -106,7 +106,7 @@ void kasan_restore_multi_shot(bool enabled); #else /* CONFIG_KASAN */ -static inline void kasan_unpoison_shadow(const void *address, size_t size) {} +static inline void kasan_unpoison_memory(const void *address, size_t size) {} static inline void kasan_unpoison_task_stack(struct task_struct *task) {} diff --git a/kernel/fork.c b/kernel/fork.c index 4d32190861bd..b41fecca59d7 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -224,8 +224,8 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node) if (!s) continue; - /* Clear the KASAN shadow of the stack. */ - kasan_unpoison_shadow(s->addr, THREAD_SIZE); + /* Mark stack accessible for KASAN. */ + kasan_unpoison_memory(s->addr, THREAD_SIZE); /* Clear stale pointers from reused stack. */ memset(s->addr, 0, THREAD_SIZE); diff --git a/mm/kasan/common.c b/mm/kasan/common.c index d1c987f324cd..65933b27df81 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -113,7 +113,7 @@ void *memcpy(void *dest, const void *src, size_t len) * Poisons the shadow memory for 'size' bytes starting from 'addr'. * Memory addresses should be aligned to KASAN_SHADOW_SCALE_SIZE. */ -void kasan_poison_shadow(const void *address, size_t size, u8 value) +void kasan_poison_memory(const void *address, size_t size, u8 value) { void *shadow_start, *shadow_end; @@ -130,7 +130,7 @@ void kasan_poison_shadow(const void *address, size_t size, u8 value) __memset(shadow_start, value, shadow_end - shadow_start); } -void kasan_unpoison_shadow(const void *address, size_t size) +void kasan_unpoison_memory(const void *address, size_t size) { u8 tag = get_tag(address); @@ -141,7 +141,7 @@ void kasan_unpoison_shadow(const void *address, size_t size) */ address = reset_tag(address); - kasan_poison_shadow(address, size, tag); + kasan_poison_memory(address, size, tag); if (size & KASAN_SHADOW_MASK) { u8 *shadow = (u8 *)kasan_mem_to_shadow(address + size); @@ -158,7 +158,7 @@ static void __kasan_unpoison_stack(struct task_struct *task, const void *sp) void *base = task_stack_page(task); size_t size = sp - base; - kasan_unpoison_shadow(base, size); + kasan_unpoison_memory(base, size); } /* Unpoison the entire stack for a task. */ @@ -177,7 +177,7 @@ asmlinkage void kasan_unpoison_task_stack_below(const void *watermark) */ void *base = (void *)((unsigned long)watermark & ~(THREAD_SIZE - 1)); - kasan_unpoison_shadow(base, watermark - base); + kasan_unpoison_memory(base, watermark - base); } void kasan_alloc_pages(struct page *page, unsigned int order) @@ -191,13 +191,13 @@ void kasan_alloc_pages(struct page *page, unsigned int order) tag = random_tag(); for (i = 0; i < (1 << order); i++) page_kasan_tag_set(page + i, tag); - kasan_unpoison_shadow(page_address(page), PAGE_SIZE << order); + kasan_unpoison_memory(page_address(page), PAGE_SIZE << order); } void kasan_free_pages(struct page *page, unsigned int order) { if (likely(!PageHighMem(page))) - kasan_poison_shadow(page_address(page), + kasan_poison_memory(page_address(page), PAGE_SIZE << order, KASAN_FREE_PAGE); } @@ -289,18 +289,18 @@ void kasan_poison_slab(struct page *page) for (i = 0; i < compound_nr(page); i++) page_kasan_tag_reset(page + i); - kasan_poison_shadow(page_address(page), page_size(page), + kasan_poison_memory(page_address(page), page_size(page), KASAN_KMALLOC_REDZONE); } void kasan_unpoison_object_data(struct kmem_cache *cache, void *object) { - kasan_unpoison_shadow(object, cache->object_size); + kasan_unpoison_memory(object, cache->object_size); } void kasan_poison_object_data(struct kmem_cache *cache, void *object) { - kasan_poison_shadow(object, + kasan_poison_memory(object, round_up(cache->object_size, KASAN_SHADOW_SCALE_SIZE), KASAN_KMALLOC_REDZONE); } @@ -413,7 +413,7 @@ static bool __kasan_slab_free(struct kmem_cache *cache, void *object, } rounded_up_size = round_up(cache->object_size, KASAN_SHADOW_SCALE_SIZE); - kasan_poison_shadow(object, rounded_up_size, KASAN_KMALLOC_FREE); + kasan_poison_memory(object, rounded_up_size, KASAN_KMALLOC_FREE); if ((IS_ENABLED(CONFIG_KASAN_GENERIC) && !quarantine) || unlikely(!(cache->flags & SLAB_KASAN))) @@ -453,8 +453,8 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, tag = assign_tag(cache, object, false, keep_tag); /* Tag is ignored in set_tag without CONFIG_KASAN_SW_TAGS */ - kasan_unpoison_shadow(set_tag(object, tag), size); - kasan_poison_shadow((void *)redzone_start, redzone_end - redzone_start, + kasan_unpoison_memory(set_tag(object, tag), size); + kasan_poison_memory((void *)redzone_start, redzone_end - redzone_start, KASAN_KMALLOC_REDZONE); if (cache->flags & SLAB_KASAN) @@ -494,8 +494,8 @@ void * __must_check kasan_kmalloc_large(const void *ptr, size_t size, KASAN_SHADOW_SCALE_SIZE); redzone_end = (unsigned long)ptr + page_size(page); - kasan_unpoison_shadow(ptr, size); - kasan_poison_shadow((void *)redzone_start, redzone_end - redzone_start, + kasan_unpoison_memory(ptr, size); + kasan_poison_memory((void *)redzone_start, redzone_end - redzone_start, KASAN_PAGE_REDZONE); return (void *)ptr; @@ -528,7 +528,7 @@ void kasan_poison_kfree(void *ptr, unsigned long ip) kasan_report_invalid_free(ptr, ip); return; } - kasan_poison_shadow(ptr, page_size(page), KASAN_FREE_PAGE); + kasan_poison_memory(ptr, page_size(page), KASAN_FREE_PAGE); } else { __kasan_slab_free(page->slab_cache, ptr, ip, false); } @@ -714,7 +714,7 @@ int kasan_populate_vmalloc(unsigned long addr, unsigned long size) * // vmalloc() allocates memory * // let a = area->addr * // we reach kasan_populate_vmalloc - * // and call kasan_unpoison_shadow: + * // and call kasan_unpoison_memory: * STORE shadow(a), unpoison_val * ... * STORE shadow(a+99), unpoison_val x = LOAD p @@ -749,7 +749,7 @@ void kasan_poison_vmalloc(const void *start, unsigned long size) return; size = round_up(size, KASAN_SHADOW_SCALE_SIZE); - kasan_poison_shadow(start, size, KASAN_VMALLOC_INVALID); + kasan_poison_memory(start, size, KASAN_VMALLOC_INVALID); } void kasan_unpoison_vmalloc(const void *start, unsigned long size) @@ -757,7 +757,7 @@ void kasan_unpoison_vmalloc(const void *start, unsigned long size) if (!is_vmalloc_or_module_addr(start)) return; - kasan_unpoison_shadow(start, size); + kasan_unpoison_memory(start, size); } static int kasan_depopulate_vmalloc_pte(pte_t *ptep, unsigned long addr, diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 248264b9cb76..4b5f905198d8 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -207,9 +207,9 @@ static void register_global(struct kasan_global *global) { size_t aligned_size = round_up(global->size, KASAN_SHADOW_SCALE_SIZE); - kasan_unpoison_shadow(global->beg, global->size); + kasan_unpoison_memory(global->beg, global->size); - kasan_poison_shadow(global->beg + aligned_size, + kasan_poison_memory(global->beg + aligned_size, global->size_with_redzone - aligned_size, KASAN_GLOBAL_REDZONE); } @@ -290,11 +290,11 @@ void __asan_alloca_poison(unsigned long addr, size_t size) WARN_ON(!IS_ALIGNED(addr, KASAN_ALLOCA_REDZONE_SIZE)); - kasan_unpoison_shadow((const void *)(addr + rounded_down_size), + kasan_unpoison_memory((const void *)(addr + rounded_down_size), size - rounded_down_size); - kasan_poison_shadow(left_redzone, KASAN_ALLOCA_REDZONE_SIZE, + kasan_poison_memory(left_redzone, KASAN_ALLOCA_REDZONE_SIZE, KASAN_ALLOCA_LEFT); - kasan_poison_shadow(right_redzone, + kasan_poison_memory(right_redzone, padding_size + KASAN_ALLOCA_REDZONE_SIZE, KASAN_ALLOCA_RIGHT); } @@ -306,7 +306,7 @@ void __asan_allocas_unpoison(const void *stack_top, const void *stack_bottom) if (unlikely(!stack_top || stack_top > stack_bottom)) return; - kasan_unpoison_shadow(stack_top, stack_bottom - stack_top); + kasan_unpoison_memory(stack_top, stack_bottom - stack_top); } EXPORT_SYMBOL(__asan_allocas_unpoison); diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index ac499456740f..03450d3b31f7 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -150,7 +150,7 @@ static inline bool addr_has_shadow(const void *addr) return (addr >= kasan_shadow_to_mem((void *)KASAN_SHADOW_START)); } -void kasan_poison_shadow(const void *address, size_t size, u8 value); +void kasan_poison_memory(const void *address, size_t size, u8 value); /** * check_memory_region - Check memory region, and report if invalid access. diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c index e02a36a51f42..4d5a1fe8251f 100644 --- a/mm/kasan/tags.c +++ b/mm/kasan/tags.c @@ -158,7 +158,7 @@ EXPORT_SYMBOL(__hwasan_storeN_noabort); void __hwasan_tag_memory(unsigned long addr, u8 tag, unsigned long size) { - kasan_poison_shadow((void *)addr, size, tag); + kasan_poison_memory((void *)addr, size, tag); } EXPORT_SYMBOL(__hwasan_tag_memory); diff --git a/mm/slab_common.c b/mm/slab_common.c index f9ccd5dc13f3..53d0f8bb57ea 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -1176,7 +1176,7 @@ size_t ksize(const void *objp) * We assume that ksize callers could use whole allocated area, * so we need to unpoison this area. */ - kasan_unpoison_shadow(objp, size); + kasan_unpoison_memory(objp, size); return size; } EXPORT_SYMBOL(ksize); From patchwork Tue Sep 15 21:15:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777723 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D0376CA for ; Tue, 15 Sep 2020 21:16:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2136E20770 for ; Tue, 15 Sep 2020 21:16:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="t0eTYWs7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2136E20770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2639D900072; Tue, 15 Sep 2020 17:16:38 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 19FEA900012; Tue, 15 Sep 2020 17:16:38 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0B1B900072; Tue, 15 Sep 2020 17:16:37 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0005.hostedemail.com [216.40.44.5]) by kanga.kvack.org (Postfix) with ESMTP id D0BF3900012 for ; Tue, 15 Sep 2020 17:16:37 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 999F8824999B for ; Tue, 15 Sep 2020 21:16:37 +0000 (UTC) X-FDA: 77266554834.21.story71_02037b927114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id BA9E4180442D3 for ; Tue, 15 Sep 2020 21:16:36 +0000 (UTC) X-Spam-Summary: 1,0,0,605a18ed9ef8f8c2,d41d8cd98f00b204,3mi9hxwokcbcxa0e1l7ai83bb381.zb985ahk-997ixz7.be3@flex--andreyknvl.bounces.google.com,,RULES_HIT:4:41:69:152:355:379:541:800:960:966:968:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1593:1594:1605:1730:1747:1777:1792:1981:2194:2196:2198:2199:2200:2201:2393:2559:2562:2693:2901:2903:3138:3139:3140:3141:3142:3152:3865:3866:3867:3868:3870:3871:3872:3874:4250:4321:4385:4605:5007:6119:6261:6653:6742:7903:7904:8603:9036:9969:10004:11026:11232:11473:11658:11914:12043:12048:12296:12297:12438:12555:12683:12895:12986:13161:13229:13972:14394:14659:21080:21222:21324:21365:21444:21451:21611:21627:21939:21987:21990:30003:30012:30054:30056:30069:30070:30075,0,RBL:209.85.221.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yr9rgwj14j3te576oauic48nfj8ycajqmsr16817ejwmesr7d5j8qngg4774q.bqwiys8dawhz5dt9qxnheg3nqq7h7fr3y4jsfibhsahyyc3soiq4zqtcobazh8b.q-lbl8.mailshell.net-223.238.255.10 0,CacheI X-HE-Tag: story71_02037b927114 X-Filterd-Recvd-Size: 18494 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:16:36 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id l9so1687265wrq.20 for ; Tue, 15 Sep 2020 14:16:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=XoIhA9NWDSF4RgwX3fO6DA1DH9CaH0djORIURJ0FEcY=; b=t0eTYWs73H7cw3k/cn1TA0qOyRvltHau2XqAEoAuUwrDFcOBF1DKF3Sp/Yzvnt+7ak V/Efcz6Lqq+rzto7W9cJRrxM9CC1HQEn/rox1DfQGD1RIHzAFh2Ztw6XeAr3r1Naipu4 SecoSQo+K+iWFtI4Vylkh49Ue8gXQhztfDAIIjaZQ3PQarudOLZiukEoiCAORaOqtvNu sHsKg0tQ3UQIyeeIZE8qkMiNny3xKEyP+7+KG38N/U/1CBbPLev9JdQn5ECun3ued/gJ OhkqC+9wNRcgf+8c7d7+cfxG2yD1gjGoQeeUbKHlTr+tWZpxMpwjggS2tfM+u1zhnHMf kUYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=XoIhA9NWDSF4RgwX3fO6DA1DH9CaH0djORIURJ0FEcY=; b=POtfmi2heOQ8XQCw5Sk5Qwp/jaymC127Gbjmv3/aJEoIRc00m2dOj8EHNnB/eEBPdQ qFiYsDLCVKp7mdZ3IkIaXyH7F537cruwk0HZwYZ+dxQ0QjlIq7KaUdUfFli5CStNN3th m/AE7Th0Qr7I1LTTwy3htynhDn1b9we7J15m4p0x41curZXCu7GH8sxl7jzyx6rOv6DT cNq6L/YOCHFleWR8BtumzAkcSlOnp5n9SBF/HmJQHev439ZPcMMTBcF+SkEeVHBDPtFM 7VWEhWBgQ5+j6h81ovBz6kFl5FWd4HRvq/y+KASa8rTi58AcubkIBBIJrTp5mx+RuoAP HGrw== X-Gm-Message-State: AOAM533AAh6vN7kRyh8OOIlHVIq6RSBXfvn4pj11ID3Ij42ckc+mlcpq 0sBlMpJoaz5BEiVtiV8Zw2yUcj7KneV4s1xU X-Google-Smtp-Source: ABdhPJx6bzoISoOiZ5VlEurvAbEikaZOLgZsy8NdMF63Aj2x628p40tEkflSfb95nLlKmg1F7V/Ngb6g3DitpMcP X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:9ecb:: with SMTP id h194mr1206364wme.140.1600204594842; Tue, 15 Sep 2020 14:16:34 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:47 +0200 In-Reply-To: Message-Id: <0d1862fec200eec644bbf0e2d5969fb94d2e923e.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 05/37] kasan: rename KASAN_SHADOW_* to KASAN_GRANULE_* From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: BA9E4180442D3 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. The new mode won't be using shadow memory, but will still use the concept of memory granules. Rename KASAN_SHADOW_SCALE_SIZE to KASAN_GRANULE_SIZE, and KASAN_SHADOW_MASK to KASAN_GRANULE_MASK. Also use MASK when used as a mask, otherwise use SIZE. No functional changes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: Iac733e2248aa9d29f6fc425d8946ba07cca73ecf --- Documentation/dev-tools/kasan.rst | 2 +- lib/test_kasan.c | 2 +- mm/kasan/common.c | 39 ++++++++++++++++--------------- mm/kasan/generic.c | 14 +++++------ mm/kasan/generic_report.c | 8 +++---- mm/kasan/init.c | 8 +++---- mm/kasan/kasan.h | 4 ++-- mm/kasan/report.c | 10 ++++---- mm/kasan/tags_report.c | 2 +- 9 files changed, 45 insertions(+), 44 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index 38fd5681fade..a3030fc6afe5 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -264,7 +264,7 @@ Most mappings in vmalloc space are small, requiring less than a full page of shadow space. Allocating a full shadow page per mapping would therefore be wasteful. Furthermore, to ensure that different mappings use different shadow pages, mappings would have to be aligned to -``KASAN_SHADOW_SCALE_SIZE * PAGE_SIZE``. +``KASAN_GRANULE_SIZE * PAGE_SIZE``. Instead, we share backing space across multiple mappings. We allocate a backing page when a mapping in vmalloc space uses a particular page diff --git a/lib/test_kasan.c b/lib/test_kasan.c index 53e953bb1d1d..ddd0b80f24a1 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c @@ -25,7 +25,7 @@ #include "../mm/kasan/kasan.h" -#define OOB_TAG_OFF (IS_ENABLED(CONFIG_KASAN_GENERIC) ? 0 : KASAN_SHADOW_SCALE_SIZE) +#define OOB_TAG_OFF (IS_ENABLED(CONFIG_KASAN_GENERIC) ? 0 : KASAN_GRANULE_SIZE) /* * We assign some test results to these globals to make sure the tests diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 65933b27df81..c9daf2c33651 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -111,7 +111,7 @@ void *memcpy(void *dest, const void *src, size_t len) /* * Poisons the shadow memory for 'size' bytes starting from 'addr'. - * Memory addresses should be aligned to KASAN_SHADOW_SCALE_SIZE. + * Memory addresses should be aligned to KASAN_GRANULE_SIZE. */ void kasan_poison_memory(const void *address, size_t size, u8 value) { @@ -143,13 +143,13 @@ void kasan_unpoison_memory(const void *address, size_t size) kasan_poison_memory(address, size, tag); - if (size & KASAN_SHADOW_MASK) { + if (size & KASAN_GRANULE_MASK) { u8 *shadow = (u8 *)kasan_mem_to_shadow(address + size); if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) *shadow = tag; else - *shadow = size & KASAN_SHADOW_MASK; + *shadow = size & KASAN_GRANULE_MASK; } } @@ -301,7 +301,7 @@ void kasan_unpoison_object_data(struct kmem_cache *cache, void *object) void kasan_poison_object_data(struct kmem_cache *cache, void *object) { kasan_poison_memory(object, - round_up(cache->object_size, KASAN_SHADOW_SCALE_SIZE), + round_up(cache->object_size, KASAN_GRANULE_SIZE), KASAN_KMALLOC_REDZONE); } @@ -373,7 +373,7 @@ static inline bool shadow_invalid(u8 tag, s8 shadow_byte) { if (IS_ENABLED(CONFIG_KASAN_GENERIC)) return shadow_byte < 0 || - shadow_byte >= KASAN_SHADOW_SCALE_SIZE; + shadow_byte >= KASAN_GRANULE_SIZE; /* else CONFIG_KASAN_SW_TAGS: */ if ((u8)shadow_byte == KASAN_TAG_INVALID) @@ -412,7 +412,7 @@ static bool __kasan_slab_free(struct kmem_cache *cache, void *object, return true; } - rounded_up_size = round_up(cache->object_size, KASAN_SHADOW_SCALE_SIZE); + rounded_up_size = round_up(cache->object_size, KASAN_GRANULE_SIZE); kasan_poison_memory(object, rounded_up_size, KASAN_KMALLOC_FREE); if ((IS_ENABLED(CONFIG_KASAN_GENERIC) && !quarantine) || @@ -445,9 +445,9 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, return NULL; redzone_start = round_up((unsigned long)(object + size), - KASAN_SHADOW_SCALE_SIZE); + KASAN_GRANULE_SIZE); redzone_end = round_up((unsigned long)object + cache->object_size, - KASAN_SHADOW_SCALE_SIZE); + KASAN_GRANULE_SIZE); if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) tag = assign_tag(cache, object, false, keep_tag); @@ -491,7 +491,7 @@ void * __must_check kasan_kmalloc_large(const void *ptr, size_t size, page = virt_to_page(ptr); redzone_start = round_up((unsigned long)(ptr + size), - KASAN_SHADOW_SCALE_SIZE); + KASAN_GRANULE_SIZE); redzone_end = (unsigned long)ptr + page_size(page); kasan_unpoison_memory(ptr, size); @@ -589,8 +589,8 @@ static int __meminit kasan_mem_notifier(struct notifier_block *nb, shadow_size = nr_shadow_pages << PAGE_SHIFT; shadow_end = shadow_start + shadow_size; - if (WARN_ON(mem_data->nr_pages % KASAN_SHADOW_SCALE_SIZE) || - WARN_ON(start_kaddr % (KASAN_SHADOW_SCALE_SIZE << PAGE_SHIFT))) + if (WARN_ON(mem_data->nr_pages % KASAN_GRANULE_SIZE) || + WARN_ON(start_kaddr % (KASAN_GRANULE_SIZE << PAGE_SHIFT))) return NOTIFY_BAD; switch (action) { @@ -748,7 +748,7 @@ void kasan_poison_vmalloc(const void *start, unsigned long size) if (!is_vmalloc_or_module_addr(start)) return; - size = round_up(size, KASAN_SHADOW_SCALE_SIZE); + size = round_up(size, KASAN_GRANULE_SIZE); kasan_poison_memory(start, size, KASAN_VMALLOC_INVALID); } @@ -861,22 +861,22 @@ void kasan_release_vmalloc(unsigned long start, unsigned long end, unsigned long region_start, region_end; unsigned long size; - region_start = ALIGN(start, PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE); - region_end = ALIGN_DOWN(end, PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE); + region_start = ALIGN(start, PAGE_SIZE * KASAN_GRANULE_SIZE); + region_end = ALIGN_DOWN(end, PAGE_SIZE * KASAN_GRANULE_SIZE); free_region_start = ALIGN(free_region_start, - PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE); + PAGE_SIZE * KASAN_GRANULE_SIZE); if (start != region_start && free_region_start < region_start) - region_start -= PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE; + region_start -= PAGE_SIZE * KASAN_GRANULE_SIZE; free_region_end = ALIGN_DOWN(free_region_end, - PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE); + PAGE_SIZE * KASAN_GRANULE_SIZE); if (end != region_end && free_region_end > region_end) - region_end += PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE; + region_end += PAGE_SIZE * KASAN_GRANULE_SIZE; shadow_start = kasan_mem_to_shadow((void *)region_start); shadow_end = kasan_mem_to_shadow((void *)region_end); @@ -902,7 +902,8 @@ int kasan_module_alloc(void *addr, size_t size) unsigned long shadow_start; shadow_start = (unsigned long)kasan_mem_to_shadow(addr); - scaled_size = (size + KASAN_SHADOW_MASK) >> KASAN_SHADOW_SCALE_SHIFT; + scaled_size = (size + KASAN_GRANULE_SIZE - 1) >> + KASAN_SHADOW_SCALE_SHIFT; shadow_size = round_up(scaled_size, PAGE_SIZE); if (WARN_ON(!PAGE_ALIGNED(shadow_start))) diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 4b5f905198d8..f6d68aa9872f 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -51,7 +51,7 @@ static __always_inline bool memory_is_poisoned_1(unsigned long addr) s8 shadow_value = *(s8 *)kasan_mem_to_shadow((void *)addr); if (unlikely(shadow_value)) { - s8 last_accessible_byte = addr & KASAN_SHADOW_MASK; + s8 last_accessible_byte = addr & KASAN_GRANULE_MASK; return unlikely(last_accessible_byte >= shadow_value); } @@ -67,7 +67,7 @@ static __always_inline bool memory_is_poisoned_2_4_8(unsigned long addr, * Access crosses 8(shadow size)-byte boundary. Such access maps * into 2 shadow bytes, so we need to check them both. */ - if (unlikely(((addr + size - 1) & KASAN_SHADOW_MASK) < size - 1)) + if (unlikely(((addr + size - 1) & KASAN_GRANULE_MASK) < size - 1)) return *shadow_addr || memory_is_poisoned_1(addr + size - 1); return memory_is_poisoned_1(addr + size - 1); @@ -78,7 +78,7 @@ static __always_inline bool memory_is_poisoned_16(unsigned long addr) u16 *shadow_addr = (u16 *)kasan_mem_to_shadow((void *)addr); /* Unaligned 16-bytes access maps into 3 shadow bytes. */ - if (unlikely(!IS_ALIGNED(addr, KASAN_SHADOW_SCALE_SIZE))) + if (unlikely(!IS_ALIGNED(addr, KASAN_GRANULE_SIZE))) return *shadow_addr || memory_is_poisoned_1(addr + 15); return *shadow_addr; @@ -139,7 +139,7 @@ static __always_inline bool memory_is_poisoned_n(unsigned long addr, s8 *last_shadow = (s8 *)kasan_mem_to_shadow((void *)last_byte); if (unlikely(ret != (unsigned long)last_shadow || - ((long)(last_byte & KASAN_SHADOW_MASK) >= *last_shadow))) + ((long)(last_byte & KASAN_GRANULE_MASK) >= *last_shadow))) return true; } return false; @@ -205,7 +205,7 @@ void kasan_cache_shutdown(struct kmem_cache *cache) static void register_global(struct kasan_global *global) { - size_t aligned_size = round_up(global->size, KASAN_SHADOW_SCALE_SIZE); + size_t aligned_size = round_up(global->size, KASAN_GRANULE_SIZE); kasan_unpoison_memory(global->beg, global->size); @@ -279,10 +279,10 @@ EXPORT_SYMBOL(__asan_handle_no_return); /* Emitted by compiler to poison alloca()ed objects. */ void __asan_alloca_poison(unsigned long addr, size_t size) { - size_t rounded_up_size = round_up(size, KASAN_SHADOW_SCALE_SIZE); + size_t rounded_up_size = round_up(size, KASAN_GRANULE_SIZE); size_t padding_size = round_up(size, KASAN_ALLOCA_REDZONE_SIZE) - rounded_up_size; - size_t rounded_down_size = round_down(size, KASAN_SHADOW_SCALE_SIZE); + size_t rounded_down_size = round_down(size, KASAN_GRANULE_SIZE); const void *left_redzone = (const void *)(addr - KASAN_ALLOCA_REDZONE_SIZE); diff --git a/mm/kasan/generic_report.c b/mm/kasan/generic_report.c index a38c7a9e192a..4dce1633b082 100644 --- a/mm/kasan/generic_report.c +++ b/mm/kasan/generic_report.c @@ -39,7 +39,7 @@ void *find_first_bad_addr(void *addr, size_t size) void *p = addr; while (p < addr + size && !(*(u8 *)kasan_mem_to_shadow(p))) - p += KASAN_SHADOW_SCALE_SIZE; + p += KASAN_GRANULE_SIZE; return p; } @@ -51,14 +51,14 @@ static const char *get_shadow_bug_type(struct kasan_access_info *info) shadow_addr = (u8 *)kasan_mem_to_shadow(info->first_bad_addr); /* - * If shadow byte value is in [0, KASAN_SHADOW_SCALE_SIZE) we can look + * If shadow byte value is in [0, KASAN_GRANULE_SIZE) we can look * at the next shadow byte to determine the type of the bad access. */ - if (*shadow_addr > 0 && *shadow_addr <= KASAN_SHADOW_SCALE_SIZE - 1) + if (*shadow_addr > 0 && *shadow_addr <= KASAN_GRANULE_SIZE - 1) shadow_addr++; switch (*shadow_addr) { - case 0 ... KASAN_SHADOW_SCALE_SIZE - 1: + case 0 ... KASAN_GRANULE_SIZE - 1: /* * In theory it's still possible to see these shadow values * due to a data race in the kernel code. diff --git a/mm/kasan/init.c b/mm/kasan/init.c index fe6be0be1f76..754b641c83c7 100644 --- a/mm/kasan/init.c +++ b/mm/kasan/init.c @@ -447,8 +447,8 @@ void kasan_remove_zero_shadow(void *start, unsigned long size) end = addr + (size >> KASAN_SHADOW_SCALE_SHIFT); if (WARN_ON((unsigned long)start % - (KASAN_SHADOW_SCALE_SIZE * PAGE_SIZE)) || - WARN_ON(size % (KASAN_SHADOW_SCALE_SIZE * PAGE_SIZE))) + (KASAN_GRANULE_SIZE * PAGE_SIZE)) || + WARN_ON(size % (KASAN_GRANULE_SIZE * PAGE_SIZE))) return; for (; addr < end; addr = next) { @@ -482,8 +482,8 @@ int kasan_add_zero_shadow(void *start, unsigned long size) shadow_end = shadow_start + (size >> KASAN_SHADOW_SCALE_SHIFT); if (WARN_ON((unsigned long)start % - (KASAN_SHADOW_SCALE_SIZE * PAGE_SIZE)) || - WARN_ON(size % (KASAN_SHADOW_SCALE_SIZE * PAGE_SIZE))) + (KASAN_GRANULE_SIZE * PAGE_SIZE)) || + WARN_ON(size % (KASAN_GRANULE_SIZE * PAGE_SIZE))) return -EINVAL; ret = kasan_populate_early_shadow(shadow_start, shadow_end); diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 03450d3b31f7..c31e2c739301 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -5,8 +5,8 @@ #include #include -#define KASAN_SHADOW_SCALE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT) -#define KASAN_SHADOW_MASK (KASAN_SHADOW_SCALE_SIZE - 1) +#define KASAN_GRANULE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT) +#define KASAN_GRANULE_MASK (KASAN_GRANULE_SIZE - 1) #define KASAN_TAG_KERNEL 0xFF /* native kernel pointers tag */ #define KASAN_TAG_INVALID 0xFE /* inaccessible memory tag */ diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 4f49fa6cd1aa..7c025d792e2f 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -317,24 +317,24 @@ static bool __must_check get_address_stack_frame_info(const void *addr, return false; aligned_addr = round_down((unsigned long)addr, sizeof(long)); - mem_ptr = round_down(aligned_addr, KASAN_SHADOW_SCALE_SIZE); + mem_ptr = round_down(aligned_addr, KASAN_GRANULE_SIZE); shadow_ptr = kasan_mem_to_shadow((void *)aligned_addr); shadow_bottom = kasan_mem_to_shadow(end_of_stack(current)); while (shadow_ptr >= shadow_bottom && *shadow_ptr != KASAN_STACK_LEFT) { shadow_ptr--; - mem_ptr -= KASAN_SHADOW_SCALE_SIZE; + mem_ptr -= KASAN_GRANULE_SIZE; } while (shadow_ptr >= shadow_bottom && *shadow_ptr == KASAN_STACK_LEFT) { shadow_ptr--; - mem_ptr -= KASAN_SHADOW_SCALE_SIZE; + mem_ptr -= KASAN_GRANULE_SIZE; } if (shadow_ptr < shadow_bottom) return false; - frame = (const unsigned long *)(mem_ptr + KASAN_SHADOW_SCALE_SIZE); + frame = (const unsigned long *)(mem_ptr + KASAN_GRANULE_SIZE); if (frame[0] != KASAN_CURRENT_STACK_FRAME_MAGIC) { pr_err("KASAN internal error: frame info validation failed; invalid marker: %lu\n", frame[0]); @@ -572,6 +572,6 @@ void kasan_non_canonical_hook(unsigned long addr) else bug_type = "maybe wild-memory-access"; pr_alert("KASAN: %s in range [0x%016lx-0x%016lx]\n", bug_type, - orig_addr, orig_addr + KASAN_SHADOW_MASK); + orig_addr, orig_addr + KASAN_GRANULE_SIZE - 1); } #endif diff --git a/mm/kasan/tags_report.c b/mm/kasan/tags_report.c index bee43717d6f0..6ddb55676a7c 100644 --- a/mm/kasan/tags_report.c +++ b/mm/kasan/tags_report.c @@ -81,7 +81,7 @@ void *find_first_bad_addr(void *addr, size_t size) void *end = p + size; while (p < end && tag == *(u8 *)kasan_mem_to_shadow(p)) - p += KASAN_SHADOW_SCALE_SIZE; + p += KASAN_GRANULE_SIZE; return p; } From patchwork Tue Sep 15 21:15:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777725 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8746A59D for ; Tue, 15 Sep 2020 21:16:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 44A6320770 for ; Tue, 15 Sep 2020 21:16:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="dSJTHqOZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 44A6320770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 176F8900079; Tue, 15 Sep 2020 17:16:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0D882900012; Tue, 15 Sep 2020 17:16:39 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE31C900079; Tue, 15 Sep 2020 17:16:38 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0163.hostedemail.com [216.40.44.163]) by kanga.kvack.org (Postfix) with ESMTP id D6E08900012 for ; Tue, 15 Sep 2020 17:16:38 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 982223630 for ; Tue, 15 Sep 2020 21:16:38 +0000 (UTC) X-FDA: 77266554876.17.thing28_281444b27114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 64EEA180D0181 for ; Tue, 15 Sep 2020 21:16:38 +0000 (UTC) X-Spam-Summary: 1,0,0,ca6cb15e91a53662,d41d8cd98f00b204,3ns9hxwokcbo0d3h4oadlb6ee6b4.2ecb8dkn-ccal02a.eh6@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1541:1593:1594:1711:1730:1747:1777:1792:1981:2194:2199:2393:2538:2559:2562:3138:3139:3140:3141:3142:3152:3352:3865:3866:3871:3874:4250:4321:5007:6261:6653:6742:7514:9969:10004:10400:10450:10455:11026:11232:11473:11658:11914:12043:12048:12296:12297:12438:12555:12895:13069:13161:13229:13311:13357:14096:14097:14181:14394:14659:14721:19904:19999:21080:21365:21444:21451:21627:21772:30012:30054:30067,0,RBL:209.85.219.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yfeh4d8r8jjdanoxcjidkbegz37opz6zh8nfn9p8uxxiszkq7hct7rae3s93n.ubq64iky13j8owkx8sme3izacg9uufbkoq9u4sut96u4fitemyqsqjhqb853gi3.r-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not b ulk,SPF: X-HE-Tag: thing28_281444b27114 X-Filterd-Recvd-Size: 5080 Received: from mail-qv1-f73.google.com (mail-qv1-f73.google.com [209.85.219.73]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:16:37 +0000 (UTC) Received: by mail-qv1-f73.google.com with SMTP id l29so3026977qve.18 for ; Tue, 15 Sep 2020 14:16:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=rBEpAT9/SFMGCMSd5Os7EsFNXqLe39zVSJtjGGUatVU=; b=dSJTHqOZiuuDXKvtsDQ8oQ1PqjUxDy7pC2eYouUYa/AFSAuodkr6j/TZ2jO5NgNaAc g7YofzhuPIXWqXGAttfKHdujHDCWUY1lgj8UQWTG+rsmQYy0rl997KUAGV7Dsmnv1SOm rEnBBrKjBEb3+9EL1PxJaDOkTUUwqdUTCY98t15qBwyJqlTJ8qCncGTw29O5PD3gDUMY WaoaiAZLu+iktghDPpg4OCF7suInLAbvgvxlQ5D36dLCsOCKOWCa8mV8FjAOEhEObaNn IOu6FRq2u1BojQwe6vsGpGw10jJ/Diw2orJidd+Bi3EgKSzbpa7fb2iHxoKCAW35Mbvr JYpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=rBEpAT9/SFMGCMSd5Os7EsFNXqLe39zVSJtjGGUatVU=; b=eNCfvAWdmU0wlaDeRBC+TtcGzT7ct5ctMUueJRsjhXkSgA3qrlPD5z5Ss5Lh70164E M/0qecOvEJBfr9qL7+tI2G19NCa7Gbi3W2bNtTfhfz6rV8xLlAVdUVIQjq6SlFhf3UrX KwhHOGTPwiivEZ81y9M/Iwxl76WCmO8sqVlKiJ+Pxy+CJtbtLzxuoM/rQNqy/Iw076BL cifrwXcxWZyzRZwpRsIlV3HaIZZ+U6mRYkEBttQtEs6tvBsbX5nQbRmwgXXp7lV4ceRA PVMaZcyGc3A5gRqxmv49vhTzJN5r1otASdnJpUwBZO1Qzo3Ljkv/zXrDBFwEEJIMPLKk cAgw== X-Gm-Message-State: AOAM533bEhA56kfx2YAPzAdjUklfUoTi2vyVq+ibCRhz8pDG0BR2yiM1 ffhu2tLegVgLE5KQFecSTBGVGL5CQyxqWC5n X-Google-Smtp-Source: ABdhPJwVtoNlwGtVWMSadXgwwXxS2o67SZR8HangbbD87rRH9KN5qPngrQJpmzAic4pHTiuGP2p7N8MS0/tYgX6p X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:58aa:: with SMTP id ea10mr3757654qvb.58.1600204597332; Tue, 15 Sep 2020 14:16:37 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:48 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 06/37] kasan: only build init.c for software modes From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 64EEA180D0181 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 X-Bogosity: Ham, tests=bogofilter, spamicity=0.007218, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. The new mode won't be using shadow memory, so only build init.c that contains shadow initialization code for software modes. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: I8d68c47345afc1dbedadde738f34a874dcae5080 --- mm/kasan/Makefile | 6 +++--- mm/kasan/init.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/kasan/Makefile b/mm/kasan/Makefile index 370d970e5ab5..7cf685bb51bd 100644 --- a/mm/kasan/Makefile +++ b/mm/kasan/Makefile @@ -29,6 +29,6 @@ CFLAGS_report.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_tags.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_tags_report.o := $(CC_FLAGS_KASAN_RUNTIME) -obj-$(CONFIG_KASAN) := common.o init.o report.o -obj-$(CONFIG_KASAN_GENERIC) += generic.o generic_report.o quarantine.o -obj-$(CONFIG_KASAN_SW_TAGS) += tags.o tags_report.o +obj-$(CONFIG_KASAN) := common.o report.o +obj-$(CONFIG_KASAN_GENERIC) += init.o generic.o generic_report.o quarantine.o +obj-$(CONFIG_KASAN_SW_TAGS) += init.o tags.o tags_report.o diff --git a/mm/kasan/init.c b/mm/kasan/init.c index 754b641c83c7..20f5e1ab8d95 100644 --- a/mm/kasan/init.c +++ b/mm/kasan/init.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * This file contains some kasan initialization code. + * This file contains KASAN shadow initialization code. * * Copyright (c) 2015 Samsung Electronics Co., Ltd. * Author: Andrey Ryabinin From patchwork Tue Sep 15 21:15:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777727 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 193446CA for ; Tue, 15 Sep 2020 21:16:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9D4B820770 for ; Tue, 15 Sep 2020 21:16:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="IRThtfw2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9D4B820770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C532790007A; Tue, 15 Sep 2020 17:16:41 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C0398900012; Tue, 15 Sep 2020 17:16:41 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D89490007A; Tue, 15 Sep 2020 17:16:41 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0173.hostedemail.com [216.40.44.173]) by kanga.kvack.org (Postfix) with ESMTP id 7E31B900012 for ; Tue, 15 Sep 2020 17:16:41 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 43482362E for ; Tue, 15 Sep 2020 21:16:41 +0000 (UTC) X-FDA: 77266555002.16.clock23_090092127114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 156C2100E6912 for ; Tue, 15 Sep 2020 21:16:41 +0000 (UTC) X-Spam-Summary: 1,0,0,c2360a81002847f2,d41d8cd98f00b204,3ny9hxwokcbw2f5j6qcfnd8gg8d6.4gedafmp-eecn24c.gj8@flex--andreyknvl.bounces.google.com,,RULES_HIT:69:152:327:355:379:541:960:966:967:968:973:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1593:1594:1605:1730:1747:1777:1792:1801:1981:2194:2196:2198:2199:2200:2201:2393:2525:2538:2559:2563:2682:2685:2693:2731:2859:2903:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3865:3866:3867:3868:3870:3871:3872:3873:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4385:4605:5007:6261:6653:6691:6742:7514:7875:7903:7904:8603:8660:9025:9036:9121:9592:9969:10004:11026:11232:11233:11657:11854:11914:12043:12048:12291:12296:12297:12438:12555:12683:12895:12986:13148:13161:13229:13230:14096:14097:14394:14659:21080:21324:21365:21444:21451:21627:21740:21772:21796:21939:21987:21990:30003:30012:30036:30054:30055:30067,0,RBL:209.85.160.202:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell .net-62. X-HE-Tag: clock23_090092127114 X-Filterd-Recvd-Size: 37966 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:16:40 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id j35so3995743qtk.14 for ; Tue, 15 Sep 2020 14:16:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=m6D7dHkvwjdaFH4BtYThp4DoX0Pg+nOZ+Zx/xU3JNr8=; b=IRThtfw2OiVC/m3IJTgy76Tzhg5Mym+zib7RMc7Bs0Hkd8E82Tm/LGu1Kvz8+2qMX3 5B9BGWWr78IfkImvG5IOUU2TjzMH5to0dZWi0bJ5Q+JTBfCh4lMfPlAGSqi647lkVoRL LngBQwbLWdt6lIKo6CHcAWcCwddFh/VqWgI/4zNYBLo49HwbqvREsNDAQ0UhkRLVbO2K JdbK8iEAX1Oh7E4Jes8QBeEaYhmU5hCMWq6+U5DZNHyMPL+J6kmIm0la+pM5/TXbu/t9 e7HX3W15sDklcF0LBPFX1RPndBMuu45LO391X8XKdBb9mZG1f95PUWaihH7fjueOK1sY MpDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=m6D7dHkvwjdaFH4BtYThp4DoX0Pg+nOZ+Zx/xU3JNr8=; b=kH5EwnjjN8v4ZM/pJOP9RyOszvefDNckH8XHH3q2eyx8Ko9kduWqQ/Ytw0A6HAYrtX VjNVvlsCL2Ma4tUXw0Tn5fhe0En7nQd+kgviRZM4DOwNGy4rQI2mc5UeMEy4k8KqlQ/X AiN4kKgK+2izH5FkXZGs/qLZ3ZLztxPO6wtCQaG7OU/DC1lYmYp7EYZvROLKJgFSRmHU sdIAYt0qs4XEdhfDl035NI8iy723dmMKktkgTCHlkL9c3MT4SW2l2HPgZ3mVUgEgQwzx Zc5JrEWi8KhobctZmNWEkvKgH3KRGvZkUizLqlwso+LKCump35ygnmho2bVONIntaCnM WO6g== X-Gm-Message-State: AOAM531Vzs32MbZzb7Ht5p6P5KjVnJbB2QkX64SbiUtsf8IXGcnZorZq 64vIpIVV/Nuh5vXh0+xqct8GDBw/eMiXnJUp X-Google-Smtp-Source: ABdhPJwC+Bac8VFkog5L58LOv2hGQgomm6AuwXpqTDU77SgWeP1xZ0tIBdWT4dAbTqMtUMbz8YPno45uXQXdXA6f X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:f6c4:: with SMTP id d4mr3785883qvo.41.1600204599606; Tue, 15 Sep 2020 14:16:39 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:49 +0200 In-Reply-To: Message-Id: <88c275dc4eef13c8bcbe74ecec661733dcbc67b8.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 07/37] kasan: split out shadow.c from common.c From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 156C2100E6912 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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: This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. The new mode won't be using shadow memory. Move all shadow-related code to shadow.c, which is only enabled for software KASAN modes that use shadow memory. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: Ic1c32ce72d4649848e9e6a1f2c8dd269c77673f2 --- mm/kasan/Makefile | 6 +- mm/kasan/common.c | 486 +------------------------------------------ mm/kasan/shadow.c | 509 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 514 insertions(+), 487 deletions(-) create mode 100644 mm/kasan/shadow.c diff --git a/mm/kasan/Makefile b/mm/kasan/Makefile index 7cf685bb51bd..7cc1031e1ef8 100644 --- a/mm/kasan/Makefile +++ b/mm/kasan/Makefile @@ -10,6 +10,7 @@ CFLAGS_REMOVE_generic_report.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_init.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_quarantine.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_shadow.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_tags.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_tags_report.o = $(CC_FLAGS_FTRACE) @@ -26,9 +27,10 @@ CFLAGS_generic_report.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_init.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_quarantine.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_report.o := $(CC_FLAGS_KASAN_RUNTIME) +CFLAGS_shadow.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_tags.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_tags_report.o := $(CC_FLAGS_KASAN_RUNTIME) obj-$(CONFIG_KASAN) := common.o report.o -obj-$(CONFIG_KASAN_GENERIC) += init.o generic.o generic_report.o quarantine.o -obj-$(CONFIG_KASAN_SW_TAGS) += init.o tags.o tags_report.o +obj-$(CONFIG_KASAN_GENERIC) += init.o generic.o generic_report.o shadow.o quarantine.o +obj-$(CONFIG_KASAN_SW_TAGS) += init.o shadow.o tags.o tags_report.o diff --git a/mm/kasan/common.c b/mm/kasan/common.c index c9daf2c33651..43a927e70067 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * This file contains common generic and tag-based KASAN code. + * This file contains common KASAN code. * * Copyright (c) 2014 Samsung Electronics Co., Ltd. * Author: Andrey Ryabinin @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -31,12 +30,8 @@ #include #include #include -#include #include -#include -#include - #include "kasan.h" #include "../slab.h" @@ -66,93 +61,6 @@ void kasan_disable_current(void) current->kasan_depth--; } -bool __kasan_check_read(const volatile void *p, unsigned int size) -{ - return check_memory_region((unsigned long)p, size, false, _RET_IP_); -} -EXPORT_SYMBOL(__kasan_check_read); - -bool __kasan_check_write(const volatile void *p, unsigned int size) -{ - return check_memory_region((unsigned long)p, size, true, _RET_IP_); -} -EXPORT_SYMBOL(__kasan_check_write); - -#undef memset -void *memset(void *addr, int c, size_t len) -{ - if (!check_memory_region((unsigned long)addr, len, true, _RET_IP_)) - return NULL; - - return __memset(addr, c, len); -} - -#ifdef __HAVE_ARCH_MEMMOVE -#undef memmove -void *memmove(void *dest, const void *src, size_t len) -{ - if (!check_memory_region((unsigned long)src, len, false, _RET_IP_) || - !check_memory_region((unsigned long)dest, len, true, _RET_IP_)) - return NULL; - - return __memmove(dest, src, len); -} -#endif - -#undef memcpy -void *memcpy(void *dest, const void *src, size_t len) -{ - if (!check_memory_region((unsigned long)src, len, false, _RET_IP_) || - !check_memory_region((unsigned long)dest, len, true, _RET_IP_)) - return NULL; - - return __memcpy(dest, src, len); -} - -/* - * Poisons the shadow memory for 'size' bytes starting from 'addr'. - * Memory addresses should be aligned to KASAN_GRANULE_SIZE. - */ -void kasan_poison_memory(const void *address, size_t size, u8 value) -{ - void *shadow_start, *shadow_end; - - /* - * Perform shadow offset calculation based on untagged address, as - * some of the callers (e.g. kasan_poison_object_data) pass tagged - * addresses to this function. - */ - address = reset_tag(address); - - shadow_start = kasan_mem_to_shadow(address); - shadow_end = kasan_mem_to_shadow(address + size); - - __memset(shadow_start, value, shadow_end - shadow_start); -} - -void kasan_unpoison_memory(const void *address, size_t size) -{ - u8 tag = get_tag(address); - - /* - * Perform shadow offset calculation based on untagged address, as - * some of the callers (e.g. kasan_unpoison_object_data) pass tagged - * addresses to this function. - */ - address = reset_tag(address); - - kasan_poison_memory(address, size, tag); - - if (size & KASAN_GRANULE_MASK) { - u8 *shadow = (u8 *)kasan_mem_to_shadow(address + size); - - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) - *shadow = tag; - else - *shadow = size & KASAN_GRANULE_MASK; - } -} - static void __kasan_unpoison_stack(struct task_struct *task, const void *sp) { void *base = task_stack_page(task); @@ -540,395 +448,3 @@ void kasan_kfree_large(void *ptr, unsigned long ip) kasan_report_invalid_free(ptr, ip); /* The object will be poisoned by page_alloc. */ } - -#ifdef CONFIG_MEMORY_HOTPLUG -static bool shadow_mapped(unsigned long addr) -{ - pgd_t *pgd = pgd_offset_k(addr); - p4d_t *p4d; - pud_t *pud; - pmd_t *pmd; - pte_t *pte; - - if (pgd_none(*pgd)) - return false; - p4d = p4d_offset(pgd, addr); - if (p4d_none(*p4d)) - return false; - pud = pud_offset(p4d, addr); - if (pud_none(*pud)) - return false; - - /* - * We can't use pud_large() or pud_huge(), the first one is - * arch-specific, the last one depends on HUGETLB_PAGE. So let's abuse - * pud_bad(), if pud is bad then it's bad because it's huge. - */ - if (pud_bad(*pud)) - return true; - pmd = pmd_offset(pud, addr); - if (pmd_none(*pmd)) - return false; - - if (pmd_bad(*pmd)) - return true; - pte = pte_offset_kernel(pmd, addr); - return !pte_none(*pte); -} - -static int __meminit kasan_mem_notifier(struct notifier_block *nb, - unsigned long action, void *data) -{ - struct memory_notify *mem_data = data; - unsigned long nr_shadow_pages, start_kaddr, shadow_start; - unsigned long shadow_end, shadow_size; - - nr_shadow_pages = mem_data->nr_pages >> KASAN_SHADOW_SCALE_SHIFT; - start_kaddr = (unsigned long)pfn_to_kaddr(mem_data->start_pfn); - shadow_start = (unsigned long)kasan_mem_to_shadow((void *)start_kaddr); - shadow_size = nr_shadow_pages << PAGE_SHIFT; - shadow_end = shadow_start + shadow_size; - - if (WARN_ON(mem_data->nr_pages % KASAN_GRANULE_SIZE) || - WARN_ON(start_kaddr % (KASAN_GRANULE_SIZE << PAGE_SHIFT))) - return NOTIFY_BAD; - - switch (action) { - case MEM_GOING_ONLINE: { - void *ret; - - /* - * If shadow is mapped already than it must have been mapped - * during the boot. This could happen if we onlining previously - * offlined memory. - */ - if (shadow_mapped(shadow_start)) - return NOTIFY_OK; - - ret = __vmalloc_node_range(shadow_size, PAGE_SIZE, shadow_start, - shadow_end, GFP_KERNEL, - PAGE_KERNEL, VM_NO_GUARD, - pfn_to_nid(mem_data->start_pfn), - __builtin_return_address(0)); - if (!ret) - return NOTIFY_BAD; - - kmemleak_ignore(ret); - return NOTIFY_OK; - } - case MEM_CANCEL_ONLINE: - case MEM_OFFLINE: { - struct vm_struct *vm; - - /* - * shadow_start was either mapped during boot by kasan_init() - * or during memory online by __vmalloc_node_range(). - * In the latter case we can use vfree() to free shadow. - * Non-NULL result of the find_vm_area() will tell us if - * that was the second case. - * - * Currently it's not possible to free shadow mapped - * during boot by kasan_init(). It's because the code - * to do that hasn't been written yet. So we'll just - * leak the memory. - */ - vm = find_vm_area((void *)shadow_start); - if (vm) - vfree((void *)shadow_start); - } - } - - return NOTIFY_OK; -} - -static int __init kasan_memhotplug_init(void) -{ - hotplug_memory_notifier(kasan_mem_notifier, 0); - - return 0; -} - -core_initcall(kasan_memhotplug_init); -#endif - -#ifdef CONFIG_KASAN_VMALLOC - -static int kasan_populate_vmalloc_pte(pte_t *ptep, unsigned long addr, - void *unused) -{ - unsigned long page; - pte_t pte; - - if (likely(!pte_none(*ptep))) - return 0; - - page = __get_free_page(GFP_KERNEL); - if (!page) - return -ENOMEM; - - memset((void *)page, KASAN_VMALLOC_INVALID, PAGE_SIZE); - pte = pfn_pte(PFN_DOWN(__pa(page)), PAGE_KERNEL); - - spin_lock(&init_mm.page_table_lock); - if (likely(pte_none(*ptep))) { - set_pte_at(&init_mm, addr, ptep, pte); - page = 0; - } - spin_unlock(&init_mm.page_table_lock); - if (page) - free_page(page); - return 0; -} - -int kasan_populate_vmalloc(unsigned long addr, unsigned long size) -{ - unsigned long shadow_start, shadow_end; - int ret; - - if (!is_vmalloc_or_module_addr((void *)addr)) - return 0; - - shadow_start = (unsigned long)kasan_mem_to_shadow((void *)addr); - shadow_start = ALIGN_DOWN(shadow_start, PAGE_SIZE); - shadow_end = (unsigned long)kasan_mem_to_shadow((void *)addr + size); - shadow_end = ALIGN(shadow_end, PAGE_SIZE); - - ret = apply_to_page_range(&init_mm, shadow_start, - shadow_end - shadow_start, - kasan_populate_vmalloc_pte, NULL); - if (ret) - return ret; - - flush_cache_vmap(shadow_start, shadow_end); - - /* - * We need to be careful about inter-cpu effects here. Consider: - * - * CPU#0 CPU#1 - * WRITE_ONCE(p, vmalloc(100)); while (x = READ_ONCE(p)) ; - * p[99] = 1; - * - * With compiler instrumentation, that ends up looking like this: - * - * CPU#0 CPU#1 - * // vmalloc() allocates memory - * // let a = area->addr - * // we reach kasan_populate_vmalloc - * // and call kasan_unpoison_memory: - * STORE shadow(a), unpoison_val - * ... - * STORE shadow(a+99), unpoison_val x = LOAD p - * // rest of vmalloc process - * STORE p, a LOAD shadow(x+99) - * - * If there is no barrier between the end of unpoisioning the shadow - * and the store of the result to p, the stores could be committed - * in a different order by CPU#0, and CPU#1 could erroneously observe - * poison in the shadow. - * - * We need some sort of barrier between the stores. - * - * In the vmalloc() case, this is provided by a smp_wmb() in - * clear_vm_uninitialized_flag(). In the per-cpu allocator and in - * get_vm_area() and friends, the caller gets shadow allocated but - * doesn't have any pages mapped into the virtual address space that - * has been reserved. Mapping those pages in will involve taking and - * releasing a page-table lock, which will provide the barrier. - */ - - return 0; -} - -/* - * Poison the shadow for a vmalloc region. Called as part of the - * freeing process at the time the region is freed. - */ -void kasan_poison_vmalloc(const void *start, unsigned long size) -{ - if (!is_vmalloc_or_module_addr(start)) - return; - - size = round_up(size, KASAN_GRANULE_SIZE); - kasan_poison_memory(start, size, KASAN_VMALLOC_INVALID); -} - -void kasan_unpoison_vmalloc(const void *start, unsigned long size) -{ - if (!is_vmalloc_or_module_addr(start)) - return; - - kasan_unpoison_memory(start, size); -} - -static int kasan_depopulate_vmalloc_pte(pte_t *ptep, unsigned long addr, - void *unused) -{ - unsigned long page; - - page = (unsigned long)__va(pte_pfn(*ptep) << PAGE_SHIFT); - - spin_lock(&init_mm.page_table_lock); - - if (likely(!pte_none(*ptep))) { - pte_clear(&init_mm, addr, ptep); - free_page(page); - } - spin_unlock(&init_mm.page_table_lock); - - return 0; -} - -/* - * Release the backing for the vmalloc region [start, end), which - * lies within the free region [free_region_start, free_region_end). - * - * This can be run lazily, long after the region was freed. It runs - * under vmap_area_lock, so it's not safe to interact with the vmalloc/vmap - * infrastructure. - * - * How does this work? - * ------------------- - * - * We have a region that is page aligned, labelled as A. - * That might not map onto the shadow in a way that is page-aligned: - * - * start end - * v v - * |????????|????????|AAAAAAAA|AA....AA|AAAAAAAA|????????| < vmalloc - * -------- -------- -------- -------- -------- - * | | | | | - * | | | /-------/ | - * \-------\|/------/ |/---------------/ - * ||| || - * |??AAAAAA|AAAAAAAA|AA??????| < shadow - * (1) (2) (3) - * - * First we align the start upwards and the end downwards, so that the - * shadow of the region aligns with shadow page boundaries. In the - * example, this gives us the shadow page (2). This is the shadow entirely - * covered by this allocation. - * - * Then we have the tricky bits. We want to know if we can free the - * partially covered shadow pages - (1) and (3) in the example. For this, - * we are given the start and end of the free region that contains this - * allocation. Extending our previous example, we could have: - * - * free_region_start free_region_end - * | start end | - * v v v v - * |FFFFFFFF|FFFFFFFF|AAAAAAAA|AA....AA|AAAAAAAA|FFFFFFFF| < vmalloc - * -------- -------- -------- -------- -------- - * | | | | | - * | | | /-------/ | - * \-------\|/------/ |/---------------/ - * ||| || - * |FFAAAAAA|AAAAAAAA|AAF?????| < shadow - * (1) (2) (3) - * - * Once again, we align the start of the free region up, and the end of - * the free region down so that the shadow is page aligned. So we can free - * page (1) - we know no allocation currently uses anything in that page, - * because all of it is in the vmalloc free region. But we cannot free - * page (3), because we can't be sure that the rest of it is unused. - * - * We only consider pages that contain part of the original region for - * freeing: we don't try to free other pages from the free region or we'd - * end up trying to free huge chunks of virtual address space. - * - * Concurrency - * ----------- - * - * How do we know that we're not freeing a page that is simultaneously - * being used for a fresh allocation in kasan_populate_vmalloc(_pte)? - * - * We _can_ have kasan_release_vmalloc and kasan_populate_vmalloc running - * at the same time. While we run under free_vmap_area_lock, the population - * code does not. - * - * free_vmap_area_lock instead operates to ensure that the larger range - * [free_region_start, free_region_end) is safe: because __alloc_vmap_area and - * the per-cpu region-finding algorithm both run under free_vmap_area_lock, - * no space identified as free will become used while we are running. This - * means that so long as we are careful with alignment and only free shadow - * pages entirely covered by the free region, we will not run in to any - * trouble - any simultaneous allocations will be for disjoint regions. - */ -void kasan_release_vmalloc(unsigned long start, unsigned long end, - unsigned long free_region_start, - unsigned long free_region_end) -{ - void *shadow_start, *shadow_end; - unsigned long region_start, region_end; - unsigned long size; - - region_start = ALIGN(start, PAGE_SIZE * KASAN_GRANULE_SIZE); - region_end = ALIGN_DOWN(end, PAGE_SIZE * KASAN_GRANULE_SIZE); - - free_region_start = ALIGN(free_region_start, - PAGE_SIZE * KASAN_GRANULE_SIZE); - - if (start != region_start && - free_region_start < region_start) - region_start -= PAGE_SIZE * KASAN_GRANULE_SIZE; - - free_region_end = ALIGN_DOWN(free_region_end, - PAGE_SIZE * KASAN_GRANULE_SIZE); - - if (end != region_end && - free_region_end > region_end) - region_end += PAGE_SIZE * KASAN_GRANULE_SIZE; - - shadow_start = kasan_mem_to_shadow((void *)region_start); - shadow_end = kasan_mem_to_shadow((void *)region_end); - - if (shadow_end > shadow_start) { - size = shadow_end - shadow_start; - apply_to_existing_page_range(&init_mm, - (unsigned long)shadow_start, - size, kasan_depopulate_vmalloc_pte, - NULL); - flush_tlb_kernel_range((unsigned long)shadow_start, - (unsigned long)shadow_end); - } -} - -#else /* CONFIG_KASAN_VMALLOC */ - -int kasan_module_alloc(void *addr, size_t size) -{ - void *ret; - size_t scaled_size; - size_t shadow_size; - unsigned long shadow_start; - - shadow_start = (unsigned long)kasan_mem_to_shadow(addr); - scaled_size = (size + KASAN_GRANULE_SIZE - 1) >> - KASAN_SHADOW_SCALE_SHIFT; - shadow_size = round_up(scaled_size, PAGE_SIZE); - - if (WARN_ON(!PAGE_ALIGNED(shadow_start))) - return -EINVAL; - - ret = __vmalloc_node_range(shadow_size, 1, shadow_start, - shadow_start + shadow_size, - GFP_KERNEL, - PAGE_KERNEL, VM_NO_GUARD, NUMA_NO_NODE, - __builtin_return_address(0)); - - if (ret) { - __memset(ret, KASAN_SHADOW_INIT, shadow_size); - find_vm_area(addr)->flags |= VM_KASAN; - kmemleak_ignore(ret); - return 0; - } - - return -ENOMEM; -} - -void kasan_free_shadow(const struct vm_struct *vm) -{ - if (vm->flags & VM_KASAN) - vfree(kasan_mem_to_shadow(vm->addr)); -} - -#endif diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c new file mode 100644 index 000000000000..4888084ecdfc --- /dev/null +++ b/mm/kasan/shadow.c @@ -0,0 +1,509 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This file contains KASAN shadow runtime code. + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Author: Andrey Ryabinin + * + * Some code borrowed from https://github.com/xairy/kasan-prototype by + * Andrey Konovalov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "kasan.h" + +bool __kasan_check_read(const volatile void *p, unsigned int size) +{ + return check_memory_region((unsigned long)p, size, false, _RET_IP_); +} +EXPORT_SYMBOL(__kasan_check_read); + +bool __kasan_check_write(const volatile void *p, unsigned int size) +{ + return check_memory_region((unsigned long)p, size, true, _RET_IP_); +} +EXPORT_SYMBOL(__kasan_check_write); + +#undef memset +void *memset(void *addr, int c, size_t len) +{ + if (!check_memory_region((unsigned long)addr, len, true, _RET_IP_)) + return NULL; + + return __memset(addr, c, len); +} + +#ifdef __HAVE_ARCH_MEMMOVE +#undef memmove +void *memmove(void *dest, const void *src, size_t len) +{ + if (!check_memory_region((unsigned long)src, len, false, _RET_IP_) || + !check_memory_region((unsigned long)dest, len, true, _RET_IP_)) + return NULL; + + return __memmove(dest, src, len); +} +#endif + +#undef memcpy +void *memcpy(void *dest, const void *src, size_t len) +{ + if (!check_memory_region((unsigned long)src, len, false, _RET_IP_) || + !check_memory_region((unsigned long)dest, len, true, _RET_IP_)) + return NULL; + + return __memcpy(dest, src, len); +} + +/* + * Poisons the shadow memory for 'size' bytes starting from 'addr'. + * Memory addresses should be aligned to KASAN_GRANULE_SIZE. + */ +void kasan_poison_memory(const void *address, size_t size, u8 value) +{ + void *shadow_start, *shadow_end; + + /* + * Perform shadow offset calculation based on untagged address, as + * some of the callers (e.g. kasan_poison_object_data) pass tagged + * addresses to this function. + */ + address = reset_tag(address); + + shadow_start = kasan_mem_to_shadow(address); + shadow_end = kasan_mem_to_shadow(address + size); + + __memset(shadow_start, value, shadow_end - shadow_start); +} + +void kasan_unpoison_memory(const void *address, size_t size) +{ + u8 tag = get_tag(address); + + /* + * Perform shadow offset calculation based on untagged address, as + * some of the callers (e.g. kasan_unpoison_object_data) pass tagged + * addresses to this function. + */ + address = reset_tag(address); + + kasan_poison_memory(address, size, tag); + + if (size & KASAN_GRANULE_MASK) { + u8 *shadow = (u8 *)kasan_mem_to_shadow(address + size); + + if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) + *shadow = tag; + else + *shadow = size & KASAN_GRANULE_MASK; + } +} + +#ifdef CONFIG_MEMORY_HOTPLUG +static bool shadow_mapped(unsigned long addr) +{ + pgd_t *pgd = pgd_offset_k(addr); + p4d_t *p4d; + pud_t *pud; + pmd_t *pmd; + pte_t *pte; + + if (pgd_none(*pgd)) + return false; + p4d = p4d_offset(pgd, addr); + if (p4d_none(*p4d)) + return false; + pud = pud_offset(p4d, addr); + if (pud_none(*pud)) + return false; + + /* + * We can't use pud_large() or pud_huge(), the first one is + * arch-specific, the last one depends on HUGETLB_PAGE. So let's abuse + * pud_bad(), if pud is bad then it's bad because it's huge. + */ + if (pud_bad(*pud)) + return true; + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + return false; + + if (pmd_bad(*pmd)) + return true; + pte = pte_offset_kernel(pmd, addr); + return !pte_none(*pte); +} + +static int __meminit kasan_mem_notifier(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct memory_notify *mem_data = data; + unsigned long nr_shadow_pages, start_kaddr, shadow_start; + unsigned long shadow_end, shadow_size; + + nr_shadow_pages = mem_data->nr_pages >> KASAN_SHADOW_SCALE_SHIFT; + start_kaddr = (unsigned long)pfn_to_kaddr(mem_data->start_pfn); + shadow_start = (unsigned long)kasan_mem_to_shadow((void *)start_kaddr); + shadow_size = nr_shadow_pages << PAGE_SHIFT; + shadow_end = shadow_start + shadow_size; + + if (WARN_ON(mem_data->nr_pages % KASAN_GRANULE_SIZE) || + WARN_ON(start_kaddr % (KASAN_GRANULE_SIZE << PAGE_SHIFT))) + return NOTIFY_BAD; + + switch (action) { + case MEM_GOING_ONLINE: { + void *ret; + + /* + * If shadow is mapped already than it must have been mapped + * during the boot. This could happen if we onlining previously + * offlined memory. + */ + if (shadow_mapped(shadow_start)) + return NOTIFY_OK; + + ret = __vmalloc_node_range(shadow_size, PAGE_SIZE, shadow_start, + shadow_end, GFP_KERNEL, + PAGE_KERNEL, VM_NO_GUARD, + pfn_to_nid(mem_data->start_pfn), + __builtin_return_address(0)); + if (!ret) + return NOTIFY_BAD; + + kmemleak_ignore(ret); + return NOTIFY_OK; + } + case MEM_CANCEL_ONLINE: + case MEM_OFFLINE: { + struct vm_struct *vm; + + /* + * shadow_start was either mapped during boot by kasan_init() + * or during memory online by __vmalloc_node_range(). + * In the latter case we can use vfree() to free shadow. + * Non-NULL result of the find_vm_area() will tell us if + * that was the second case. + * + * Currently it's not possible to free shadow mapped + * during boot by kasan_init(). It's because the code + * to do that hasn't been written yet. So we'll just + * leak the memory. + */ + vm = find_vm_area((void *)shadow_start); + if (vm) + vfree((void *)shadow_start); + } + } + + return NOTIFY_OK; +} + +static int __init kasan_memhotplug_init(void) +{ + hotplug_memory_notifier(kasan_mem_notifier, 0); + + return 0; +} + +core_initcall(kasan_memhotplug_init); +#endif + +#ifdef CONFIG_KASAN_VMALLOC + +static int kasan_populate_vmalloc_pte(pte_t *ptep, unsigned long addr, + void *unused) +{ + unsigned long page; + pte_t pte; + + if (likely(!pte_none(*ptep))) + return 0; + + page = __get_free_page(GFP_KERNEL); + if (!page) + return -ENOMEM; + + memset((void *)page, KASAN_VMALLOC_INVALID, PAGE_SIZE); + pte = pfn_pte(PFN_DOWN(__pa(page)), PAGE_KERNEL); + + spin_lock(&init_mm.page_table_lock); + if (likely(pte_none(*ptep))) { + set_pte_at(&init_mm, addr, ptep, pte); + page = 0; + } + spin_unlock(&init_mm.page_table_lock); + if (page) + free_page(page); + return 0; +} + +int kasan_populate_vmalloc(unsigned long addr, unsigned long size) +{ + unsigned long shadow_start, shadow_end; + int ret; + + if (!is_vmalloc_or_module_addr((void *)addr)) + return 0; + + shadow_start = (unsigned long)kasan_mem_to_shadow((void *)addr); + shadow_start = ALIGN_DOWN(shadow_start, PAGE_SIZE); + shadow_end = (unsigned long)kasan_mem_to_shadow((void *)addr + size); + shadow_end = ALIGN(shadow_end, PAGE_SIZE); + + ret = apply_to_page_range(&init_mm, shadow_start, + shadow_end - shadow_start, + kasan_populate_vmalloc_pte, NULL); + if (ret) + return ret; + + flush_cache_vmap(shadow_start, shadow_end); + + /* + * We need to be careful about inter-cpu effects here. Consider: + * + * CPU#0 CPU#1 + * WRITE_ONCE(p, vmalloc(100)); while (x = READ_ONCE(p)) ; + * p[99] = 1; + * + * With compiler instrumentation, that ends up looking like this: + * + * CPU#0 CPU#1 + * // vmalloc() allocates memory + * // let a = area->addr + * // we reach kasan_populate_vmalloc + * // and call kasan_unpoison_memory: + * STORE shadow(a), unpoison_val + * ... + * STORE shadow(a+99), unpoison_val x = LOAD p + * // rest of vmalloc process + * STORE p, a LOAD shadow(x+99) + * + * If there is no barrier between the end of unpoisioning the shadow + * and the store of the result to p, the stores could be committed + * in a different order by CPU#0, and CPU#1 could erroneously observe + * poison in the shadow. + * + * We need some sort of barrier between the stores. + * + * In the vmalloc() case, this is provided by a smp_wmb() in + * clear_vm_uninitialized_flag(). In the per-cpu allocator and in + * get_vm_area() and friends, the caller gets shadow allocated but + * doesn't have any pages mapped into the virtual address space that + * has been reserved. Mapping those pages in will involve taking and + * releasing a page-table lock, which will provide the barrier. + */ + + return 0; +} + +/* + * Poison the shadow for a vmalloc region. Called as part of the + * freeing process at the time the region is freed. + */ +void kasan_poison_vmalloc(const void *start, unsigned long size) +{ + if (!is_vmalloc_or_module_addr(start)) + return; + + size = round_up(size, KASAN_GRANULE_SIZE); + kasan_poison_memory(start, size, KASAN_VMALLOC_INVALID); +} + +void kasan_unpoison_vmalloc(const void *start, unsigned long size) +{ + if (!is_vmalloc_or_module_addr(start)) + return; + + kasan_unpoison_memory(start, size); +} + +static int kasan_depopulate_vmalloc_pte(pte_t *ptep, unsigned long addr, + void *unused) +{ + unsigned long page; + + page = (unsigned long)__va(pte_pfn(*ptep) << PAGE_SHIFT); + + spin_lock(&init_mm.page_table_lock); + + if (likely(!pte_none(*ptep))) { + pte_clear(&init_mm, addr, ptep); + free_page(page); + } + spin_unlock(&init_mm.page_table_lock); + + return 0; +} + +/* + * Release the backing for the vmalloc region [start, end), which + * lies within the free region [free_region_start, free_region_end). + * + * This can be run lazily, long after the region was freed. It runs + * under vmap_area_lock, so it's not safe to interact with the vmalloc/vmap + * infrastructure. + * + * How does this work? + * ------------------- + * + * We have a region that is page aligned, labelled as A. + * That might not map onto the shadow in a way that is page-aligned: + * + * start end + * v v + * |????????|????????|AAAAAAAA|AA....AA|AAAAAAAA|????????| < vmalloc + * -------- -------- -------- -------- -------- + * | | | | | + * | | | /-------/ | + * \-------\|/------/ |/---------------/ + * ||| || + * |??AAAAAA|AAAAAAAA|AA??????| < shadow + * (1) (2) (3) + * + * First we align the start upwards and the end downwards, so that the + * shadow of the region aligns with shadow page boundaries. In the + * example, this gives us the shadow page (2). This is the shadow entirely + * covered by this allocation. + * + * Then we have the tricky bits. We want to know if we can free the + * partially covered shadow pages - (1) and (3) in the example. For this, + * we are given the start and end of the free region that contains this + * allocation. Extending our previous example, we could have: + * + * free_region_start free_region_end + * | start end | + * v v v v + * |FFFFFFFF|FFFFFFFF|AAAAAAAA|AA....AA|AAAAAAAA|FFFFFFFF| < vmalloc + * -------- -------- -------- -------- -------- + * | | | | | + * | | | /-------/ | + * \-------\|/------/ |/---------------/ + * ||| || + * |FFAAAAAA|AAAAAAAA|AAF?????| < shadow + * (1) (2) (3) + * + * Once again, we align the start of the free region up, and the end of + * the free region down so that the shadow is page aligned. So we can free + * page (1) - we know no allocation currently uses anything in that page, + * because all of it is in the vmalloc free region. But we cannot free + * page (3), because we can't be sure that the rest of it is unused. + * + * We only consider pages that contain part of the original region for + * freeing: we don't try to free other pages from the free region or we'd + * end up trying to free huge chunks of virtual address space. + * + * Concurrency + * ----------- + * + * How do we know that we're not freeing a page that is simultaneously + * being used for a fresh allocation in kasan_populate_vmalloc(_pte)? + * + * We _can_ have kasan_release_vmalloc and kasan_populate_vmalloc running + * at the same time. While we run under free_vmap_area_lock, the population + * code does not. + * + * free_vmap_area_lock instead operates to ensure that the larger range + * [free_region_start, free_region_end) is safe: because __alloc_vmap_area and + * the per-cpu region-finding algorithm both run under free_vmap_area_lock, + * no space identified as free will become used while we are running. This + * means that so long as we are careful with alignment and only free shadow + * pages entirely covered by the free region, we will not run in to any + * trouble - any simultaneous allocations will be for disjoint regions. + */ +void kasan_release_vmalloc(unsigned long start, unsigned long end, + unsigned long free_region_start, + unsigned long free_region_end) +{ + void *shadow_start, *shadow_end; + unsigned long region_start, region_end; + unsigned long size; + + region_start = ALIGN(start, PAGE_SIZE * KASAN_GRANULE_SIZE); + region_end = ALIGN_DOWN(end, PAGE_SIZE * KASAN_GRANULE_SIZE); + + free_region_start = ALIGN(free_region_start, + PAGE_SIZE * KASAN_GRANULE_SIZE); + + if (start != region_start && + free_region_start < region_start) + region_start -= PAGE_SIZE * KASAN_GRANULE_SIZE; + + free_region_end = ALIGN_DOWN(free_region_end, + PAGE_SIZE * KASAN_GRANULE_SIZE); + + if (end != region_end && + free_region_end > region_end) + region_end += PAGE_SIZE * KASAN_GRANULE_SIZE; + + shadow_start = kasan_mem_to_shadow((void *)region_start); + shadow_end = kasan_mem_to_shadow((void *)region_end); + + if (shadow_end > shadow_start) { + size = shadow_end - shadow_start; + apply_to_existing_page_range(&init_mm, + (unsigned long)shadow_start, + size, kasan_depopulate_vmalloc_pte, + NULL); + flush_tlb_kernel_range((unsigned long)shadow_start, + (unsigned long)shadow_end); + } +} + +#else /* CONFIG_KASAN_VMALLOC */ + +int kasan_module_alloc(void *addr, size_t size) +{ + void *ret; + size_t scaled_size; + size_t shadow_size; + unsigned long shadow_start; + + shadow_start = (unsigned long)kasan_mem_to_shadow(addr); + scaled_size = (size + KASAN_GRANULE_SIZE - 1) >> + KASAN_SHADOW_SCALE_SHIFT; + shadow_size = round_up(scaled_size, PAGE_SIZE); + + if (WARN_ON(!PAGE_ALIGNED(shadow_start))) + return -EINVAL; + + ret = __vmalloc_node_range(shadow_size, 1, shadow_start, + shadow_start + shadow_size, + GFP_KERNEL, + PAGE_KERNEL, VM_NO_GUARD, NUMA_NO_NODE, + __builtin_return_address(0)); + + if (ret) { + __memset(ret, KASAN_SHADOW_INIT, shadow_size); + find_vm_area(addr)->flags |= VM_KASAN; + kmemleak_ignore(ret); + return 0; + } + + return -ENOMEM; +} + +void kasan_free_shadow(const struct vm_struct *vm) +{ + if (vm->flags & VM_KASAN) + vfree(kasan_mem_to_shadow(vm->addr)); +} + +#endif From patchwork Tue Sep 15 21:15:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777729 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4448F59D for ; Tue, 15 Sep 2020 21:16:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 08CAC20770 for ; Tue, 15 Sep 2020 21:16:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="X1G6wMyZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 08CAC20770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BD77990007B; Tue, 15 Sep 2020 17:16:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B38AA900012; Tue, 15 Sep 2020 17:16:43 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98A6C90007B; Tue, 15 Sep 2020 17:16:43 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id 8141E900012 for ; Tue, 15 Sep 2020 17:16:43 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 48E29362C for ; Tue, 15 Sep 2020 21:16:43 +0000 (UTC) X-FDA: 77266555086.06.unit36_20126dd27114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 1765210057567 for ; Tue, 15 Sep 2020 21:16:43 +0000 (UTC) X-Spam-Summary: 50,3,0,bdcb919ac817f2b0,d41d8cd98f00b204,3os9hxwokcb44h7l8sehpfaiiaf8.6igfchor-ggep46e.ila@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:967:968:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:1801:1978:1981:2178:2194:2199:2393:2525:2538:2559:2563:2682:2685:2859:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3353:3867:3868:3870:3871:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4117:4250:4321:4605:5007:6261:6653:6742:7514:8784:9025:9969:10004:10400:11026:11232:11473:11657:11658:11914:12043:12048:12296:12297:12438:12555:12679:12698:12737:12895:12986:13161:13221:13229:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:30012:30054:30067,0,RBL:209.85.160.201:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yg47nsj6xdpfm8doot8jitmii76yce4med4k7ysd6pytgk6sbwh85b9rod7fd.7p8eikwu8is8f5r7h5up4ga8wagzu 594bj7uy X-HE-Tag: unit36_20126dd27114 X-Filterd-Recvd-Size: 6859 Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:16:42 +0000 (UTC) Received: by mail-qt1-f201.google.com with SMTP id a26so3974335qtb.16 for ; Tue, 15 Sep 2020 14:16:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=lWHaJYmPEYXJBP/uBzeOe/Zb1P7kD+TOmnHXvVDLg6g=; b=X1G6wMyZnS0lFwntgqQ3I+0XIixMw148p5tbu1Ca6n2GwNII42i1iBjxsCHJ8bLWEJ brbOGV4PIS1Mcw3TfpsrgNLfQWcuCIQzUJp6f6nciACXJz9boNIsBAlbCC8OyLXJSFyH rDDwtuz3J04t0BH/IxWmJTFa7xsdSGeULeEQFiSjvX9vqXI/YxpHK0hwzfJfHIzdLmLP Xwk+JPV5ovdJuVAA66KoTuD6R0X723FVzVo9zgSHwXCD8b/Hi39h/A+tpvWab2kk8WoT KTO5x+ZN1f60CPDjPwmgKRz8X0x//OW+xCS5sM0WaeBCIR+C2agcD0lHuQmWYd0yZBlU hrdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=lWHaJYmPEYXJBP/uBzeOe/Zb1P7kD+TOmnHXvVDLg6g=; b=tKzMtqdfPo9xcUNN2DTxAXGE+dAgvmkd8eswX1C1M0+c8+55ij88f2bmK7c0uzgyDb AkSMb1DrM8H1md0H8+8fGURLbvHYyAofdhu0KVmuHlCSxXF/OA9ww4KdPN94KZP6WJT8 /RhJvg2HvTZXrTpbCj6xJ9LdD2HIpP95mLZaaOFyFE06QWqnSF7qExMb7ougYDzcYKi8 6jqRU9hWY2kJ6cc/h3XFNJ622BJI8QzSysjNd1okATZmgmxQQVJr8eC7LDyPvvkOd329 YzQHK/yr2k1zH7IBPEx7VYIqsQzQYLmWIhry+LGBp9Jer95YW4bBqDq/0ZDG4NBC5ie4 k7eg== X-Gm-Message-State: AOAM532xo3kkZnZ8JLp+KI2hb+Qg5cWX0IWWUM8s84Y1yDdu5E7g6ExL QXTtIkUspOkG9/4ll6KDo6f1U7WSjdEy3z6+ X-Google-Smtp-Source: ABdhPJzqx2nBY54AKA197aaxoxbVynCv9f/Nxd6C3jrVPdy9Fw9LOLQht1+nWsZCHmX9VM/m02HSqlFAfZiI/P4r X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:4891:: with SMTP id bv17mr20207397qvb.27.1600204601843; Tue, 15 Sep 2020 14:16:41 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:50 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 08/37] kasan: rename generic/tags_report.c files From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 1765210057567 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Rename generic_report.c to report_generic.c and tags_report.c to report_tags.c, as their content is more relevant to report.c file, then to generic.c or tags.c. No functional changes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: If77d21f655d52ef3e58c4c37fd6621a07f505f18 --- mm/kasan/Makefile | 12 ++++++------ mm/kasan/report.c | 2 +- mm/kasan/{generic_report.c => report_generic.c} | 0 mm/kasan/{tags_report.c => report_tags.c} | 0 4 files changed, 7 insertions(+), 7 deletions(-) rename mm/kasan/{generic_report.c => report_generic.c} (100%) rename mm/kasan/{tags_report.c => report_tags.c} (100%) diff --git a/mm/kasan/Makefile b/mm/kasan/Makefile index 7cc1031e1ef8..b2596512421a 100644 --- a/mm/kasan/Makefile +++ b/mm/kasan/Makefile @@ -6,13 +6,13 @@ KCOV_INSTRUMENT := n # Disable ftrace to avoid recursion. CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_generic.o = $(CC_FLAGS_FTRACE) -CFLAGS_REMOVE_generic_report.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_init.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_quarantine.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_report_generic.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_report_tags.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_shadow.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_tags.o = $(CC_FLAGS_FTRACE) -CFLAGS_REMOVE_tags_report.o = $(CC_FLAGS_FTRACE) # Function splitter causes unnecessary splits in __asan_load1/__asan_store1 # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533 @@ -23,14 +23,14 @@ CC_FLAGS_KASAN_RUNTIME += -DDISABLE_BRANCH_PROFILING CFLAGS_common.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_generic.o := $(CC_FLAGS_KASAN_RUNTIME) -CFLAGS_generic_report.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_init.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_quarantine.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_report.o := $(CC_FLAGS_KASAN_RUNTIME) +CFLAGS_report_generic.o := $(CC_FLAGS_KASAN_RUNTIME) +CFLAGS_report_tags.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_shadow.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_tags.o := $(CC_FLAGS_KASAN_RUNTIME) -CFLAGS_tags_report.o := $(CC_FLAGS_KASAN_RUNTIME) obj-$(CONFIG_KASAN) := common.o report.o -obj-$(CONFIG_KASAN_GENERIC) += init.o generic.o generic_report.o shadow.o quarantine.o -obj-$(CONFIG_KASAN_SW_TAGS) += init.o shadow.o tags.o tags_report.o +obj-$(CONFIG_KASAN_GENERIC) += init.o generic.o report_generic.o shadow.o quarantine.o +obj-$(CONFIG_KASAN_SW_TAGS) += init.o report_tags.o shadow.o tags.o diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 7c025d792e2f..f16591ba9e2e 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * This file contains common generic and tag-based KASAN error reporting code. + * This file contains common KASAN error reporting code. * * Copyright (c) 2014 Samsung Electronics Co., Ltd. * Author: Andrey Ryabinin diff --git a/mm/kasan/generic_report.c b/mm/kasan/report_generic.c similarity index 100% rename from mm/kasan/generic_report.c rename to mm/kasan/report_generic.c diff --git a/mm/kasan/tags_report.c b/mm/kasan/report_tags.c similarity index 100% rename from mm/kasan/tags_report.c rename to mm/kasan/report_tags.c From patchwork Tue Sep 15 21:15:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777731 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E7F659D for ; Tue, 15 Sep 2020 21:16:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4323420770 for ; Tue, 15 Sep 2020 21:16:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="X1oFaYJ3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4323420770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DFDBB90007C; Tue, 15 Sep 2020 17:16:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D38FE900012; Tue, 15 Sep 2020 17:16:46 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BFBA290007C; Tue, 15 Sep 2020 17:16:46 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0153.hostedemail.com [216.40.44.153]) by kanga.kvack.org (Postfix) with ESMTP id A8199900012 for ; Tue, 15 Sep 2020 17:16:46 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6F003181AEF07 for ; Tue, 15 Sep 2020 21:16:46 +0000 (UTC) X-FDA: 77266555212.30.top89_580636f27114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 44EAE180B3C83 for ; Tue, 15 Sep 2020 21:16:46 +0000 (UTC) X-Spam-Summary: 1,0,0,a3ea20317d4098e5,d41d8cd98f00b204,3pc9hxwokcce7kaobvhksidlldib.9ljifkru-jjhs79h.lod@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:966:973:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:1981:2194:2196:2199:2200:2393:2559:2562:3138:3139:3140:3141:3142:3152:3352:3866:3867:3868:4250:4321:4385:5007:6261:6653:6742:7875:8957:9969:10004:10400:11026:11232:11473:11658:11914:12043:12048:12296:12297:12438:12555:12895:13069:13311:13357:14096:14097:14181:14394:14659:14721:21080:21324:21365:21444:21451:21627:21740:21772:30054,0,RBL:209.85.221.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yg7anx6s1sk5m9fe7m1dqk84tgsopu4wuiw4o6gyzfb8gujbec3nwrrw93mnq.x1x4uqtcqsab5u9399hm9j34aj3noctrhtrzonjuxar9qabikct8kyh48op9swt.w-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neu tral,Cus X-HE-Tag: top89_580636f27114 X-Filterd-Recvd-Size: 4970 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:16:45 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id b7so1711591wrn.6 for ; Tue, 15 Sep 2020 14:16:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=BdONTOcHhT5ryTedju+DUoHznOnFqEEPqO/13OyviNc=; b=X1oFaYJ3ruHAFYTNWhnNVd4ydUZPygtts9K7sLHGb4tL8soibh0M5VHrDRf8er6czC S3Bn9yMJmOywdqnJEpdb/8BnHtS6pKui5SvEFZs9pUnNbq5PwhYVkyTXXEQ/d5l88eo+ IjKYNtfww1UIZzqXqee6/vjaJdvWRoJD69TBXYgKT0WwZgX7TC3GJw+w4FmxT2lg+BLz J8Nkv3KOemu1M29hF5q6jkkaBkAGczwP4Fet7xpF+UoTNV4F978v/Vq/F+zUMGsIWY3E sdHEwpmqPkFbbulvvEhZssP09nuxFYuRdXW4rz/ERIQGqOpA6OK8rysgnJvDzj8sxUos o/2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=BdONTOcHhT5ryTedju+DUoHznOnFqEEPqO/13OyviNc=; b=apthBGsqzREVWiuNFfVNfzqiExZ/vEwz7PFojHOZfS99iuyjv9/xAMoyeOooKQBFcE v2V3iZoyEWy51VR2bb43ws8cdqwtKhHfN96MWnGxJSxJNpBldA8QQlc5ae+e3HKobY16 C5UUgRPBCTkZrDKwIc0F8N2kzdZXtgO95AR7RkefcEEv6sBAOQ1jCYO86DhdAZbSnf8a D/lUjkfsOiGunuHDdmyo9Y6RixXcF1QcLigSKXdlAQFMfMUGaKL2iyVSkPApKoEpKf8R HGRxQj8LhmjfeDjsfGmoAqU1m/4ckegHBhpk6P2o34WZUiF90wTWMCgRFodnNTp02LLO HIRg== X-Gm-Message-State: AOAM530WI3zqLDrMJPRD14udsejh3k63obD4Pxk1n7Nwqbws8Le/Wm0L Zap8zQEx6gN8H6LMLcOViPH3oTdBLHj6WrVL X-Google-Smtp-Source: ABdhPJyRaB4++4piH+N0WrxzDm3lIXLWNtbPvrqZh7r0LOgztg6BdoQfKl+Xjg2AISEKwNb86A0SmdpEYhDETYjx X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a5d:4709:: with SMTP id y9mr23509475wrq.59.1600204604330; Tue, 15 Sep 2020 14:16:44 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:51 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 09/37] kasan: don't duplicate config dependencies From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 44EAE180B3C83 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: Both KASAN_GENERIC and KASAN_SW_TAGS have common dependencies, move those to KASAN. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: I77e475802e8f1750b9154fe4a6e6da4456054fcd --- lib/Kconfig.kasan | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan index e1d55331b618..b4cf6c519d71 100644 --- a/lib/Kconfig.kasan +++ b/lib/Kconfig.kasan @@ -24,6 +24,9 @@ menuconfig KASAN (HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS) depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB) depends on CC_HAS_WORKING_NOSANITIZE_ADDRESS + select SLUB_DEBUG if SLUB + select CONSTRUCTORS + select STACKDEPOT help Enables KASAN (KernelAddressSANitizer) - runtime memory debugger, designed to find out-of-bounds accesses and use-after-free bugs. @@ -46,10 +49,6 @@ choice config KASAN_GENERIC bool "Generic mode" depends on HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC - depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB) - select SLUB_DEBUG if SLUB - select CONSTRUCTORS - select STACKDEPOT help Enables generic KASAN mode. @@ -70,10 +69,6 @@ config KASAN_GENERIC config KASAN_SW_TAGS bool "Software tag-based mode" depends on HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS - depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB) - select SLUB_DEBUG if SLUB - select CONSTRUCTORS - select STACKDEPOT help Enables software tag-based KASAN mode. From patchwork Tue Sep 15 21:15:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777733 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD6096CA for ; Tue, 15 Sep 2020 21:16:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 66B1D20770 for ; Tue, 15 Sep 2020 21:16:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Pyez5vKz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 66B1D20770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C714D90007D; Tue, 15 Sep 2020 17:16:48 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C4A79900012; Tue, 15 Sep 2020 17:16:48 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B3BD990007D; Tue, 15 Sep 2020 17:16:48 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0111.hostedemail.com [216.40.44.111]) by kanga.kvack.org (Postfix) with ESMTP id 968FA900012 for ; Tue, 15 Sep 2020 17:16:48 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 632198249980 for ; Tue, 15 Sep 2020 21:16:48 +0000 (UTC) X-FDA: 77266555296.08.crate05_5a0a5ca27114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 3344F1819E793 for ; Tue, 15 Sep 2020 21:16:48 +0000 (UTC) X-Spam-Summary: 1,0,0,fac5b71765cfc0c4,d41d8cd98f00b204,3py9hxwokccqandreyknvlgoogle.comlinux-mmkvack.org@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:69:152:355:379:541:800:960:965:966:968:973:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:1981:2194:2196:2199:2200:2393:2559:2562:3138:3139:3140:3141:3142:3152:3354:3865:3866:3870:3871:4118:4250:4321:4385:4390:4395:4605:5007:6261:6653:6742:8603:9592:9969:10004:10400:10450:10455:11026:11232:11473:11658:11914:12043:12048:12296:12297:12438:12555:12895:12986:14181:14394:14659:14721:19904:19999:21080:21324:21365:21444:21451:21627:21772:21990:30003:30054:30070:30075,0,RBL:209.85.219.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04ygxf6bpehr5serjbbcipid8xq1aycgc3jxa5w7eathaudo4a8ji69bs13i8e6.7339wnmay9ss3t55ppn6nio6waw5e6oyyn5y55grcsrba91sx1gjr6npejwf5ii.r-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netch eck:none X-HE-Tag: crate05_5a0a5ca27114 X-Filterd-Recvd-Size: 7145 Received: from mail-qv1-f74.google.com (mail-qv1-f74.google.com [209.85.219.74]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:16:47 +0000 (UTC) Received: by mail-qv1-f74.google.com with SMTP id ct11so3063521qvb.16 for ; Tue, 15 Sep 2020 14:16:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=PJMOcA8gqYHqxhIXShAJ08j6C1UfzhHyZzvegxBV4p8=; b=Pyez5vKz+XLZ00ncbPcRUbrzjMjQrhm4FyXOKO0rf6GibdPjrahX4Dav2SHfv1yhRT i+YdOyuFp7w811xTJhmS8U5yzQA1RiOozM52MmAJYzwigWzxwukAtwabIZ62PQJwet4m /NLPTWYJlfPY/5F5DXaspPdyP2BsnQFdE52otIMmNbLJjT3/4dh4I9oIm/YejEYaie4R nQA5dszVd+YZ9oX2VErcwOMwi7vDvgwqbTCzlnbwzfKO3rdq1z/f2yzTupMx23vej94N lhtF+yoHeVLagt1I4Lqle8dAvBLPSY0uLRmZZt1Vyktpmw8FDsmMASdlOKNxxj4GWDjU RfLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=PJMOcA8gqYHqxhIXShAJ08j6C1UfzhHyZzvegxBV4p8=; b=QLRq8JTkjtugIWc+XDcZFwSRSpmco4NhygUxLs77sIIJiu6nLCCmqCwEcX3EYoahU/ WWTqPMiRm5Ocf125DjAtG+SU2n1L0VZcE+2VTaf7kxuyvHbrk+iP/nX3xHzic7SMnVti CJQaA6Ay1H64V2Q4vkmGP88JCKDOyenvtjiWIvGjOD9esTzY9qUo4NdBPeSepoAuzRtt bYMrDrTuRLTxJBuFF5mO1I5QYLG29v08h175QNPvIqa5/PTet6NYMeqP7GRoexckOfZK qjpFntBiMyh1uL/vx7iiDEaBkTpq9Gse/TFgHCuSGfP8TkZPCSnBd7RWvMCTpdh7jd5R 7GMg== X-Gm-Message-State: AOAM532ht1U/FM6jwe9GohOHfI0gvVherX7vx+1o2KNQq6a1tTHyLP2H LR1fXL3gKI7fV/EvC5K5UnzWdjFLa48PAPmu X-Google-Smtp-Source: ABdhPJyhaTd4yQYZ8onO2P+Zy+eqzSStAHDt5/e2wfJn4SyvBNEh8CRe7qqQKWFJB8cy29L9yd907X0cOOY8mKev X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:5743:: with SMTP id q3mr19874682qvx.6.1600204607062; Tue, 15 Sep 2020 14:16:47 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:52 +0200 In-Reply-To: Message-Id: <29aaa1e9ab63d03891f8fae268a5f71582db5778.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 10/37] kasan: hide invalid free check implementation From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 3344F1819E793 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000050, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. For software KASAN modes the check is based on the value in the shadow memory. Hardware tag-based KASAN won't be using shadow, so hide the implementation of the check in check_invalid_free(). No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: I5fae9531c9fc948eb4d4e0c589744032fc5a0789 --- mm/kasan/common.c | 19 +------------------ mm/kasan/generic.c | 7 +++++++ mm/kasan/kasan.h | 2 ++ mm/kasan/tags.c | 12 ++++++++++++ 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 43a927e70067..a2321d35390e 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -277,25 +277,9 @@ void * __must_check kasan_init_slab_obj(struct kmem_cache *cache, return (void *)object; } -static inline bool shadow_invalid(u8 tag, s8 shadow_byte) -{ - if (IS_ENABLED(CONFIG_KASAN_GENERIC)) - return shadow_byte < 0 || - shadow_byte >= KASAN_GRANULE_SIZE; - - /* else CONFIG_KASAN_SW_TAGS: */ - if ((u8)shadow_byte == KASAN_TAG_INVALID) - return true; - if ((tag != KASAN_TAG_KERNEL) && (tag != (u8)shadow_byte)) - return true; - - return false; -} - static bool __kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip, bool quarantine) { - s8 shadow_byte; u8 tag; void *tagged_object; unsigned long rounded_up_size; @@ -314,8 +298,7 @@ static bool __kasan_slab_free(struct kmem_cache *cache, void *object, if (unlikely(cache->flags & SLAB_TYPESAFE_BY_RCU)) return false; - shadow_byte = READ_ONCE(*(s8 *)kasan_mem_to_shadow(object)); - if (shadow_invalid(tag, shadow_byte)) { + if (check_invalid_free(tagged_object)) { kasan_report_invalid_free(tagged_object, ip); return true; } diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index f6d68aa9872f..73f4d786ad5d 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -192,6 +192,13 @@ bool check_memory_region(unsigned long addr, size_t size, bool write, return check_memory_region_inline(addr, size, write, ret_ip); } +bool check_invalid_free(void *addr) +{ + s8 shadow_byte = READ_ONCE(*(s8 *)kasan_mem_to_shadow(addr)); + + return shadow_byte < 0 || shadow_byte >= KASAN_GRANULE_SIZE; +} + void kasan_cache_shrink(struct kmem_cache *cache) { quarantine_remove_cache(cache); diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index c31e2c739301..cf6a135860f2 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -163,6 +163,8 @@ void kasan_poison_memory(const void *address, size_t size, u8 value); bool check_memory_region(unsigned long addr, size_t size, bool write, unsigned long ret_ip); +bool check_invalid_free(void *addr); + void *find_first_bad_addr(void *addr, size_t size); const char *get_bug_type(struct kasan_access_info *info); diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c index 4d5a1fe8251f..feb42c1763b8 100644 --- a/mm/kasan/tags.c +++ b/mm/kasan/tags.c @@ -126,6 +126,18 @@ bool check_memory_region(unsigned long addr, size_t size, bool write, return true; } +bool check_invalid_free(void *addr) +{ + u8 tag = get_tag(addr); + u8 shadow_byte = READ_ONCE(*(u8 *)kasan_mem_to_shadow(reset_tag(addr))); + + if (shadow_byte == KASAN_TAG_INVALID) + return true; + if (tag != KASAN_TAG_KERNEL && tag != shadow_byte) + return true; + return false; +} + #define DEFINE_HWASAN_LOAD_STORE(size) \ void __hwasan_load##size##_noabort(unsigned long addr) \ { \ From patchwork Tue Sep 15 21:15:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777735 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4BF8D59D for ; Tue, 15 Sep 2020 21:16:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0461B20770 for ; Tue, 15 Sep 2020 21:16:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Wlgqfbdc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0461B20770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9657B90007E; Tue, 15 Sep 2020 17:16:51 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 93968900012; Tue, 15 Sep 2020 17:16:51 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8054890007E; Tue, 15 Sep 2020 17:16:51 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0163.hostedemail.com [216.40.44.163]) by kanga.kvack.org (Postfix) with ESMTP id 67C46900012 for ; Tue, 15 Sep 2020 17:16:51 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2F721362C for ; Tue, 15 Sep 2020 21:16:51 +0000 (UTC) X-FDA: 77266555422.05.story98_1a05ec127114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 0DF4C1826B6AB for ; Tue, 15 Sep 2020 21:16:51 +0000 (UTC) X-Spam-Summary: 1,0,0,bad300c8c2d381f7,d41d8cd98f00b204,3qs9hxwokccycpftgampxniqqing.eqonkpwz-oomxcem.qti@flex--andreyknvl.bounces.google.com,,RULES_HIT:1:41:69:152:305:355:379:541:800:960:966:973:982:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1593:1594:1605:1730:1747:1777:1792:1801:1981:2194:2196:2199:2200:2393:2553:2559:2562:2637:2892:2901:3138:3139:3140:3141:3142:3152:3740:3865:3866:3867:3870:3871:3872:4250:4321:4385:4605:5007:6261:6653:6742:8603:9149:9163:9164:9592:9969:10004:11026:11232:11233:11473:11658:11914:12043:12048:12291:12296:12297:12438:12555:12683:12895:12986:13221:13229:14394:14659:21080:21324:21365:21444:21451:21627:21772:21990:30029:30034:30054:30056:30069:30075:30079:30090,0,RBL:209.85.221.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yr68491ehi6xyrk63un33iofnfrocssa53bjpnauauichusm3geaqhsuy56zs.ym6g9wsnfwqq1ebpjwpeu738d3jruq8gcdpxwfisr7jgouca8w74qg3fh7oyr4a.q-lbl8.mailshell.net-223.238.255.100, CacheIP: X-HE-Tag: story98_1a05ec127114 X-Filterd-Recvd-Size: 14456 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:16:50 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id l15so1704279wro.10 for ; Tue, 15 Sep 2020 14:16:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=il1SIhPFx0Iy9ZzAUl8CD9DH1Fd3wsEA/MCT7vsJArk=; b=WlgqfbdcwijoxYLSauG9kDS3Q11Wg08WgB5ILU5ywsPDYtQMQzb5umjKSE1TgKA1aY WgaN+JPigRi3qEqkICeMS8QpqEiokfb4z8gqprdfUYNEJuO2O0zBTMduTZZAKeGc/0IY PrrHopImHzadaCLZ3gS6PbFzomy7Sbro6v/rf53cpzEIQj1P0yo3aWbBntjWd2DxOdRO KvTAPpe21IsqTYwPkNUoHQy2eKH9CLzpOfDoZUL7pISFFTxSGuihZzA2UGXuBxLRbSA8 w2r3aITSYwSBUMO116DUSNspEto1A9iDO/g690i8g5m1Q+W8DQokdNwQt0ipg7rhMq3o PS7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=il1SIhPFx0Iy9ZzAUl8CD9DH1Fd3wsEA/MCT7vsJArk=; b=fGs3Fhm896AoXnZQSENTv+jlUcb1s594S1SIOBlJFUmkTaBsX6BWfBkBaEV8v1wwi4 UMf3a+AqxkPo3LQPxF+L4qAeLVt7QUdEji9+nId2MWxK/wsViR5EFEjX244kS1kE7lGQ QhC6Tcd1GaOFH4GL//9k4KlIRdSpP1mbDXLUnm0kOVOBmMMHP6S56uLGR3r5zTtgfum8 q0ATNh9fXwBvZM9u2AyAXFxLLN6KlQf8XaFr3SObfkzUPxgE1j2rXh6lqKJ7Cy3pyrFn nEVjjeHGLsMTDuInwGkl97+vEmvar3J4tZl3C/qudiwgquZqn+QZWGPXHpsq2Kufdd8C FNrA== X-Gm-Message-State: AOAM532Tp3DCktYlgiSJPk5rkKMpAfbM07DP0r5Nif7SvLF9nMlUsuWq anziA4X0xApdXLH054/jQOBtkrDvvoL68p8K X-Google-Smtp-Source: ABdhPJxpc088wJab51F2jr9HmjD6aALB+PGiEk/MgDWGk3cC4IwmLSszdk1Z+cfe2UVnyAchVl8jPB9k/ebizUYh X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a5d:6404:: with SMTP id z4mr24456902wru.423.1600204609523; Tue, 15 Sep 2020 14:16:49 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:53 +0200 In-Reply-To: Message-Id: <525c5a6baa12f976590e27afce132dd14bdd0b0c.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 11/37] kasan: decode stack frame only with KASAN_STACK_ENABLE From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 0DF4C1826B6AB X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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: Decoding routines aren't needed when CONFIG_KASAN_STACK_ENABLE is not enabled. Currently only generic KASAN mode implements stack error reporting. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: I084e3214f2b40dc0bef7c5a9fafdc6f5c42b06a2 --- mm/kasan/kasan.h | 6 ++ mm/kasan/report.c | 162 -------------------------------------- mm/kasan/report_generic.c | 161 +++++++++++++++++++++++++++++++++++++ 3 files changed, 167 insertions(+), 162 deletions(-) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index cf6a135860f2..15cf3e0018ae 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -168,6 +168,12 @@ bool check_invalid_free(void *addr); void *find_first_bad_addr(void *addr, size_t size); const char *get_bug_type(struct kasan_access_info *info); +#ifdef CONFIG_KASAN_STACK_ENABLE +void print_address_stack_frame(const void *addr); +#else +static inline void print_address_stack_frame(const void *addr) { } +#endif + bool kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip); void kasan_report_invalid_free(void *object, unsigned long ip); diff --git a/mm/kasan/report.c b/mm/kasan/report.c index f16591ba9e2e..ddaf9d14ca81 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -214,168 +214,6 @@ static inline bool init_task_stack_addr(const void *addr) sizeof(init_thread_union.stack)); } -static bool __must_check tokenize_frame_descr(const char **frame_descr, - char *token, size_t max_tok_len, - unsigned long *value) -{ - const char *sep = strchr(*frame_descr, ' '); - - if (sep == NULL) - sep = *frame_descr + strlen(*frame_descr); - - if (token != NULL) { - const size_t tok_len = sep - *frame_descr; - - if (tok_len + 1 > max_tok_len) { - pr_err("KASAN internal error: frame description too long: %s\n", - *frame_descr); - return false; - } - - /* Copy token (+ 1 byte for '\0'). */ - strlcpy(token, *frame_descr, tok_len + 1); - } - - /* Advance frame_descr past separator. */ - *frame_descr = sep + 1; - - if (value != NULL && kstrtoul(token, 10, value)) { - pr_err("KASAN internal error: not a valid number: %s\n", token); - return false; - } - - return true; -} - -static void print_decoded_frame_descr(const char *frame_descr) -{ - /* - * We need to parse the following string: - * "n alloc_1 alloc_2 ... alloc_n" - * where alloc_i looks like - * "offset size len name" - * or "offset size len name:line". - */ - - char token[64]; - unsigned long num_objects; - - if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), - &num_objects)) - return; - - pr_err("\n"); - pr_err("this frame has %lu %s:\n", num_objects, - num_objects == 1 ? "object" : "objects"); - - while (num_objects--) { - unsigned long offset; - unsigned long size; - - /* access offset */ - if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), - &offset)) - return; - /* access size */ - if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), - &size)) - return; - /* name length (unused) */ - if (!tokenize_frame_descr(&frame_descr, NULL, 0, NULL)) - return; - /* object name */ - if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), - NULL)) - return; - - /* Strip line number; without filename it's not very helpful. */ - strreplace(token, ':', '\0'); - - /* Finally, print object information. */ - pr_err(" [%lu, %lu) '%s'", offset, offset + size, token); - } -} - -static bool __must_check get_address_stack_frame_info(const void *addr, - unsigned long *offset, - const char **frame_descr, - const void **frame_pc) -{ - unsigned long aligned_addr; - unsigned long mem_ptr; - const u8 *shadow_bottom; - const u8 *shadow_ptr; - const unsigned long *frame; - - BUILD_BUG_ON(IS_ENABLED(CONFIG_STACK_GROWSUP)); - - /* - * NOTE: We currently only support printing frame information for - * accesses to the task's own stack. - */ - if (!object_is_on_stack(addr)) - return false; - - aligned_addr = round_down((unsigned long)addr, sizeof(long)); - mem_ptr = round_down(aligned_addr, KASAN_GRANULE_SIZE); - shadow_ptr = kasan_mem_to_shadow((void *)aligned_addr); - shadow_bottom = kasan_mem_to_shadow(end_of_stack(current)); - - while (shadow_ptr >= shadow_bottom && *shadow_ptr != KASAN_STACK_LEFT) { - shadow_ptr--; - mem_ptr -= KASAN_GRANULE_SIZE; - } - - while (shadow_ptr >= shadow_bottom && *shadow_ptr == KASAN_STACK_LEFT) { - shadow_ptr--; - mem_ptr -= KASAN_GRANULE_SIZE; - } - - if (shadow_ptr < shadow_bottom) - return false; - - frame = (const unsigned long *)(mem_ptr + KASAN_GRANULE_SIZE); - if (frame[0] != KASAN_CURRENT_STACK_FRAME_MAGIC) { - pr_err("KASAN internal error: frame info validation failed; invalid marker: %lu\n", - frame[0]); - return false; - } - - *offset = (unsigned long)addr - (unsigned long)frame; - *frame_descr = (const char *)frame[1]; - *frame_pc = (void *)frame[2]; - - return true; -} - -static void print_address_stack_frame(const void *addr) -{ - unsigned long offset; - const char *frame_descr; - const void *frame_pc; - - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) - return; - - if (!get_address_stack_frame_info(addr, &offset, &frame_descr, - &frame_pc)) - return; - - /* - * get_address_stack_frame_info only returns true if the given addr is - * on the current task's stack. - */ - pr_err("\n"); - pr_err("addr %px is located in stack of task %s/%d at offset %lu in frame:\n", - addr, current->comm, task_pid_nr(current), offset); - pr_err(" %pS\n", frame_pc); - - if (!frame_descr) - return; - - print_decoded_frame_descr(frame_descr); -} - static void print_address_description(void *addr, u8 tag) { struct page *page = kasan_addr_to_page(addr); diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c index 4dce1633b082..427f4ac80cca 100644 --- a/mm/kasan/report_generic.c +++ b/mm/kasan/report_generic.c @@ -127,6 +127,167 @@ const char *get_bug_type(struct kasan_access_info *info) return get_wild_bug_type(info); } +#ifdef CONFIG_KASAN_STACK_ENABLE +static bool __must_check tokenize_frame_descr(const char **frame_descr, + char *token, size_t max_tok_len, + unsigned long *value) +{ + const char *sep = strchr(*frame_descr, ' '); + + if (sep == NULL) + sep = *frame_descr + strlen(*frame_descr); + + if (token != NULL) { + const size_t tok_len = sep - *frame_descr; + + if (tok_len + 1 > max_tok_len) { + pr_err("KASAN internal error: frame description too long: %s\n", + *frame_descr); + return false; + } + + /* Copy token (+ 1 byte for '\0'). */ + strlcpy(token, *frame_descr, tok_len + 1); + } + + /* Advance frame_descr past separator. */ + *frame_descr = sep + 1; + + if (value != NULL && kstrtoul(token, 10, value)) { + pr_err("KASAN internal error: not a valid number: %s\n", token); + return false; + } + + return true; +} + +static void print_decoded_frame_descr(const char *frame_descr) +{ + /* + * We need to parse the following string: + * "n alloc_1 alloc_2 ... alloc_n" + * where alloc_i looks like + * "offset size len name" + * or "offset size len name:line". + */ + + char token[64]; + unsigned long num_objects; + + if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), + &num_objects)) + return; + + pr_err("\n"); + pr_err("this frame has %lu %s:\n", num_objects, + num_objects == 1 ? "object" : "objects"); + + while (num_objects--) { + unsigned long offset; + unsigned long size; + + /* access offset */ + if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), + &offset)) + return; + /* access size */ + if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), + &size)) + return; + /* name length (unused) */ + if (!tokenize_frame_descr(&frame_descr, NULL, 0, NULL)) + return; + /* object name */ + if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), + NULL)) + return; + + /* Strip line number; without filename it's not very helpful. */ + strreplace(token, ':', '\0'); + + /* Finally, print object information. */ + pr_err(" [%lu, %lu) '%s'", offset, offset + size, token); + } +} + +static bool __must_check get_address_stack_frame_info(const void *addr, + unsigned long *offset, + const char **frame_descr, + const void **frame_pc) +{ + unsigned long aligned_addr; + unsigned long mem_ptr; + const u8 *shadow_bottom; + const u8 *shadow_ptr; + const unsigned long *frame; + + BUILD_BUG_ON(IS_ENABLED(CONFIG_STACK_GROWSUP)); + + /* + * NOTE: We currently only support printing frame information for + * accesses to the task's own stack. + */ + if (!object_is_on_stack(addr)) + return false; + + aligned_addr = round_down((unsigned long)addr, sizeof(long)); + mem_ptr = round_down(aligned_addr, KASAN_GRANULE_SIZE); + shadow_ptr = kasan_mem_to_shadow((void *)aligned_addr); + shadow_bottom = kasan_mem_to_shadow(end_of_stack(current)); + + while (shadow_ptr >= shadow_bottom && *shadow_ptr != KASAN_STACK_LEFT) { + shadow_ptr--; + mem_ptr -= KASAN_GRANULE_SIZE; + } + + while (shadow_ptr >= shadow_bottom && *shadow_ptr == KASAN_STACK_LEFT) { + shadow_ptr--; + mem_ptr -= KASAN_GRANULE_SIZE; + } + + if (shadow_ptr < shadow_bottom) + return false; + + frame = (const unsigned long *)(mem_ptr + KASAN_GRANULE_SIZE); + if (frame[0] != KASAN_CURRENT_STACK_FRAME_MAGIC) { + pr_err("KASAN internal error: frame info validation failed; invalid marker: %lu\n", + frame[0]); + return false; + } + + *offset = (unsigned long)addr - (unsigned long)frame; + *frame_descr = (const char *)frame[1]; + *frame_pc = (void *)frame[2]; + + return true; +} + +void print_address_stack_frame(const void *addr) +{ + unsigned long offset; + const char *frame_descr; + const void *frame_pc; + + if (!get_address_stack_frame_info(addr, &offset, &frame_descr, + &frame_pc)) + return; + + /* + * get_address_stack_frame_info only returns true if the given addr is + * on the current task's stack. + */ + pr_err("\n"); + pr_err("addr %px is located in stack of task %s/%d at offset %lu in frame:\n", + addr, current->comm, task_pid_nr(current), offset); + pr_err(" %pS\n", frame_pc); + + if (!frame_descr) + return; + + print_decoded_frame_descr(frame_descr); +} +#endif /* CONFIG_KASAN_STACK_ENABLE */ + #define DEFINE_ASAN_REPORT_LOAD(size) \ void __asan_report_load##size##_noabort(unsigned long addr) \ { \ From patchwork Tue Sep 15 21:15:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777737 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C824259D for ; Tue, 15 Sep 2020 21:16:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 88B3720770 for ; Tue, 15 Sep 2020 21:16:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="KwKBifrT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 88B3720770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5E2B990007F; Tue, 15 Sep 2020 17:16:54 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 56D06900012; Tue, 15 Sep 2020 17:16:54 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4596590007F; Tue, 15 Sep 2020 17:16:54 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0021.hostedemail.com [216.40.44.21]) by kanga.kvack.org (Postfix) with ESMTP id 2ECD5900012 for ; Tue, 15 Sep 2020 17:16:54 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EA2EB2C07 for ; Tue, 15 Sep 2020 21:16:53 +0000 (UTC) X-FDA: 77266555506.08.vase62_5206bf027114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id C14D21819E793 for ; Tue, 15 Sep 2020 21:16:53 +0000 (UTC) X-Spam-Summary: 1,0,0,c8f15b42c20b1d6c,d41d8cd98f00b204,3rc9hxwokcckfsiwjdpsaqlttlqj.htrqnszc-rrpafhp.twl@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:1981:2194:2199:2282:2393:2559:2562:3138:3139:3140:3141:3142:3152:3353:3865:3866:3871:3872:4117:4250:4321:4605:5007:6261:6653:6742:7875:9969:10004:10400:10450:10455:11026:11232:11473:11657:11658:11914:12043:12048:12296:12297:12438:12555:12895:14096:14097:14181:14394:14659:14721:19904:19999:21080:21365:21433:21444:21451:21627:21772:30054,0,RBL:209.85.128.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04y865pjqhaqbfxsq5cxfm9q5tinkocdnuwtxgfg4j6dz6dfd7xcbmeggee4w3k.3bo7puu9dg98tx51sjah5j1sd3qe7xcujgm5emgzp9mcxcxaneii6jwwpmxftgo.c-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DN SBL:neut X-HE-Tag: vase62_5206bf027114 X-Filterd-Recvd-Size: 6201 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:16:53 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id y18so225114wma.4 for ; Tue, 15 Sep 2020 14:16:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=IohLAiQritHYDUsEyFojJvH0Itf5Q6tgZwjJNHAxVZI=; b=KwKBifrTZVrDXaHnoOdwHc/M5dni2e323Mp+mNPmCsK0W8O7Y8VXJVi3AE5Jo+ENnk EkGS8GuntJzkIIof+6wo2+RelNqEkT8AzAWR+IYpLFmN9+9mhgXciRNcQQBmCWFxXwOW mm18KrwH9w5clj7/igQ6hoHVFcw9+8yJ1xmQfA93dgtSY5QSor7XXk5jyo+crlVKAWnp btvVEGqWSJknyo34NzbkH+W5g8uCKLArOGU++xd3ifOZaGtxnNyjf/e3LxwCnrnbNtRQ 4iW7Q/YXlGnFBNG8pOB2sAvLVRvRfNRGuUGU+X9u/OAZqVMesvc6GxLKobPKyE9Sgi9E xvGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=IohLAiQritHYDUsEyFojJvH0Itf5Q6tgZwjJNHAxVZI=; b=PgBbMkQWjtb76LeiUJhfx7bOlTPJUkn55BQGIlz25kz0BxWNlgX9smaMDrpJmo8R3m LLgWTSFrS5g6xSlfkGJ9et9bhYEe1cFtu8H3suFpM2s0uqeYzmoZhXcpptPqv1Nt6bC8 Mx6RUQPJ1Q5L/4UWQVhe9ekhiufpvc9aqVZnoW3Him+saJ/5VP90r4Tlud7kjhr0fYfW HvCWs4t3QY4nxaMITJ37yMEe2VXnO7gJtZ/05jyD/7y1oLVZejSHw5AAnJgQ6dxrzKkj mkYy2ii45R+vBTxJ8hydG7ATPkGcHOdtEUWcBfY1VmGBnECTARKCf/R5LnDfJIIklmuN Z1yg== X-Gm-Message-State: AOAM533NktMPDmDJYhormQakmXKcSRr4M6sa3bijkNXZf5erRtfEjeb9 HHZLVYQx9EzmsYq0o8z+bxR6+68XCBI8FsiQ X-Google-Smtp-Source: ABdhPJw1CmWQAP9tJjtlXp/HfdjCVKqfCNtO3HPAI+fWlLqJnWhmg0N55nUWjB6VKGB/XuTbHQN3196z0TpRBXCx X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:adf:cf01:: with SMTP id o1mr23727593wrj.421.1600204612062; Tue, 15 Sep 2020 14:16:52 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:54 +0200 In-Reply-To: Message-Id: <2d009928ca496df0d7c061749c6a74d9ad36588c.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 12/37] kasan, arm64: only init shadow for software modes From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: C14D21819E793 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Hardware tag-based KASAN won't be using shadow memory. Only initialize it when one of the software KASAN modes are enabled. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Catalin Marinas --- Change-Id: I055e0651369b14d3e54cdaa8c48e6329b2e8952d --- arch/arm64/include/asm/kasan.h | 8 ++++++-- arch/arm64/mm/kasan_init.c | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kasan.h b/arch/arm64/include/asm/kasan.h index b0dc4abc3589..f7ea70d02cab 100644 --- a/arch/arm64/include/asm/kasan.h +++ b/arch/arm64/include/asm/kasan.h @@ -13,6 +13,12 @@ #define arch_kasan_get_tag(addr) __tag_get(addr) #ifdef CONFIG_KASAN +void kasan_init(void); +#else +static inline void kasan_init(void) { } +#endif + +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) /* * KASAN_SHADOW_START: beginning of the kernel virtual addresses. @@ -33,12 +39,10 @@ #define _KASAN_SHADOW_START(va) (KASAN_SHADOW_END - (1UL << ((va) - KASAN_SHADOW_SCALE_SHIFT))) #define KASAN_SHADOW_START _KASAN_SHADOW_START(vabits_actual) -void kasan_init(void); void kasan_copy_shadow(pgd_t *pgdir); asmlinkage void kasan_early_init(void); #else -static inline void kasan_init(void) { } static inline void kasan_copy_shadow(pgd_t *pgdir) { } #endif diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index 7291b26ce788..4d35eaf3ec97 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -21,6 +21,8 @@ #include #include +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) + static pgd_t tmp_pg_dir[PTRS_PER_PGD] __initdata __aligned(PGD_SIZE); /* @@ -208,7 +210,7 @@ static void __init clear_pgds(unsigned long start, set_pgd(pgd_offset_k(start), __pgd(0)); } -void __init kasan_init(void) +static void __init kasan_init_shadow(void) { u64 kimg_shadow_start, kimg_shadow_end; u64 mod_shadow_start, mod_shadow_end; @@ -269,6 +271,17 @@ void __init kasan_init(void) memset(kasan_early_shadow_page, KASAN_SHADOW_INIT, PAGE_SIZE); cpu_replace_ttbr1(lm_alias(swapper_pg_dir)); +} + +#else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) */ + +static inline void __init kasan_init_shadow(void) { } + +#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ + +void __init kasan_init(void) +{ + kasan_init_shadow(); /* At this point kasan is fully initialized. Enable error messages */ init_task.kasan_depth = 0; From patchwork Tue Sep 15 21:15:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777739 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 340C359D for ; Tue, 15 Sep 2020 21:16:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E16FA2078E for ; Tue, 15 Sep 2020 21:16:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="cyy2ohm5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E16FA2078E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7DC62900080; Tue, 15 Sep 2020 17:16:56 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 78EA9900012; Tue, 15 Sep 2020 17:16:56 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62C91900080; Tue, 15 Sep 2020 17:16:56 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0223.hostedemail.com [216.40.44.223]) by kanga.kvack.org (Postfix) with ESMTP id 4B803900012 for ; Tue, 15 Sep 2020 17:16:56 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 135118249980 for ; Tue, 15 Sep 2020 21:16:56 +0000 (UTC) X-FDA: 77266555632.16.brush36_0a07e7327114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id D8C29100E6912 for ; Tue, 15 Sep 2020 21:16:55 +0000 (UTC) X-Spam-Summary: 1,0,0,7b4b162523056fd3,d41d8cd98f00b204,3ri9hxwokccshukylfrucsnvvnsl.jvtspube-ttrchjr.vyn@flex--andreyknvl.bounces.google.com,,RULES_HIT:2:41:152:355:379:541:800:960:966:968:973:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1593:1594:1606:1730:1747:1777:1792:1981:2194:2196:2198:2199:2200:2201:2393:2559:2562:2731:3138:3139:3140:3141:3142:3152:3355:3865:3866:3868:3871:3872:4119:4250:4385:4605:5007:6261:6653:6742:8603:8957:9592:9969:10004:11026:11232:11473:11658:11914:12043:12048:12296:12297:12438:12555:12895:14096:14097:14394:14659:21080:21365:21433:21444:21451:21627:21772:21990:30003:30054:30070,0,RBL:209.85.221.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04y8e8o9kyo16obr7kab5k5znyq4fop5o3ch83ho71q4t6y53zr8m1fp59scene.gpygbj77ugdmfodkqxrqjb5qr7wk1639b5gp6wxe6rawe745zmj5fipmsdfsjp9.g-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp ,MSBL:0, X-HE-Tag: brush36_0a07e7327114 X-Filterd-Recvd-Size: 8479 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf12.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:16:55 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id l15so1704353wro.10 for ; Tue, 15 Sep 2020 14:16:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=7yDwng4+Hj3dGnoK2YA+rQbDNoxu46t3AMw9ie+3lv0=; b=cyy2ohm5w6ggEbHNtfTyEPuLaPLW/r0sbYxz1pJiROpFFdODKk96Vv5nZGiCbAmxox uaF4I9gb5PcleAQxxYTgfSw4dKBlQ1jIM06fPnETtQ82McJ8++Rg4C8MKuJ03whix1K1 bmAaZLjQYSxkpX0yQZc2/ajy2GuW1bMQ+n6UYo/GwpXvN+xmvGePfO6UXWUTKfi+So/v GJ5vLr67Mhy9RBtn7uZ2HCdyd0nf5XAsZCywwKYP9jfKgm+4vinlMhNN3oaMZUtsakYD o8bER/j0Xzed90ubZppJN+KpdH8VznlQmN6lK90xT0N/YPNCH5R7HSTlTChRvyF6FRX2 4/TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=7yDwng4+Hj3dGnoK2YA+rQbDNoxu46t3AMw9ie+3lv0=; b=Rei0kK/T+9krHQrmDY7qCEbu1nDv6V0UwjThjwWX8d50nyBFftJEqcwRClF/He7yAP iA1aWe/crnPEsA7Suqf8lc/3swk68Xx7sy3PcU6rtWa/zCC0gt6CU6WPUfkIOsE14B1F qUp2uzD9IOFuBnDhbkc1JnQeYnFa+/TXx0C5JL+eETGjmmHYzDkW1mNOpHvEESdm+RWR DBxk8RVp1X0BvYw+MBEPL60C+Zu/7INKMna0Z/Vbw6hao57VjtRP4qg3BAArpuuC5iOT 7KD/bT420QjRwq+kgSWUEDWe89V9rLa7tuBFvb61Zw/BJn8UBP+1paAOmTJiEGm1mV8x JWgg== X-Gm-Message-State: AOAM5310vRp2NGAJsWrPmfsvWZryXkuXt0Ns+eOegiLwnJTcOU8DycD8 e28XT7ov6+8YiNL/tNQglHBYXWb3iuiytWFC X-Google-Smtp-Source: ABdhPJzTRyPDUOBFxI01fgHN2kmssDbF4Zb7r+npdVx5YvhJZ+SJU6VWf3cqQth+B2Mv2NIdDjznvYy/ahDUTD3H X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:e108:: with SMTP id y8mr1249357wmg.178.1600204614417; Tue, 15 Sep 2020 14:16:54 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:55 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 13/37] kasan, arm64: only use kasan_depth for software modes From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: D8C29100E6912 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Hardware tag-based KASAN won't use kasan_depth. Only define and use it when one of the software KASAN modes are enabled. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Catalin Marinas --- Change-Id: I6109ea96c8df41ef6d75ad71bf22c1c8fa234a9a --- arch/arm64/mm/kasan_init.c | 11 ++++++++--- include/linux/kasan.h | 14 ++++++++++---- include/linux/sched.h | 2 +- init/init_task.c | 2 +- mm/kasan/common.c | 2 ++ mm/kasan/report.c | 2 ++ 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index 4d35eaf3ec97..b6b9d55bb72e 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -273,17 +273,22 @@ static void __init kasan_init_shadow(void) cpu_replace_ttbr1(lm_alias(swapper_pg_dir)); } +void __init kasan_init_depth(void) +{ + init_task.kasan_depth = 0; +} + #else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) */ static inline void __init kasan_init_shadow(void) { } +static inline void __init kasan_init_depth(void) { } + #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ void __init kasan_init(void) { kasan_init_shadow(); - - /* At this point kasan is fully initialized. Enable error messages */ - init_task.kasan_depth = 0; + kasan_init_depth(); pr_info("KernelAddressSanitizer initialized\n"); } diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 18617d5c4cd7..894f4d9163ee 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -52,7 +52,7 @@ static inline void kasan_remove_zero_shadow(void *start, #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) /* Enable reporting bugs after kasan_disable_current() */ extern void kasan_enable_current(void); @@ -60,6 +60,15 @@ 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 */ + +static inline void kasan_enable_current(void) {} +static inline void kasan_disable_current(void) {} + +#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ + +#ifdef CONFIG_KASAN + void kasan_unpoison_memory(const void *address, size_t size); void kasan_unpoison_task_stack(struct task_struct *task); @@ -110,9 +119,6 @@ static inline void kasan_unpoison_memory(const void *address, size_t size) {} static inline void kasan_unpoison_task_stack(struct task_struct *task) {} -static inline void kasan_enable_current(void) {} -static inline void kasan_disable_current(void) {} - static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} static inline void kasan_free_pages(struct page *page, unsigned int order) {} diff --git a/include/linux/sched.h b/include/linux/sched.h index afe01e232935..db38b7ecf46d 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1192,7 +1192,7 @@ struct task_struct { u64 timer_slack_ns; u64 default_timer_slack_ns; -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) unsigned int kasan_depth; #endif diff --git a/init/init_task.c b/init/init_task.c index f6889fce64af..b93078f1708b 100644 --- a/init/init_task.c +++ b/init/init_task.c @@ -173,7 +173,7 @@ struct task_struct init_task .numa_group = NULL, .numa_faults = NULL, #endif -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) .kasan_depth = 1, #endif #ifdef CONFIG_KCSAN diff --git a/mm/kasan/common.c b/mm/kasan/common.c index a2321d35390e..41c7f1105eaa 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -51,6 +51,7 @@ void kasan_set_track(struct kasan_track *track, gfp_t flags) track->stack = kasan_save_stack(flags); } +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) void kasan_enable_current(void) { current->kasan_depth++; @@ -60,6 +61,7 @@ void kasan_disable_current(void) { current->kasan_depth--; } +#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ static void __kasan_unpoison_stack(struct task_struct *task, const void *sp) { diff --git a/mm/kasan/report.c b/mm/kasan/report.c index ddaf9d14ca81..8463e35b489f 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -295,8 +295,10 @@ static void print_shadow_for_address(const void *addr) static bool report_enabled(void) { +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) if (current->kasan_depth) return false; +#endif if (test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags)) return true; return !test_and_set_bit(KASAN_BIT_REPORTED, &kasan_flags); From patchwork Tue Sep 15 21:15:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777741 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 92C236CA for ; Tue, 15 Sep 2020 21:17:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4ADF620770 for ; Tue, 15 Sep 2020 21:17:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="LidLdQly" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4ADF620770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 210B1900081; Tue, 15 Sep 2020 17:16:59 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 198D9900012; Tue, 15 Sep 2020 17:16:59 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B13D900081; Tue, 15 Sep 2020 17:16:59 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0099.hostedemail.com [216.40.44.99]) by kanga.kvack.org (Postfix) with ESMTP id E86E6900012 for ; Tue, 15 Sep 2020 17:16:58 -0400 (EDT) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A1E301DE0 for ; Tue, 15 Sep 2020 21:16:58 +0000 (UTC) X-FDA: 77266555716.15.store97_131733e27114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 7532F1814B0C1 for ; Tue, 15 Sep 2020 21:16:58 +0000 (UTC) X-Spam-Summary: 1,0,0,5482fca7e9e4d3ea,d41d8cd98f00b204,3sc9hxwokcc0jwmanhtweupxxpun.lxvurwdg-vvtejlt.xap@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:982:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:1981:2194:2199:2393:2559:2562:2693:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3871:4117:4250:4321:4605:5007:6261:6653:6742:8603:9969:10004:10400:10450:10455:11026:11232:11473:11658:11914:12043:12048:12297:12438:12555:12895:12986:14093:14097:14181:14394:14659:14721:19904:19999:21080:21324:21365:21444:21451:21627:21990:30054:30075,0,RBL:209.85.128.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yrwoz3hp7wng4ea5rx4fu9kybdsopp8xs4neqrykxktwonw7n8ow4t1oeou6z.yw37kjjq3kyk668o15tyyzd4nqmunbsbo4bb5pdz19je4cobsehmgricno74y9p.4-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNS BL:neutr X-HE-Tag: store97_131733e27114 X-Filterd-Recvd-Size: 6073 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:16:57 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id t8so122319wmj.6 for ; Tue, 15 Sep 2020 14:16:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=NFU27GtWbL95WCt8F/LRedzvWo/LtApbnjc66sNmtks=; b=LidLdQlyti52eZWrhFHwUDuJizCaKRW6hyaJQDPEh27JNL1d+0SqlmcdF2NYGQzQTj 8OmpJEhJfeBEK+B+bvCO4r45A6t+VdFYb/W5Yl9uh3fbjCL1YPof98V406NWsKQbngiv fcL/GZ7KtxfdSHcYClU5y8Hdw2j+sPyP8HmJq/MYUC9y1HZTu7MT4ivkE1G5+ln/A2ir 2LMRHdmZxtC2INIfJmAdFUjD5w1Yw+zYrZAZXUuxQcB6fjznILZzEieeiixnMw+S8F/l DP5W0iRnd5/4Sjl8Ye0p4BbDkF9pmZ48GHG7sBUL+6Bdz7/AFgNBjuMWvzR3goJmJgl+ buwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=NFU27GtWbL95WCt8F/LRedzvWo/LtApbnjc66sNmtks=; b=tMcHxMyitjsm2Ax/MhHKyAbSG+M3QGzapq5ymX0xujJh9Yq8gxT0a+Hdh3Vi6LMtdT /79ccAguVckL9/bYlihIa564LAdVzH5jEhpW7SeaWrbpsmqzvaEhvkV/qPLLS4uj+u3a A0hieXgSkKa5mcHefKJQDYKpP/bdmhn4WZ+B0Ewq2GyX/ayuUKQlFeSq0iM11zNC9w2G KLlfgKYpJJL447FK7DznBNH0wzYJtjr7jnYVzVswxxbKNWYjh9f/6ohuCBnPUL9r3uqU 9cxGu+Vku0fZ1t8YrBFs3f6UBJuz3F88shxBWYo/BThyG/rvGFv4ps+izyARuKc10sH+ qjTA== X-Gm-Message-State: AOAM531A1K/YR7Ym5SC84dumWTcqzWbuOx8iHrg9yuK4rMl+I2T9HAvH pF0brDQxI2XzEdr+wTZ11P83wfB+jdqG1nMr X-Google-Smtp-Source: ABdhPJymDPmDOkSNHrHOdoAiOAhuUVRheTqBJLYFZ0ONbNVc2apw1tqvXIMsxB8eYidBcUGd0R+qoYr0kPN/EPVS X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:adf:9c93:: with SMTP id d19mr23867458wre.275.1600204616832; Tue, 15 Sep 2020 14:16:56 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:56 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 14/37] kasan: rename addr_has_shadow to addr_has_metadata From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 7532F1814B0C1 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Hardware tag-based KASAN won't be using shadow memory, but will reuse this function. Rename "shadow" to implementation-neutral "metadata". No functional changes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: I03706fe34b38da7860c39aa0968e00001a7d1873 --- mm/kasan/kasan.h | 2 +- mm/kasan/report.c | 6 +++--- mm/kasan/report_generic.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 15cf3e0018ae..38fa4c202e9a 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -145,7 +145,7 @@ static inline const void *kasan_shadow_to_mem(const void *shadow_addr) << KASAN_SHADOW_SCALE_SHIFT); } -static inline bool addr_has_shadow(const void *addr) +static inline bool addr_has_metadata(const void *addr) { return (addr >= kasan_shadow_to_mem((void *)KASAN_SHADOW_START)); } diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 8463e35b489f..ada3cfb43764 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -334,7 +334,7 @@ static void __kasan_report(unsigned long addr, size_t size, bool is_write, untagged_addr = reset_tag(tagged_addr); info.access_addr = tagged_addr; - if (addr_has_shadow(untagged_addr)) + if (addr_has_metadata(untagged_addr)) info.first_bad_addr = find_first_bad_addr(tagged_addr, size); else info.first_bad_addr = untagged_addr; @@ -345,11 +345,11 @@ static void __kasan_report(unsigned long addr, size_t size, bool is_write, start_report(&flags); print_error_description(&info); - if (addr_has_shadow(untagged_addr)) + if (addr_has_metadata(untagged_addr)) print_tags(get_tag(tagged_addr), info.first_bad_addr); pr_err("\n"); - if (addr_has_shadow(untagged_addr)) { + if (addr_has_metadata(untagged_addr)) { print_address_description(untagged_addr, get_tag(tagged_addr)); pr_err("\n"); print_shadow_for_address(info.first_bad_addr); diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c index 427f4ac80cca..29d30fae9421 100644 --- a/mm/kasan/report_generic.c +++ b/mm/kasan/report_generic.c @@ -122,7 +122,7 @@ const char *get_bug_type(struct kasan_access_info *info) if (info->access_addr + info->access_size < info->access_addr) return "out-of-bounds"; - if (addr_has_shadow(info->access_addr)) + if (addr_has_metadata(info->access_addr)) return get_shadow_bug_type(info); return get_wild_bug_type(info); } From patchwork Tue Sep 15 21:15:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777743 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CC2516CA for ; Tue, 15 Sep 2020 21:17:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 937AE20770 for ; Tue, 15 Sep 2020 21:17:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="pe/gphJl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 937AE20770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DF6C9900082; Tue, 15 Sep 2020 17:17:01 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DA73F900012; Tue, 15 Sep 2020 17:17:01 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CBDCF900082; Tue, 15 Sep 2020 17:17:01 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0187.hostedemail.com [216.40.44.187]) by kanga.kvack.org (Postfix) with ESMTP id A6C66900012 for ; Tue, 15 Sep 2020 17:17:01 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 440C3181AEF09 for ; Tue, 15 Sep 2020 21:17:01 +0000 (UTC) X-FDA: 77266555842.16.jail18_270a5fd27114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 155D4100E6912 for ; Tue, 15 Sep 2020 21:17:01 +0000 (UTC) X-Spam-Summary: 1,0,0,022c079308592f69,d41d8cd98f00b204,3sy9hxwokcdamzpdqkwzhxsaasxq.oayxuzgj-yywhmow.ads@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:966:973:982:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1541:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2693:3138:3139:3140:3141:3142:3152:3352:3865:3866:3867:3871:4250:4385:5007:6261:6653:6742:8603:9969:10004:10400:10450:10455:11026:11232:11473:11658:11914:12043:12048:12114:12297:12438:12555:12895:13069:13255:13311:13357:14093:14097:14181:14394:14659:14721:19904:19999:21080:21365:21444:21451:21627:30054,0,RBL:209.85.218.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04y8e7yeoynns3jbwj8b3a9kecsniyc47pgwjau8rdjkk5hq84568yi97zxenah.nz15mqssquzwzqdbnxhfwjm9ij3froxmmbn5g63sxgzyait97yastjdwrfhwbpt.o-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:ne utral,Cu X-HE-Tag: jail18_270a5fd27114 X-Filterd-Recvd-Size: 5063 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:00 +0000 (UTC) Received: by mail-ej1-f73.google.com with SMTP id d8so1841762ejt.14 for ; Tue, 15 Sep 2020 14:17:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=LA/JoGm8S/g3KI3imjTGafEDoL5GY8vPZ9zGXBZ3JZQ=; b=pe/gphJlmzAMPX95VYWAWtz0vwnZxs6ztYU65lG5adc1Tsk5t16qxRObv0Fj78BTSJ iwSptltcdPvW3+OF4mGCnZhaEWg+JrGEY7fltofc/Uvy170czTjYtmpTqrQxeO5cTors DUkW54UUWrIAkCn04SZt8YY9jW5LRnUzG6pS5MQwXXQTAk0P0ailXdGkYLXtFL+GcfEX gb8feGkSX2iuI9vchI2EWoWLx66sPY4tCZaZrM1jB2aASttRsRkr5F41mNUodOkeEiRD 1rp0p3F3AskTrLyn7OweXmv7p8Y7CNrOic+Q1tm4c8J7xWeFzo5nr9q/+g2CvECOo/2D 7Ydg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=LA/JoGm8S/g3KI3imjTGafEDoL5GY8vPZ9zGXBZ3JZQ=; b=hakF4VbzZuyVTS2YN6OmZu9ZtQ2okVZgifUuKREGfBL3MTtWpJL+XyuXr0tWtNMd+Y t7qBrL3NAlep3czXlJ3a8c9PglAMCnLagBYU1yq1zI+XdMZ5PxXA49t92Kh49D18GBCz 0mS+hd60Dmy91pl2GQ1BhOFCMycYAI9fP8rHVwIoxY01gssSpo3Qu/gDoxipfxlRBht4 Nf90TaQEsaurCPVy/AtAyOm6YXz3APxagC5bWGX1CkqcmKffKTjz2RzuMNuZWYr54L1x 10s5XtI5v4JC1jylT5dTLiCUCVvWingnqIJOETLBCOItMUUx+uK18o0mMnOwwmlsQwEA 4yoA== X-Gm-Message-State: AOAM5304HooxfFenTqsQReBK17ZkSxfIiUrdplPvCfieOW4bneQo/sqR 8lITluDL/3Q/jggsrsCdd6ZuvBbbaiE6T2tg X-Google-Smtp-Source: ABdhPJzHKloR/2nKSDoHn+YLky9R8AWO2YdB/ozJDPuL7EOFOdEaeBg49qPy/gRjjmd0lXtFLrzQSULF0gOQ3rhU X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:aa7:d30b:: with SMTP id p11mr24645433edq.80.1600204619159; Tue, 15 Sep 2020 14:16:59 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:57 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 15/37] kasan: rename print_shadow_for_address to print_memory_metadata From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 155D4100E6912 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Hardware tag-based KASAN won't be using shadow memory, but will reuse this function. Rename "shadow" to implementation-neutral "metadata". No functional changes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: I18397dddbed6bc6d365ddcaf063a83948e1150a5 --- mm/kasan/report.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index ada3cfb43764..8ad1ced1607d 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -255,7 +255,7 @@ static int shadow_pointer_offset(const void *row, const void *shadow) (shadow - row) / SHADOW_BYTES_PER_BLOCK + 1; } -static void print_shadow_for_address(const void *addr) +static void print_memory_metadata(const void *addr) { int i; const void *shadow = kasan_mem_to_shadow(addr); @@ -316,7 +316,7 @@ void kasan_report_invalid_free(void *object, unsigned long ip) pr_err("\n"); print_address_description(object, tag); pr_err("\n"); - print_shadow_for_address(object); + print_memory_metadata(object); end_report(&flags); } @@ -352,7 +352,7 @@ static void __kasan_report(unsigned long addr, size_t size, bool is_write, if (addr_has_metadata(untagged_addr)) { print_address_description(untagged_addr, get_tag(tagged_addr)); pr_err("\n"); - print_shadow_for_address(info.first_bad_addr); + print_memory_metadata(info.first_bad_addr); } else { dump_stack(); } From patchwork Tue Sep 15 21:15:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777745 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E1DBD59D for ; Tue, 15 Sep 2020 21:17:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A474320770 for ; Tue, 15 Sep 2020 21:17:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="vWPqCcAo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A474320770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D5AA7900067; Tue, 15 Sep 2020 17:17:03 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CE49F900012; Tue, 15 Sep 2020 17:17:03 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B84E1900067; Tue, 15 Sep 2020 17:17:03 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0085.hostedemail.com [216.40.44.85]) by kanga.kvack.org (Postfix) with ESMTP id 8EFFE900012 for ; Tue, 15 Sep 2020 17:17:03 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 4C3673489 for ; Tue, 15 Sep 2020 21:17:03 +0000 (UTC) X-FDA: 77266555926.18.help90_0510a9527114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 19647100EC683 for ; Tue, 15 Sep 2020 21:17:03 +0000 (UTC) X-Spam-Summary: 1,0,0,8c30b646f494e805,d41d8cd98f00b204,3ts9hxwokcdiobrfsmybjzuccuzs.qcazwbil-aayjoqy.cfu@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:1981:2194:2199:2393:2559:2562:3138:3139:3140:3141:3142:3152:3352:3865:3866:3867:3868:3871:3874:4250:4321:5007:6261:6653:6742:8603:9969:10004:10400:10450:10455:11026:11232:11473:11658:11914:12043:12048:12114:12297:12438:12555:12895:12986:13069:13311:13357:14181:14394:14659:14721:19904:19999:21080:21365:21444:21451:21627:21772:21990:30054,0,RBL:209.85.221.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04y8xruqtt6tub9mt77ur5nq4jiqsyphwmt9351zjpogx8t41ubtbkh47z6pb85.mjm5xs36zhgxshc1pjq7e63kw6inam78u3cekeeme59jprgwfcq8q83hgjchim1.k-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,D NSBL:neu X-HE-Tag: help90_0510a9527114 X-Filterd-Recvd-Size: 4531 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:02 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id j7so1706870wro.14 for ; Tue, 15 Sep 2020 14:17:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=4/ByT/O4Nvro4TMeKsqTFF+dTSNFkXyz3Nr2NgmhNnY=; b=vWPqCcAogi/jKWDdSun+38aXUOu71RzUkxMZHry8mER86ei6RngcWX7q1L6xR8ZMlh QRknTpkFeRjQB1Jy58mQQL41sc1vD8ym2kiC7LjDoQmF23mcwpIPTsdDobRXsA+wx7se onuLgOwct/FFx9HpJ53MiI1FHLQ58Z70nV57zxp96T1XBGa23PiyDtLZxuL6P9a36qYD TJ/ejxtH2CWVIhfzyck0X++QNvuP0WMwnWGT8AdjRRBPqiKJfMUb1CzXadGEgAli4123 XCjrmwUFGZDw094+VZFg3RpgzxrCIaGO/3PmKr636pE4cvr0uy2ePrBnNkou2IwHJHFD c5mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=4/ByT/O4Nvro4TMeKsqTFF+dTSNFkXyz3Nr2NgmhNnY=; b=oYapPqvOiyAtMc+i88jPNkCp792Zx0p473WUGgZSYkM/62cDfvfDCt9lpW6F1H6t8x kFx8kFw+Hz281CZ1fFGnMinybzXhtajbB+F/NDfEeh1ZyLsJ1CHMD7dXDl/lLO2Hmg+9 0nMKVWYtW7cNwh2/UOre0U2+5ehkqgprXyAkyYGi5e3ehG66C80ftPuRSZ6fQGrW/GFN gDtvjLj2k42K2Bte0CT/TGEPeuuXc1GRTf6Jx+sd+vgQpmaXymMnVTS6AvwXx5uTRsNl w2VicIQWLqvnALG7ALJ4fE1HyFsrwzTLMjF8z3HoEyZSjcEqlyY0uC/GQM/lkbg+I20+ 50Qg== X-Gm-Message-State: AOAM530m6a7BJJMY9xyIsa+zX+8ALTZu/wANDTF7nz/XftZl8DoegoEf EFFlDmr6dcdGBElzBaPu2k1uD0QpcgDJbXWr X-Google-Smtp-Source: ABdhPJyJzy0pAfIpJ83kYJpmfubqjIv8bKNgjP3h8jm4Z1uHk8W7Ngaeixu1VZJreyO5PJKTsLfJTs9OkhL7AtDF X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:6385:: with SMTP id x127mr1274747wmb.95.1600204621569; Tue, 15 Sep 2020 14:17:01 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:58 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 16/37] kasan: kasan_non_canonical_hook only for software modes From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 19647100EC683 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. kasan_non_canonical_hook() is only applicable to KASAN modes that use shadow memory, and won't be needed for hardware tag-based KASAN. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: Icc9f5ef100a2e86f3a4214a0c3131a68266181b2 --- mm/kasan/report.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 8ad1ced1607d..2cce7c9beea3 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -376,7 +376,8 @@ bool kasan_report(unsigned long addr, size_t size, bool is_write, return ret; } -#ifdef CONFIG_KASAN_INLINE +#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ + defined(CONFIG_KASAN_INLINE) /* * With CONFIG_KASAN_INLINE, accesses to bogus pointers (outside the high * canonical half of the address space) cause out-of-bounds shadow memory reads From patchwork Tue Sep 15 21:15:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777747 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8FD6159D for ; Tue, 15 Sep 2020 21:17:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5465120770 for ; Tue, 15 Sep 2020 21:17:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="DmRECeLt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5465120770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 34C0A900083; Tue, 15 Sep 2020 17:17:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2D499900012; Tue, 15 Sep 2020 17:17:06 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 068AB900083; Tue, 15 Sep 2020 17:17:05 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0156.hostedemail.com [216.40.44.156]) by kanga.kvack.org (Postfix) with ESMTP id D39D2900012 for ; Tue, 15 Sep 2020 17:17:05 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9BFC3181AEF09 for ; Tue, 15 Sep 2020 21:17:05 +0000 (UTC) X-FDA: 77266556010.18.sack44_5b0ba6727114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin18.hostedemail.com (Postfix) with ESMTP id 80164100EC688 for ; Tue, 15 Sep 2020 21:17:05 +0000 (UTC) X-Spam-Summary: 1,0,0,485a25907761f2ef,d41d8cd98f00b204,3ty9hxwokcdqqdthuoadlbweewbu.secbydkn-ccalqsa.ehw@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:69:152:355:379:541:800:960:973:982:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:1981:2194:2199:2393:2553:2559:2562:2693:2901:3138:3139:3140:3141:3142:3152:3354:3865:3866:3867:3871:4117:4250:4321:5007:6119:6261:6653:6742:7875:7903:9165:9969:10004:10400:10450:10455:11026:11232:11473:11658:11914:12043:12048:12297:12438:12555:12683:12895:12986:13161:13229:14181:14394:14659:14721:19904:19999:21080:21092:21365:21444:21451:21627:21990:30003:30045:30054:30090,0,RBL:209.85.221.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yfctcu59kej3tn4froqpeo354joopybr4a81jxirz69fbx6kma1s95dqqdqhk.jmhzbagjcbgudki17i8ahp8oeishhaxo7955qz58adjceixn3yarwe7gkbdkqpq.h-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,Dom ainCache X-HE-Tag: sack44_5b0ba6727114 X-Filterd-Recvd-Size: 6916 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:05 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id s8so1694188wrb.15 for ; Tue, 15 Sep 2020 14:17:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=5DI33wLk49GBiOtTKNywoiQR13ppWemjtswafD/fR5U=; b=DmRECeLtjagddPxzdBOI/cbUSIcCj9YlPlFtWUGZkzza+NWDct/TWNwEPz49SkuWzo 4XQ7FcE4/MEiXpjPl01IHdiQwJYMt00fu0owgHpTvGvGT+eMNRTAQyUBSw7MGEz1LPds fJU/HHM7oIvGTYV1Mc+eNzlXkwhdz871BCVnbNulA2XQm1qI86ZIPP6YCV3EtqYxFvYG iRkHaw+QV9t140r1KzUFLN2g2XUIEAYeKG0F4vY/BOAepISVUVn/Xo6bguhF2wAvuhih 7oSjhQJQ5xC5tLBr1fJslldAHgfLvHYyb5euCX1qmVxpt9cZDAZ7p/g2Hr0elLpu77GO gnUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=5DI33wLk49GBiOtTKNywoiQR13ppWemjtswafD/fR5U=; b=RDCWh0F6hse2kW9e5O59ei3q3GZ8DXu0a0vOy8ETnsDs76xsEtmWuSfeoT4pvnQ+Jf a04Eip57cYzHGpDs0FQLAtbdlh9Y540ka3szFMjulrexZGpTWGtMJ9CQW9ynClNyNGWn 0S/z69mh7tMXDTdUexBBV+RWdz0iPSoITzVRlzPgF47tLfibPSOX4c5ini5tnbcJA7b/ ZXHc92DvYtmtDssUY/90py2DhFMCQ/fZAFHAZ3Z4kaQgMDxnU5ppXX50LfJ2ihnwYZUQ QK45lFoqj1XGJhjJE+0U9FefKKn2HuG4xv+nOlUgm/PuYYv835iraJTQy/wOMxzlibXM l2wQ== X-Gm-Message-State: AOAM532XLB+SL1NGYcFQd7dDEs1J2xP1uiGOXaj+S3SjQxqPJB4BbEm+ A1k3wjaLXc10tNu4graTnzB7SvdR5uWcrIFe X-Google-Smtp-Source: ABdhPJx/IVWOUWzO63QUKRnkUC+iv4qskfpZBykHR2uWLCKAJcd6r7yMu0uGFJNhTPzIa56S3Bl1rZixp5HAYJUE X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a5d:6343:: with SMTP id b3mr24815500wrw.179.1600204623954; Tue, 15 Sep 2020 14:17:03 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:59 +0200 In-Reply-To: Message-Id: <3f3ee8faf0eb24b7bf6121a5708c4f4ac9ff68d9.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 17/37] kasan: rename SHADOW layout macros to META From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 80164100EC688 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Hardware tag-based KASAN won't be using shadow memory, but will reuse these macros. Rename "SHADOW" to implementation-neutral "META". No functional changes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: Id2d836bf43b401bce1221cc06e745185f17b1cc --- mm/kasan/report.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 2cce7c9beea3..6306673e7062 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -36,11 +36,11 @@ #include "kasan.h" #include "../slab.h" -/* Shadow layout customization. */ -#define SHADOW_BYTES_PER_BLOCK 1 -#define SHADOW_BLOCKS_PER_ROW 16 -#define SHADOW_BYTES_PER_ROW (SHADOW_BLOCKS_PER_ROW * SHADOW_BYTES_PER_BLOCK) -#define SHADOW_ROWS_AROUND_ADDR 2 +/* Metadata layout customization. */ +#define META_BYTES_PER_BLOCK 1 +#define META_BLOCKS_PER_ROW 16 +#define META_BYTES_PER_ROW (META_BLOCKS_PER_ROW * META_BYTES_PER_BLOCK) +#define META_ROWS_AROUND_ADDR 2 static unsigned long kasan_flags; @@ -243,7 +243,7 @@ static void print_address_description(void *addr, u8 tag) static bool row_is_guilty(const void *row, const void *guilty) { - return (row <= guilty) && (guilty < row + SHADOW_BYTES_PER_ROW); + return (row <= guilty) && (guilty < row + META_BYTES_PER_ROW); } static int shadow_pointer_offset(const void *row, const void *shadow) @@ -252,7 +252,7 @@ static int shadow_pointer_offset(const void *row, const void *shadow) * 3 + (BITS_PER_LONG/8)*2 chars. */ return 3 + (BITS_PER_LONG/8)*2 + (shadow - row)*2 + - (shadow - row) / SHADOW_BYTES_PER_BLOCK + 1; + (shadow - row) / META_BYTES_PER_BLOCK + 1; } static void print_memory_metadata(const void *addr) @@ -262,15 +262,15 @@ static void print_memory_metadata(const void *addr) const void *shadow_row; shadow_row = (void *)round_down((unsigned long)shadow, - SHADOW_BYTES_PER_ROW) - - SHADOW_ROWS_AROUND_ADDR * SHADOW_BYTES_PER_ROW; + META_BYTES_PER_ROW) + - META_ROWS_AROUND_ADDR * META_BYTES_PER_ROW; pr_err("Memory state around the buggy address:\n"); - for (i = -SHADOW_ROWS_AROUND_ADDR; i <= SHADOW_ROWS_AROUND_ADDR; i++) { + for (i = -META_ROWS_AROUND_ADDR; i <= META_ROWS_AROUND_ADDR; i++) { const void *kaddr = kasan_shadow_to_mem(shadow_row); char buffer[4 + (BITS_PER_LONG/8)*2]; - char shadow_buf[SHADOW_BYTES_PER_ROW]; + char shadow_buf[META_BYTES_PER_ROW]; snprintf(buffer, sizeof(buffer), (i == 0) ? ">%px: " : " %px: ", kaddr); @@ -279,17 +279,17 @@ static void print_memory_metadata(const void *addr) * function, because generic functions may try to * access kasan mapping for the passed address. */ - memcpy(shadow_buf, shadow_row, SHADOW_BYTES_PER_ROW); + memcpy(shadow_buf, shadow_row, META_BYTES_PER_ROW); print_hex_dump(KERN_ERR, buffer, - DUMP_PREFIX_NONE, SHADOW_BYTES_PER_ROW, 1, - shadow_buf, SHADOW_BYTES_PER_ROW, 0); + DUMP_PREFIX_NONE, META_BYTES_PER_ROW, 1, + shadow_buf, META_BYTES_PER_ROW, 0); if (row_is_guilty(shadow_row, shadow)) pr_err("%*c\n", shadow_pointer_offset(shadow_row, shadow), '^'); - shadow_row += SHADOW_BYTES_PER_ROW; + shadow_row += META_BYTES_PER_ROW; } } From patchwork Tue Sep 15 21:16:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777749 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ECCF76CA for ; Tue, 15 Sep 2020 21:17:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9D3B120770 for ; Tue, 15 Sep 2020 21:17:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Uqy/64yl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9D3B120770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 770BC900086; Tue, 15 Sep 2020 17:17:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7188B900012; Tue, 15 Sep 2020 17:17:08 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62CBD900086; Tue, 15 Sep 2020 17:17:08 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0028.hostedemail.com [216.40.44.28]) by kanga.kvack.org (Postfix) with ESMTP id 4926B900012 for ; Tue, 15 Sep 2020 17:17:08 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 0F9EB8249980 for ; Tue, 15 Sep 2020 21:17:08 +0000 (UTC) X-FDA: 77266556136.23.ray89_340663727114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id DBC0F37604 for ; Tue, 15 Sep 2020 21:17:07 +0000 (UTC) X-Spam-Summary: 1,0,0,bcb2cc32a36e8a2d,d41d8cd98f00b204,3ui9hxwokcdctgwkxrdgoezhhzex.vhfebgnq-ffdotvd.hkz@flex--andreyknvl.bounces.google.com,,RULES_HIT:2:41:69:152:355:379:541:800:960:966:973:982:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1593:1594:1605:1730:1747:1777:1792:1981:2194:2196:2199:2200:2393:2553:2559:2562:2693:2901:3138:3139:3140:3141:3142:3152:3865:3866:3867:3871:3872:3874:4049:4120:4250:4321:4385:4605:5007:6119:6261:6653:6742:7875:7903:8603:9165:9592:9969:10004:11026:11232:11473:11658:11914:12043:12048:12297:12438:12555:12683:12740:12895:12986:14096:14097:14394:14659:21080:21324:21365:21444:21451:21627:21740:21772:21796:21990:30003:30036:30045:30054:30075:30090,0,RBL:209.85.128.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yfjxic3pyo8sks4a1f541698z7qyp1qhpgabnkfc6nmnx8w9aixqs9m65xrr9.pdz4fecn9gnpqyndhocuwgdgmomm8ymdj9nyaeineo1759yaswe8t5aaxxcyrg8.w-lbl8.mailshell.net-223.238.255.100,CacheIP:non e,Bayesi X-HE-Tag: ray89_340663727114 X-Filterd-Recvd-Size: 9544 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:07 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id x6so256397wmi.1 for ; Tue, 15 Sep 2020 14:17:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=cNUkjw3h6h2vvdGQHstiUCBBTL6uA9taUHJKEUHsZNs=; b=Uqy/64yl/TSrssjZLH9qRL0b1Q9ojBJrOiiVPJ6ffDQyrLQwhEesqFOJzIy2SSQmB6 5Wrl7d+D7GwJr3iWjqN/g1Ny2ldoUFt/lxuop9KNLjFnQAb2HjaHQKWj7TRjUdJC2lWd hQ4u7RssH2+XZd6nSzU8L9eWNVu4lSjWsQPxXgZQGxMY/ynXM8tFY+vKO9z+j0VGLgaN u979tZVDr+n6SAG0gkOE5MPgiZXcWW7rtVKsnD6/NdRFxC5Ve11juxVWE4kEhLdnaz1x SZ7nt3Wfnj/6q1QYIc3/bAtTVIKiLtanjm1hhdDEPfwaS62q9mGK2QonxuEACBYt+zCJ zwMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=cNUkjw3h6h2vvdGQHstiUCBBTL6uA9taUHJKEUHsZNs=; b=VQJGlyUmN1y2ABhaBV6tgzk8hrTLTkOpsToJMP9BFPW4b2lWJhZrLqt9QWFk9UaIOU zSbExBrkUIUp9KUdM1hvubm3+KKy0/7ZtNbbfgyVGMstR1JGTBNKzQAxXQamVUvi12ZU dLGcJABJANHY7DFjLAC4pnMZfpenwdfCMvLjw7SlFDiM/vmxUFji8c33VugGGUEBx9p4 goqPj3nK3OXNcRs38G7l6WAjCEaCDD4Sy6wCbpRvp3d9y2vvcOuZnT25BA+izbA0Qyvy 1Dp+c7vMwhhJ0f7DoCVQ6IG9QgjjElVMT1TrEui3K1JxK+0E1DM3G0lo8/Qsd6JZOER+ +urg== X-Gm-Message-State: AOAM531oUGwvKxCg3Gb3Vl7iF6uNW0KSF8SpgLZPIVAKVAKcnt//s4oc w+VTy31FWEE50g9W92XqdqikKz/NhnExoLcy X-Google-Smtp-Source: ABdhPJzL8BhYNRzK4slQohtZ+7TSTK/+JbYrZ5VcU+mY7HWwBH8wrvRTXucYiWwyPZaxtMd5XV7Uyp2JR6WDFw6Q X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:600c:245:: with SMTP id 5mr1264364wmj.33.1600204626209; Tue, 15 Sep 2020 14:17:06 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:00 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 18/37] kasan: separate metadata_fetch_row for each mode From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: DBC0F37604 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Rework print_memory_metadata() to make it agnostic with regard to the way metadata is stored. Allow providing a separate metadata_fetch_row() implementation for each KASAN mode. Hardware tag-based KASAN will provide its own implementation that doesn't use shadow memory. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: I5b0ed1d079ea776e620beca6a529a861e7dced95 --- mm/kasan/kasan.h | 8 ++++++ mm/kasan/report.c | 56 +++++++++++++++++++-------------------- mm/kasan/report_generic.c | 5 ++++ mm/kasan/report_tags.c | 5 ++++ 4 files changed, 45 insertions(+), 29 deletions(-) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 38fa4c202e9a..1d3c7c6ce771 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -56,6 +56,13 @@ #define KASAN_ABI_VERSION 1 #endif +/* Metadata layout customization. */ +#define META_BYTES_PER_BLOCK 1 +#define META_BLOCKS_PER_ROW 16 +#define META_BYTES_PER_ROW (META_BLOCKS_PER_ROW * META_BYTES_PER_BLOCK) +#define META_MEM_BYTES_PER_ROW (META_BYTES_PER_ROW * KASAN_GRANULE_SIZE) +#define META_ROWS_AROUND_ADDR 2 + struct kasan_access_info { const void *access_addr; const void *first_bad_addr; @@ -167,6 +174,7 @@ bool check_invalid_free(void *addr); void *find_first_bad_addr(void *addr, size_t size); const char *get_bug_type(struct kasan_access_info *info); +void metadata_fetch_row(char *buffer, void *row); #ifdef CONFIG_KASAN_STACK_ENABLE void print_address_stack_frame(const void *addr); diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 6306673e7062..c904edab33b8 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -36,12 +36,6 @@ #include "kasan.h" #include "../slab.h" -/* Metadata layout customization. */ -#define META_BYTES_PER_BLOCK 1 -#define META_BLOCKS_PER_ROW 16 -#define META_BYTES_PER_ROW (META_BLOCKS_PER_ROW * META_BYTES_PER_BLOCK) -#define META_ROWS_AROUND_ADDR 2 - static unsigned long kasan_flags; #define KASAN_BIT_REPORTED 0 @@ -241,55 +235,59 @@ static void print_address_description(void *addr, u8 tag) print_address_stack_frame(addr); } -static bool row_is_guilty(const void *row, const void *guilty) +static bool meta_row_is_guilty(const void *row, const void *addr) { - return (row <= guilty) && (guilty < row + META_BYTES_PER_ROW); + return (row <= addr) && (addr < row + META_MEM_BYTES_PER_ROW); } -static int shadow_pointer_offset(const void *row, const void *shadow) +static int meta_pointer_offset(const void *row, const void *addr) { - /* The length of ">ff00ff00ff00ff00: " is - * 3 + (BITS_PER_LONG/8)*2 chars. + /* + * Memory state around the buggy address: + * ff00ff00ff00ff00: 00 00 00 05 fe fe fe fe fe fe fe fe fe fe fe fe + * ... + * + * The length of ">ff00ff00ff00ff00: " is + * 3 + (BITS_PER_LONG / 8) * 2 chars. + * The length of each granule metadata is 2 bytes + * plus 1 byte for space. */ - return 3 + (BITS_PER_LONG/8)*2 + (shadow - row)*2 + - (shadow - row) / META_BYTES_PER_BLOCK + 1; + return 3 + (BITS_PER_LONG / 8) * 2 + + (addr - row) / KASAN_GRANULE_SIZE * 3 + 1; } static void print_memory_metadata(const void *addr) { int i; - const void *shadow = kasan_mem_to_shadow(addr); - const void *shadow_row; + void *row; - shadow_row = (void *)round_down((unsigned long)shadow, - META_BYTES_PER_ROW) - - META_ROWS_AROUND_ADDR * META_BYTES_PER_ROW; + row = (void *)round_down((unsigned long)addr, META_MEM_BYTES_PER_ROW) + - META_ROWS_AROUND_ADDR * META_MEM_BYTES_PER_ROW; pr_err("Memory state around the buggy address:\n"); for (i = -META_ROWS_AROUND_ADDR; i <= META_ROWS_AROUND_ADDR; i++) { - const void *kaddr = kasan_shadow_to_mem(shadow_row); - char buffer[4 + (BITS_PER_LONG/8)*2]; - char shadow_buf[META_BYTES_PER_ROW]; + char buffer[4 + (BITS_PER_LONG / 8) * 2]; + char metadata[META_BYTES_PER_ROW]; snprintf(buffer, sizeof(buffer), - (i == 0) ? ">%px: " : " %px: ", kaddr); + (i == 0) ? ">%px: " : " %px: ", row); + /* * We should not pass a shadow pointer to generic * function, because generic functions may try to * access kasan mapping for the passed address. */ - memcpy(shadow_buf, shadow_row, META_BYTES_PER_ROW); + metadata_fetch_row(&metadata[0], row); + print_hex_dump(KERN_ERR, buffer, DUMP_PREFIX_NONE, META_BYTES_PER_ROW, 1, - shadow_buf, META_BYTES_PER_ROW, 0); + metadata, META_BYTES_PER_ROW, 0); - if (row_is_guilty(shadow_row, shadow)) - pr_err("%*c\n", - shadow_pointer_offset(shadow_row, shadow), - '^'); + if (meta_row_is_guilty(row, addr)) + pr_err("%*c\n", meta_pointer_offset(row, addr), '^'); - shadow_row += META_BYTES_PER_ROW; + row += META_MEM_BYTES_PER_ROW; } } diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c index 29d30fae9421..6524651b5d2e 100644 --- a/mm/kasan/report_generic.c +++ b/mm/kasan/report_generic.c @@ -127,6 +127,11 @@ const char *get_bug_type(struct kasan_access_info *info) return get_wild_bug_type(info); } +void metadata_fetch_row(char *buffer, void *row) +{ + memcpy(buffer, kasan_mem_to_shadow(row), META_BYTES_PER_ROW); +} + #ifdef CONFIG_KASAN_STACK_ENABLE static bool __must_check tokenize_frame_descr(const char **frame_descr, char *token, size_t max_tok_len, diff --git a/mm/kasan/report_tags.c b/mm/kasan/report_tags.c index 6ddb55676a7c..4060d0503462 100644 --- a/mm/kasan/report_tags.c +++ b/mm/kasan/report_tags.c @@ -85,6 +85,11 @@ void *find_first_bad_addr(void *addr, size_t size) return p; } +void metadata_fetch_row(char *buffer, void *row) +{ + memcpy(buffer, kasan_mem_to_shadow(row), META_BYTES_PER_ROW); +} + void print_tags(u8 addr_tag, const void *addr) { u8 *shadow = (u8 *)kasan_mem_to_shadow(addr); From patchwork Tue Sep 15 21:16:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777751 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2538E6CA for ; Tue, 15 Sep 2020 21:17:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DD4A020770 for ; Tue, 15 Sep 2020 21:17:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="ETreXfWq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DD4A020770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A4D6B900087; Tue, 15 Sep 2020 17:17:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9DCE7900012; Tue, 15 Sep 2020 17:17:10 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80A34900087; Tue, 15 Sep 2020 17:17:10 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0072.hostedemail.com [216.40.44.72]) by kanga.kvack.org (Postfix) with ESMTP id 65572900012 for ; Tue, 15 Sep 2020 17:17:10 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 2772C3489 for ; Tue, 15 Sep 2020 21:17:10 +0000 (UTC) X-FDA: 77266556220.14.basin88_35134cd27114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id DC88C18229835 for ; Tue, 15 Sep 2020 21:17:09 +0000 (UTC) X-Spam-Summary: 1,0,0,0a2f6637d3e77f1b,d41d8cd98f00b204,3vc9hxwokcdkviymztfiqgbjjbgz.xjhgdips-hhfqvxf.jmb@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1534:1541:1593:1594:1711:1714:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3152:3351:3871:3874:3876:4250:4321:5007:6261:6653:6742:9969:10004:10400:11026:11232:11473:11658:11914:12043:12048:12297:12438:12555:12895:13069:13311:13357:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:21772:30054:30070,0,RBL:209.85.222.201:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04y8ymgsc1x6gpznh5u1irb7ua39aop7ryrqmwrzup1kx6iapsqgqkbifnq5nh3.d7o3um9me6ybtdf9npp9ppsf4qiosg68dctfgt3yxidbjdqqp1ti7gmtynsnida.4-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY :none X-HE-Tag: basin88_35134cd27114 X-Filterd-Recvd-Size: 4390 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:09 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id x191so4117694qkb.3 for ; Tue, 15 Sep 2020 14:17:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=mh8O150eeMuxxMH0jStzmqkyZ8vLujB12mmwVNwjeBw=; b=ETreXfWqm2ORqdMXEMxCL+KWztT+SunXDBq3Z8Y5/Ta9DUNYpbGEq+rfeJBjq3TwOi bDvSLCjukG2rPbXHHVN5lgj+ngjup+3ad42VnPwe0Wbs1Kd861h1wkjrCAFCKMeLiJd6 f83l8FT2dSaGmHBbiVpnJXzd1AyYGbBMVhJkngqxDMtOP50ghNzSQkovTErdD50IYAYL ize0dUMXPLYQkEezeC4pjaFj8IIAua6feAl1B4mMmYaE+AguzMo11v21qwJ3LE/KV/ZR xoAphSZl10RGs5gC4IhwNE/WKHefh12mj/++rdP85rI3078p9dLncrqeXcd6owNyoBaM eD4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=mh8O150eeMuxxMH0jStzmqkyZ8vLujB12mmwVNwjeBw=; b=omaH0CaC4KUKDa20GxXQCdrrExSaGXz70n6nA6ehvpW19AkO0T4qspmiIIdN6WVvlZ GF1bEyB7HfE787GKRR7bry7U5Jt2Lv7g1d6tvVjweYI8afyzgjvsJt/Vs09jSipT4bI9 FwhpuuXPE5Ykuov7Kmzdbua5RU6VK8Fe9nkzdlZTXbviyteCFLRnzV84b50MmIR7QPex CEaV16QGpqSKiq/E73p7PeJssZD0xvB5P2ZX5YCqvzgvZ7HHbz1G6otX3kekEyX7KKrO wXGFH1KBefrNWdJqSXGex4fNpUTZzl3nh8/YXK5/Rs+7wOWFco9A06M5fSNiLG96Q9ma fWBw== X-Gm-Message-State: AOAM5308CZHVZIUPfxcrv20QuuxOkOZiVhGQs8gWujUhXrSC1wPUUhVj 2CwQstjBxDqTq5ggJp6jKZNeenSMi5DRwKPo X-Google-Smtp-Source: ABdhPJw8kuypKDjq36m+5MWDEBM2m2sdKvtM6e8W1eHE1KXnLuswMPPxAtQrR0GbHR2xbkTzUQB3mGa+9I5iKj5Y X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:f2c1:: with SMTP id c1mr11709701qvm.30.1600204628690; Tue, 15 Sep 2020 14:17:08 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:01 +0200 In-Reply-To: Message-Id: <42f25c11d97aa8497ee3851ee3531b379d6a922e.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 19/37] kasan: don't allow SW_TAGS with ARM64_MTE From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: DC88C18229835 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: Software tag-based KASAN provides its own tag checking machinery that can conflict with MTE. Don't allow enabling software tag-based KASAN when MTE is enabled. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Catalin Marinas --- Change-Id: Icd29bd0c6b1d3d7a0ee3d50c20490f404d34fc97 --- arch/arm64/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index e7450fbd0aa7..e875db8e1c86 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -131,7 +131,7 @@ config ARM64 select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_JUMP_LABEL_RELATIVE select HAVE_ARCH_KASAN if !(ARM64_16K_PAGES && ARM64_VA_BITS_48) - select HAVE_ARCH_KASAN_SW_TAGS if HAVE_ARCH_KASAN + select HAVE_ARCH_KASAN_SW_TAGS if (HAVE_ARCH_KASAN && !ARM64_MTE) select HAVE_ARCH_KGDB select HAVE_ARCH_MMAP_RND_BITS select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT From patchwork Tue Sep 15 21:16:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777753 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8881F59D for ; Tue, 15 Sep 2020 21:17:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4BC4020770 for ; Tue, 15 Sep 2020 21:17:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="ujKP7f36" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4BC4020770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D0D1C900088; Tue, 15 Sep 2020 17:17:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CBCBB900012; Tue, 15 Sep 2020 17:17:13 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BAD38900088; Tue, 15 Sep 2020 17:17:13 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0098.hostedemail.com [216.40.44.98]) by kanga.kvack.org (Postfix) with ESMTP id A5B94900012 for ; Tue, 15 Sep 2020 17:17:13 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6759D181AEF09 for ; Tue, 15 Sep 2020 21:17:13 +0000 (UTC) X-FDA: 77266556346.27.mint87_0b0799827114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id 3B85A3D668 for ; Tue, 15 Sep 2020 21:17:13 +0000 (UTC) X-Spam-Summary: 1,0,0,95c34396a203edfe,d41d8cd98f00b204,3vy9hxwokcdwylbpcwiltjemmejc.amkjglsv-kkityai.mpe@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:967:968:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:1801:1981:2194:2199:2393:2525:2559:2563:2682:2685:2693:2859:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3868:3870:3871:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4605:5007:6261:6653:6742:9025:9969:10004:10400:11026:11232:11473:11657:11658:11914:12043:12048:12296:12297:12438:12555:12679:12698:12737:12895:12986:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:30054,0,RBL:209.85.221.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04y88jrwmph78wt5aefxj6hs9ukr3yppb6eohid4acbyiqddz8nripgsr6bnr3i.47d7esjbmh8apkqamrjj1i6e3j6r9ebah886a6anknddst8yx11apukzowmtxb8.g-lbl8.mails hell.net X-HE-Tag: mint87_0b0799827114 X-Filterd-Recvd-Size: 5981 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:12 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id r16so1692922wrm.18 for ; Tue, 15 Sep 2020 14:17:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=esxSXj6mlAjehqEnyoU+Xpp5A2AelPI+Y2Gwz7MtjPo=; b=ujKP7f3676l72cWSInq5T3BbJ1ePrrsTWesoXaljrb3jzdEAOeQg9Ap8DBJKkPTnUA VB2vx3VHlei3rH+0RnjabUY/ixqcWjZw2y5lzkCfx6MzmDOroHPawZJt6uInPJMXU90j HS6aIT/g4L1kJ6E4mb0/xDt6scUTaOJLSlt6KsAcBNpmndBLe6TcTof0Ua5de0FMqqg6 5diX4jZZDu07mSajtmyv2OaNR6lFEHkV2YtbhwvqUzaLDUjpVRbX1qGkErZiFgQUD5ZV S61AucVPy0W2K8hGiDP20CYQAC5uzNXI/s5l/IYVSWE8QZ4SEAbKQQmJl02QArsG9u2C oEFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=esxSXj6mlAjehqEnyoU+Xpp5A2AelPI+Y2Gwz7MtjPo=; b=iNd/RdtLhg8OKOodBVfBd4pEqpbUbLfi/HCuKgOkI+Vlm1lFbp2xgIf8gElXBrmAiz RKWnJ6Z5qmrp8IKPnBw7co7UMlfjHF8RPKphWeSonEBqc4O+joN917vu/DN39ZzUSGtL TtmcQEh5Vmg4Wc0JjQ7pnWZFNNRK+vJJ/ynvytS/rIuG9EuCjLBjIxqjj/eReudtXsP8 /mMLhqIpqtpX6Rl9lbKT/S0rG70Mh+EsXhq5XSCbqgMucRP96iYgYJ1aF0k8dzhw/li+ O9LtQ6TWEw8kuTIY4nmraENCOrvnCtBdQqclOIQISFRpxzR0VYgKBme0RURrOvpu8kwk 16Mg== X-Gm-Message-State: AOAM53234Tg+a56M/qy2A8XSvbnJQyiXXyIrgZcfW8f2y3Iojr8qm4tn Ynr+19trV9JAaOHjDTEPfilYfo7cRBHAljDv X-Google-Smtp-Source: ABdhPJxcytv3DgzuyYcVFGJMlv8Oz2ucCD3HgDMSQ5j66wJnUEU9r4DqngEjJLt07XY6hdWbMt1ObH6FNDSH9bD8 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:e256:: with SMTP id z83mr1249442wmg.33.1600204631443; Tue, 15 Sep 2020 14:17:11 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:02 +0200 In-Reply-To: Message-Id: <28d17537bbd029104cf7de4f7ca92246449efa50.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 20/37] kasan: rename tags.c to tags_sw.c From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 3B85A3D668 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Hardware tag-based KASAN will also be using tag-based approach, so rename tags.c to tags_sw.c and report_tags.c to report_tags_sw.c to avoid confusion once the new mode is added Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: I922ab246c5903e8ce3dd3766b923aaf250599850 --- mm/kasan/Makefile | 10 +++++----- mm/kasan/{report_tags.c => report_tags_sw.c} | 0 mm/kasan/{tags.c => tags_sw.c} | 0 3 files changed, 5 insertions(+), 5 deletions(-) rename mm/kasan/{report_tags.c => report_tags_sw.c} (100%) rename mm/kasan/{tags.c => tags_sw.c} (100%) diff --git a/mm/kasan/Makefile b/mm/kasan/Makefile index b2596512421a..0789f9023884 100644 --- a/mm/kasan/Makefile +++ b/mm/kasan/Makefile @@ -10,9 +10,9 @@ CFLAGS_REMOVE_init.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_quarantine.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report_generic.o = $(CC_FLAGS_FTRACE) -CFLAGS_REMOVE_report_tags.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_report_tags_sw.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_shadow.o = $(CC_FLAGS_FTRACE) -CFLAGS_REMOVE_tags.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_tags_sw.o = $(CC_FLAGS_FTRACE) # Function splitter causes unnecessary splits in __asan_load1/__asan_store1 # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533 @@ -27,10 +27,10 @@ CFLAGS_init.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_quarantine.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_report.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_report_generic.o := $(CC_FLAGS_KASAN_RUNTIME) -CFLAGS_report_tags.o := $(CC_FLAGS_KASAN_RUNTIME) +CFLAGS_report_tags_sw.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_shadow.o := $(CC_FLAGS_KASAN_RUNTIME) -CFLAGS_tags.o := $(CC_FLAGS_KASAN_RUNTIME) +CFLAGS_tags_sw.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_SW_TAGS) += init.o report_tags.o shadow.o tags.o +obj-$(CONFIG_KASAN_SW_TAGS) += init.o report_tags_sw.o shadow.o tags_sw.o diff --git a/mm/kasan/report_tags.c b/mm/kasan/report_tags_sw.c similarity index 100% rename from mm/kasan/report_tags.c rename to mm/kasan/report_tags_sw.c diff --git a/mm/kasan/tags.c b/mm/kasan/tags_sw.c similarity index 100% rename from mm/kasan/tags.c rename to mm/kasan/tags_sw.c From patchwork Tue Sep 15 21:16:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777755 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C775E6CA for ; Tue, 15 Sep 2020 21:17:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 742FC20770 for ; Tue, 15 Sep 2020 21:17:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="dSybjoro" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 742FC20770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D5CC2900089; Tue, 15 Sep 2020 17:17:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CBBBD900012; Tue, 15 Sep 2020 17:17:16 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B37BD900089; Tue, 15 Sep 2020 17:17:16 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9A04E900012 for ; Tue, 15 Sep 2020 17:17:16 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 61F292826 for ; Tue, 15 Sep 2020 21:17:16 +0000 (UTC) X-FDA: 77266556472.21.humor83_4905c5727114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 82A61180442D0 for ; Tue, 15 Sep 2020 21:17:15 +0000 (UTC) X-Spam-Summary: 1,0,0,aaaa13fb9d6d71ec,d41d8cd98f00b204,3ws9hxwokcd4fsiwj3ps0qlttlqj.htrqnsz2-rrp0fhp.twl@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:69:152:355:379:541:800:960:973:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1544:1593:1594:1605:1711:1730:1747:1777:1792:1981:2194:2199:2393:2559:2562:2901:2908:3138:3139:3140:3141:3142:3152:3865:3866:3867:3868:3870:3871:3872:3874:4119:4250:4321:5007:6117:6261:6653:6742:7903:9592:9969:10004:11026:11232:11473:11658:11914:12043:12048:12114:12291:12296:12297:12438:12555:12683:12895:14096:14097:14181:14394:14659:14721:14819:21080:21365:21444:21451:21627:21740:21772:30003:30054:30070,0,RBL:209.85.128.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yfzjedtx7k79z8eofosp34hd7ajyceuhsruay1mrurayy3ue5zhbyj838j395.p9bnr13iuz7fn5io8w9rh6yk9pku8n35z47e98ddxrd3qp74m9b4647d8d7ch6i.1-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCach e:0,MSF: X-HE-Tag: humor83_4905c5727114 X-Filterd-Recvd-Size: 8258 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:14 +0000 (UTC) Received: by mail-wm1-f73.google.com with SMTP id s19so229840wme.2 for ; Tue, 15 Sep 2020 14:17:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=5EqdZprNAKl8DcEkoPF/XnJisJp3YxDsBKGpOsfCaUM=; b=dSybjorouN3NX0oNwA+x/Pfy82WuWHZzJkliyJ9G8vLV3eiqslCz/+Z7Dofurm+OQU 6xt7TzC60W2hVg1gmZ5qNCb0iUzLzB1lEj9UTl/pXsD9+GKR0Y+Zl1DrXZfz4cmACWPw eGEJIlTsSzgg+GuFCr6N1x3HcQdLlvyy5XEDOM9chOh+OE9z9MZWHgwwZUqwRib7J3Vz 4FPo5iaWX+3eM89m5j6V9grz+91IcNlDryV9LeHDG5kttNRmq6stcRIZ1j1CB9w89YlN /TFcUJzUXOu/e+bsoV4JzcpK/4+wrAByQ+Cl011OL70vmbvlMP19NrW4UjJCtwLrrKzQ c2OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=5EqdZprNAKl8DcEkoPF/XnJisJp3YxDsBKGpOsfCaUM=; b=fyw4xq/qV43QUaASXNTbxXPdaE1e3syZI44CL7CF+nwKGprw/Iff1DJnmqowIXhfDr cuGiSiQWeOjMIPq8P/LtYtgkJY5ZamQHcYW8kVWgcZTrXSVKEAwsE6YVizG8pDe32ygr Vy+EQ5hW2eKhJ2yyTRoOI11pjV6RwrL/M2RbayVRBb/rQtxLcyw6mWWeuVfV+QizcI3M eHkoGRO5Scs0h2vi6z+FPRiKok6DZv/T46WK8VBlBAd12Mrs9b4eiwuFfpn3pJ7wxIX8 aWa3VRY1IjlCVUmxCeEq8cDGXhCxcw2AGOnonkz2QSQyTRvCAPtc5VtfWX6Cog30hZUL 1mRw== X-Gm-Message-State: AOAM532U4pPhcL3dVdIz65Oclwqu5XUZOvQtnFYIvPefFA2d79tx7QoY e5s+YdEslsRYGckRFAbwkyUPfQwlstccbmDF X-Google-Smtp-Source: ABdhPJy2hiIuBBUwzXu4fh5D45KSrPKugB1l3b4uwIRzOuOGVhH/dFn2WZDGZUvt0VUc2SO+mtpkIwFuzCEvX2bV X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:c4d1:: with SMTP id g17mr1160652wmk.167.1600204633702; Tue, 15 Sep 2020 14:17:13 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:03 +0200 In-Reply-To: Message-Id: <329ece34759c5208ae32a126dc5c978695ab1776.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 21/37] kasan: introduce CONFIG_KASAN_HW_TAGS From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 82A61180442D0 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: This patch adds a configuration option for a new KASAN mode called hardware tag-based KASAN. This mode uses the memory tagging approach like the software tag-based mode, but relies on arm64 Memory Tagging Extension feature for tag management and access checking. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: I246c2def9fffa6563278db1bddfbe742ca7bdefe --- lib/Kconfig.kasan | 56 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan index b4cf6c519d71..17c9ecfaecb9 100644 --- a/lib/Kconfig.kasan +++ b/lib/Kconfig.kasan @@ -6,7 +6,10 @@ config HAVE_ARCH_KASAN config HAVE_ARCH_KASAN_SW_TAGS bool -config HAVE_ARCH_KASAN_VMALLOC +config HAVE_ARCH_KASAN_HW_TAGS + bool + +config HAVE_ARCH_KASAN_VMALLOC bool config CC_HAS_KASAN_GENERIC @@ -20,10 +23,11 @@ config CC_HAS_WORKING_NOSANITIZE_ADDRESS menuconfig KASAN bool "KASAN: runtime memory debugger" - depends on (HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC) || \ - (HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS) + depends on (((HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC) || \ + (HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS)) && \ + CC_HAS_WORKING_NOSANITIZE_ADDRESS) || \ + HAVE_ARCH_KASAN_HW_TAGS depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB) - depends on CC_HAS_WORKING_NOSANITIZE_ADDRESS select SLUB_DEBUG if SLUB select CONSTRUCTORS select STACKDEPOT @@ -38,13 +42,18 @@ choice prompt "KASAN mode" default KASAN_GENERIC help - KASAN has two modes: generic KASAN (similar to userspace ASan, - x86_64/arm64/xtensa, enabled with CONFIG_KASAN_GENERIC) and - software tag-based KASAN (a version based on software memory - tagging, arm64 only, similar to userspace HWASan, enabled with - CONFIG_KASAN_SW_TAGS). + KASAN has three modes: + 1. generic KASAN (similar to userspace ASan, + x86_64/arm64/xtensa, enabled with CONFIG_KASAN_GENERIC), + 2. software tag-based KASAN (arm64 only, based on software + memory tagging (similar to userspace HWASan), enabled with + CONFIG_KASAN_SW_TAGS), and + 3. hardware tag-based KASAN (arm64 only, based on hardware + memory tagging, enabled with CONFIG_KASAN_HW_TAGS). - Both generic and tag-based KASAN are strictly debugging features. + All KASAN modes are strictly debugging features. + + For better error detection enable CONFIG_STACKTRACE. config KASAN_GENERIC bool "Generic mode" @@ -61,8 +70,6 @@ config KASAN_GENERIC and introduces an overhead of ~x1.5 for the rest of the allocations. The performance slowdown is ~x3. - For better error detection enable CONFIG_STACKTRACE. - Currently CONFIG_KASAN_GENERIC doesn't work with CONFIG_DEBUG_SLAB (the resulting kernel does not boot). @@ -72,9 +79,11 @@ config KASAN_SW_TAGS help Enables software tag-based KASAN mode. - This mode requires Top Byte Ignore support by the CPU and therefore - is only supported for arm64. This mode requires Clang version 7.0.0 - or later. + This mode require software memory tagging support in the form of + HWASan-like compiler instrumentation. + + Currently this mode is only implemented for arm64 CPUs and relies on + Top Byte Ignore. This mode requires Clang version 7.0.0 or later. This mode consumes about 1/16th of available memory at kernel start and introduces an overhead of ~20% for the rest of the allocations. @@ -82,15 +91,27 @@ config KASAN_SW_TAGS casting and comparison, as it embeds tags into the top byte of each pointer. - For better error detection enable CONFIG_STACKTRACE. - Currently CONFIG_KASAN_SW_TAGS doesn't work with CONFIG_DEBUG_SLAB (the resulting kernel does not boot). +config KASAN_HW_TAGS + bool "Hardware tag-based mode" + depends on HAVE_ARCH_KASAN_HW_TAGS + depends on SLUB + help + Enables hardware tag-based KASAN mode. + + This mode requires hardware memory tagging support, and can be used + by any architecture that provides it. + + Currently this mode is only implemented for arm64 CPUs starting from + ARMv8.5 and relies on Memory Tagging Extension and Top Byte Ignore. + endchoice choice prompt "Instrumentation type" + depends on KASAN_GENERIC || KASAN_SW_TAGS default KASAN_OUTLINE config KASAN_OUTLINE @@ -114,6 +135,7 @@ endchoice config KASAN_STACK_ENABLE bool "Enable stack instrumentation (unsafe)" if CC_IS_CLANG && !COMPILE_TEST + depends on KASAN_GENERIC || KASAN_SW_TAGS help The LLVM stack address sanitizer has a know problem that causes excessive stack usage in a lot of functions, see From patchwork Tue Sep 15 21:16:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777759 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C288D6CA for ; Tue, 15 Sep 2020 21:17:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 79C8520770 for ; Tue, 15 Sep 2020 21:17:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="qdt0h6m8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 79C8520770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EE4A3900012; Tue, 15 Sep 2020 17:17:17 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E1E0490008A; Tue, 15 Sep 2020 17:17:17 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D43A4900012; Tue, 15 Sep 2020 17:17:17 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0059.hostedemail.com [216.40.44.59]) by kanga.kvack.org (Postfix) with ESMTP id B2109900012 for ; Tue, 15 Sep 2020 17:17:17 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 74ECD181AEF09 for ; Tue, 15 Sep 2020 21:17:17 +0000 (UTC) X-FDA: 77266556514.12.floor41_0e0339d27114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 3CC2B1800FB4E for ; Tue, 15 Sep 2020 21:17:17 +0000 (UTC) X-Spam-Summary: 1,0,0,f43260fb9594086d,d41d8cd98f00b204,3wy9hxwokceacpftg0mpxniqqing.eqonkpwz-oomxcem.qti@flex--andreyknvl.bounces.google.com,,RULES_HIT:1:2:41:152:355:379:541:800:960:968:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1593:1594:1605:1730:1747:1777:1792:2194:2199:2393:2538:2559:2562:3138:3139:3140:3141:3142:3152:3865:3866:3867:3868:3870:3871:3874:4049:4321:4605:5007:6117:6119:6261:6653:6742:7576:7875:8603:9036:9969:10004:11026:11232:11473:11657:11658:11914:12043:12048:12291:12296:12297:12438:12555:12679:12895:12986:13141:13230:14394:14659:21080:21365:21444:21451:21627:21990:30054:30067,0,RBL:209.85.160.202:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yfsr3x6s8rn9k5rx58nkss5z3u3ypahushopfm3kdnuaxdwy6hnfhdg5jyie4.nu5yid68bsqokicip11k66zs69i9nat6h9xrpehq56fdxfap4f1oouifxkue46n.y-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:n eutral,C X-HE-Tag: floor41_0e0339d27114 X-Filterd-Recvd-Size: 10030 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:16 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id f12so4022047qtq.5 for ; Tue, 15 Sep 2020 14:17:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=EjJhT+aBWvSW5tBYtrKg3j1ds+SSoe7l1pzkwlzhcIA=; b=qdt0h6m8e2SenBJw4pJS9GsmWMYLu8NOi7oiFi1Rv92NfIRxvfsipYsvTcVoKTlHpK Ldl1N8GaVV1DDSEH8gDfetZKkRP7pBl2PMclflpfKZ0+GuvAFrUbgnj8UHRW1PeVqPKD niVwylJdv1rwGbdXMO6yVLufFTifRYqPN8IRL9dlb3lShyFz9lUdQUDchKsof3qCxTxJ fxjh20xjN4Uo9czM6gCFVb342//Mymj0Uy2U7eZz2clrjyOh7LNARQ5heJbmWuvwMNQX dEvCNC6tym/ZlVJaD9vXUtlM8ZcY4zmvaaCRzhVF1QU9+QIzvtawZJJd0g2Jlxt5hUuz kYuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=EjJhT+aBWvSW5tBYtrKg3j1ds+SSoe7l1pzkwlzhcIA=; b=ja3UsFnQtEtxA+XpCusEYBy5doV5gjskBUG1NjIVldpPmRby4houKBJxuJX5IqA2Y4 k6XVKADEdwO55aeV5C9Zi0AFxvyPX0FTkVkGgwOeNZM1anT3u6RVfnkNhdoG2IzjHOab C+bsvR50YjDExVSUdfUEq8r3KXqi4Jmty/qitpViMNV2xvs1cBLxCM4fTiHI3ZK+CNka J66AKZzr1sguzxiNbNg3eDlPoW3lXUyJqAFXgvjneuUhURvThMwIiNCh4OwczJF1uU7K K3S3Zmm0OIlJvg1708Sspvc8B72skwUeN3aqTpV5lgI/RbGx1RMw7yNLA8mcVliDyIhb 6Cew== X-Gm-Message-State: AOAM533J/lLb0IpdJhZFadFH+PEHDfTkyzd1n5Z7aVeWff7QiClT51b+ TCO4pW5mZwjFHw7h/UsBsWCoq94I/2dgOWWS X-Google-Smtp-Source: ABdhPJznItyo9JV9Agypgfsx+XA9jc3Pb/E/RCFXo1JU2ePp9jsJUkcTNA4b04dCI/jdX8/lZDQEsr4Nu3dvBCff X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:57cc:: with SMTP id y12mr3796349qvx.48.1600204635905; Tue, 15 Sep 2020 14:17:15 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:04 +0200 In-Reply-To: Message-Id: <4ac1ed624dd1b0851d8cf2861b4f4aac4d2dbc83.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 22/37] arm64: mte: Add in-kernel MTE helpers From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 3CC2B1800FB4E X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: From: Vincenzo Frascino Provide helper functions to manipulate allocation and pointer tags for kernel addresses. Low-level helper functions (mte_assign_*, written in assembly) operate tag values from the [0x0, 0xF] range. High-level helper functions (mte_get/set_*) use the [0xF0, 0xFF] range to preserve compatibility with normal kernel pointers that have 0xFF in their top byte. MTE_GRANULE_SIZE and related definitions are moved to mte-def.h header that doesn't have any dependencies and is safe to include into any low-level header. Signed-off-by: Vincenzo Frascino Co-developed-by: Andrey Konovalov Signed-off-by: Andrey Konovalov --- Change-Id: I1b5230254f90dc21a913447cb17f07fea7944ece --- arch/arm64/include/asm/esr.h | 1 + arch/arm64/include/asm/mte-helpers.h | 48 ++++++++++++++++++++++++++++ arch/arm64/include/asm/mte.h | 17 ++++++---- arch/arm64/kernel/mte.c | 48 ++++++++++++++++++++++++++++ arch/arm64/lib/mte.S | 17 ++++++++++ 5 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 arch/arm64/include/asm/mte-helpers.h diff --git a/arch/arm64/include/asm/esr.h b/arch/arm64/include/asm/esr.h index 035003acfa87..bc0dc66a6a27 100644 --- a/arch/arm64/include/asm/esr.h +++ b/arch/arm64/include/asm/esr.h @@ -103,6 +103,7 @@ #define ESR_ELx_FSC (0x3F) #define ESR_ELx_FSC_TYPE (0x3C) #define ESR_ELx_FSC_EXTABT (0x10) +#define ESR_ELx_FSC_MTE (0x11) #define ESR_ELx_FSC_SERROR (0x11) #define ESR_ELx_FSC_ACCESS (0x08) #define ESR_ELx_FSC_FAULT (0x04) diff --git a/arch/arm64/include/asm/mte-helpers.h b/arch/arm64/include/asm/mte-helpers.h new file mode 100644 index 000000000000..5dc2d443851b --- /dev/null +++ b/arch/arm64/include/asm/mte-helpers.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2020 ARM Ltd. + */ +#ifndef __ASM_MTE_ASM_H +#define __ASM_MTE_ASM_H + +#define __MTE_PREAMBLE ".arch armv8.5-a\n.arch_extension memtag\n" + +#define MTE_GRANULE_SIZE UL(16) +#define MTE_GRANULE_MASK (~(MTE_GRANULE_SIZE - 1)) +#define MTE_TAG_SHIFT 56 +#define MTE_TAG_SIZE 4 +#define MTE_TAG_MASK GENMASK((MTE_TAG_SHIFT + (MTE_TAG_SIZE - 1)), MTE_TAG_SHIFT) +#define MTE_TAG_MAX (MTE_TAG_MASK >> MTE_TAG_SHIFT) + +#ifndef __ASSEMBLY__ + +#include + +#ifdef CONFIG_ARM64_MTE + +#define mte_get_ptr_tag(ptr) ((u8)(((u64)(ptr)) >> MTE_TAG_SHIFT)) +u8 mte_get_mem_tag(void *addr); +u8 mte_get_random_tag(void); +void *mte_set_mem_tag_range(void *addr, size_t size, u8 tag); + +#else /* CONFIG_ARM64_MTE */ + +#define mte_get_ptr_tag(ptr) 0xFF +static inline u8 mte_get_mem_tag(void *addr) +{ + return 0xFF; +} +static inline u8 mte_get_random_tag(void) +{ + return 0xFF; +} +static inline void *mte_set_mem_tag_range(void *addr, size_t size, u8 tag) +{ + return addr; +} + +#endif /* CONFIG_ARM64_MTE */ + +#endif /* __ASSEMBLY__ */ + +#endif /* __ASM_MTE_ASM_H */ diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h index 1c99fcadb58c..82cd7c89edec 100644 --- a/arch/arm64/include/asm/mte.h +++ b/arch/arm64/include/asm/mte.h @@ -5,14 +5,13 @@ #ifndef __ASM_MTE_H #define __ASM_MTE_H -#define MTE_GRANULE_SIZE UL(16) -#define MTE_GRANULE_MASK (~(MTE_GRANULE_SIZE - 1)) -#define MTE_TAG_SHIFT 56 -#define MTE_TAG_SIZE 4 +#include #ifndef __ASSEMBLY__ +#include #include +#include #include @@ -45,7 +44,9 @@ long get_mte_ctrl(struct task_struct *task); int mte_ptrace_copy_tags(struct task_struct *child, long request, unsigned long addr, unsigned long data); -#else +void mte_assign_mem_tag_range(void *addr, size_t size); + +#else /* CONFIG_ARM64_MTE */ /* unused if !CONFIG_ARM64_MTE, silence the compiler */ #define PG_mte_tagged 0 @@ -80,7 +81,11 @@ static inline int mte_ptrace_copy_tags(struct task_struct *child, return -EIO; } -#endif +static inline void mte_assign_mem_tag_range(void *addr, size_t size) +{ +} + +#endif /* CONFIG_ARM64_MTE */ #endif /* __ASSEMBLY__ */ #endif /* __ASM_MTE_H */ diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index 52a0638ed967..e238ffde2679 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -13,8 +13,10 @@ #include #include #include +#include #include +#include #include #include #include @@ -72,6 +74,52 @@ int memcmp_pages(struct page *page1, struct page *page2) return ret; } +u8 mte_get_mem_tag(void *addr) +{ + if (system_supports_mte()) + asm volatile(ALTERNATIVE("ldr %0, [%0]", + __MTE_PREAMBLE "ldg %0, [%0]", + ARM64_MTE) + : "+r" (addr)); + + return 0xF0 | mte_get_ptr_tag(addr); +} + +u8 mte_get_random_tag(void) +{ + u8 tag = 0xF; + u64 addr = 0; + + if (system_supports_mte()) { + asm volatile(ALTERNATIVE("add %0, %0, %0", + __MTE_PREAMBLE "irg %0, %0", + ARM64_MTE) + : "+r" (addr)); + + tag = mte_get_ptr_tag(addr); + } + + return 0xF0 | tag; +} + +void *mte_set_mem_tag_range(void *addr, size_t size, u8 tag) +{ + void *ptr = addr; + + if ((!system_supports_mte()) || (size == 0)) + return addr; + + /* Make sure that size is aligned. */ + WARN_ON(size & (MTE_GRANULE_SIZE - 1)); + + tag = 0xF0 | (tag & 0xF); + ptr = (void *)__tag_set(ptr, tag); + + mte_assign_mem_tag_range(ptr, size); + + return ptr; +} + static void update_sctlr_el1_tcf0(u64 tcf0) { /* ISB required for the kernel uaccess routines */ diff --git a/arch/arm64/lib/mte.S b/arch/arm64/lib/mte.S index 03ca6d8b8670..cc2c3a378c00 100644 --- a/arch/arm64/lib/mte.S +++ b/arch/arm64/lib/mte.S @@ -149,3 +149,20 @@ SYM_FUNC_START(mte_restore_page_tags) ret SYM_FUNC_END(mte_restore_page_tags) + +/* + * Assign allocation tags for a region of memory based on the pointer tag + * x0 - source pointer + * x1 - size + * + * Note: size must be non-zero and MTE_GRANULE_SIZE aligned + */ +SYM_FUNC_START(mte_assign_mem_tag_range) + /* if (src == NULL) return; */ + cbz x0, 2f +1: stg x0, [x0] + add x0, x0, #MTE_GRANULE_SIZE + sub x1, x1, #MTE_GRANULE_SIZE + cbnz x1, 1b +2: ret +SYM_FUNC_END(mte_assign_mem_tag_range) From patchwork Tue Sep 15 21:16:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777761 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D7D366CA for ; Tue, 15 Sep 2020 21:17:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8F3412078E for ; Tue, 15 Sep 2020 21:17:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="BMgCiDxI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8F3412078E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 039EE90008B; Tue, 15 Sep 2020 17:17:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F2FB990008A; Tue, 15 Sep 2020 17:17:20 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E43DE90008B; Tue, 15 Sep 2020 17:17:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0086.hostedemail.com [216.40.44.86]) by kanga.kvack.org (Postfix) with ESMTP id CF96190008A for ; Tue, 15 Sep 2020 17:17:20 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 9DF488249980 for ; Tue, 15 Sep 2020 21:17:20 +0000 (UTC) X-FDA: 77266556640.09.music58_5a0408427114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 6B3AC180AD81F for ; Tue, 15 Sep 2020 21:17:20 +0000 (UTC) X-Spam-Summary: 1,0,0,47ec04d40f82adaf,d41d8cd98f00b204,3xi9hxwokcemfsiwj3ps0qlttlqj.htrqnsz2-rrp0fhp.twl@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2693:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3870:3871:4117:4250:4321:4605:5007:6261:6653:6742:7903:8603:9969:10004:10400:11026:11232:11473:11657:11658:11914:12043:12048:12297:12438:12555:12895:12986:13149:13161:13229:13230:14181:14394:14659:14721:21080:21365:21433:21444:21451:21627:21990:30003:30012:30054,0,RBL:209.85.208.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.84.100 66.100.201.100;04y8dta39xjs3zppf7fw78urundahycxs8cioen1m9gpbjrg81jfkboyqzbng6c.ebeb97qjk69q1ogzqy58trtnriffp8st59rnm196yd4mfwbb6kybf9xekqjtpx9.y-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutr al,Custo X-HE-Tag: music58_5a0408427114 X-Filterd-Recvd-Size: 6155 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:19 +0000 (UTC) Received: by mail-ed1-f74.google.com with SMTP id d13so1776609edz.18 for ; Tue, 15 Sep 2020 14:17:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=uQBUcw70N5/pZNHz2QWMX765YU53M7496uPmAAbH/iU=; b=BMgCiDxI+ewSN9duc+vPhe1zL2wKt3c6rQlKYz9QH0ToEvMf9sfoL11ylpKV3yAh4t oALaiLPmKJtO5+cn5UwTLE5xrflMtIwwKQQj+kzXXG8bipIoxcKPpay1Pm37fb4lRf0+ W6NOp5qYE/ik0nutl3QC6yPy5/M4NVt8dzp09IBcnMvPV3OrigakDyyt1sI8LJi+kdKu vrK/smCBgTxnx2bBlpJKODNo5p5lX2c20XklJ5LKqv+YYdcyFPtVo+PBEuEQBdesT8l1 u+qj0kr40IC0Ark3xu2y4Ic/2Y+pTpby0p0pJqKia3b7oH5zmigy+cSlmRQ8HvgTACO5 ZBfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=uQBUcw70N5/pZNHz2QWMX765YU53M7496uPmAAbH/iU=; b=QwJ/4FQ6dsxEPdiXzWrX01ndB20tCUHpPc6U2v2uamve7QmnaW9o+NaIueUB4tnuuM fZ1NIEKBj8zHb1xTNZjBLgkVyyy+psA3wmF2WqrD/RiZWBCYmcHYvoAy35xx+kOkKQac GkhYlX7dzHejpF2WPAEXc8O2fAEIiZ1llLFLwfd/zRGd9IzvtVc6L0cUEf6rP4HY6XeE eJRUfgjWtsjzQzIBYvLShqVfIwWQe+NX7Ye9DJCzE8+Q5mAY5sqSxUkvFMudJ5cGFISF yUO9NKE/u9tu7Y1np4y1VppX6rD+BHn2Po2eIogUoEWxABHDUp4qRfgQTA7aqbdyKLDj 0eow== X-Gm-Message-State: AOAM533F+vRwnpbj2Gm78e5ZAeyU8uIqOQh7BXJiCJOzMyyTiTODDpVL G+4kO2CEjeO5Xn1SGn3ykJr10Ot/L8/d1wSX X-Google-Smtp-Source: ABdhPJwWctjYlK1i0RQ9U5rwbx1MXyXTqF8P/2W35vyRuLyCkaQtqJgTmv97oJ7dLulE5XOcJgCU96m1Yrxfbnde X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6402:18d:: with SMTP id r13mr23596971edv.267.1600204638418; Tue, 15 Sep 2020 14:17:18 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:05 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 23/37] arm64: kasan: Add arch layer for memory tagging helpers From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 6B3AC180AD81F X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: This patch add a set of arch_*() memory tagging helpers currently only defined for arm64 when hardware tag-based KASAN is enabled. These helpers will be used by KASAN runtime to implement the hardware tag-based mode. The arch-level indirection level is introduced to simplify adding hardware tag-based KASAN support for other architectures in the future by defining the appropriate arch_*() macros. Signed-off-by: Andrey Konovalov Co-developed-by: Vincenzo Frascino Signed-off-by: Vincenzo Frascino Reviewed-by: Catalin Marinas --- Change-Id: I42b0795a28067872f8308e00c6f0195bca435c2a --- arch/arm64/include/asm/memory.h | 8 ++++++++ mm/kasan/kasan.h | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index e424fc3a68cb..268a3b6cebd2 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -231,6 +231,14 @@ static inline const void *__tag_set(const void *addr, u8 tag) return (const void *)(__addr | __tag_shifted(tag)); } +#ifdef CONFIG_KASAN_HW_TAGS +#define arch_init_tags(max_tag) mte_init_tags(max_tag) +#define arch_get_random_tag() mte_get_random_tag() +#define arch_get_mem_tag(addr) mte_get_mem_tag(addr) +#define arch_set_mem_tag_range(addr, size, tag) \ + mte_set_mem_tag_range((addr), (size), (tag)) +#endif /* CONFIG_KASAN_HW_TAGS */ + /* * Physical vs virtual RAM address space conversion. These are * private definitions which should NOT be used outside memory.h diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 1d3c7c6ce771..8b43fc163ed1 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -240,6 +240,25 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) #define reset_tag(addr) ((void *)arch_kasan_reset_tag(addr)) #define get_tag(addr) arch_kasan_get_tag(addr) +#ifndef arch_init_tags +#define arch_init_tags(max_tag) +#endif +#ifndef arch_get_random_tag +#define arch_get_random_tag() (0xFF) +#endif +#ifndef arch_get_mem_tag +#define arch_get_mem_tag(addr) (0xFF) +#endif +#ifndef arch_set_mem_tag_range +#define arch_set_mem_tag_range(addr, size, tag) ((void *)(addr)) +#endif + +#define init_tags(max_tag) arch_init_tags(max_tag) +#define get_random_tag() arch_get_random_tag() +#define get_mem_tag(addr) arch_get_mem_tag(addr) +#define set_mem_tag_range(addr, size, tag) \ + arch_set_mem_tag_range((addr), (size), (tag)) + /* * Exported functions for interfaces called from assembly or from generated * code. Declarations here to avoid warning about missing declarations. From patchwork Tue Sep 15 21:16:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777763 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DE13B59D for ; Tue, 15 Sep 2020 21:17:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9917820770 for ; Tue, 15 Sep 2020 21:17:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="vmOgCDX4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9917820770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A506190008C; Tue, 15 Sep 2020 17:17:22 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A341990008A; Tue, 15 Sep 2020 17:17:22 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8ECE390008C; Tue, 15 Sep 2020 17:17:22 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0005.hostedemail.com [216.40.44.5]) by kanga.kvack.org (Postfix) with ESMTP id 760EF90008A for ; Tue, 15 Sep 2020 17:17:22 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2FF328249980 for ; Tue, 15 Sep 2020 21:17:22 +0000 (UTC) X-FDA: 77266556724.11.toys18_2a0bbfb27114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id 0236F180F8B80 for ; Tue, 15 Sep 2020 21:17:21 +0000 (UTC) X-Spam-Summary: 1,0,0,6b27c6fd7daf8446,d41d8cd98f00b204,3yc9hxwokceuhukyl5ru2snvvnsl.jvtspu14-ttr2hjr.vyn@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2693:3138:3139:3140:3141:3142:3152:3354:3865:3866:3868:3870:3871:3872:4117:4321:4605:5007:6117:6261:6653:6742:7576:9036:9165:9969:10004:10400:11026:11232:11473:11658:11914:12043:12048:12291:12296:12297:12438:12555:12679:12683:12895:12986:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:21795:21939:21966:21990:30003:30051:30054:30070,0,RBL:209.85.222.201:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yrbrr4fwnm1jrddhdu8np8tkbs9ophfa19wk8b5fdte456pgsef9peu3yiwjd.sgjh1d598kwakwnaci3wxz5xdtye4xt6kwqtb6gt37ymwgiwiqfj9i6okcap9pu.s-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF: not bulk X-HE-Tag: toys18_2a0bbfb27114 X-Filterd-Recvd-Size: 6037 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:21 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id 205so4115192qkd.2 for ; Tue, 15 Sep 2020 14:17:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=8gCy5LzCrZ4Ippif5C2Kr6pI1Q8A3vPTLrXylwHP5Is=; b=vmOgCDX4Ovlo+g3q/YjlH2gzNXCBg6oYk1uHca7WFAJy0wEyxCaO7diA4/HQFhbfTm vZCxg8qtkEXtSmNVkwvmd3y9aPHfb1O3HzVcCMYG5GkvRSxpNmSqOEo731jm0j0k1tVu OEKw5b06tRh6HL9jAeFZXqBsP1qLSDni5lS66o6K10BKTIu2Gh3yDizNmuHcNyx++XHH tHYzDWRe+6TQkK1QpWT99yOl6ce7cDGFlAIEDlSgVkns9356jlEzO60Y5PwCulcoS0Vx tVwDbjoZHJktHkYmPTJ4GRQBmCpdAnlxFId4luoMymcP63yZ58/CEn/wg3c6xs89g66t gxGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=8gCy5LzCrZ4Ippif5C2Kr6pI1Q8A3vPTLrXylwHP5Is=; b=D4vzuee78GCAbPgUtIpzpWPxSShi3Dlyz7wkf3dbWbt6rL+cdGaloYvf8nlP0yD/mW 1vWUoXVxH5QZ1+pR9RI71xaumeK/jIcFkeuBHpXsBIA1iYaCrg9iAknnCQ7uI9Rqfmu8 XMEdwHN0n+STnp4+iwoGYryFBonuILSf7HQFGGsl71ga89oK9g9/X7ZLYQtDOlecRfYt 7dPN57Xkd60EZVaeVheJoTEJxsOtZYzQyc/Qlu6DbtG1QhgjLHfCz6rSidEPN7cTdCjW lxe3dxlQ1ZiduQ7Dc+WILK6EYY9p+rToIvixLaO0fZyjrO+3W/zwXufHvWzHefPeo9cc 9Qtw== X-Gm-Message-State: AOAM532Ycq7pYL4Dngousd7c/iuOOFr89z8mCS0t6ryZOh8be4xNRP3o Y/b2QBxOwWcXz8GMJ1eZAbd/qO+LDyh6C4vN X-Google-Smtp-Source: ABdhPJx1hOhDWmjDE0HlzEorlVjxg9QmeE8fIeKQfK3gTvzMzRC6zTbmaUqg7dVWWCVncgIssdu5E4KU6Pu81Z6R X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:5745:: with SMTP id q5mr19950252qvx.29.1600204640737; Tue, 15 Sep 2020 14:17:20 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:06 +0200 In-Reply-To: Message-Id: <7866d9e6f11f12f1bad42c895bf4947addba71c2.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 24/37] arm64: mte: Add in-kernel tag fault handler From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 0236F180F8B80 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: From: Vincenzo Frascino Add the implementation of the in-kernel fault handler. When a tag fault happens on a kernel address: * a warning is logged, * MTE is disabled on the current CPU, * the execution continues. When a tag fault happens on a user address: * the kernel executes do_bad_area() and panics. Signed-off-by: Vincenzo Frascino Co-developed-by: Andrey Konovalov Signed-off-by: Andrey Konovalov --- Change-Id: I9b8aa79567f7c45f4d6a1290efcf34567e620717 --- arch/arm64/mm/fault.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index a3bd189602df..cdc23662691c 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -294,6 +295,18 @@ static void die_kernel_fault(const char *msg, unsigned long addr, do_exit(SIGKILL); } +static void report_tag_fault(unsigned long addr, unsigned int esr, + struct pt_regs *regs) +{ + bool is_write = ((esr & ESR_ELx_WNR) >> ESR_ELx_WNR_SHIFT) != 0; + + pr_alert("Memory Tagging Extension Fault in %pS\n", (void *)regs->pc); + pr_alert(" %s at address %lx\n", is_write ? "Write" : "Read", addr); + pr_alert(" Pointer tag: [%02x], memory tag: [%02x]\n", + mte_get_ptr_tag(addr), + mte_get_mem_tag((void *)addr)); +} + static void __do_kernel_fault(unsigned long addr, unsigned int esr, struct pt_regs *regs) { @@ -641,10 +654,31 @@ static int do_sea(unsigned long addr, unsigned int esr, struct pt_regs *regs) return 0; } +static void do_tag_recovery(unsigned long addr, unsigned int esr, + struct pt_regs *regs) +{ + report_tag_fault(addr, esr, regs); + + /* + * Disable Memory Tagging Extension Tag Checking on the local CPU + * for the current EL. + * It will be done lazily on the other CPUs when they will hit a + * tag fault. + */ + sysreg_clear_set(sctlr_el1, SCTLR_ELx_TCF_MASK, SCTLR_ELx_TCF_NONE); + isb(); +} + + static int do_tag_check_fault(unsigned long addr, unsigned int esr, struct pt_regs *regs) { - do_bad_area(addr, esr, regs); + /* The tag check fault (TCF) is per TTBR */ + if (is_ttbr0_addr(addr)) + do_bad_area(addr, esr, regs); + else + do_tag_recovery(addr, esr, regs); + return 0; } From patchwork Tue Sep 15 21:16:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777765 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 19FF36CA for ; Tue, 15 Sep 2020 21:17:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C5FB02078E for ; Tue, 15 Sep 2020 21:17:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="p2QNOStD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C5FB02078E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9D6D190008D; Tue, 15 Sep 2020 17:17:25 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 988A590008A; Tue, 15 Sep 2020 17:17:25 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87D9990008D; Tue, 15 Sep 2020 17:17:25 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0061.hostedemail.com [216.40.44.61]) by kanga.kvack.org (Postfix) with ESMTP id 6FBCA90008A for ; Tue, 15 Sep 2020 17:17:25 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3668B3489 for ; Tue, 15 Sep 2020 21:17:25 +0000 (UTC) X-FDA: 77266556850.29.spark48_0b0a96527114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id 06219180868E5 for ; Tue, 15 Sep 2020 21:17:25 +0000 (UTC) X-Spam-Summary: 1,0,0,2c92ff64136e3d73,d41d8cd98f00b204,3yy9hxwokcegkxn1o8ux5vqyyqvo.mywvsx47-wwu5kmu.y1q@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2895:2899:2901:3138:3139:3140:3141:3142:3152:3354:3865:3866:3867:3868:3870:3871:3872:4117:4250:4321:4605:5007:6117:6119:6261:6653:6742:7576:7903:9969:10004:10400:11026:11232:11473:11657:11658:11914:12043:12048:12296:12297:12438:12555:12679:12895:12986:13138:13141:13161:13180:13229:13230:13231:13868:14181:14394:14659:14721:21080:21365:21444:21451:21627:21795:30051:30054:30070,0,RBL:209.85.208.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.84.100 66.100.201.100;04yfka544rokcidckqht318q81d98oc6f3mitaiu6bka1zrxybrhz6drik1oa1e.zsrnymbz84owntefa8zwgkq1wj791eyaq8zrt79ycw7te9xgtr5c7st9rzrkqhs.n-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netche ck:none, X-HE-Tag: spark48_0b0a96527114 X-Filterd-Recvd-Size: 6158 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:24 +0000 (UTC) Received: by mail-ed1-f74.google.com with SMTP id n19so68530eds.8 for ; Tue, 15 Sep 2020 14:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=pBsGqTIqbR91modi76ePsvmJJRuaBk1hVSkVG5VFwBQ=; b=p2QNOStDgd3DtDO2HMju2iMROSw8FGR9GwRtHaoapNRKPL7jpItd7Nvrv9ZUMnx5Q9 8omi9isnPo7q0hA0GQq1Gb/n+Qtd3gOUgcadRA63YAzQ5c7yW5bSifPYsUlu3RfXsOhw bKib5qq1Nz/zAypPDCWC6iYRJGxZO7ltEPxS+e+VLmx2xbYqSyangq+OO1QbSjCtxQfg nbiluYCPKo4yVY4Rm0yu2q7JTG14E6A9ir3gafO3HGJ6NORNnkxFV3omQs5MUN8mRZxp +p6amVva7PebyyovbInJ7KY0jaCFmoG0p9bHmALDzXjrJgSelm+GhpxYd0+OQ6a5kx4m v76Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=pBsGqTIqbR91modi76ePsvmJJRuaBk1hVSkVG5VFwBQ=; b=LOZzDB9wwnZ8NVd5VMKeC9lL+PfmPFKSMEZfO8jA7rgxw60VP0d+Sa9NXMsRcumdma BPnMeL41wrYtl5taiv7YAbLHJc01rXb4gddnjgsRor5BvGFwES4wSt++GbVYNFTzA29+ 6X1tKmvEAVJmCGmalRa9DTGb0Tv9ase1MI8quFgSDyQOHSMHZyS8MqPMAsyQZADz98tW H1qHkvrAGCKFHAdpuow22UsCBypkNb7p3xx/nFc968iB/P1YgXPSTz3bgIGOonbSvz3R nrchxLCHTfEwuOsBFqUFEraTWQpEb4nT61xUDcydLJspRJXNawcAf1sLCNVVgWGTb/CE QZAw== X-Gm-Message-State: AOAM530HW1J9oHGgsEzXryl0fbmoPMj8FW/zVEns+F/3wk4iHkAY4uxy QhZnc1lyr2lZ7efUfUDC155zHWYYE3bIvHH3 X-Google-Smtp-Source: ABdhPJw8M8WWCio4qpRA1ZXyUA8Var1LZEn3zoWxmx7gA98yPdjDztcJ9EMI1/V5rg5Qsem0Jb9eVOShbM9zEULm X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a17:906:8559:: with SMTP id h25mr21784179ejy.536.1600204643277; Tue, 15 Sep 2020 14:17:23 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:07 +0200 In-Reply-To: Message-Id: <859111cf1d862ce26f094cf14511461c372e5bbc.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 25/37] arm64: kasan: Enable in-kernel MTE From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 06219180868E5 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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: From: Vincenzo Frascino Hardware tag-based KASAN relies on Memory Tagging Extension (MTE) feature and requires it to be enabled. The Tag Checking operation causes a synchronous data abort as a consequence of a tag check fault when MTE is configured in synchronous mode. Enable MTE in Synchronous mode in EL1 to provide a more immediate way of tag check failure detection in the kernel. As part of this change enable match-all tag for EL1 to allow the kernel to access user pages without faulting. This is required because the kernel does not have knowledge of the tags set by the user in a page. Note: For MTE, the TCF bit field in SCTLR_EL1 affects only EL1 in a similar way as TCF0 affects EL0. Signed-off-by: Vincenzo Frascino Signed-off-by: Andrey Konovalov --- Change-Id: I4d67497268bb7f0c2fc5dcacefa1e273df4af71d --- arch/arm64/kernel/cpufeature.c | 7 +++++++ arch/arm64/mm/proc.S | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index add9da5d8ea3..eca06b8c74db 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -1718,6 +1718,13 @@ static void cpu_enable_mte(struct arm64_cpu_capabilities const *cap) cleared_zero_page = true; mte_clear_page_tags(lm_alias(empty_zero_page)); } + + /* Enable in-kernel MTE only if KASAN_HW_TAGS is enabled */ + if (IS_ENABLED(CONFIG_KASAN_HW_TAGS)) { + /* Enable MTE Sync Mode for EL1 */ + sysreg_clear_set(sctlr_el1, SCTLR_ELx_TCF_MASK, SCTLR_ELx_TCF_SYNC); + isb(); + } } #endif /* CONFIG_ARM64_MTE */ diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 23c326a06b2d..5ba7ac5e9c77 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -427,6 +427,10 @@ SYM_FUNC_START(__cpu_setup) */ mov_q x5, MAIR_EL1_SET #ifdef CONFIG_ARM64_MTE + mte_present .req x20 + + mov mte_present, #0 + /* * Update MAIR_EL1, GCR_EL1 and TFSR*_EL1 if MTE is supported * (ID_AA64PFR1_EL1[11:8] > 1). @@ -447,6 +451,8 @@ SYM_FUNC_START(__cpu_setup) /* clear any pending tag check faults in TFSR*_EL1 */ msr_s SYS_TFSR_EL1, xzr msr_s SYS_TFSRE0_EL1, xzr + + mov mte_present, #1 1: #endif msr mair_el1, x5 @@ -485,6 +491,13 @@ SYM_FUNC_START(__cpu_setup) orr x10, x10, #TCR_HA // hardware Access flag update 1: #endif /* CONFIG_ARM64_HW_AFDBM */ +#ifdef CONFIG_ARM64_MTE + /* Update TCR_EL1 if MTE is supported (ID_AA64PFR1_EL1[11:8] > 1) */ + cbz mte_present, 1f + orr x10, x10, #SYS_TCR_EL1_TCMA1 +1: + .unreq mte_present +#endif msr tcr_el1, x10 /* * Prepare SCTLR From patchwork Tue Sep 15 21:16:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777767 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 523C86CA for ; Tue, 15 Sep 2020 21:17:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0A7B92078E for ; Tue, 15 Sep 2020 21:17:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="OPHSGMgy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0A7B92078E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 56B5B90008E; Tue, 15 Sep 2020 17:17:27 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5420990008A; Tue, 15 Sep 2020 17:17:27 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42ED690008E; Tue, 15 Sep 2020 17:17:27 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0092.hostedemail.com [216.40.44.92]) by kanga.kvack.org (Postfix) with ESMTP id 2817390008A for ; Tue, 15 Sep 2020 17:17:27 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id E6B5D180AD807 for ; Tue, 15 Sep 2020 21:17:26 +0000 (UTC) X-FDA: 77266556892.19.base40_320800327114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id BB2141AD1B1 for ; Tue, 15 Sep 2020 21:17:26 +0000 (UTC) X-Spam-Summary: 1,0,0,1f92a5b817f3b139,d41d8cd98f00b204,3zs9hxwokceomzp3qawz7xs00sxq.o0yxuz69-yyw7mow.03s@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:69:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1544:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2693:3138:3139:3140:3141:3142:3152:3355:3865:3867:3868:3871:3872:3874:4118:4250:4321:4605:5007:6261:6653:6742:7576:7903:9036:9969:10004:11026:11232:11473:11657:11658:11914:12043:12048:12296:12297:12438:12555:12679:12895:13149:13161:13180:13229:13230:13972:14181:14394:14659:14721:21063:21080:21365:21433:21444:21451:21627:21795:21990:30051:30054:30070,0,RBL:209.85.222.201:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yf7mau1cfty7mu9x8g6hd5fhgmaocgprbxnrd48dq1wo6epqnn9xiqakbxpgq.xitp3y7a95hr6pbb1f46qwhrzw94ug7mwznx8rguynqswbytftsjn6pnrw37mj7.n-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,M SF:not b X-HE-Tag: base40_320800327114 X-Filterd-Recvd-Size: 7801 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:26 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id m23so4079433qkh.10 for ; Tue, 15 Sep 2020 14:17:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=LoMLrgCJ4NCLa6lDkl4/AfQRlbckNXKPTR9s0h+8nto=; b=OPHSGMgyTOEYfNPCqFtxP8N6XSZ6nxthp788gfaQ6LZK88+NP4G9p8EfPPO64vxsMI 1Vp+LwO8Ch8ajFcrNwd8R/XStc+zaNO399CyV8mmtSNtCE9oUIixxEu685oh+92ui+x0 KbAP5RApmPxXLCNI3A/nPLpPQafWdGNAXJPXruFJ68rI+OQej/eb3gAUyXcc/NurYUOQ 9r0CIjJc6n5UatLdS8F96jkE+QhbQcVnS+6Q6PA6qsVY8mpL1iUib6dCdh79f60Vi7t5 u7KNZOzWlUTFEIH80ecHOhmW0gkQgt0jqxCSW8AtwiJLtXVHpndqXBWyDQeJvuen3TFn f+Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=LoMLrgCJ4NCLa6lDkl4/AfQRlbckNXKPTR9s0h+8nto=; b=ISfBieUvMbAFqXP44jiAU6EJyDmTfXVbjQxosaiCE9VLZCXq5fL9w/wMblRzxxl+bE KYHhkgxUpI/qpvF6BGY+bG1OgZg61dvzKmc+4DvpjhsptFFRi30aehVGSzeAxSHdfI+r pRDi9SRzS/g+lRKqjpNWkdG6BfBOCnaPZf12PMAi5Qkw3kRe+VFnyqFe5pGRUq3Wfl/Z ZhxPSB3jFBjkcbIVmVqGGIvnnRjcrFh8QSy+5HWwZmnza1M/hnczFOStjO+lpAVwfXEL Embgi8tGyKDb0v9dgZsrl7Q8+riwlM2AFA3uF2IuUTAVTi3A9PybBZvwMfVBQ61Wt3yD 9wCQ== X-Gm-Message-State: AOAM530qrDXMR5RAe0jgrooP+pucHsI0SbSshwuwnHZfn2mIQFuGR5N/ sN/1QaaElph1zvUeDVTovDZkbH64v/rTVAEW X-Google-Smtp-Source: ABdhPJxmY0qJcpgV1DP7goE8DV5QQTLm7VX7KUqDAy2WnXdtmug7VK++0MBCbCzt8X4HcHNViflvrcMh5ai1FDcA X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:b21b:: with SMTP id x27mr20134857qvd.12.1600204645596; Tue, 15 Sep 2020 14:17:25 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:08 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 26/37] arm64: mte: Convert gcr_user into an exclude mask From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: BB2141AD1B1 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: From: Vincenzo Frascino The gcr_user mask is a per thread mask that represents the tags that are excluded from random generation when the Memory Tagging Extension is present and an 'irg' instruction is invoked. gcr_user affects the behavior on EL0 only. Currently that mask is an include mask and it is controlled by the user via prctl() while GCR_EL1 accepts an exclude mask. Convert the include mask into an exclude one to make it easier the register setting. Note: This change will affect gcr_kernel (for EL1) introduced with a future patch. Signed-off-by: Vincenzo Frascino Signed-off-by: Andrey Konovalov Reviewed-by: Catalin Marinas --- Change-Id: Id15c0b47582fb51594bb26fb8353d78c7d0953c1 --- arch/arm64/include/asm/processor.h | 2 +- arch/arm64/kernel/mte.c | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index fec204d28fce..ed9efa5be8eb 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -153,7 +153,7 @@ struct thread_struct { #endif #ifdef CONFIG_ARM64_MTE u64 sctlr_tcf0; - u64 gcr_user_incl; + u64 gcr_user_excl; #endif }; diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index e238ffde2679..858e75cfcaa0 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -140,23 +140,22 @@ static void set_sctlr_el1_tcf0(u64 tcf0) preempt_enable(); } -static void update_gcr_el1_excl(u64 incl) +static void update_gcr_el1_excl(u64 excl) { - u64 excl = ~incl & SYS_GCR_EL1_EXCL_MASK; /* - * Note that 'incl' is an include mask (controlled by the user via - * prctl()) while GCR_EL1 accepts an exclude mask. + * Note that the mask controlled by the user via prctl() is an + * include while GCR_EL1 accepts an exclude mask. * No need for ISB since this only affects EL0 currently, implicit * with ERET. */ sysreg_clear_set_s(SYS_GCR_EL1, SYS_GCR_EL1_EXCL_MASK, excl); } -static void set_gcr_el1_excl(u64 incl) +static void set_gcr_el1_excl(u64 excl) { - current->thread.gcr_user_incl = incl; - update_gcr_el1_excl(incl); + current->thread.gcr_user_excl = excl; + update_gcr_el1_excl(excl); } void flush_mte_state(void) @@ -171,7 +170,7 @@ void flush_mte_state(void) /* disable tag checking */ set_sctlr_el1_tcf0(SCTLR_EL1_TCF0_NONE); /* reset tag generation mask */ - set_gcr_el1_excl(0); + set_gcr_el1_excl(SYS_GCR_EL1_EXCL_MASK); } void mte_thread_switch(struct task_struct *next) @@ -182,7 +181,7 @@ void mte_thread_switch(struct task_struct *next) /* avoid expensive SCTLR_EL1 accesses if no change */ if (current->thread.sctlr_tcf0 != next->thread.sctlr_tcf0) update_sctlr_el1_tcf0(next->thread.sctlr_tcf0); - update_gcr_el1_excl(next->thread.gcr_user_incl); + update_gcr_el1_excl(next->thread.gcr_user_excl); } void mte_suspend_exit(void) @@ -190,13 +189,14 @@ void mte_suspend_exit(void) if (!system_supports_mte()) return; - update_gcr_el1_excl(current->thread.gcr_user_incl); + update_gcr_el1_excl(current->thread.gcr_user_excl); } long set_mte_ctrl(struct task_struct *task, unsigned long arg) { u64 tcf0; - u64 gcr_incl = (arg & PR_MTE_TAG_MASK) >> PR_MTE_TAG_SHIFT; + u64 gcr_excl = ~((arg & PR_MTE_TAG_MASK) >> PR_MTE_TAG_SHIFT) & + SYS_GCR_EL1_EXCL_MASK; if (!system_supports_mte()) return 0; @@ -217,10 +217,10 @@ long set_mte_ctrl(struct task_struct *task, unsigned long arg) if (task != current) { task->thread.sctlr_tcf0 = tcf0; - task->thread.gcr_user_incl = gcr_incl; + task->thread.gcr_user_excl = gcr_excl; } else { set_sctlr_el1_tcf0(tcf0); - set_gcr_el1_excl(gcr_incl); + set_gcr_el1_excl(gcr_excl); } return 0; @@ -229,11 +229,12 @@ long set_mte_ctrl(struct task_struct *task, unsigned long arg) long get_mte_ctrl(struct task_struct *task) { unsigned long ret; + u64 incl = ~task->thread.gcr_user_excl & SYS_GCR_EL1_EXCL_MASK; if (!system_supports_mte()) return 0; - ret = task->thread.gcr_user_incl << PR_MTE_TAG_SHIFT; + ret = incl << PR_MTE_TAG_SHIFT; switch (task->thread.sctlr_tcf0) { case SCTLR_EL1_TCF0_NONE: From patchwork Tue Sep 15 21:16:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777769 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 37CC559D for ; Tue, 15 Sep 2020 21:17:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E70B820770 for ; Tue, 15 Sep 2020 21:17:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="dj076h3H" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E70B820770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C491790008F; Tue, 15 Sep 2020 17:17:30 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BF76290008A; Tue, 15 Sep 2020 17:17:30 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE5A390008F; Tue, 15 Sep 2020 17:17:30 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 9312A90008A for ; Tue, 15 Sep 2020 17:17:30 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 584C98249980 for ; Tue, 15 Sep 2020 21:17:30 +0000 (UTC) X-FDA: 77266557060.24.pies23_5b026f227114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id 32FA81A4A5 for ; Tue, 15 Sep 2020 21:17:30 +0000 (UTC) X-Spam-Summary: 1,0,0,27919053db2c6113,d41d8cd98f00b204,3ac9hxwokce0p2s6tdz2a0v33v0t.r310x29c-11zaprz.36v@flex--andreyknvl.bounces.google.com,,RULES_HIT:1:2:41:152:355:379:541:800:960:973:981:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1593:1594:1605:1730:1747:1777:1792:2393:2559:2562:2693:3138:3139:3140:3141:3142:3152:3865:3866:3867:3868:3870:3871:3874:4049:4250:4321:4605:5007:6117:6119:6261:6653:6742:7576:7903:7904:8603:8784:9969:10004:11026:11232:11473:11657:11658:11914:12043:12048:12291:12296:12297:12438:12555:12679:12895:12986:13141:13161:13229:13230:13972:14096:14097:14394:14659:14877:21063:21080:21365:21444:21451:21611:21627:21795:21990:30051:30054:30069:30070,0,RBL:209.85.221.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yrmbia5p8d7m5mcnnfceekws5h1ocqawo1shxnnejk1ytodzdwqaxsff7gczh.1rq9zt4ohihtfnqpz6k3yfqf6ghe4p4xidzq1oqgibsgzd8yqqyr4ydebgmfg7o.6-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0 .5,Netch X-HE-Tag: pies23_5b026f227114 X-Filterd-Recvd-Size: 10012 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:29 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id g6so1717345wrv.3 for ; Tue, 15 Sep 2020 14:17:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=bCscEPFr1p8biWaTnMvAabXKFPxq9bPZ2kCBns9eE1M=; b=dj076h3Hq0EZ5vJsqvWYXNTgDdvEZskWR3MgYexaY/cHXXt/eNQ961DFynen3V5ls3 1gM+0JhfkHfRhDJv2EgyJpd8fTFxLm+Ie9EAP37+QlOFhJsoOwlIjPNv7pTfIRxQpnEN wZQOiN28rW7bBvA4c8d2fnW1qmdR5cJwGsUi5tatyu/J2LGJb4en6ZIwkIh/BSFC/vJ6 1w6pM4PpIThFUj0A3FikYijkbdliUSF3+7yELSk1fB5ELKjHSFKTwyjOuylsHYFnkRUm CYU7gh3lliG2hefWhZp0KC0fuXs2zCDlkOQP0Q/GvkntJVd0BVujYDp8RP9yrNScuDsz oW5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=bCscEPFr1p8biWaTnMvAabXKFPxq9bPZ2kCBns9eE1M=; b=HfcidvjbRVoD/kzQ/ufV709Qa5SAf2H6sRD5l/OuwrDeoEpM3D4if634jJnWl0VPFX PwhUqx06mSjGWnwHiexSdAzmLUZy1kluYyVC+vrTCf79xR2j2BxSA6yl0CCcMqcw29+a AmEvRWSkb98OinqAIHDRukpSQjjurqRR5dg1evxW/qgvv2o/1n9nWRx35+YiIL9O2HAc d1iwUbGmnuNHq5s4pngzrmj603p+glx/6SF8xmKxrq04YZUo9YXzIk5EdwnY39UbIHFA oY145XqW++HzbmrzbB+p7HZj9MBaTYRmce0dhZqvw80bMaUIlZ9h7IG+tcBVu9hmPBsI 3mRQ== X-Gm-Message-State: AOAM533xz0xqAt4/gzaLxwaX8v5hlv7B1J+2x5AoL1WIbaRW7ZWytHVe klOp7l4jrxkfeU2Iz/NnWGVoMAc8/wegD7Fx X-Google-Smtp-Source: ABdhPJxLok4nKh03xLUM/OQWLXouOIoUSpe2Vwhf8TfNubNG71ESeL1AFAa3x8/3NFceAmkBHHqlope7y9QQo3dJ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:4d0c:: with SMTP id o12mr181612wmh.0.1600204648094; Tue, 15 Sep 2020 14:17:28 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:09 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 27/37] arm64: mte: Switch GCR_EL1 in kernel entry and exit From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 32FA81A4A5 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: From: Vincenzo Frascino When MTE is present, the GCR_EL1 register contains the tags mask that allows to exclude tags from the random generation via the IRG instruction. With the introduction of the new Tag-Based KASAN API that provides a mechanism to reserve tags for special reasons, the MTE implementation has to make sure that the GCR_EL1 setting for the kernel does not affect the userspace processes and viceversa. Save and restore the kernel/user mask in GCR_EL1 in kernel entry and exit. Signed-off-by: Vincenzo Frascino Signed-off-by: Andrey Konovalov --- Change-Id: I0081cba5ace27a9111bebb239075c9a466af4c84 --- arch/arm64/include/asm/mte-helpers.h | 6 ++++++ arch/arm64/include/asm/mte.h | 2 ++ arch/arm64/kernel/asm-offsets.c | 3 +++ arch/arm64/kernel/cpufeature.c | 3 +++ arch/arm64/kernel/entry.S | 26 ++++++++++++++++++++++++++ arch/arm64/kernel/mte.c | 19 ++++++++++++++++--- 6 files changed, 56 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/mte-helpers.h b/arch/arm64/include/asm/mte-helpers.h index 5dc2d443851b..60a292fc747c 100644 --- a/arch/arm64/include/asm/mte-helpers.h +++ b/arch/arm64/include/asm/mte-helpers.h @@ -25,6 +25,8 @@ u8 mte_get_mem_tag(void *addr); u8 mte_get_random_tag(void); void *mte_set_mem_tag_range(void *addr, size_t size, u8 tag); +void mte_init_tags(u64 max_tag); + #else /* CONFIG_ARM64_MTE */ #define mte_get_ptr_tag(ptr) 0xFF @@ -41,6 +43,10 @@ static inline void *mte_set_mem_tag_range(void *addr, size_t size, u8 tag) return addr; } +static inline void mte_init_tags(u64 max_tag) +{ +} + #endif /* CONFIG_ARM64_MTE */ #endif /* __ASSEMBLY__ */ diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h index 82cd7c89edec..3142a2de51ae 100644 --- a/arch/arm64/include/asm/mte.h +++ b/arch/arm64/include/asm/mte.h @@ -15,6 +15,8 @@ #include +extern u64 gcr_kernel_excl; + void mte_clear_page_tags(void *addr); unsigned long mte_copy_tags_from_user(void *to, const void __user *from, unsigned long n); diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index 7d32fc959b1a..dfe6ed8446ac 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -47,6 +47,9 @@ int main(void) #ifdef CONFIG_ARM64_PTR_AUTH DEFINE(THREAD_KEYS_USER, offsetof(struct task_struct, thread.keys_user)); DEFINE(THREAD_KEYS_KERNEL, offsetof(struct task_struct, thread.keys_kernel)); +#endif +#ifdef CONFIG_ARM64_MTE + DEFINE(THREAD_GCR_EL1_USER, offsetof(struct task_struct, thread.gcr_user_excl)); #endif BLANK(); DEFINE(S_X0, offsetof(struct pt_regs, regs[0])); diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index eca06b8c74db..3602ac45d093 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -1721,6 +1721,9 @@ static void cpu_enable_mte(struct arm64_cpu_capabilities const *cap) /* Enable in-kernel MTE only if KASAN_HW_TAGS is enabled */ if (IS_ENABLED(CONFIG_KASAN_HW_TAGS)) { + /* Enable the kernel exclude mask for random tags generation */ + write_sysreg_s((SYS_GCR_EL1_RRND | gcr_kernel_excl), SYS_GCR_EL1); + /* Enable MTE Sync Mode for EL1 */ sysreg_clear_set(sctlr_el1, SCTLR_ELx_TCF_MASK, SCTLR_ELx_TCF_SYNC); isb(); diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index ff34461524d4..79a6848840bd 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -175,6 +175,28 @@ alternative_else_nop_endif #endif .endm + .macro mte_restore_gcr, el, tsk, tmp, tmp2 +#ifdef CONFIG_ARM64_MTE +alternative_if_not ARM64_MTE + b 1f +alternative_else_nop_endif + .if \el == 0 + ldr \tmp, [\tsk, #THREAD_GCR_EL1_USER] + .else + ldr_l \tmp, gcr_kernel_excl + .endif + /* + * Calculate and set the exclude mask preserving + * the RRND (bit[16]) setting. + */ + mrs_s \tmp2, SYS_GCR_EL1 + bfi \tmp2, \tmp, #0, #16 + msr_s SYS_GCR_EL1, \tmp2 + isb +1: +#endif + .endm + .macro kernel_entry, el, regsize = 64 .if \regsize == 32 mov w0, w0 // zero upper 32 bits of x0 @@ -214,6 +236,8 @@ alternative_else_nop_endif ptrauth_keys_install_kernel tsk, x20, x22, x23 + mte_restore_gcr 1, tsk, x22, x23 + scs_load tsk, x20 .else add x21, sp, #S_FRAME_SIZE @@ -332,6 +356,8 @@ alternative_else_nop_endif /* No kernel C function calls after this as user keys are set. */ ptrauth_keys_install_user tsk, x0, x1, x2 + mte_restore_gcr 0, tsk, x0, x1 + apply_ssbd 0, x0, x1 .endif diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index 858e75cfcaa0..1c7d963b5038 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -18,10 +18,13 @@ #include #include +#include #include #include #include +u64 gcr_kernel_excl __ro_after_init; + static void mte_sync_page_tags(struct page *page, pte_t *ptep, bool check_swap) { pte_t old_pte = READ_ONCE(*ptep); @@ -120,6 +123,13 @@ void *mte_set_mem_tag_range(void *addr, size_t size, u8 tag) return ptr; } +void mte_init_tags(u64 max_tag) +{ + u64 incl = GENMASK(max_tag & MTE_TAG_MAX, 0); + + gcr_kernel_excl = ~incl & SYS_GCR_EL1_EXCL_MASK; +} + static void update_sctlr_el1_tcf0(u64 tcf0) { /* ISB required for the kernel uaccess routines */ @@ -155,7 +165,11 @@ static void update_gcr_el1_excl(u64 excl) static void set_gcr_el1_excl(u64 excl) { current->thread.gcr_user_excl = excl; - update_gcr_el1_excl(excl); + + /* + * SYS_GCR_EL1 will be set to current->thread.gcr_user_incl value + * by mte_restore_gcr() in kernel_exit, + */ } void flush_mte_state(void) @@ -181,7 +195,6 @@ void mte_thread_switch(struct task_struct *next) /* avoid expensive SCTLR_EL1 accesses if no change */ if (current->thread.sctlr_tcf0 != next->thread.sctlr_tcf0) update_sctlr_el1_tcf0(next->thread.sctlr_tcf0); - update_gcr_el1_excl(next->thread.gcr_user_excl); } void mte_suspend_exit(void) @@ -189,7 +202,7 @@ void mte_suspend_exit(void) if (!system_supports_mte()) return; - update_gcr_el1_excl(current->thread.gcr_user_excl); + update_gcr_el1_excl(gcr_kernel_excl); } long set_mte_ctrl(struct task_struct *task, unsigned long arg) From patchwork Tue Sep 15 21:16:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777771 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 502FA59D for ; Tue, 15 Sep 2020 21:17:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 15AAB20770 for ; Tue, 15 Sep 2020 21:17:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Yy3NAxKG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 15AAB20770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AE8BE900090; Tue, 15 Sep 2020 17:17:32 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id ABF1990008A; Tue, 15 Sep 2020 17:17:32 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98818900090; Tue, 15 Sep 2020 17:17:32 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0094.hostedemail.com [216.40.44.94]) by kanga.kvack.org (Postfix) with ESMTP id 819FD90008A for ; Tue, 15 Sep 2020 17:17:32 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4CA662497 for ; Tue, 15 Sep 2020 21:17:32 +0000 (UTC) X-FDA: 77266557144.09.elbow76_161565b27114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 2A8F5180AD807 for ; Tue, 15 Sep 2020 21:17:32 +0000 (UTC) X-Spam-Summary: 1,0,0,c55f5cec440b0a5d,d41d8cd98f00b204,3ai9hxwokce8r4u8vf14c2x55x2v.t532z4be-331crt1.58x@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2895:3138:3139:3140:3141:3142:3152:3352:3865:3866:3870:3871:3874:4250:4321:5007:6119:6261:6653:6742:7576:7903:9969:10004:10400:11026:11232:11473:11658:11914:12043:12048:12296:12297:12438:12555:12679:12895:12986:13069:13161:13229:13311:13357:14181:14394:14659:14721:21080:21365:21444:21451:21627:30054:30070,0,RBL:209.85.221.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yre59j5tiwpy3tfnma94ecdpb3pop1ao7b5uz17hc6awuyherkk9qy1mewtxz.fj64gcqy4c58htxhs5sx5ncqxjc67ediapxdgmkxe96oi6gk4w7fmmow3o7b7te.h-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_ru les:0:0: X-HE-Tag: elbow76_161565b27114 X-Filterd-Recvd-Size: 5149 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf44.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:31 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id y3so1697420wrl.21 for ; Tue, 15 Sep 2020 14:17:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=gQNZi1xbbNqueATb+Ofst812z+wTX6Uhy5JHBLW29HQ=; b=Yy3NAxKGs0090BOPTba/nzO4cFPD9qSiFj0muhX6uXXMpAPGomh/ZDVdoYoyMlJR2H lIazQ2HvczoFsJTOWPdKzJYfc2/WOOw9C0hGyRF9UQYgPE3AgqDYVZNtdqTPibhmoXf1 VMf+YKRB6flrLwpkd/7RoFRlnJ08ZGYvHEW2PcJoF+BsjcFwlCOhxqpdr/MY9g7x5o7R VH9u2MeaeqzIdTc+ZxJb27i3vPDxpiSRfNRQmZDcS6TPnaY9a9KOzceh+71b+fUis8/9 GkMM1tMTE9Ao04l35J6odqEAVgW/k0Ib0q1fXWI+cyy/5MUehNYMowaBVV3WbqukJYDt FAgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=gQNZi1xbbNqueATb+Ofst812z+wTX6Uhy5JHBLW29HQ=; b=dnqAvh3W8B5zQCbsoc+xE7AjLaV4dIn1HfjHe1+AhI5TDhzyap9PgNXEFHOfqLQxN8 2dnAYrnA8hO/2WtIWu8KMZhgZDYfekN44AUb81CVX+Zi1z8JpO0tiQp2E+c8Sh/4GHvO +WRRU4i0nxfn09IOQeHV+z1kIXRh8fkqYsEWcLq+vSxc8DCoXjXyqL60B9vNaDIG7GSw pzqI10+fVJP+yBLtUHB1Z2+IBvVKZZySOuK1ENv28qAkixgn3gRur2KBKSF3GWrcA6dE AREHVBqKp61JKttykaeoNbVkCotLwe02dhhYueGDGEPUWDt32cLPbX/6lpccJPh4EsYp jiiw== X-Gm-Message-State: AOAM533w6EmKTgeydJOG0ZsTrKQxp4nkTer56TRE0D0CJI1D3MOstloZ EUdz3cc1QiOI7JiFyJW5W3yp9SvrOOlMwMOL X-Google-Smtp-Source: ABdhPJxSdz7eZtkr4LcxuG7RUBwuiBQj3nl4wipePG7BDeui7hcx3jwqP/ZGF3lGDPtyJkewnREY16db2QT71g3F X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:adf:dd44:: with SMTP id u4mr22386734wrm.22.1600204650809; Tue, 15 Sep 2020 14:17:30 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:10 +0200 In-Reply-To: Message-Id: <9ecc27d43a01ca32bcacf44b393a9a100e0dfdb2.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 28/37] arm64: kasan: Enable TBI EL1 From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 2A8F5180AD807 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: From: Vincenzo Frascino Hardware tag-based KASAN relies on Memory Tagging Extension (MTE) that is built on top of the Top Byte Ignore (TBI) feature. Enable in-kernel TBI when CONFIG_KASAN_HW_TAGS is turned on by enabling the TCR_TBI1 bit in proc.S. Signed-off-by: Vincenzo Frascino Co-developed-by: Andrey Konovalov Signed-off-by: Andrey Konovalov --- Change-Id: I91944903bc9c9c9044f0d50e74bcd6b9971d21ff --- arch/arm64/mm/proc.S | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 5ba7ac5e9c77..1687447dee7a 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -40,9 +40,13 @@ #define TCR_CACHE_FLAGS TCR_IRGN_WBWA | TCR_ORGN_WBWA #ifdef CONFIG_KASAN_SW_TAGS -#define TCR_KASAN_FLAGS TCR_TBI1 +#define TCR_KASAN_SW_FLAGS TCR_TBI1 #else -#define TCR_KASAN_FLAGS 0 +#define TCR_KASAN_SW_FLAGS 0 +#endif + +#ifdef CONFIG_KASAN_HW_TAGS +#define TCR_KASAN_HW_FLAGS TCR_TBI1 #endif /* @@ -462,7 +466,7 @@ SYM_FUNC_START(__cpu_setup) */ mov_q x10, TCR_TxSZ(VA_BITS) | TCR_CACHE_FLAGS | TCR_SMP_FLAGS | \ TCR_TG_FLAGS | TCR_KASLR_FLAGS | TCR_ASID16 | \ - TCR_TBI0 | TCR_A1 | TCR_KASAN_FLAGS + TCR_TBI0 | TCR_A1 | TCR_KASAN_SW_FLAGS tcr_clear_errata_bits x10, x9, x5 #ifdef CONFIG_ARM64_VA_BITS_52 @@ -495,6 +499,9 @@ SYM_FUNC_START(__cpu_setup) /* Update TCR_EL1 if MTE is supported (ID_AA64PFR1_EL1[11:8] > 1) */ cbz mte_present, 1f orr x10, x10, #SYS_TCR_EL1_TCMA1 +#ifdef CONFIG_KASAN_HW_TAGS + orr x10, x10, #TCR_KASAN_HW_FLAGS +#endif 1: .unreq mte_present #endif From patchwork Tue Sep 15 21:16:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777773 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E64726CA for ; Tue, 15 Sep 2020 21:17:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A2D6A20809 for ; Tue, 15 Sep 2020 21:17:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="ejaRrNgw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A2D6A20809 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 740B6900091; Tue, 15 Sep 2020 17:17:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6F78B90008A; Tue, 15 Sep 2020 17:17:35 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56C36900091; Tue, 15 Sep 2020 17:17:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0092.hostedemail.com [216.40.44.92]) by kanga.kvack.org (Postfix) with ESMTP id 3B9BE90008A for ; Tue, 15 Sep 2020 17:17:35 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 0DEBA181AEF09 for ; Tue, 15 Sep 2020 21:17:35 +0000 (UTC) X-FDA: 77266557270.19.show71_13177f327114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id CDA8C1AD1B1 for ; Tue, 15 Sep 2020 21:17:34 +0000 (UTC) X-Spam-Summary: 1,0,0,f019d9c17f8b16e1,d41d8cd98f00b204,3bs9hxwokcfiu7xbyi47f508805y.w86527eh-664fuw4.8b0@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1534:1541:1593:1594:1711:1714:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3152:3351:3865:3867:3871:4250:5007:6261:6653:6742:8603:9969:10004:10400:11026:11232:11473:11657:11658:11914:12043:12048:12297:12438:12555:12895:13069:13311:13357:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:30054,0,RBL:209.85.218.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04ygb4b7uqmn47qxzy66bx1ehsb9eypxcqpdpxwuwoosru1jy7xn7gtjyos6ft5.5rdfyq161pg3hafppzfrrxne8oa1n1org6x7jbpqhx5jd1ysr3gm4631yrg9a9k.q-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: show71_13177f327114 X-Filterd-Recvd-Size: 4508 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) by imf21.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:34 +0000 (UTC) Received: by mail-ej1-f73.google.com with SMTP id dc22so1822390ejb.21 for ; Tue, 15 Sep 2020 14:17:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=TX70ilGdAcdyg1YBqmaSz5QEacCDiTB+zVlfonsPQRU=; b=ejaRrNgwlp8ys+4BQrnEIRa6JCD1DMaKcBwnb6OubgjCfWn7NE3QbT78QsJNlgYl8X uM2iLdYkRCRZVwVQWIM0JNTTlqRSByOm+y9tVhjfylzf2VSM6Txz24Jfwoj9xuRUu5eq XSk5LuejKSujNUpLhSZYHYDVvGikaSYVQ8zW8/c8swLI3F17HrPWXWe1JnzbayOYXV6i +h8vg0HiS72Ql8kaieke3o6g5BZgc9WxK8gmLJsv1NXIvY/KTPaiJiBAX2UrbUTN4O2f VmRLgpabm/mNCrvMiI/7bDXbGRB3zjFVqbCyJv7JAbUl4unwvVSbE53x8P7LPnXJYDCT /dfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=TX70ilGdAcdyg1YBqmaSz5QEacCDiTB+zVlfonsPQRU=; b=NkSZ6G5/V60MrxnQREUTvld0F8i/umlmZytO0MC7Bo3GNh8GPPxYyTglMzV4Rth9wt nxJ8pAyirwBpaKDqdD8OoFRdG2lTJNHa6UrKYPuPQdYjXqs9t1/lN0e5/i3P3hTBCFsJ FuUyUXxG0xODVIYMZLfqaC6klU68TlOlJiatKE7/mx3D9z+/50AtNMB2+JEc0M9B3C2o ZeDh3bXE4nV1GdGikIOL+9p9uyL2/4ZraJ1XJyZy88sqG7IpL1ThWo35tDyBH7Iaa/23 NH59jBtEYDTxzndjk7wK3+hKdp6uECGc7wtsbHgRbysSh2hVD9bZpZnkvopADuk0yFBu UlFg== X-Gm-Message-State: AOAM533iDabDxuwI9P+oGJ2iVsJ/kUA96QVvu89dcogP5aYCJCidPLSv cWPq1TkAFsVh+Ks4a3JHknPTshymE12+Eg6O X-Google-Smtp-Source: ABdhPJzXD5k/cAT+QhVmJFoutrziWlgaMN8QxqxV/HqrCs5L8f197jAYO7cCyYNJOGv6gz2W5knXALPYvJNw370q X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a17:906:4902:: with SMTP id b2mr21685991ejq.208.1600204653213; Tue, 15 Sep 2020 14:17:33 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:11 +0200 In-Reply-To: Message-Id: <0845668a82ddd3eeb3f652712597ffd056f97504.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 29/37] arm64: kasan: Align allocations for HW_TAGS From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: CDA8C1AD1B1 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: Hardware tag-based KASAN uses the memory tagging approach, which requires all allocations to be aligned to the memory granule size. Align the allocations to MTE_GRANULE_SIZE via ARCH_SLAB_MINALIGN when CONFIG_KASAN_HW_TAGS is enabled. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Catalin Marinas --- Change-Id: I51ebd3f9645e6330e5a92973bf7c86b62d632c2b --- arch/arm64/include/asm/cache.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/include/asm/cache.h b/arch/arm64/include/asm/cache.h index a4d1b5f771f6..acf6a5097cce 100644 --- a/arch/arm64/include/asm/cache.h +++ b/arch/arm64/include/asm/cache.h @@ -6,6 +6,7 @@ #define __ASM_CACHE_H #include +#include #define CTR_L1IP_SHIFT 14 #define CTR_L1IP_MASK 3 @@ -50,6 +51,8 @@ #ifdef CONFIG_KASAN_SW_TAGS #define ARCH_SLAB_MINALIGN (1ULL << KASAN_SHADOW_SCALE_SHIFT) +#elif defined(CONFIG_KASAN_HW_TAGS) +#define ARCH_SLAB_MINALIGN MTE_GRANULE_SIZE #endif #ifndef __ASSEMBLY__ From patchwork Tue Sep 15 21:16:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777775 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EFAC06CA for ; Tue, 15 Sep 2020 21:17:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B733D20795 for ; Tue, 15 Sep 2020 21:17:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="et5na2Sr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B733D20795 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AE6B3900092; Tue, 15 Sep 2020 17:17:38 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A96A890008A; Tue, 15 Sep 2020 17:17:38 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9AD25900092; Tue, 15 Sep 2020 17:17:38 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0218.hostedemail.com [216.40.44.218]) by kanga.kvack.org (Postfix) with ESMTP id 86D3990008A for ; Tue, 15 Sep 2020 17:17:38 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4E8228249980 for ; Tue, 15 Sep 2020 21:17:38 +0000 (UTC) X-FDA: 77266557396.08.humor97_3712d0f27114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id AD4A51819E621 for ; Tue, 15 Sep 2020 21:17:37 +0000 (UTC) X-Spam-Summary: 1,0,0,5db544313f29021f,d41d8cd98f00b204,3by9hxwokcfqw9zd0k69h72aa270.ya8749gj-886hwy6.ad2@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1534:1540:1568:1593:1594:1711:1714:1730:1747:1777:1792:1981:2194:2199:2393:2559:2562:3138:3139:3140:3141:3142:3152:3866:3867:4250:4321:5007:6261:6642:6653:6742:9969:10004:10400:11026:11232:11473:11658:11914:12043:12048:12297:12438:12555:12895:12986:13069:13311:13357:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:30054,0,RBL:209.85.221.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yrhz8rykqqfrzwh6uqcqyub9remyph3k756aq3745wtgbmxti1spstrx5uft6.5f8mo78t5wjyoforwhx9tfktg6fbbkni4xkeumgi3ycna7xngns554yza6mo6cr.q-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMM ARY:none X-HE-Tag: humor97_3712d0f27114 X-Filterd-Recvd-Size: 4366 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:36 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id g6so1717451wrv.3 for ; Tue, 15 Sep 2020 14:17:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=SMbpusk9UPFJ5bty/4o1CBzmR923bOTqJu4p/yHyDoA=; b=et5na2SrMTeEtk7EWiOzMg0RIlxhLHym2BHU/vxQbTuVAB46m56Vgt+uJkfq6C1HPC LdLXNgovu/Qc5xh0rc0eA0wF96LwrPAujajBypmTg2C9f00xeyv2mMhZBtqDmrJPwnmx wItchGs3NqcMVlvP2XrDs63cj25TUc29zJtXuj8oAElnc584tZimCx/2j9MN+aveLpbe 6CExqkZyjmo1zU4cX09+bUDu5QeTKo0OoBQfzNRGLVcv7Pxfas6s/765v6fOyapNv95w Ef+ox4JfLp90yekqgK4IN7gatUONDMd8P8B2lydG89kADRCDIGIqUbs8vlf0OeozcRfe bYNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=SMbpusk9UPFJ5bty/4o1CBzmR923bOTqJu4p/yHyDoA=; b=jJVCM/5O11VQENWmj+YfFS2ojxFQfF52QwjtkctctsLHKeOPF7u/b36CJvJXPncWQC q8m7cPqZmLRVhBpX75gHuMrPyCM/vKXEAPw6dvPCbG1tbLcEi9t9ZbtN0eStWBDq5HwX 8fPJ0wm75jeU0oaeLwqvtAlyZd7FEc0nuk/0YhiRGZzEsmSbJt249DRdgD9g9qQI4RlC zPOs1Y1qS518xB7VBrW5p651iDByHRXWQbjK1lhK0+vAERs0mUY9Z4sWmC75l6Ofwb5I DiOcgqMeAJI++faolkWXCs0lNDCNaiytbtaEFvraFOuENAW4OzXPHe5Ad26Q9JEwGRyW 6s+Q== X-Gm-Message-State: AOAM532t9bT2PpI+OpbGVLSVzipjKmpiUtnmCA9NZfpNedUMOEFX2ujV b7Oxsne0QPhd53gIYntyHbzpcBDON7RxtrX6 X-Google-Smtp-Source: ABdhPJwujyv1jICnb8Z84hBJXMAHZtwatucCSBcuhq+9tnfe5N4bmea9C5aR+KvNqkTUUlaGyRY0Mdi7Bwl5AIg1 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a5d:5281:: with SMTP id c1mr23095217wrv.184.1600204655669; Tue, 15 Sep 2020 14:17:35 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:12 +0200 In-Reply-To: Message-Id: <3a3002e1d70f8faf2dfc07176c3ece22450b68a3.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 30/37] kasan: define KASAN_GRANULE_SIZE for HW_TAGS From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: AD4A51819E621 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: Hardware tag-based KASAN has granules of MTE_GRANULE_SIZE. Define KASAN_GRANULE_SIZE to MTE_GRANULE_SIZE for CONFIG_KASAN_HW_TAGS. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: I5d1117e6a991cbca00d2cfb4ba66e8ae2d8f513a --- mm/kasan/kasan.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 8b43fc163ed1..ba63d8a62968 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -5,7 +5,13 @@ #include #include +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) #define KASAN_GRANULE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT) +#else +#include +#define KASAN_GRANULE_SIZE (MTE_GRANULE_SIZE) +#endif + #define KASAN_GRANULE_MASK (KASAN_GRANULE_SIZE - 1) #define KASAN_TAG_KERNEL 0xFF /* native kernel pointers tag */ From patchwork Tue Sep 15 21:16:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777777 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3CD7B59D for ; Tue, 15 Sep 2020 21:17:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EC5032078E for ; Tue, 15 Sep 2020 21:17:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="gGShhG9R" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC5032078E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E6AB090008A; Tue, 15 Sep 2020 17:17:41 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E40FD900070; Tue, 15 Sep 2020 17:17:41 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D55EB90008A; Tue, 15 Sep 2020 17:17:41 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id BFF2F900070 for ; Tue, 15 Sep 2020 17:17:41 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8B11E362B for ; Tue, 15 Sep 2020 21:17:41 +0000 (UTC) X-FDA: 77266557522.08.line68_5c155e827114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 0F6271819E621 for ; Tue, 15 Sep 2020 21:17:40 +0000 (UTC) X-Spam-Summary: 1,0,0,7afaccb675700ccb,d41d8cd98f00b204,3cs9hxwokcfyyb1f2m8bj94cc492.0ca96bil-aa8jy08.cf4@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:1981:2194:2199:2393:2559:2562:2693:2895:3138:3139:3140:3141:3142:3152:3352:3865:3866:3867:3868:3874:4250:4321:4605:5007:6261:6653:6742:9969:10004:10400:11026:11232:11473:11657:11658:11914:12043:12048:12296:12297:12438:12555:12895:12986:13069:13311:13357:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:30012:30054:30070,0,RBL:209.85.221.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04ygf4trtch9y6c5hmfgyu5es7p1sypji41r768xic3feaq5jsgewdckjmoafam.xf4btg7y56fsjydgw4b76twzprhjkuqwiuenbthxhoe9gy8bqw6rsfrgj7xm7s8.s-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:n eutral,C X-HE-Tag: line68_5c155e827114 X-Filterd-Recvd-Size: 4926 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf35.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:39 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id y3so1697540wrl.21 for ; Tue, 15 Sep 2020 14:17:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=gJaj9HJzY/xay7XUoLkj6R2OGJl/aiV7rlwVCZ5wZTg=; b=gGShhG9RfzxUJORAJUGoVV6FU0vEowbn6auu7yKf41CX89p6/5xtaqWfZfXtwdZseO ZZkWleubVSVVwvcV7jdnoJqptNYV+oLuntmAJqV8koLWbiNMEzMMeiBZLrXD4AyJdKlV QAdI2WRzVXOEXSqdulCZ22bdnCSfJlMn+TSKTjmlwBNAFLWjBb4QZ9nUDXs/geDhodZF lHdn/CMNBDNzl6HPU3g6w5p110DUQ4p6Q3/NxDbK5DQ5dFZSe3FkhOBElojem+jjPsqq Vf2OAk+IONfZnGJx+bpkcYWy8P79TampsVQtbxCtLDNbAJD1++c+8rwz1LKrIQwGojKw KgQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=gJaj9HJzY/xay7XUoLkj6R2OGJl/aiV7rlwVCZ5wZTg=; b=oZFF9LL7tFpCCJY5xUrD8LNfjwmyWeNohoOB7tcL+wwaXWaWuFX7/Pcq5a7ndl03HK S0jzhaCKTEqi2RRVHXc+GS/bUE+0Z+gvGHefM6g3ILuoH5lMYJk5C1kBx9MZWajcs3pc 88eJd6iYSeidhGPjqMWmXktaUgoWXcG8/syFuXmOQCKhtxNsLf4Xsu0iJXPkTa5sRx4/ tIVR9Xnnpkm/O7lYC7o5wDrDlRHAJXjQwBFDMa1OdI46bwPwPzA/WnE48lNmE2gZ0prY 0LUL/Mhwmq8YqGil5gF7YOS3NaCMZRgzXf5kL6zNPCsBzu0K34tHw3Cl8g0htvQ2khC0 R/OA== X-Gm-Message-State: AOAM533pLEqpc6AMAi/tBSD6ZdUj1n/tWuaK3dDKl4DZTTfb3FWqLu8U hjOrY7dxmxD/+CJUD5sWohspYRVk57NNneIX X-Google-Smtp-Source: ABdhPJz5Xohf4ARkglaPkRRJQxL2SqgjcqjnN5AC/Am00hGW5Wrd6XlIFiWLgi6EalEXv6txBloeoUIiPWUmpXXK X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:c14f:: with SMTP id z15mr181253wmi.1.1600204657873; Tue, 15 Sep 2020 14:17:37 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:13 +0200 In-Reply-To: Message-Id: <0a35b29d161bf2559d6e16fbd903e49351c7f6b8.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 31/37] kasan, x86, s390: update undef CONFIG_KASAN From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 0F6271819E621 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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: With the intoduction of hardware tag-based KASAN some kernel checks of this kind: ifdef CONFIG_KASAN will be updated to: if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) x86 and s390 use a trick to #undef CONFIG_KASAN for some of the code that isn't linked with KASAN runtime and shouldn't have any KASAN annotations. Also #undef CONFIG_KASAN_GENERIC with CONFIG_KASAN. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: I2a622db0cb86a8feb60c30d8cb09190075be2a90 --- arch/s390/boot/string.c | 1 + arch/x86/boot/compressed/misc.h | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/s390/boot/string.c b/arch/s390/boot/string.c index b11e8108773a..faccb33b462c 100644 --- a/arch/s390/boot/string.c +++ b/arch/s390/boot/string.c @@ -3,6 +3,7 @@ #include #include #undef CONFIG_KASAN +#undef CONFIG_KASAN_GENERIC #include "../lib/string.c" int strncmp(const char *cs, const char *ct, size_t count) diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h index 726e264410ff..2ac973983a8e 100644 --- a/arch/x86/boot/compressed/misc.h +++ b/arch/x86/boot/compressed/misc.h @@ -12,6 +12,7 @@ #undef CONFIG_PARAVIRT_XXL #undef CONFIG_PARAVIRT_SPINLOCKS #undef CONFIG_KASAN +#undef CONFIG_KASAN_GENERIC /* cpu_feature_enabled() cannot be used this early */ #define USE_EARLY_PGTABLE_L5 From patchwork Tue Sep 15 21:16:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777779 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E78656CA for ; Tue, 15 Sep 2020 21:17:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9455020B1F for ; Tue, 15 Sep 2020 21:17:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="fNwYgUma" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9455020B1F Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3E7CF900093; Tue, 15 Sep 2020 17:17:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2F6E6900070; Tue, 15 Sep 2020 17:17:44 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20C4D900093; Tue, 15 Sep 2020 17:17:44 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0091.hostedemail.com [216.40.44.91]) by kanga.kvack.org (Postfix) with ESMTP id 0A4F4900070 for ; Tue, 15 Sep 2020 17:17:44 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B9B8A362B for ; Tue, 15 Sep 2020 21:17:43 +0000 (UTC) X-FDA: 77266557606.25.hill53_000a6fb27114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 7E4D41804E3A0 for ; Tue, 15 Sep 2020 21:17:43 +0000 (UTC) X-Spam-Summary: 1,0,0,024a5cec59e1b64e,d41d8cd98f00b204,3dc9hxwokcfk1e4i5pbemc7ff7c5.3fdc9elo-ddbm13b.fi7@flex--andreyknvl.bounces.google.com,,RULES_HIT:4:41:152:355:379:541:617:800:960:966:973:982:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1593:1594:1605:1730:1747:1777:1792:1801:1981:2194:2196:2199:2200:2393:2559:2562:2638:2901:3138:3139:3140:3141:3142:3152:3865:3866:3867:3870:3871:3874:4250:4321:4385:4605:5007:6119:6261:6653:6742:7875:8603:8660:9040:9969:10004:11026:11232:11473:11657:11658:11914:12043:12048:12296:12297:12438:12555:12895:12986:13148:13230:14394:14659:14877:21080:21325:21365:21433:21444:21451:21627:21772:21795:21939:21987:21990:30003:30029:30051:30054:30069:30070,0,RBL:209.85.128.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yfgyicrqbuxfwowymjrf5endegtypenu4b5hm4ok1htnxozwdbeognektpj6s.e7khb9znrwjseabyw14bpksadrawkkourxqahd5sze7ijgizonk37geb45zxa3q.4-lbl8.mailshell.net-223.238.255.100,CacheIP:none ,Bayesia X-HE-Tag: hill53_000a6fb27114 X-Filterd-Recvd-Size: 15449 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:42 +0000 (UTC) Received: by mail-wm1-f73.google.com with SMTP id t10so214323wmi.9 for ; Tue, 15 Sep 2020 14:17:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=4oqpf0JqwvFvIJamqFE84ovA/ACXnIzXTKv1EN0+3tQ=; b=fNwYgUmajITcBcN2nTaLXSl+sVqKIU4waf4VQ+IapICBweQK7LPFEOXzP/IYu+9gKm QztTF2rHnCH2I/x97Ds4oboHydxdcqKJRB4zVmzu3lG+dAQ+gb1n6D2X5p6UP9r04jZA NdWtnevmMFmUkN4sMt2Z1UklMEysC/jARoRmm0Kdi5TcVc5tVN2CdIeY5wsa4Gr9XPr1 8VH0rnl6CRmJugYByA0Al3v2rem935mCsuZn2DngRJSIdSmBiodsXDNG1tdXECyeD+7B x0QC2db40z3LYMOBPUUi+Y4xGcKmjxkDazjTUFg3c5/sG11I0hjltu/eaVOnmeibPpa+ ghGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=4oqpf0JqwvFvIJamqFE84ovA/ACXnIzXTKv1EN0+3tQ=; b=N/AmlkP2uZzi37G6GNKZ8wXCO73FqmxynujSFTDi/AJYdDcqX8wclGUNC71vjQBB+w 5fH6Vd8qDyiiCQl3gbx9Eemfz4y9tkweTYxo8HE65BKPnD3oiawZCuj9pZSvWN5p8J98 hW2VFD/C0sKlzKwbuIOFbdwaLJDsZhb9hiHtVe4EQM/NwBlwuE+Bm79hEm/C+PFjUeHX 2+TJC0LVfiiXNQrO2+ICp4TfvmthQOzfY634Lfw42JkkfVKiqmRHYRduhDq4MJ2AUb2z WR3L70HU8+JD9Q7FZRTP9FjODJ+3GDS2H3Yrj5/LlBTlN2YQ7r1eJ7KzVhey7f0WBQyZ WOyw== X-Gm-Message-State: AOAM532ytKFaKvgCCVssA3YCtAMrwZVMSOokp5BXBhDxo7Mdo71irbrs MbwCxDYHcFrNOjodQIfol+JQagXfTzWDzBvr X-Google-Smtp-Source: ABdhPJwUmN7UnvmkDKZwR3YtMZr1DhXCnJlff2/EBoZwhIUpZyj27Hmw1zzN0FrjnQmOu3MFYLj0ZMFZJ79CFFRp X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:c14f:: with SMTP id z15mr181279wmi.1.1600204660655; Tue, 15 Sep 2020 14:17:40 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:14 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 32/37] kasan, arm64: expand CONFIG_KASAN checks From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 7E4D41804E3A0 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: Some #ifdef CONFIG_KASAN checks are only relevant for software KASAN modes (either related to shadow memory or compiler instrumentation). Expand those into CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Catalin Marinas --- Change-Id: I91e661e2c1627783cb845d877c6371dfc8779505 --- arch/arm64/Kconfig | 2 +- arch/arm64/Makefile | 2 +- arch/arm64/include/asm/assembler.h | 2 +- arch/arm64/include/asm/memory.h | 2 +- arch/arm64/include/asm/string.h | 5 +++-- arch/arm64/kernel/head.S | 2 +- arch/arm64/kernel/image-vars.h | 2 +- arch/arm64/mm/dump.c | 6 +++--- include/linux/kasan-checks.h | 2 +- include/linux/kasan.h | 7 ++++--- include/linux/moduleloader.h | 3 ++- include/linux/string.h | 2 +- mm/ptdump.c | 13 ++++++++----- scripts/Makefile.lib | 2 ++ 14 files changed, 30 insertions(+), 22 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index e875db8e1c86..c8e45870e993 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -320,7 +320,7 @@ config BROKEN_GAS_INST config KASAN_SHADOW_OFFSET hex - depends on KASAN + depends on KASAN_GENERIC || KASAN_SW_TAGS default 0xdfffa00000000000 if (ARM64_VA_BITS_48 || ARM64_VA_BITS_52) && !KASAN_SW_TAGS default 0xdfffd00000000000 if ARM64_VA_BITS_47 && !KASAN_SW_TAGS default 0xdffffe8000000000 if ARM64_VA_BITS_42 && !KASAN_SW_TAGS diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 130569f90c54..888a9359f905 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -137,7 +137,7 @@ TEXT_OFFSET := 0x0 ifeq ($(CONFIG_KASAN_SW_TAGS), y) KASAN_SHADOW_SCALE_SHIFT := 4 -else +else ifeq ($(CONFIG_KASAN_GENERIC), y) KASAN_SHADOW_SCALE_SHIFT := 3 endif diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index 54d181177656..bc9ace1e5f3a 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -464,7 +464,7 @@ USER(\label, ic ivau, \tmp2) // invalidate I line PoU #define NOKPROBE(x) #endif -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) #define EXPORT_SYMBOL_NOKASAN(name) #else #define EXPORT_SYMBOL_NOKASAN(name) EXPORT_SYMBOL(name) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 268a3b6cebd2..de9af7bea90d 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -72,7 +72,7 @@ * address space for the shadow region respectively. They can bloat the stack * significantly, so double the (minimum) stack size when they are in use. */ -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) #define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL) #define KASAN_SHADOW_END ((UL(1) << (64 - KASAN_SHADOW_SCALE_SHIFT)) \ + KASAN_SHADOW_OFFSET) diff --git a/arch/arm64/include/asm/string.h b/arch/arm64/include/asm/string.h index b31e8e87a0db..3a3264ff47b9 100644 --- a/arch/arm64/include/asm/string.h +++ b/arch/arm64/include/asm/string.h @@ -5,7 +5,7 @@ #ifndef __ASM_STRING_H #define __ASM_STRING_H -#ifndef CONFIG_KASAN +#if !(defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) #define __HAVE_ARCH_STRRCHR extern char *strrchr(const char *, int c); @@ -48,7 +48,8 @@ extern void *__memset(void *, int, __kernel_size_t); void memcpy_flushcache(void *dst, const void *src, size_t cnt); #endif -#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) +#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ + !defined(__SANITIZE_ADDRESS__) /* * For files that are not instrumented (e.g. mm/slub.c) we diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 037421c66b14..427ded9e68e8 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -452,7 +452,7 @@ SYM_FUNC_START_LOCAL(__primary_switched) bl __pi_memset dsb ishst // Make zero page visible to PTW -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) bl kasan_early_init #endif #ifdef CONFIG_RANDOMIZE_BASE diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h index 8982b68289b7..ed8d086d601c 100644 --- a/arch/arm64/kernel/image-vars.h +++ b/arch/arm64/kernel/image-vars.h @@ -37,7 +37,7 @@ __efistub_strncmp = __pi_strncmp; __efistub_strrchr = __pi_strrchr; __efistub___clean_dcache_area_poc = __pi___clean_dcache_area_poc; -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) __efistub___memcpy = __pi_memcpy; __efistub___memmove = __pi_memmove; __efistub___memset = __pi_memset; diff --git a/arch/arm64/mm/dump.c b/arch/arm64/mm/dump.c index ba6d1d89f9b2..bf8ddeac5d8f 100644 --- a/arch/arm64/mm/dump.c +++ b/arch/arm64/mm/dump.c @@ -29,7 +29,7 @@ enum address_markers_idx { PAGE_OFFSET_NR = 0, PAGE_END_NR, -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) KASAN_START_NR, #endif }; @@ -37,7 +37,7 @@ enum address_markers_idx { static struct addr_marker address_markers[] = { { PAGE_OFFSET, "Linear Mapping start" }, { 0 /* PAGE_END */, "Linear Mapping end" }, -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) { 0 /* KASAN_SHADOW_START */, "Kasan shadow start" }, { KASAN_SHADOW_END, "Kasan shadow end" }, #endif @@ -381,7 +381,7 @@ void ptdump_check_wx(void) static int ptdump_init(void) { address_markers[PAGE_END_NR].start_address = PAGE_END; -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) address_markers[KASAN_START_NR].start_address = KASAN_SHADOW_START; #endif ptdump_initialize(); diff --git a/include/linux/kasan-checks.h b/include/linux/kasan-checks.h index ac6aba632f2d..ca5e89fb10d3 100644 --- a/include/linux/kasan-checks.h +++ b/include/linux/kasan-checks.h @@ -9,7 +9,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! */ -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) 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 894f4d9163ee..875bbcedd994 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -232,7 +232,8 @@ static inline void kasan_release_vmalloc(unsigned long start, #endif /* CONFIG_KASAN_VMALLOC */ -#if defined(CONFIG_KASAN) && !defined(CONFIG_KASAN_VMALLOC) +#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ + !defined(CONFIG_KASAN_VMALLOC) /* * These functions provide a special case to support backing module @@ -242,12 +243,12 @@ static inline void kasan_release_vmalloc(unsigned long start, int kasan_module_alloc(void *addr, size_t size); void kasan_free_shadow(const struct vm_struct *vm); -#else /* CONFIG_KASAN && !CONFIG_KASAN_VMALLOC */ +#else /* (CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) && !CONFIG_KASAN_VMALLOC */ static inline int kasan_module_alloc(void *addr, size_t size) { return 0; } static inline void kasan_free_shadow(const struct vm_struct *vm) {} -#endif /* CONFIG_KASAN && !CONFIG_KASAN_VMALLOC */ +#endif /* (CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) && !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 4fa67a8b2265..9e09d11ffe5b 100644 --- a/include/linux/moduleloader.h +++ b/include/linux/moduleloader.h @@ -96,7 +96,8 @@ 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) && !defined(CONFIG_KASAN_VMALLOC) +#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ + !defined(CONFIG_KASAN_VMALLOC) #include #define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT) #else diff --git a/include/linux/string.h b/include/linux/string.h index 9b7a0632e87a..607322616363 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -273,7 +273,7 @@ void __write_overflow(void) __compiletime_error("detected write beyond size of o #if !defined(__NO_FORTIFY) && defined(__OPTIMIZE__) && defined(CONFIG_FORTIFY_SOURCE) -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) 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/mm/ptdump.c b/mm/ptdump.c index ba88ec43ff21..4354c1422d57 100644 --- a/mm/ptdump.c +++ b/mm/ptdump.c @@ -4,7 +4,7 @@ #include #include -#ifdef CONFIG_KASAN +#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() @@ -31,7 +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) +#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))) return note_kasan_page_table(walk, addr); #endif @@ -51,7 +52,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) +#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))) return note_kasan_page_table(walk, addr); #endif @@ -71,7 +73,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) +#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))) return note_kasan_page_table(walk, addr); #endif @@ -91,7 +94,7 @@ 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) +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) if (pmd_page(val) == virt_to_page(lm_alias(kasan_early_shadow_pte))) return note_kasan_page_table(walk, addr); #endif diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 3d599716940c..dc2d13c4455a 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -148,10 +148,12 @@ endif # we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE) # ifeq ($(CONFIG_KASAN),y) +ifneq ($(CONFIG_KASAN_HW_TAGS),y) _c_flags += $(if $(patsubst n%,, \ $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \ $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE)) endif +endif ifeq ($(CONFIG_UBSAN),y) _c_flags += $(if $(patsubst n%,, \ From patchwork Tue Sep 15 21:16:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777781 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8A2636CA for ; Tue, 15 Sep 2020 21:17:48 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 30D4A20B1F for ; Tue, 15 Sep 2020 21:17:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="eGUywzkx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 30D4A20B1F Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 48060900094; Tue, 15 Sep 2020 17:17:45 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 45A2B900070; Tue, 15 Sep 2020 17:17:45 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D011900094; Tue, 15 Sep 2020 17:17:45 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0097.hostedemail.com [216.40.44.97]) by kanga.kvack.org (Postfix) with ESMTP id 0EAE8900070 for ; Tue, 15 Sep 2020 17:17:45 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id CA26E180AD807 for ; Tue, 15 Sep 2020 21:17:44 +0000 (UTC) X-FDA: 77266557648.23.coast19_370771827114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id A442637604 for ; Tue, 15 Sep 2020 21:17:44 +0000 (UTC) X-Spam-Summary: 1,0,0,c99f07ac53f04982,d41d8cd98f00b204,3dy9hxwokcfw4h7l8sehpfaiiaf8.6igfchor-ggep46e.ila@flex--andreyknvl.bounces.google.com,,RULES_HIT:4:41:152:355:379:541:800:960:966:967:968:973:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1593:1594:1605:1730:1747:1777:1792:1981:2194:2196:2198:2199:2200:2201:2393:2525:2538:2559:2563:2640:2682:2685:2731:2859:2901:2918:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3865:3866:3867:3868:3870:3871:3872:3873:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4385:4605:5007:6261:6653:6742:7514:7875:7903:8603:9025:9036:9592:9969:10004:11026:11232:11473:11657:11658:11914:12043:12048:12291:12296:12297:12438:12555:12679:12683:12691:12698:12737:12895:12986:13141:13230:14394:14659:21080:21324:21365:21444:21451:21611:21627:21772:21990:30003:30012:30054:30067:30070:30075,0,RBL:209.85.160.201:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yf9zhof nmtu81xe X-HE-Tag: coast19_370771827114 X-Filterd-Recvd-Size: 17975 Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:43 +0000 (UTC) Received: by mail-qt1-f201.google.com with SMTP id r22so4018651qtc.9 for ; Tue, 15 Sep 2020 14:17:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=GS63ueuB4la1O7X0K9617yAQx4ln+SDXx/Ooc+f8eKM=; b=eGUywzkx6pQSB6MB14SdSSZHwENYdnE2dovxVA2CNCAaJIPmrGwaMepZ/GkSHH8mbZ FjuVEYhgJF5gPBD2NyWvpmhsF/UdK93iIQjKmXKhAp4LB1vTgNoMglvZQDAVBolO3WaB BkcMTkab/KVnLbb0Ym6OvxIk/gzF4M0Vg0C7dTTlJDYywSeGoo/lzRDupg2db6yq8MnE 7/J2VtEOl1etcOONWSj6no5s9WCAL4uvx2rflJqbtgfm1W5apOZPs+E75mEg0gc23ue2 03vNlqM1du3fvGyyZHUVoOQBFuJy/pCoNRd1ftRtyM5HI3HMUTlAOhX3qjEX7oYjqhZO 5mkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=GS63ueuB4la1O7X0K9617yAQx4ln+SDXx/Ooc+f8eKM=; b=rSIAVBTcK8mL8W0c3oZxurA6CzHCBjjVZ70fveuwSDxGXzuuXHPhTSBtVFklERda/i M5+wDcdiLdi9JGUMCwDADxvVcJ6RwhhxO5dM504CFc53bwegf8kP3Ne9HV5kb3VLWtlB B3TO7n8/Rwoq7yc3EXKbiPxjtqLKGf3sePRZNTxWPZLwaDjFpC2IBfUlwHrfn1aLfpCY MeJMNERjpc10X1DzBTLBWHg8OFbMS8f74NCZofCDzVuhertxsiYDjmopfZiP3TtYxKr/ axSdfXQ9Ji3G9LzvptIDoO3g1OxD1mQOo2tUkeNyQxH0/rS95mVx0P0QMKc3GT/96ubV aL4w== X-Gm-Message-State: AOAM531Kz5lmGK4V7pCUObOlXaAUD/Hvfuy16PW/hmWiUuG+loj4pRYW TNUqyHdNpIy3t9KNMSjsHArp8Zus9lDVuRja X-Google-Smtp-Source: ABdhPJwjAVnhesWjxwBJtc9dtwgII6LSMyBmQtEiC1DsYXdw5HZxd+M1R+meLCNr2dgUBGKj+8j44Sq1rftM9PRY X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:9d04:: with SMTP id m4mr3781463qvf.50.1600204663244; Tue, 15 Sep 2020 14:17:43 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:15 +0200 In-Reply-To: Message-Id: <74133d1a57c47cb8fec791dd5d1e6417b0579fc3.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 33/37] kasan, arm64: implement HW_TAGS runtime From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: A442637604 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: Provide implementation of KASAN functions required for the hardware tag-based mode. Those include core functions for memory and pointer tagging (tags_hw.c) and bug reporting (report_tags_hw.c). Also adapt common KASAN code to support the new mode. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Acked-by: Catalin Marinas --- Change-Id: I8a8689ba098174a4d0ef3f1d008178387c80ee1c --- arch/arm64/include/asm/memory.h | 4 +- arch/arm64/kernel/setup.c | 1 - include/linux/kasan.h | 6 +-- include/linux/mm.h | 2 +- include/linux/page-flags-layout.h | 2 +- mm/kasan/Makefile | 5 ++ mm/kasan/common.c | 14 +++--- mm/kasan/kasan.h | 17 +++++-- mm/kasan/report_tags_hw.c | 47 +++++++++++++++++++ mm/kasan/report_tags_sw.c | 2 +- mm/kasan/shadow.c | 2 +- mm/kasan/tags_hw.c | 78 +++++++++++++++++++++++++++++++ mm/kasan/tags_sw.c | 2 +- 13 files changed, 162 insertions(+), 20 deletions(-) create mode 100644 mm/kasan/report_tags_hw.c create mode 100644 mm/kasan/tags_hw.c diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index de9af7bea90d..b5d6b824c21c 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -215,7 +215,7 @@ static inline unsigned long kaslr_offset(void) (__force __typeof__(addr))__addr; \ }) -#ifdef CONFIG_KASAN_SW_TAGS +#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) #define __tag_shifted(tag) ((u64)(tag) << 56) #define __tag_reset(addr) __untagged_addr(addr) #define __tag_get(addr) (__u8)((u64)(addr) >> 56) @@ -223,7 +223,7 @@ static inline unsigned long kaslr_offset(void) #define __tag_shifted(tag) 0UL #define __tag_reset(addr) (addr) #define __tag_get(addr) 0 -#endif /* CONFIG_KASAN_SW_TAGS */ +#endif /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS */ static inline const void *__tag_set(const void *addr, u8 tag) { diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 77c4c9bad1b8..5985be8af2c6 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -358,7 +358,6 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) smp_init_cpus(); smp_build_mpidr_hash(); - /* Init percpu seeds for random tags after cpus are set up. */ kasan_init_tags(); #ifdef CONFIG_ARM64_SW_TTBR0_PAN diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 875bbcedd994..613c9d38eee5 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -184,7 +184,7 @@ static inline void kasan_record_aux_stack(void *ptr) {} #endif /* CONFIG_KASAN_GENERIC */ -#ifdef CONFIG_KASAN_SW_TAGS +#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) void kasan_init_tags(void); @@ -193,7 +193,7 @@ void *kasan_reset_tag(const void *addr); bool kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip); -#else /* CONFIG_KASAN_SW_TAGS */ +#else /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS */ static inline void kasan_init_tags(void) { } @@ -202,7 +202,7 @@ static inline void *kasan_reset_tag(const void *addr) return (void *)addr; } -#endif /* CONFIG_KASAN_SW_TAGS */ +#endif /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS*/ #ifdef CONFIG_KASAN_VMALLOC diff --git a/include/linux/mm.h b/include/linux/mm.h index 4312c6c808e9..a3cac68c737c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1411,7 +1411,7 @@ static inline bool cpupid_match_pid(struct task_struct *task, int cpupid) } #endif /* CONFIG_NUMA_BALANCING */ -#ifdef CONFIG_KASAN_SW_TAGS +#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) static inline u8 page_kasan_tag(const struct page *page) { return (page->flags >> KASAN_TAG_PGSHIFT) & KASAN_TAG_MASK; diff --git a/include/linux/page-flags-layout.h b/include/linux/page-flags-layout.h index e200eef6a7fd..7d4ec26d8a3e 100644 --- a/include/linux/page-flags-layout.h +++ b/include/linux/page-flags-layout.h @@ -77,7 +77,7 @@ #define LAST_CPUPID_SHIFT 0 #endif -#ifdef CONFIG_KASAN_SW_TAGS +#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) #define KASAN_TAG_WIDTH 8 #else #define KASAN_TAG_WIDTH 0 diff --git a/mm/kasan/Makefile b/mm/kasan/Makefile index 0789f9023884..f8cf9ba674a1 100644 --- a/mm/kasan/Makefile +++ b/mm/kasan/Makefile @@ -10,9 +10,11 @@ CFLAGS_REMOVE_init.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_quarantine.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report_generic.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_report_tags_hw.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report_tags_sw.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_shadow.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_tags_sw.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_tags_hw.o = $(CC_FLAGS_FTRACE) # Function splitter causes unnecessary splits in __asan_load1/__asan_store1 # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533 @@ -27,10 +29,13 @@ CFLAGS_init.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_quarantine.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_report.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_report_generic.o := $(CC_FLAGS_KASAN_RUNTIME) +CFLAGS_report_tags_hw.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_report_tags_sw.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_shadow.o := $(CC_FLAGS_KASAN_RUNTIME) +CFLAGS_tags_hw.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_tags_sw.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_SW_TAGS) += init.o report_tags_sw.o shadow.o tags_sw.o +obj-$(CONFIG_KASAN_HW_TAGS) += tags_hw.o report_tags_hw.o diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 41c7f1105eaa..412a23d1546b 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -118,7 +118,7 @@ void kasan_free_pages(struct page *page, unsigned int order) */ static inline unsigned int optimal_redzone(unsigned int object_size) { - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) + if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) return 0; return @@ -183,14 +183,14 @@ size_t kasan_metadata_size(struct kmem_cache *cache) struct kasan_alloc_meta *get_alloc_info(struct kmem_cache *cache, const void *object) { - return (void *)object + cache->kasan_info.alloc_meta_offset; + return (void *)reset_tag(object) + cache->kasan_info.alloc_meta_offset; } struct kasan_free_meta *get_free_info(struct kmem_cache *cache, const void *object) { BUILD_BUG_ON(sizeof(struct kasan_free_meta) > 32); - return (void *)object + cache->kasan_info.free_meta_offset; + return (void *)reset_tag(object) + cache->kasan_info.free_meta_offset; } void kasan_poison_slab(struct page *page) @@ -272,7 +272,8 @@ void * __must_check kasan_init_slab_obj(struct kmem_cache *cache, alloc_info = get_alloc_info(cache, object); __memset(alloc_info, 0, sizeof(*alloc_info)); - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) + if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) || + IS_ENABLED(CONFIG_KASAN_HW_TAGS)) object = set_tag(object, assign_tag(cache, object, true, false)); @@ -342,10 +343,11 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, redzone_end = round_up((unsigned long)object + cache->object_size, KASAN_GRANULE_SIZE); - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) + if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) || + IS_ENABLED(CONFIG_KASAN_HW_TAGS)) tag = assign_tag(cache, object, false, keep_tag); - /* Tag is ignored in set_tag without CONFIG_KASAN_SW_TAGS */ + /* Tag is ignored in set_tag without CONFIG_KASAN_SW/HW_TAGS */ kasan_unpoison_memory(set_tag(object, tag), size); kasan_poison_memory((void *)redzone_start, redzone_end - redzone_start, KASAN_KMALLOC_REDZONE); diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index ba63d8a62968..1e9eda217be7 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -152,6 +152,10 @@ struct kasan_alloc_meta *get_alloc_info(struct kmem_cache *cache, struct kasan_free_meta *get_free_info(struct kmem_cache *cache, const void *object); +void kasan_poison_memory(const void *address, size_t size, u8 value); + +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) + static inline const void *kasan_shadow_to_mem(const void *shadow_addr) { return (void *)(((unsigned long)shadow_addr - KASAN_SHADOW_OFFSET) @@ -163,8 +167,6 @@ static inline bool addr_has_metadata(const void *addr) return (addr >= kasan_shadow_to_mem((void *)KASAN_SHADOW_START)); } -void kasan_poison_memory(const void *address, size_t size, u8 value); - /** * check_memory_region - Check memory region, and report if invalid access. * @addr: the accessed address @@ -176,6 +178,15 @@ void kasan_poison_memory(const void *address, size_t size, u8 value); bool check_memory_region(unsigned long addr, size_t size, bool write, unsigned long ret_ip); +#else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ + +static inline bool addr_has_metadata(const void *addr) +{ + return true; +} + +#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ + bool check_invalid_free(void *addr); void *find_first_bad_addr(void *addr, size_t size); @@ -212,7 +223,7 @@ static inline void quarantine_reduce(void) { } static inline void quarantine_remove_cache(struct kmem_cache *cache) { } #endif -#ifdef CONFIG_KASAN_SW_TAGS +#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) void print_tags(u8 addr_tag, const void *addr); diff --git a/mm/kasan/report_tags_hw.c b/mm/kasan/report_tags_hw.c new file mode 100644 index 000000000000..c2f73c46279a --- /dev/null +++ b/mm/kasan/report_tags_hw.c @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This file contains hardware tag-based KASAN specific error reporting code. + * + * Copyright (c) 2020 Google, Inc. + * Author: Andrey Konovalov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#include +#include +#include +#include +#include +#include + +#include "kasan.h" + +const char *get_bug_type(struct kasan_access_info *info) +{ + return "invalid-access"; +} + +void *find_first_bad_addr(void *addr, size_t size) +{ + return reset_tag(addr); +} + +void metadata_fetch_row(char *buffer, void *row) +{ + int i; + + for (i = 0; i < META_BYTES_PER_ROW; i++) + buffer[i] = mte_get_mem_tag(row + i * KASAN_GRANULE_SIZE); +} + +void print_tags(u8 addr_tag, const void *addr) +{ + u8 memory_tag = mte_get_mem_tag((void *)addr); + + pr_err("Pointer tag: [%02x], memory tag: [%02x]\n", + addr_tag, memory_tag); +} diff --git a/mm/kasan/report_tags_sw.c b/mm/kasan/report_tags_sw.c index 4060d0503462..b2894902bc47 100644 --- a/mm/kasan/report_tags_sw.c +++ b/mm/kasan/report_tags_sw.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * This file contains tag-based KASAN specific error reporting code. + * This file contains software tag-based KASAN specific error reporting code. * * Copyright (c) 2014 Samsung Electronics Co., Ltd. * Author: Andrey Ryabinin diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index 4888084ecdfc..ca69726adf8f 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -111,7 +111,7 @@ void kasan_unpoison_memory(const void *address, size_t size) if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) *shadow = tag; - else + else /* CONFIG_KASAN_GENERIC */ *shadow = size & KASAN_GRANULE_MASK; } } diff --git a/mm/kasan/tags_hw.c b/mm/kasan/tags_hw.c new file mode 100644 index 000000000000..c93d43379e39 --- /dev/null +++ b/mm/kasan/tags_hw.c @@ -0,0 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This file contains core hardware tag-based KASAN code. + * + * Copyright (c) 2020 Google, Inc. + * Author: Andrey Konovalov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#include +#include +#include +#include +#include +#include + +#include "kasan.h" + +void kasan_init_tags(void) +{ + init_tags(KASAN_TAG_MAX); +} + +void *kasan_reset_tag(const void *addr) +{ + return reset_tag(addr); +} + +void kasan_poison_memory(const void *address, size_t size, u8 value) +{ + set_mem_tag_range(reset_tag(address), + round_up(size, KASAN_GRANULE_SIZE), value); +} + +void kasan_unpoison_memory(const void *address, size_t size) +{ + set_mem_tag_range(reset_tag(address), + round_up(size, KASAN_GRANULE_SIZE), get_tag(address)); +} + +u8 random_tag(void) +{ + return get_random_tag(); +} + +bool check_invalid_free(void *addr) +{ + u8 ptr_tag = get_tag(addr); + u8 mem_tag = get_mem_tag(addr); + + if (mem_tag == KASAN_TAG_INVALID) + return true; + if (ptr_tag != KASAN_TAG_KERNEL && ptr_tag != mem_tag) + return true; + return false; +} + +void kasan_set_free_info(struct kmem_cache *cache, + void *object, u8 tag) +{ + struct kasan_alloc_meta *alloc_meta; + + alloc_meta = get_alloc_info(cache, object); + kasan_set_track(&alloc_meta->free_track[0], GFP_NOWAIT); +} + +struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, + void *object, u8 tag) +{ + struct kasan_alloc_meta *alloc_meta; + + alloc_meta = get_alloc_info(cache, object); + return &alloc_meta->free_track[0]; +} diff --git a/mm/kasan/tags_sw.c b/mm/kasan/tags_sw.c index feb42c1763b8..3df978b8d1d9 100644 --- a/mm/kasan/tags_sw.c +++ b/mm/kasan/tags_sw.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * This file contains core tag-based KASAN code. + * This file contains core software tag-based KASAN code. * * Copyright (c) 2018 Google, Inc. * Author: Andrey Konovalov From patchwork Tue Sep 15 21:16:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777783 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AA0346CA for ; Tue, 15 Sep 2020 21:17:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6FF4820770 for ; Tue, 15 Sep 2020 21:17:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="JLHBY9Ag" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6FF4820770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 591DE900095; Tue, 15 Sep 2020 17:17:47 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4F5FA900070; Tue, 15 Sep 2020 17:17:47 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3BAB8900095; Tue, 15 Sep 2020 17:17:47 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0076.hostedemail.com [216.40.44.76]) by kanga.kvack.org (Postfix) with ESMTP id 2130F900070 for ; Tue, 15 Sep 2020 17:17:47 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id DE3491F1A for ; Tue, 15 Sep 2020 21:17:46 +0000 (UTC) X-FDA: 77266557732.06.wash51_4506bb027114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id ABFB01005F0A5 for ; Tue, 15 Sep 2020 21:17:46 +0000 (UTC) X-Spam-Summary: 1,0,0,20e9719e34d84b34,d41d8cd98f00b204,3es9hxwokcf46j9naugjrhckkcha.8kihejqt-iigr68g.knc@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:982:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2901:3138:3139:3140:3141:3142:3152:3354:3865:3866:3867:3870:3871:3872:4117:4250:4321:4605:5007:6261:6653:6742:7903:8603:9036:9969:10004:10400:11026:11232:11473:11658:11914:12043:12048:12296:12297:12438:12555:12895:12986:14181:14394:14659:14721:21080:21324:21365:21444:21451:21626:30003:30012:30054:30056:30075,0,RBL:209.85.160.202:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04y8zyqp4rkphawbpmhg79rq33b6yyc8j4roxprp45w9nib99ye6h8ndf8tq4tw.copujugi9ue1soamnxpcgrngwore9sfd6o5drz6rptqbjssxnb5fnxnxz7rrqwh.a-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,C ustom_ru X-HE-Tag: wash51_4506bb027114 X-Filterd-Recvd-Size: 6535 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:46 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id g10so4041122qto.1 for ; Tue, 15 Sep 2020 14:17:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=D8sG/cEP7djDLTapvipoPil4TaVPwtS1uBYZ8/rqMfU=; b=JLHBY9AgkNxAqLTKFWQdxcgJcgqdPUV3TxpRVzNYHFqfab1asZTfQTMH+AqvVnwgCH BnUUjUz0j3cp5q50TzevAEZDIAJ0lOMhBCpOnwtBSEh0VnSduULw/f/WRSJ73y/PSR3g wAtqSI76OkKjfWf3WP25K5JUjRztC3SdAV4hoFEGhsvOomwFaXZfyUboATVZWnH9zU6D TQIjujxm5SaToqhiVOXT9DXzAt8rmJsm0fOCCNW7HoJrb4YrW0Q0m8CDIdPkQBW+HfF8 vXzn130goo1cQM6GpPk5iZ4YGlPC9oVunx0rEnt4NZEdRJcb4DVF1GJSyIHZDe5/ruiQ l/jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=D8sG/cEP7djDLTapvipoPil4TaVPwtS1uBYZ8/rqMfU=; b=EiFd882Is9KjuGv5+qc8R4oTgr7SomEiCJwd+D1oocCytsyNAnviUknqlcsWkfLeiB BS9vZodvciDjgEFRQGMPUk1UUMp2voG4QrVVUqxrGRPHewcgg/6cS9qkoUj8RyLoADLK VVOqEGX6OkQ0C2PQQ6vZmPmaQ+yEDmTD55BECHdRLCXFRUFHXFDdFODlh/2x6KxPpo8b QKTC7ELgK8yW46GQJXbbD7BC3bxvz10d+cEj1qbovsF5mZOzGARkFH6CD8ZlNWGa0S/p OriK6ksQovc5obqrt823yfB6zemyssKwDQRJfEJ9tPhMPrbv9CmI/pFuCOwwPTj0NJ1p xHaA== X-Gm-Message-State: AOAM530Uplrweq4glSTWfGSEM3rxmQO9BRxbkhknyzlDtjNljIdj/Gjn nrJ3/ahBWffNXb7BEouK1aTox+r1n1oaGBhY X-Google-Smtp-Source: ABdhPJzlRX414ae6dY3KcWoPCkTBwkZK3ld5YB1kdMEENNAIrBphNAvoJTIWKdIYK4+jfcGWQyTwv8zsQNqqfSmk X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:58e3:: with SMTP id di3mr3798476qvb.54.1600204665622; Tue, 15 Sep 2020 14:17:45 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:16 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 34/37] kasan, arm64: print report from tag fault handler From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: ABFB01005F0A5 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: Add error reporting for hardware tag-based KASAN. When CONFIG_KASAN_HW_TAGS is enabled, print KASAN report from the arm64 tag fault handler. SAS bits aren't set in ESR for all faults reported in EL1, so it's impossible to find out the size of the access the caused the fault. Adapt KASAN reporting code to handle this case. Signed-off-by: Andrey Konovalov Co-developed-by: Vincenzo Frascino Signed-off-by: Vincenzo Frascino --- Change-Id: I3780fe7db6e075dff2937d3d8508f55c9322b095 --- arch/arm64/mm/fault.c | 19 +++++++++++++------ mm/kasan/report.c | 11 ++++++++--- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index cdc23662691c..ac79819317f2 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -295,17 +296,23 @@ static void die_kernel_fault(const char *msg, unsigned long addr, do_exit(SIGKILL); } +#ifdef CONFIG_KASAN_HW_TAGS static void report_tag_fault(unsigned long addr, unsigned int esr, struct pt_regs *regs) { - bool is_write = ((esr & ESR_ELx_WNR) >> ESR_ELx_WNR_SHIFT) != 0; + bool is_write = ((esr & ESR_ELx_WNR) >> ESR_ELx_WNR_SHIFT) != 0; - pr_alert("Memory Tagging Extension Fault in %pS\n", (void *)regs->pc); - pr_alert(" %s at address %lx\n", is_write ? "Write" : "Read", addr); - pr_alert(" Pointer tag: [%02x], memory tag: [%02x]\n", - mte_get_ptr_tag(addr), - mte_get_mem_tag((void *)addr)); + /* + * SAS bits aren't set for all faults reported in EL1, so we can't + * find out access size. + */ + kasan_report(addr, 0, is_write, regs->pc); } +#else +/* Tag faults aren't enabled without CONFIG_KASAN_HW_TAGS. */ +static inline void report_tag_fault(unsigned long addr, unsigned int esr, + struct pt_regs *regs) { } +#endif static void __do_kernel_fault(unsigned long addr, unsigned int esr, struct pt_regs *regs) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index c904edab33b8..34ef81736d73 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -65,9 +65,14 @@ static void print_error_description(struct kasan_access_info *info) { pr_err("BUG: KASAN: %s in %pS\n", get_bug_type(info), (void *)info->ip); - pr_err("%s of size %zu at addr %px by task %s/%d\n", - info->is_write ? "Write" : "Read", info->access_size, - info->access_addr, current->comm, task_pid_nr(current)); + if (info->access_size) + pr_err("%s of size %zu at addr %px by task %s/%d\n", + info->is_write ? "Write" : "Read", info->access_size, + info->access_addr, current->comm, task_pid_nr(current)); + else + pr_err("%s at addr %px by task %s/%d\n", + info->is_write ? "Write" : "Read", + info->access_addr, current->comm, task_pid_nr(current)); } static DEFINE_SPINLOCK(report_lock); From patchwork Tue Sep 15 21:16:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777785 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E26FD59D for ; Tue, 15 Sep 2020 21:17:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9DB812078E for ; Tue, 15 Sep 2020 21:17:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="fsTRc89Y" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9DB812078E Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3485A900096; Tue, 15 Sep 2020 17:17:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2FA27900070; Tue, 15 Sep 2020 17:17:50 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14C10900096; Tue, 15 Sep 2020 17:17:50 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0006.hostedemail.com [216.40.44.6]) by kanga.kvack.org (Postfix) with ESMTP id ECDE2900070 for ; Tue, 15 Sep 2020 17:17:49 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B1D6E181AEF09 for ; Tue, 15 Sep 2020 21:17:49 +0000 (UTC) X-FDA: 77266557858.20.pet36_3e012f527114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 83DF5180C07A3 for ; Tue, 15 Sep 2020 21:17:49 +0000 (UTC) X-Spam-Summary: 1,0,0,b138c76f27a07722,d41d8cd98f00b204,3fc9hxwokcge9mcqdxjmukfnnfkd.bnlkhmtw-llju9bj.nqf@flex--andreyknvl.bounces.google.com,,RULES_HIT:2:41:69:152:355:379:541:800:960:966:973:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1593:1594:1605:1606:1730:1747:1777:1792:2196:2199:2393:2553:2559:2562:2918:3138:3139:3140:3141:3142:3152:3865:3866:3867:3868:3870:3871:3872:3874:4119:4250:4385:4605:5007:6261:6653:6742:7875:7904:9969:10004:11026:11232:11473:11658:11914:12043:12048:12296:12297:12438:12555:12895:14096:14097:14394:14659:21080:21365:21433:21444:21451:21627:21772:21939:21966:21990:30012:30054:30055:30062:30070:30090,0,RBL:209.85.221.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04y8gqns6unfeeiaayeuido73qif6ocanq4fd6m43w4n46wa9w1t16kagb4g4xe.fhz5y1wosmj1pdj6zunj4nfe8jppn8gsfo5amxttn834pwm5937uzk1ipwf5kxx.1-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0, MSF:not X-HE-Tag: pet36_3e012f527114 X-Filterd-Recvd-Size: 8772 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:49 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id l15so1705121wro.10 for ; Tue, 15 Sep 2020 14:17:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=OJ/8AnntxXTECtkQTOaxjfZECPzBTRORy6i2yS83kOo=; b=fsTRc89Y8Zxhcw1t5FHcT2l04+Vs91ABV7dJ+vBPhhaHv+cdI42HIqPxytva99Oc/f tEF8Ajhet3GGkGV0lxMNdANtx58YTLh2raBV++EuvcTDG4lfRtVuBPZ3dhERXQrVolz5 qR6ht87ldpJ+K6V9qf/aTiaHgi3Rtj8MoV5qm6W2Yu0VKdVnI/+pNvbLjwyDqlInDyuy ixzwUN/j7DQ1s685G6q7r/X917lEDMjNnDlwT5fg2nngAWAgJG608O+mBfOBdT4/IE+Y +oA5tacqx8skGTtNElJzGeTixoBhDz1eN9lgftdMtVlInLtvMnDII+IeqTWP3nfZ3K5e Mfdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=OJ/8AnntxXTECtkQTOaxjfZECPzBTRORy6i2yS83kOo=; b=lm2Q1f4VST8QCwXQYm7MIhafNTCodKNpfJoJy1FHjpumnOczhMfPhPclCo1ODhPp5k CN5w7qH1xKfV1FctEVDPnpp4xextm9G6UiDvQRcGAh4t2BR9LbCntsjYxIyr/pC9QcBC axF8r4mYba9/xVgJcgT5Sle4MAY0JeVBRQZ7hOj7WftNjgU5IStebUUEw18EYUr4MHkB wBrh77VUud0aY0fV5kvEFJ+yZcnSZpL29zhHhJK5rQCPUjeiGBx6eMZox8SkMPvkyn4J iYkGYSgeSOSQgtmmojy03+id6rBtKtJMWgqBaVExgvdNQVZZN1BXTmb9CATDpRKtyHaW 3GPA== X-Gm-Message-State: AOAM531Yl3uwGV3TqLiI7hF3e9+ZZS/fdqFLt00g6GzUBY32mIF4zFhI LKidR4T8jJK8md0pKudHSf07YuzUH7KtDuEv X-Google-Smtp-Source: ABdhPJyB2fgN/4avIQbsrVPagRenog1bi9DkyzuhYeFDKwQHiHl1iiiqiRJ8H6iw/7DwoI0ckDpr8Mm/2qsFUGd0 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:600c:2283:: with SMTP id 3mr1188256wmf.37.1600204668051; Tue, 15 Sep 2020 14:17:48 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:17 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 35/37] kasan, slub: reset tags when accessing metadata From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 83DF5180C07A3 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: SLUB allocator accesses metadata for slab objects, that may lie out-of-bounds of the object itself, or be accessed when an object is freed. Such accesses trigger tag faults and lead to false-positive reports with hardware tag-based KASAN. Software KASAN modes disable instrumentation for allocator code via KASAN_SANITIZE Makefile macro, and rely on kasan_enable/disable_current() annotations which are used to ignore KASAN reports. With hardware tag-based KASAN neither of those options are available, as it doesn't use compiler instrumetation, no tag faults are ignored, and MTE is disabled after the first one. Instead, reset tags when accessing metadata. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: I39f3c4d4f29299d4fbbda039bedf230db1c746fb --- mm/page_poison.c | 2 +- mm/slub.c | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/mm/page_poison.c b/mm/page_poison.c index 34b9181ee5d1..d90d342a391f 100644 --- a/mm/page_poison.c +++ b/mm/page_poison.c @@ -43,7 +43,7 @@ static void poison_page(struct page *page) /* KASAN still think the page is in-use, so skip it. */ kasan_disable_current(); - memset(addr, PAGE_POISON, PAGE_SIZE); + memset(kasan_reset_tag(addr), PAGE_POISON, PAGE_SIZE); kasan_enable_current(); kunmap_atomic(addr); } diff --git a/mm/slub.c b/mm/slub.c index 68c02b2eecd9..8e134ca3a6fb 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -249,7 +249,7 @@ static inline void *freelist_ptr(const struct kmem_cache *s, void *ptr, { #ifdef CONFIG_SLAB_FREELIST_HARDENED /* - * When CONFIG_KASAN_SW_TAGS is enabled, ptr_addr might be tagged. + * When CONFIG_KASAN_SW/HW_TAGS is enabled, ptr_addr might be tagged. * Normally, this doesn't cause any issues, as both set_freepointer() * and get_freepointer() are called with a pointer with the same tag. * However, there are some issues with CONFIG_SLUB_DEBUG code. For @@ -275,6 +275,7 @@ static inline void *freelist_dereference(const struct kmem_cache *s, static inline void *get_freepointer(struct kmem_cache *s, void *object) { + object = kasan_reset_tag(object); return freelist_dereference(s, object + s->offset); } @@ -304,6 +305,7 @@ static inline void set_freepointer(struct kmem_cache *s, void *object, void *fp) BUG_ON(object == fp); /* naive detection of double free or corruption */ #endif + freeptr_addr = (unsigned long)kasan_reset_tag((void *)freeptr_addr); *(void **)freeptr_addr = freelist_ptr(s, fp, freeptr_addr); } @@ -538,8 +540,8 @@ static void print_section(char *level, char *text, u8 *addr, unsigned int length) { metadata_access_enable(); - print_hex_dump(level, text, DUMP_PREFIX_ADDRESS, 16, 1, addr, - length, 1); + print_hex_dump(level, kasan_reset_tag(text), DUMP_PREFIX_ADDRESS, + 16, 1, addr, length, 1); metadata_access_disable(); } @@ -570,7 +572,7 @@ static struct track *get_track(struct kmem_cache *s, void *object, p = object + get_info_end(s); - return p + alloc; + return kasan_reset_tag(p + alloc); } static void set_track(struct kmem_cache *s, void *object, @@ -583,7 +585,8 @@ static void set_track(struct kmem_cache *s, void *object, unsigned int nr_entries; metadata_access_enable(); - nr_entries = stack_trace_save(p->addrs, TRACK_ADDRS_COUNT, 3); + nr_entries = stack_trace_save(kasan_reset_tag(p->addrs), + TRACK_ADDRS_COUNT, 3); metadata_access_disable(); if (nr_entries < TRACK_ADDRS_COUNT) @@ -747,7 +750,7 @@ static __printf(3, 4) void slab_err(struct kmem_cache *s, struct page *page, static void init_object(struct kmem_cache *s, void *object, u8 val) { - u8 *p = object; + u8 *p = kasan_reset_tag(object); if (s->flags & SLAB_RED_ZONE) memset(p - s->red_left_pad, val, s->red_left_pad); @@ -777,7 +780,7 @@ static int check_bytes_and_report(struct kmem_cache *s, struct page *page, u8 *addr = page_address(page); metadata_access_enable(); - fault = memchr_inv(start, value, bytes); + fault = memchr_inv(kasan_reset_tag(start), value, bytes); metadata_access_disable(); if (!fault) return 1; @@ -873,7 +876,7 @@ static int slab_pad_check(struct kmem_cache *s, struct page *page) pad = end - remainder; metadata_access_enable(); - fault = memchr_inv(pad, POISON_INUSE, remainder); + fault = memchr_inv(kasan_reset_tag(pad), POISON_INUSE, remainder); metadata_access_disable(); if (!fault) return 1; @@ -1118,7 +1121,7 @@ void setup_page_debug(struct kmem_cache *s, struct page *page, void *addr) return; metadata_access_enable(); - memset(addr, POISON_INUSE, page_size(page)); + memset(kasan_reset_tag(addr), POISON_INUSE, page_size(page)); metadata_access_disable(); } @@ -2884,10 +2887,10 @@ static __always_inline void *slab_alloc_node(struct kmem_cache *s, stat(s, ALLOC_FASTPATH); } - maybe_wipe_obj_freeptr(s, object); + maybe_wipe_obj_freeptr(s, kasan_reset_tag(object)); if (unlikely(slab_want_init_on_alloc(gfpflags, s)) && object) - memset(object, 0, s->object_size); + memset(kasan_reset_tag(object), 0, s->object_size); slab_post_alloc_hook(s, objcg, gfpflags, 1, &object); From patchwork Tue Sep 15 21:16:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777787 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 353E659D for ; Tue, 15 Sep 2020 21:17:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E5B4E20770 for ; Tue, 15 Sep 2020 21:17:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="vpddWMvo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E5B4E20770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2341E900097; Tue, 15 Sep 2020 17:17:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 20FC4900070; Tue, 15 Sep 2020 17:17:53 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E231A900097; Tue, 15 Sep 2020 17:17:52 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0254.hostedemail.com [216.40.44.254]) by kanga.kvack.org (Postfix) with ESMTP id B0F4C900070 for ; Tue, 15 Sep 2020 17:17:52 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 7BD118249980 for ; Tue, 15 Sep 2020 21:17:52 +0000 (UTC) X-FDA: 77266557984.26.coil06_4f08e3827114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id 4F0741804B656 for ; Tue, 15 Sep 2020 21:17:52 +0000 (UTC) X-Spam-Summary: 1,0,0,d3cc692757a205af,d41d8cd98f00b204,3fi9hxwokcgmboesfzlowmhpphmf.dpnmjovy-nnlwbdl.psh@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1431:1516:1518:1534:1540:1568:1593:1594:1711:1714:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3152:3865:3871:4250:5007:6261:6653:6742:9969:10004:10400:11026:11232:11473:11658:11914:12043:12048:12114:12297:12438:12555:12895:13069:13311:13357:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:30054,0,RBL:209.85.218.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yrqzr63mk3fx3q7x8cgbc3wmyzpoptjx8zbdwxuc8r8a6je3nir9y5whhqjyg.zg3b3wbznxz9xew7e1c4p96f5dx3yyhe86mh6oryw6wspdpeqxiaox8ubhihwep.o-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: coil06_4f08e3827114 X-Filterd-Recvd-Size: 4268 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:51 +0000 (UTC) Received: by mail-ej1-f74.google.com with SMTP id r14so1848412ejb.3 for ; Tue, 15 Sep 2020 14:17:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=t8rdfVrdLyxTAYdMt/4LR6Ye4IfbP7qoWzC6FDGTZkw=; b=vpddWMvoyUB7iZMxqEeVRHqhIXDBQTU4Z6/ORGC/5trX/+UsDGo+9vpvpHW+Js/9m2 CR1wMVEWu/JeDwzOLYfrKBKObhRCu0BplW0f+6Rt5HsHIpeMC+iNwPL6Rx2whOtgTcHP OSp6chdIi2Ys4lJn8rkKzxv/5NeJF3ZwPECH4lmK6VPyN82su3s1u/4bx2Q9c0AiWt7d wSoTpJhrzNg5FZaYQWIa6/6ghxmqgrvoqtKxR0FwFjsrYmEGNSdRQj0femL5Mv17DK9O X5QTS3CEm+DYpCJmf5nCf9NjsdTf1HSrtvIekVR9X/i4ct13defwoCxykK9g43C+/LBj EZ4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=t8rdfVrdLyxTAYdMt/4LR6Ye4IfbP7qoWzC6FDGTZkw=; b=gGLAD/DYZjWJgffZ2FxpjLkc8LHJQfYowuOU5F72OP13XssPjticWzEMRyXFkJMlRB vW2SGyB//Jmv/PLW8Gj8HDhwjRi7ommbtrW70A0IphXStQZ8n7rlwjQQGD11KJbHGaPD 1Y6pJwkM+WVEMOWIaeAgUqLkkw4FRkwddljrxKVfL531/Lp+466uJ+932W6Nq/mcf+eV CI3yuyD+n3v2oBeqO6QgoTFY0J0amqhswjdejUImj20EqvyOKxaEQjXieTH7S+0AHnk1 t8K2ZtzxjnjxT32DkRJWu7T1e758u9BaTucTVSAXfe15dyWiJJY95kSskLtaepEKEPSf dEmg== X-Gm-Message-State: AOAM530/mdPPBz/Q1MLUa+iPDRlNDeVrdKImgi+y9KiXX4057L+HIgze PFP8lU8yiLJXz4C4FNZV0uApIBpxa3XPfSTv X-Google-Smtp-Source: ABdhPJxZO/za0DL/aaj/l3gIS/p97WdkPtBAB72fw5melIRWH5aX1Fyw0VwE4wOIs6/dgKwajS0HAVcZKzJ52Im5 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a17:906:60d5:: with SMTP id f21mr21975308ejk.94.1600204670609; Tue, 15 Sep 2020 14:17:50 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:18 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 36/37] kasan, arm64: enable CONFIG_KASAN_HW_TAGS From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 4F0741804B656 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: Hardware tag-based KASAN is now ready, enable the configuration option. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Acked-by: Catalin Marinas --- Change-Id: I6eb1eea770e6b61ad71c701231b8d815a7ccc853 --- arch/arm64/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index c8e45870e993..afeb5dde437d 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -132,6 +132,7 @@ config ARM64 select HAVE_ARCH_JUMP_LABEL_RELATIVE select HAVE_ARCH_KASAN if !(ARM64_16K_PAGES && ARM64_VA_BITS_48) select HAVE_ARCH_KASAN_SW_TAGS if (HAVE_ARCH_KASAN && !ARM64_MTE) + select HAVE_ARCH_KASAN_HW_TAGS if (HAVE_ARCH_KASAN && ARM64_MTE) select HAVE_ARCH_KGDB select HAVE_ARCH_MMAP_RND_BITS select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT From patchwork Tue Sep 15 21:16:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777789 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6948C59D for ; Tue, 15 Sep 2020 21:17:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 232C320770 for ; Tue, 15 Sep 2020 21:17:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="dul3rKrx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 232C320770 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E6FA5900098; Tue, 15 Sep 2020 17:17:54 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DA3C5900070; Tue, 15 Sep 2020 17:17:54 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BAEBB900098; Tue, 15 Sep 2020 17:17:54 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0050.hostedemail.com [216.40.44.50]) by kanga.kvack.org (Postfix) with ESMTP id 884FC900070 for ; Tue, 15 Sep 2020 17:17:54 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 4F9458249980 for ; Tue, 15 Sep 2020 21:17:54 +0000 (UTC) X-FDA: 77266558068.20.legs03_5b0a5dd27114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 1E598180C07AB for ; Tue, 15 Sep 2020 21:17:54 +0000 (UTC) X-Spam-Summary: 1,0,0,295b11ece174fe36,d41d8cd98f00b204,3gc9hxwokcgudqguhbnqyojrrjoh.frpolqxa-ppnydfn.ruj@flex--andreyknvl.bounces.google.com,,RULES_HIT:1:2:41:69:152:355:379:541:800:960:966:973:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1593:1594:1605:1730:1747:1777:1792:1981:2194:2196:2198:2199:2200:2201:2393:2559:2562:2901:2918:3138:3139:3140:3141:3142:3152:3865:3866:3867:3868:3870:3871:3872:3873:3874:4050:4250:4321:4385:4559:5007:6119:6261:6653:6742:7903:8957:9969:10004:11026:11232:11473:11658:11914:12043:12048:12219:12291:12296:12297:12438:12555:12683:12895:12986:13153:13228:14095:14096:14110:14394:14659:21080:21324:21365:21444:21451:21627:21740:21772:21990:30010:30054:30070:30074,0,RBL:209.85.222.202:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yr74kbxdk3ai3fx5atx4uo9p7m4ocyxax3zeda5wm6e14z9zdbbqatunx8rs6.dbsn4dwwi4u8sjwg4pmapzc7rqp6oirgm7cug3jcmxaqomwhp3qawi5aw4k8e7o.k-lbl8.mailshell.net-223.238.255.100,Cache IP:none, X-HE-Tag: legs03_5b0a5dd27114 X-Filterd-Recvd-Size: 10478 Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:53 +0000 (UTC) Received: by mail-qk1-f202.google.com with SMTP id u23so4068351qku.17 for ; Tue, 15 Sep 2020 14:17:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=efGgWAfAvEfxSZXVo3Aku/Fbu43aBpvq/2RKTLwcfy4=; b=dul3rKrxWec5gxWPnD8abxojfTAkJaFvi5g2u1EuR37S8Y9zLgwWb7KQH6dLhceBls xN8nojKa7eHen1UPkbwbus4Nh02hEBjPp/JkljJR1GzxcHN9GZdmSRV/sZ//jthle6g1 HSwhvSmYzqKtAxEZ4SB4cEtf2bFsMPxyDZyeb/E3YKAE7+S82pQwZUJNbyLr8r/FuOy1 NpBlMiI93D+OX6NpvwPT+8ot4+PCgHCYRjAM1SjyG8oLaNkGBFXhx668bw5uXj40ad3C kyVJf722wtrP37QXEfxCwqYX7dKfTJoI8ZtOJ/WlvlqltrSrCSYPmppIgp5bxMHS3LJP 9xXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=efGgWAfAvEfxSZXVo3Aku/Fbu43aBpvq/2RKTLwcfy4=; b=Jc9CkoxEswjAzZWRlAT13eQZ/J16Add+Z8KH6zJG9z7B3yFs5YgD3ICSXXdYRgQRMc irFg8wmtd61eoHBg5lSBKAsRhx0bJ7v7c6w1abvUBgJeeyDpEUa9HaQyoYlhK74BZ/56 5qiIOTbeQmwxb6tjkJslw4wXgRSTDzLxi8N7tIW5JjjfzyWWJbBlUBHPyFA494TFkIp3 Q3qkNskEZ7mxmIUBFb6ecHhoXF2H/rL0DZ1GKCu711gZMM+CvasRQD7346Rc4Bvj8TTQ P0fUks4xBTO0M5kfrc/WPW6qV5XLg1v4KS/Fuqt59xqM6h72Rfh4LOXSi+EnW8QZQzde ctSQ== X-Gm-Message-State: AOAM531a112u1SY6025CKswgVpXXqREM0Yx6kYqLXjNYhIB8LXt4KWUV 8LcETlSIp3M3uGGM7M8x9j7VRX7hV5xpxQkM X-Google-Smtp-Source: ABdhPJw3fOkNJcl3Z9hC9UEmNewcly+exjNFsHIM8lJjwFEf2/Yr9ZwOvtO9yOUsvmRbgIVVUzROgENyE0Odp4Y0 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:8645:: with SMTP id p63mr19966719qva.21.1600204672937; Tue, 15 Sep 2020 14:17:52 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:19 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 37/37] kasan: add documentation for hardware tag-based mode From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 1E598180C07AB X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: Add documentation for hardware tag-based KASAN mode and also add some clarifications for software tag-based mode. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino --- Change-Id: Ib46cb444cfdee44054628940a82f5139e10d0258 --- Documentation/dev-tools/kasan.rst | 78 ++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 21 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index a3030fc6afe5..d2d47c82a7b9 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -5,12 +5,14 @@ Overview -------- KernelAddressSANitizer (KASAN) is a dynamic memory error detector designed to -find out-of-bound and use-after-free bugs. KASAN has two modes: generic KASAN -(similar to userspace ASan) and software tag-based KASAN (similar to userspace -HWASan). +find out-of-bound and use-after-free bugs. KASAN has three modes: +1. generic KASAN (similar to userspace ASan), +2. software tag-based KASAN (similar to userspace HWASan), +3. hardware tag-based KASAN (based on hardware memory tagging). -KASAN uses compile-time instrumentation to insert validity checks before every -memory access, and therefore requires a compiler version that supports that. +Software KASAN modes (1 and 2) use compile-time instrumentation to insert +validity checks before every memory access, and therefore require a compiler +version that supports that. Generic KASAN is supported in both GCC and Clang. With GCC it requires version 8.3.0 or later. With Clang it requires version 7.0.0 or later, but detection of @@ -19,7 +21,7 @@ out-of-bounds accesses for global variables is only supported since Clang 11. Tag-based KASAN is only supported in Clang and requires version 7.0.0 or later. Currently generic KASAN is supported for the x86_64, arm64, xtensa, s390 and -riscv architectures, and tag-based KASAN is supported only for arm64. +riscv architectures, and tag-based KASAN modes are supported only for arm64. Usage ----- @@ -28,14 +30,16 @@ To enable KASAN configure kernel with:: CONFIG_KASAN = y -and choose between CONFIG_KASAN_GENERIC (to enable generic KASAN) and -CONFIG_KASAN_SW_TAGS (to enable software tag-based KASAN). +and choose between CONFIG_KASAN_GENERIC (to enable generic KASAN), +CONFIG_KASAN_SW_TAGS (to enable software tag-based KASAN), and +CONFIG_KASAN_HW_TAGS (to enable hardware tag-based KASAN). -You also need to choose between CONFIG_KASAN_OUTLINE and CONFIG_KASAN_INLINE. -Outline and inline are compiler instrumentation types. The former produces -smaller binary while the latter is 1.1 - 2 times faster. +For software modes, you also need to choose between CONFIG_KASAN_OUTLINE and +CONFIG_KASAN_INLINE. Outline and inline are compiler instrumentation types. +The former produces smaller binary while the latter is 1.1 - 2 times faster. -Both KASAN modes work with both SLUB and SLAB memory allocators. +Both software KASAN modes work with both SLUB and SLAB memory allocators, +hardware tag-based KASAN currently only support SLUB. For better bug detection and nicer reporting, enable CONFIG_STACKTRACE. To augment reports with last allocation and freeing stack of the physical page, @@ -196,17 +200,24 @@ and the second to last. Software tag-based KASAN ~~~~~~~~~~~~~~~~~~~~~~~~ -Tag-based KASAN uses the Top Byte Ignore (TBI) feature of modern arm64 CPUs to -store a pointer tag in the top byte of kernel pointers. Like generic KASAN it -uses shadow memory to store memory tags associated with each 16-byte memory +Software tag-based KASAN requires software memory tagging support in the form +of HWASan-like compiler instrumentation (see HWASan documentation for details). + +Software tag-based KASAN is currently only implemented for arm64 architecture. + +Software tag-based KASAN uses the Top Byte Ignore (TBI) feature of arm64 CPUs +to store a pointer tag in the top byte of kernel pointers. Like generic KASAN +it uses shadow memory to store memory tags associated with each 16-byte memory cell (therefore it dedicates 1/16th of the kernel memory for shadow memory). -On each memory allocation tag-based KASAN generates a random tag, tags the -allocated memory with this tag, and embeds this tag into the returned pointer. +On each memory allocation software tag-based KASAN generates a random tag, tags +the allocated memory with this tag, and embeds this tag into the returned +pointer. + Software tag-based KASAN uses compile-time instrumentation to insert checks before each memory access. These checks make sure that tag of the memory that is being accessed is equal to tag of the pointer that is used to access this -memory. In case of a tag mismatch tag-based KASAN prints a bug report. +memory. In case of a tag mismatch software tag-based KASAN prints a bug report. Software tag-based KASAN also has two instrumentation modes (outline, that emits callbacks to check memory accesses; and inline, that performs the shadow @@ -215,9 +226,34 @@ simply printed from the function that performs the access check. With inline instrumentation a brk instruction is emitted by the compiler, and a dedicated brk handler is used to print bug reports. -A potential expansion of this mode is a hardware tag-based mode, which would -use hardware memory tagging support instead of compiler instrumentation and -manual shadow memory manipulation. +Software tag-based KASAN uses 0xFF as a match-all pointer tag (accesses through +pointers with 0xFF pointer tag aren't checked). The value 0xFE is currently +reserved to tag freed memory regions. + +Software tag-based KASAN currently only supports tagging of slab memory. + +Hardware tag-based KASAN +~~~~~~~~~~~~~~~~~~~~~~~~ + +Hardware tag-based KASAN is similar to the software mode in concept, but uses +hardware memory tagging support instead of compiler instrumentation and +shadow memory. + +Hardware tag-based KASAN is currently only implemented for arm64 architecture +and based on both arm64 Memory Tagging Extension (MTE) introduced in ARMv8.5 +Instruction Set Architecture, and Top Byte Ignore (TBI). + +Special arm64 instructions are used to assign memory tags for each allocation. +Same tags are assigned to pointers to those allocations. On every memory +access, hardware makes sure that tag of the memory that is being accessed is +equal to tag of the pointer that is used to access this memory. In case of a +tag mismatch a fault is generated and a report is printed. + +Hardware tag-based KASAN uses 0xFF as a match-all pointer tag (accesses through +pointers with 0xFF pointer tag aren't checked). The value 0xFE is currently +reserved to tag freed memory regions. + +Hardware tag-based KASAN currently only supports tagging of slab memory. What memory accesses are sanitised by KASAN? --------------------------------------------