From patchwork Tue Nov 10 22:20: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: 11895639 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 468BE138B for ; Tue, 10 Nov 2020 22:20:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0035120781 for ; Tue, 10 Nov 2020 22:20: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="B6QwfVBA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0035120781 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 DADEA6B006C; Tue, 10 Nov 2020 17:20:33 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D84B36B006E; Tue, 10 Nov 2020 17:20:33 -0500 (EST) 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 C25216B0070; Tue, 10 Nov 2020 17:20:33 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0030.hostedemail.com [216.40.44.30]) by kanga.kvack.org (Postfix) with ESMTP id 96FD16B006C for ; Tue, 10 Nov 2020 17:20:33 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 44B0C1EE6 for ; Tue, 10 Nov 2020 22:20:33 +0000 (UTC) X-FDA: 77469928746.14.stew34_060aae2272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 26DAB18229835 for ; Tue, 10 Nov 2020 22:20:33 +0000 (UTC) X-Spam-Summary: 1,0,0,e10332a4e1d41c5a,d41d8cd98f00b204,3lxkrxwokcaqerhvi2orzpksskpi.gsqpmry1-qqozego.svk@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:966:967:968:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:1981:2194:2196:2199:2200:2393:2525:2559:2563:2682:2685:2859:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3353:3865:3867:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4385:4425:4605:5007:6261:6653:6742:8660:9025:9969:10004:10400:11026:11473:11658:11914:12043:12296:12297:12438:12555:12679:12895:12986:13148:13230:14096:14097:14181:14394:14659:14721:21080:21212:21365:21444:21451:21627:21939:21966:21990:30054:30075,0,RBL:209.85.128.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04y84mekecy7gpn5kmifuanewhoheycbcmn6kwxjddzask68dpttpyfneuucs75.tkdrs9qjzpzez4hxu4qr4bu6h7n6kcgxkddsfx1aerh7qurd6jzagduzicsa pmn.a-lb X-HE-Tag: stew34_060aae2272f8 X-Filterd-Recvd-Size: 5785 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:20:32 +0000 (UTC) Received: by mail-wm1-f73.google.com with SMTP id 3so1858608wms.9 for ; Tue, 10 Nov 2020 14:20:32 -0800 (PST) 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=SMV12gvgXWyti1wWozncOBF2sC/NzCwG5tM1W9vYuH4=; b=B6QwfVBAz7pkQ6yN3GQqARn2ii4rZdYmih8xg6h0+kbT6exEYUg4pd4Iohk94eyM1c mfyXHR7Pxl38SAXC+UEdfwWOGQNZDQyHqw0WxKX+1aldC5Nh33y9y1wUbwjCW1D0yajz 82APgf+BpR2WC3RpKvYiDkV8kFzJxpoXE7CFk42ZB+MpjTlBxJm0XvKG7IxF4CW0/YAU G5dkj7NUrzW4l90Z8ZrgBn308BRtQCP8KJTgZyqtc9ySrVSwXbVeMNlFKR3/b04gGUiT bClkE+hnLWgDfQGY229UlKDA4DC0pu/Iq0yDc0SmjQZcRbEmjzC5MnBcn/JR/TO1dWNI M5UA== 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=SMV12gvgXWyti1wWozncOBF2sC/NzCwG5tM1W9vYuH4=; b=j9QFaNFhH+ZwHkDKBvPFhpR8xkeYHrxd9LvQF1f0wpxgKPZXjMuOKkmf3B0RCU3Zoa YDlD5TDusg5RIhKLvyZjB+Jh+tXMG8kyYDdYUjjwcAKpkk0v4wccqlBin8UayO1n+Os6 aOZ8+Ak2G0EUN4tDQ15MS/ce8F8w4zF5sBexIdkmg5Asl09BEuUWhcrnWcPB0SsHVZRN sHKpAhobX96Iap+bIRQ18kdNZNkb7fLn3I0J06o5lD64ofFXEkBRduAFpEic/UaEreFV juGpuAOe5k2JCoTzKj+CRwYtvPbfxabw5GCicTT2spQYspJlwRS9zVYDF6gaawnl9coE LELg== X-Gm-Message-State: AOAM531Wqcg4PkrK0zf2PpPIn1vK36Mg6zwuXAvL4VonjJhqUF2N9gRv lXzFx01of1wtprOWtgXmSl3ouGFFiBt29kjF X-Google-Smtp-Source: ABdhPJxOgxlfhZQUpHjQ0Geh6GQq8dMdva8blwAYkX9VCtBB6RV5i3/j12u3n9DxhI2tM3WRQFA2yXCA2IHyyaf/ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:5f45:: with SMTP id t66mr315013wmb.20.1605046831528; Tue, 10 Nov 2020 14:20:31 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:05 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 01/20] kasan: simplify quarantine_put call site From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: Move get_free_info() call into quarantine_put() to simplify the call site. No functional changes. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/Iab0f04e7ebf8d83247024b7190c67c3c34c7940f Reviewed-by: Marco Elver --- mm/kasan/common.c | 2 +- mm/kasan/kasan.h | 5 ++--- mm/kasan/quarantine.c | 3 ++- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 2bb0ef6da6bd..5712c66c11c1 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -308,7 +308,7 @@ static bool __kasan_slab_free(struct kmem_cache *cache, void *object, kasan_set_free_info(cache, object, tag); - quarantine_put(get_free_info(cache, object), cache); + quarantine_put(cache, object); return IS_ENABLED(CONFIG_KASAN_GENERIC); } diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 21fe75c66f26..c2c40ec1544d 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -214,12 +214,11 @@ struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, #if defined(CONFIG_KASAN_GENERIC) && \ (defined(CONFIG_SLAB) || defined(CONFIG_SLUB)) -void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache); +void quarantine_put(struct kmem_cache *cache, void *object); void quarantine_reduce(void); void quarantine_remove_cache(struct kmem_cache *cache); #else -static inline void quarantine_put(struct kasan_free_meta *info, - struct kmem_cache *cache) { } +static inline void quarantine_put(struct kmem_cache *cache, void *object) { } static inline void quarantine_reduce(void) { } static inline void quarantine_remove_cache(struct kmem_cache *cache) { } #endif diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c index 580ff5610fc1..a0792f0d6d0f 100644 --- a/mm/kasan/quarantine.c +++ b/mm/kasan/quarantine.c @@ -161,11 +161,12 @@ static void qlist_free_all(struct qlist_head *q, struct kmem_cache *cache) qlist_init(q); } -void quarantine_put(struct kasan_free_meta *info, struct kmem_cache *cache) +void quarantine_put(struct kmem_cache *cache, void *object) { unsigned long flags; struct qlist_head *q; struct qlist_head temp = QLIST_INIT; + struct kasan_free_meta *info = get_free_info(cache, object); /* * Note: irq must be disabled until after we move the batch to the From patchwork Tue Nov 10 22:20: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: 11895641 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 905FA138B for ; Tue, 10 Nov 2020 22:20:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3765D20674 for ; Tue, 10 Nov 2020 22:20: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="CJ8BfCyP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3765D20674 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 23D386B0071; Tue, 10 Nov 2020 17:20:36 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1EA036B0072; Tue, 10 Nov 2020 17:20:36 -0500 (EST) 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 0B3156B0073; Tue, 10 Nov 2020 17:20:36 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0164.hostedemail.com [216.40.44.164]) by kanga.kvack.org (Postfix) with ESMTP id D07F06B0071 for ; Tue, 10 Nov 2020 17:20:35 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 76F571EE6 for ; Tue, 10 Nov 2020 22:20:35 +0000 (UTC) X-FDA: 77469928830.20.lamp73_4a03d82272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 5117A180C07AB for ; Tue, 10 Nov 2020 22:20:35 +0000 (UTC) X-Spam-Summary: 1,0,0,1cbf78d90aa32226,d41d8cd98f00b204,3mrkrxwokcaygtjxk4qt1rmuumrk.iusrot03-ssq1giq.uxm@flex--andreyknvl.bounces.google.com,,RULES_HIT:1:2:41:152:355:379:541:800:960:965:966:967: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:2525:2559:2563:2682:2685:2859:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3865:3867:3868:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4052:4321:4385:4390:4395:4425:4605:5007:6261:6653:6742:8603:8660:8957:9025:9969:10004:11026:11473:11658:11914:12043:12296:12297:12438:12555:12679:12895:12986:13148:13230:14096:14097:14394:14659:21080:21365:21444:21451:21627:21939:21966:21990:30003:30054:30075,0,RBL:209.85.221.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04y87ma1i57ot8g95ujbsz89xa4oiocorjpi9k1iiuin5oumhhobfrqs3k9hmbh.xi4mqnffqograriqdb35r3mi4qsa3w3ang4uoxua3j4y4tedp 589pohzz X-HE-Tag: lamp73_4a03d82272f8 X-Filterd-Recvd-Size: 12683 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:20:34 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id d8so5238630wrr.10 for ; Tue, 10 Nov 2020 14:20:34 -0800 (PST) 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=JDIZOBUdSYTr2qi1CrbHHoKD73faXUnEima7jMLorCA=; b=CJ8BfCyPbncwSwtW5Nci8JD1n3yUcmS6Qi/Zxu+AO5koJd203DZOBn0oO6Cv8JYj7C sLWi5+XypMyXhXDToFYMh5hN5cdjZulh23MD2DytKQfTKC5mwvnUM8j+mNToUnyFM1mN +nMOjhzrbVe7lVJ+TpZaeqRxbhBhrHdFviv4Q69TIi+QYWDXVgUHRliNYRiUIQIk2jlI lQa6dollahx6B5ha3GuwMdCmN8IKGeABTfSNFBIqeOHHs7zsOo+qiUTOofI3E43ndV36 ioZ/4b5sm7nyrNtTpoRwb7Vt3vS1rm8q8u6CnUtCuTFxjDgLDbDk8DH3AVh+f5nfv4/d lo2A== 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=JDIZOBUdSYTr2qi1CrbHHoKD73faXUnEima7jMLorCA=; b=U1MQpVTqQ26kjO09t2vf2k9xcoYx4oT2WUDgJT8cNEA5pcmFoB2DhhJZzHXrRtw6l/ m10nHCublYSpk5O23zWc34MznkRKe2ZYGlIbuy+0BU58EVlJbqflTAelJaVo/b+jj+2o zkF0XMaGYAzKhc+cehQgN50Gy/DfG6UyKuxe5PqptNkpX7DtMo0vLfA0K6n6xE4jW1Q4 T5f8ZsfuJHbrMtlcPdzZWAiROyYj+0SnU0YG89LdSoKOGfVPlTKANInX69dUbdg3MQ3K vV7K8vnxZLrOQES07j3Q/5F/yWU9vOFiPChPswu+KmBWYdCWHWZCz/2atu5xgPaZPf42 Stmg== X-Gm-Message-State: AOAM530i4Cts4Y0MMj/0GeyLWF+e9zGLD1Ted+ytpYqb1TJP3AkLMC8C gzvd54pL0TAHyBZF+eW6g/teUVfZcyUdkVji X-Google-Smtp-Source: ABdhPJySAq2llW78O6AAjPm3restP8s7ySQayVVxoAa3/zeNctA1gJD24wEL3ercpCiB7rt/FGljH7Ku8auUbxvP X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:bac1:: with SMTP id k184mr290033wmf.76.1605046833741; Tue, 10 Nov 2020 14:20:33 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:06 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 02/20] kasan: rename get_alloc/free_info From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: Rename get_alloc_info() and get_free_info() to kasan_get_alloc_meta() and kasan_get_free_meta() to better reflect what those do and avoid confusion with kasan_set_free_info(). No functional changes. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/Ib6e4ba61c8b12112b403d3479a9799ac8fff8de1 Reviewed-by: Marco Elver --- mm/kasan/common.c | 16 ++++++++-------- mm/kasan/generic.c | 12 ++++++------ mm/kasan/hw_tags.c | 4 ++-- mm/kasan/kasan.h | 8 ++++---- mm/kasan/quarantine.c | 4 ++-- mm/kasan/report.c | 12 ++++++------ mm/kasan/report_sw_tags.c | 2 +- mm/kasan/sw_tags.c | 4 ++-- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 5712c66c11c1..8fd04415d8f4 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -175,14 +175,14 @@ size_t kasan_metadata_size(struct kmem_cache *cache) sizeof(struct kasan_free_meta) : 0); } -struct kasan_alloc_meta *get_alloc_info(struct kmem_cache *cache, - const void *object) +struct kasan_alloc_meta *kasan_get_alloc_meta(struct kmem_cache *cache, + const void *object) { 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) +struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache, + const void *object) { BUILD_BUG_ON(sizeof(struct kasan_free_meta) > 32); return (void *)reset_tag(object) + cache->kasan_info.free_meta_offset; @@ -259,13 +259,13 @@ static u8 assign_tag(struct kmem_cache *cache, const void *object, void * __must_check kasan_init_slab_obj(struct kmem_cache *cache, const void *object) { - struct kasan_alloc_meta *alloc_info; + struct kasan_alloc_meta *alloc_meta; if (!(cache->flags & SLAB_KASAN)) return (void *)object; - alloc_info = get_alloc_info(cache, object); - __memset(alloc_info, 0, sizeof(*alloc_info)); + alloc_meta = kasan_get_alloc_meta(cache, object); + __memset(alloc_meta, 0, sizeof(*alloc_meta)); if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) || IS_ENABLED(CONFIG_KASAN_HW_TAGS)) object = set_tag(object, assign_tag(cache, object, true, false)); @@ -345,7 +345,7 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, KASAN_KMALLOC_REDZONE); if (cache->flags & SLAB_KASAN) - kasan_set_track(&get_alloc_info(cache, object)->alloc_track, flags); + kasan_set_track(&kasan_get_alloc_meta(cache, object)->alloc_track, flags); return set_tag(object, tag); } diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index adb254df1b1d..d259e4c3aefd 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -329,7 +329,7 @@ void kasan_record_aux_stack(void *addr) { struct page *page = kasan_addr_to_page(addr); struct kmem_cache *cache; - struct kasan_alloc_meta *alloc_info; + struct kasan_alloc_meta *alloc_meta; void *object; if (!(page && PageSlab(page))) @@ -337,13 +337,13 @@ void kasan_record_aux_stack(void *addr) cache = page->slab_cache; object = nearest_obj(cache, page, addr); - alloc_info = get_alloc_info(cache, object); + alloc_meta = kasan_get_alloc_meta(cache, object); /* * record the last two call_rcu() call stacks. */ - alloc_info->aux_stack[1] = alloc_info->aux_stack[0]; - alloc_info->aux_stack[0] = kasan_save_stack(GFP_NOWAIT); + alloc_meta->aux_stack[1] = alloc_meta->aux_stack[0]; + alloc_meta->aux_stack[0] = kasan_save_stack(GFP_NOWAIT); } void kasan_set_free_info(struct kmem_cache *cache, @@ -351,7 +351,7 @@ void kasan_set_free_info(struct kmem_cache *cache, { struct kasan_free_meta *free_meta; - free_meta = get_free_info(cache, object); + free_meta = kasan_get_free_meta(cache, object); kasan_set_track(&free_meta->free_track, GFP_NOWAIT); /* @@ -365,5 +365,5 @@ struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, { if (*(u8 *)kasan_mem_to_shadow(object) != KASAN_KMALLOC_FREETRACK) return NULL; - return &get_free_info(cache, object)->free_track; + return &kasan_get_free_meta(cache, object)->free_track; } diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 0080b78ec843..70b88dd40cd8 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -66,7 +66,7 @@ void kasan_set_free_info(struct kmem_cache *cache, { struct kasan_alloc_meta *alloc_meta; - alloc_meta = get_alloc_info(cache, object); + alloc_meta = kasan_get_alloc_meta(cache, object); kasan_set_track(&alloc_meta->free_track[0], GFP_NOWAIT); } @@ -75,6 +75,6 @@ struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, { struct kasan_alloc_meta *alloc_meta; - alloc_meta = get_alloc_info(cache, object); + alloc_meta = kasan_get_alloc_meta(cache, object); return &alloc_meta->free_track[0]; } diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index c2c40ec1544d..db8a7a508121 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -148,10 +148,10 @@ struct kasan_free_meta { #endif }; -struct kasan_alloc_meta *get_alloc_info(struct kmem_cache *cache, - const void *object); -struct kasan_free_meta *get_free_info(struct kmem_cache *cache, - const void *object); +struct kasan_alloc_meta *kasan_get_alloc_meta(struct kmem_cache *cache, + const void *object); +struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache, + const void *object); void kasan_poison_memory(const void *address, size_t size, u8 value); diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c index a0792f0d6d0f..0da3d37e1589 100644 --- a/mm/kasan/quarantine.c +++ b/mm/kasan/quarantine.c @@ -166,7 +166,7 @@ void quarantine_put(struct kmem_cache *cache, void *object) unsigned long flags; struct qlist_head *q; struct qlist_head temp = QLIST_INIT; - struct kasan_free_meta *info = get_free_info(cache, object); + struct kasan_free_meta *meta = kasan_get_free_meta(cache, object); /* * Note: irq must be disabled until after we move the batch to the @@ -179,7 +179,7 @@ void quarantine_put(struct kmem_cache *cache, void *object) local_irq_save(flags); q = this_cpu_ptr(&cpu_quarantine); - qlist_put(q, &info->quarantine_link, cache->size); + qlist_put(q, &meta->quarantine_link, cache->size); if (unlikely(q->bytes > QUARANTINE_PERCPU_SIZE)) { qlist_move_all(q, &temp); diff --git a/mm/kasan/report.c b/mm/kasan/report.c index ce06005d4052..0cac53a57c14 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -164,12 +164,12 @@ static void describe_object_addr(struct kmem_cache *cache, void *object, static void describe_object(struct kmem_cache *cache, void *object, const void *addr, u8 tag) { - struct kasan_alloc_meta *alloc_info = get_alloc_info(cache, object); + struct kasan_alloc_meta *alloc_meta = kasan_get_alloc_meta(cache, object); if (cache->flags & SLAB_KASAN) { struct kasan_track *free_track; - print_track(&alloc_info->alloc_track, "Allocated"); + print_track(&alloc_meta->alloc_track, "Allocated"); pr_err("\n"); free_track = kasan_get_free_track(cache, object, tag); if (free_track) { @@ -178,14 +178,14 @@ static void describe_object(struct kmem_cache *cache, void *object, } #ifdef CONFIG_KASAN_GENERIC - if (alloc_info->aux_stack[0]) { + if (alloc_meta->aux_stack[0]) { pr_err("Last call_rcu():\n"); - print_stack(alloc_info->aux_stack[0]); + print_stack(alloc_meta->aux_stack[0]); pr_err("\n"); } - if (alloc_info->aux_stack[1]) { + if (alloc_meta->aux_stack[1]) { pr_err("Second to last call_rcu():\n"); - print_stack(alloc_info->aux_stack[1]); + print_stack(alloc_meta->aux_stack[1]); pr_err("\n"); } #endif diff --git a/mm/kasan/report_sw_tags.c b/mm/kasan/report_sw_tags.c index aebc44a29e83..317100fd95b9 100644 --- a/mm/kasan/report_sw_tags.c +++ b/mm/kasan/report_sw_tags.c @@ -46,7 +46,7 @@ const char *get_bug_type(struct kasan_access_info *info) if (page && PageSlab(page)) { cache = page->slab_cache; object = nearest_obj(cache, page, (void *)addr); - alloc_meta = get_alloc_info(cache, object); + alloc_meta = kasan_get_alloc_meta(cache, object); for (i = 0; i < KASAN_NR_FREE_STACKS; i++) if (alloc_meta->free_pointer_tag[i] == tag) diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c index dfe707dd8d0d..3bffb489b144 100644 --- a/mm/kasan/sw_tags.c +++ b/mm/kasan/sw_tags.c @@ -174,7 +174,7 @@ void kasan_set_free_info(struct kmem_cache *cache, struct kasan_alloc_meta *alloc_meta; u8 idx = 0; - alloc_meta = get_alloc_info(cache, object); + alloc_meta = kasan_get_alloc_meta(cache, object); #ifdef CONFIG_KASAN_SW_TAGS_IDENTIFY idx = alloc_meta->free_track_idx; @@ -191,7 +191,7 @@ struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, struct kasan_alloc_meta *alloc_meta; int i = 0; - alloc_meta = get_alloc_info(cache, object); + alloc_meta = kasan_get_alloc_meta(cache, object); #ifdef CONFIG_KASAN_SW_TAGS_IDENTIFY for (i = 0; i < KASAN_NR_FREE_STACKS; i++) { From patchwork Tue Nov 10 22:20: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: 11895643 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 E56611391 for ; Tue, 10 Nov 2020 22:20:39 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A1BFE20781 for ; Tue, 10 Nov 2020 22:20: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="lCftT4m0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A1BFE20781 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 8F60B6B0074; Tue, 10 Nov 2020 17:20:38 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8A32F6B0075; Tue, 10 Nov 2020 17:20:38 -0500 (EST) 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 741636B0078; Tue, 10 Nov 2020 17:20:38 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0074.hostedemail.com [216.40.44.74]) by kanga.kvack.org (Postfix) with ESMTP id 468376B0074 for ; Tue, 10 Nov 2020 17:20:38 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id E8F49181AEF10 for ; Tue, 10 Nov 2020 22:20:37 +0000 (UTC) X-FDA: 77469928914.20.glass87_0803cc6272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id C1092180C07AB for ; Tue, 10 Nov 2020 22:20:37 +0000 (UTC) X-Spam-Summary: 1,0,0,8f93ee6c3ce31163,d41d8cd98f00b204,3nbkrxwokcakjwm0n7tw4upxxpun.lxvurw36-vvt4jlt.x0p@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:966:967:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2525:2559:2563:2682:2685:2693:2859:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3352:3865:3866:3868:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4385:4425:5007:6261:6653:6742:8603:9025:9969:10004:10400:11026:11473:11658:11914:12043:12296:12297:12438:12555:12679:12895:13069:13311:13357:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:21939:21990:30012:30054,0,RBL:209.85.128.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yg3me6jf744se6wk8iskyn68tfyopq6hf6kbeywnn7pnhnp8o6scggzd4jsim.uiwj4aijtbxoxhssdbji5qakbfwuky3c33eyfeqapkcj6trp5pr8da1qb7t4yju.n-lbl8.mailshell. net-223. X-HE-Tag: glass87_0803cc6272f8 X-Filterd-Recvd-Size: 4734 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, 10 Nov 2020 22:20:37 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id k128so1861488wme.7 for ; Tue, 10 Nov 2020 14:20:37 -0800 (PST) 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=gNopVjIT8PLD1roCXuMREiwLLvujReoC9+pcOjj05mE=; b=lCftT4m06a6889qXGQTef3H4ubHV8kKj9dGlz5f67eoPKWdz/PHnNnYEjABMQLk8d9 KObCel4cnvyGAfTLT3glV7CaPrDc0oVmARZammV+1pVoZ/2jSlMDKbk5t8ghqy2BrnAQ 6wiA3BXXhqVlgixBVMEYRnob8fIiyC/M+a6xp4u0aNMUCSSJaunS7d4ecvp+s9fgBTTl ILcUALwdqyXB6pkQZeuRw2BZ9ehON8RQWBZCFPbVG5/Tjjcf9C/MjxhSUXZvdV4Wx2sm tXxLD2ziia9ZukMCBDzC8zBSj5kuUeYjuML+1LS3YfaqORZ/tW8RY/g6NyBPCfrCuo0E RgsA== 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=gNopVjIT8PLD1roCXuMREiwLLvujReoC9+pcOjj05mE=; b=MTkRkFW4sdE8vrdYBFfjamGvZLjtkvBvyFyl81NAdmqFRxyjSLButmkMj0ek3KrE3P muw+nEReKs3XwQfetA7z+XkHvFA93+UKFyuBzAvt09xGIr41DzV4xqy5cPNNO5BSRtgQ TSFzirLXoFalrxMVRkvzka7EJMbNjpQock47R0+weMVO+7ErG2Ir5WCqGxcmOvWOyIV8 NmFWEsIVL+0utolZlbLaZLkyE9IoKXRaBexMnmXiJ2VbM7ncsONadYTC7qrC9mBoS6mU iy+Yc1qsK/XFb++kaXVlyW6Tu1nf84Vn03JG5/Brp/W1wfT5mOsMAnd1NppiWEfmVQIP BtVQ== X-Gm-Message-State: AOAM532XyCffx54UMK2+rDPpjhYtgNDsbh8IFMEX4NcmEbSshEkC5BM8 inm//pqhwdMdcQwG1Ndk965yd61beMv7NuRL X-Google-Smtp-Source: ABdhPJywHqOrMb83vobFQz6uQH+1U+IiE7bFzlSvWOmiu58rv8s7DM6ShUb7PXTFUABDWl/FwVrflkCpjtBdifZz X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:3803:: with SMTP id f3mr304885wma.14.1605046836014; Tue, 10 Nov 2020 14:20:36 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:07 +0100 In-Reply-To: Message-Id: <5302e6d48429465259bd0868a7dc357290a2e8a5.1605046662.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 03/20] kasan: introduce set_alloc_info From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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 set_alloc_info() helper and move kasan_set_track() into it. This will simplify the code for one of the upcoming changes. No functional changes. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/I0316193cbb4ecc9b87b7c2eee0dd79f8ec908c1a Reviewed-by: Marco Elver --- mm/kasan/common.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 8fd04415d8f4..a880e5a547ed 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -318,6 +318,11 @@ bool kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip) return __kasan_slab_free(cache, object, ip, true); } +static void set_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) +{ + kasan_set_track(&kasan_get_alloc_meta(cache, object)->alloc_track, flags); +} + static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, size_t size, gfp_t flags, bool keep_tag) { @@ -345,7 +350,7 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, KASAN_KMALLOC_REDZONE); if (cache->flags & SLAB_KASAN) - kasan_set_track(&kasan_get_alloc_meta(cache, object)->alloc_track, flags); + set_alloc_info(cache, (void *)object, flags); return set_tag(object, tag); } From patchwork Tue Nov 10 22:20: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: 11895645 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 263B4138B for ; Tue, 10 Nov 2020 22:20:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D3359206B2 for ; Tue, 10 Nov 2020 22:20:41 +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="Lw7P323O" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D3359206B2 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 680E26B007B; Tue, 10 Nov 2020 17:20:40 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 59A8C6B007D; Tue, 10 Nov 2020 17:20:40 -0500 (EST) 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 486826B007E; Tue, 10 Nov 2020 17:20:40 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0228.hostedemail.com [216.40.44.228]) by kanga.kvack.org (Postfix) with ESMTP id 110B16B007B for ; Tue, 10 Nov 2020 17:20:40 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B699A181AEF10 for ; Tue, 10 Nov 2020 22:20:39 +0000 (UTC) X-FDA: 77469928998.21.mark58_5300170272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 6FAA2180442C0 for ; Tue, 10 Nov 2020 22:20:39 +0000 (UTC) X-Spam-Summary: 1,0,0,fe65eef9cd8ed5c1,d41d8cd98f00b204,3nhkrxwokcaslyo2p9vy6wrzzrwp.nzxwty58-xxv6lnv.z2r@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:966:967:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:1981:2194:2196:2198:2199:2200:2201:2393:2525:2553:2559:2563:2682:2685:2731:2859:2896:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3354:3865:3866:3867:3868:3870:3871:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4118:4250:4321:4385:4425:4605:5007:6261:6653:6742:7875:8603:8660:9025:9592:9969:10004:10400:11026:11473:11657:11658:11914:12043:12295:12296:12297:12438:12555:12679:12895:12986:13148:13161:13180:13229:13230:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:21939:21990:30003:30054:30090,0,RBL:209.85.222.201:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yrmqdw4p5qd8zkfkx7sjmn54e5 topysm9p X-HE-Tag: mark58_5300170272f8 X-Filterd-Recvd-Size: 7151 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf19.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:20:38 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id w4so186369qki.20 for ; Tue, 10 Nov 2020 14:20:38 -0800 (PST) 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=tEdtRhABI1InYFpD5ltmIm/evviW/mtmaENcJYt1lmc=; b=Lw7P323OF/2i72kWQuJ4l8inThWAnZLsOW9ThJ12RKxjoJxpzU7FXD1KV+6+q4wFpg l/r4+g+lNCXzgzXgK1lygyyUKCtzwpfHl/3OlTnMhhMRfVDtB2PdYon8ei3bzhD2Vqtt Wo3uUi7dX96xLBACxd53V6ueiGeSZymzkpvnmaVcbe+7AHrMitDwaS52oyIZ68DrTouD k4aflKbowlt0EK7lot+JEbexzRr4RzOeeQC1v96jGdm7Fx8vBNCN0QhyaFYecRjubCKf y4BPPQEw0TRxyeg4FETviyB1G271O7T0w4aKkUqb+DvRw5ABtXAGXbngmp+oaS/px1Mw omsA== 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=tEdtRhABI1InYFpD5ltmIm/evviW/mtmaENcJYt1lmc=; b=D1Jw+/fOFkG/nkGg27dhce/b2FxMT/pwR0y2OuhFhk/+MTr6ramjeqfOvuL63JlEwY pbo9iQYQ15JDOT3JYKKu/WQWf86H1ilwLvggiYiNeOc5ZHbKeQaIZqU2R2Q8mBz58el/ s2cKND9r2NJkNxHvowpU2TyuwEGsqIySckfECOWx/6JbvYwydh8dlDxXLj+DqtR4BJP2 a6AncKnfnvL/BZz1deR7BFDU7/91qAwruzpn2MZvnYUipOqe5cldnY8tRLuq02149ZO0 IWh5+ykXXtD1D+Ew9q6c6FXMsfDtaSTxSaqLlpPLuQvceGTJkjjQD4LJLhDjYGX2ZbzS qzzg== X-Gm-Message-State: AOAM5309Z8AMj/Qj/Tu/GdqocFHo2cNBct/YhnLGoMUtGIPIycW1a0ji 4S4J7rA1tdmwQipwL5zJlCbBlicUQMR6xiu3 X-Google-Smtp-Source: ABdhPJxqgq6UfWHyoMS9rSSpgTD3+0B/UNYGVxM4mfhk/kYijiMY8uMFuj8WQnHSvWCojmtQAUsNukGtycyjiBdC X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6214:6a7:: with SMTP id s7mr22500256qvz.2.1605046838323; Tue, 10 Nov 2020 14:20:38 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:08 +0100 In-Reply-To: Message-Id: <7e95d4739f5617b2c1acf52f37e01f1ca83750b5.1605046662.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 04/20] kasan, arm64: unpoison stack only with CONFIG_KASAN_STACK From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: There's a config option CONFIG_KASAN_STACK that has to be enabled for KASAN to use stack instrumentation and perform validity checks for stack variables. There's no need to unpoison stack when CONFIG_KASAN_STACK is not enabled. Only call kasan_unpoison_task_stack[_below]() when CONFIG_KASAN_STACK is enabled. Note, that CONFIG_KASAN_STACK is an option that is currently always defined when CONFIG_KASAN is enabled, and therefore has to be tested with #if instead of #ifdef. Signed-off-by: Andrey Konovalov Link: https://linux-review.googlesource.com/id/If8a891e9fe01ea543e00b576852685afec0887e3 Reviewed-by: Marco Elver Acked-by: Catalin Marinas --- arch/arm64/kernel/sleep.S | 2 +- arch/x86/kernel/acpi/wakeup_64.S | 2 +- include/linux/kasan.h | 10 ++++++---- mm/kasan/common.c | 2 ++ 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/sleep.S b/arch/arm64/kernel/sleep.S index ba40d57757d6..bdadfa56b40e 100644 --- a/arch/arm64/kernel/sleep.S +++ b/arch/arm64/kernel/sleep.S @@ -133,7 +133,7 @@ SYM_FUNC_START(_cpu_resume) */ bl cpu_do_resume -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK mov x0, sp bl kasan_unpoison_task_stack_below #endif diff --git a/arch/x86/kernel/acpi/wakeup_64.S b/arch/x86/kernel/acpi/wakeup_64.S index c8daa92f38dc..5d3a0b8fd379 100644 --- a/arch/x86/kernel/acpi/wakeup_64.S +++ b/arch/x86/kernel/acpi/wakeup_64.S @@ -112,7 +112,7 @@ SYM_FUNC_START(do_suspend_lowlevel) movq pt_regs_r14(%rax), %r14 movq pt_regs_r15(%rax), %r15 -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK /* * The suspend path may have poisoned some areas deeper in the stack, * which we now need to unpoison. diff --git a/include/linux/kasan.h b/include/linux/kasan.h index f22bdef82111..b9b9db335d87 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -76,8 +76,6 @@ static inline void kasan_disable_current(void) {} void kasan_unpoison_memory(const void *address, size_t size); -void kasan_unpoison_task_stack(struct task_struct *task); - void kasan_alloc_pages(struct page *page, unsigned int order); void kasan_free_pages(struct page *page, unsigned int order); @@ -122,8 +120,6 @@ void kasan_restore_multi_shot(bool enabled); 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_alloc_pages(struct page *page, unsigned int order) {} static inline void kasan_free_pages(struct page *page, unsigned int order) {} @@ -175,6 +171,12 @@ static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } #endif /* CONFIG_KASAN */ +#if defined(CONFIG_KASAN) && CONFIG_KASAN_STACK +void kasan_unpoison_task_stack(struct task_struct *task); +#else +static inline void kasan_unpoison_task_stack(struct task_struct *task) {} +#endif + #ifdef CONFIG_KASAN_GENERIC void kasan_cache_shrink(struct kmem_cache *cache); diff --git a/mm/kasan/common.c b/mm/kasan/common.c index a880e5a547ed..a3e67d49b893 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -58,6 +58,7 @@ void kasan_disable_current(void) } #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ +#if CONFIG_KASAN_STACK static void __kasan_unpoison_stack(struct task_struct *task, const void *sp) { void *base = task_stack_page(task); @@ -84,6 +85,7 @@ asmlinkage void kasan_unpoison_task_stack_below(const void *watermark) kasan_unpoison_memory(base, watermark - base); } +#endif /* CONFIG_KASAN_STACK */ void kasan_alloc_pages(struct page *page, unsigned int order) { From patchwork Tue Nov 10 22:20: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: 11895647 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 44C561391 for ; Tue, 10 Nov 2020 22:20:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id ED6D9206B2 for ; Tue, 10 Nov 2020 22:20: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="anCq4Edn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ED6D9206B2 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 C4CA56B0080; Tue, 10 Nov 2020 17:20:43 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B873F6B0081; Tue, 10 Nov 2020 17:20:43 -0500 (EST) 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 A01786B0082; Tue, 10 Nov 2020 17:20:43 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0007.hostedemail.com [216.40.44.7]) by kanga.kvack.org (Postfix) with ESMTP id 67D6E6B0080 for ; Tue, 10 Nov 2020 17:20:43 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 0CCE0362B for ; Tue, 10 Nov 2020 22:20:43 +0000 (UTC) X-FDA: 77469929166.29.scene63_56160ed272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id DB9CD180868DA for ; Tue, 10 Nov 2020 22:20:42 +0000 (UTC) X-Spam-Summary: 1,0,0,87c55b4d637feb5c,d41d8cd98f00b204,3obkrxwokca0n0q4rbx08yt11tyr.p1zyv07a-zzx8npx.14t@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:967:973:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2525:2559:2563:2682:2685:2859:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3352:3865:3867:3868:3871:3872:3873:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4425:5007:6261:6653:6742:9025:9969:10004:10400:11026:11232:11473:11658:11914:12043:12296:12297:12438:12555:12679:12895:12986:13069:13311:13357:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:21740:21772:21939:30054:30070:30091,0,RBL:209.85.167.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04y8ezmfrix9x3h9m89ok9zf9umnpypikdzaokjtrqt7r6qqmrszyfjiqifww15.k4tbe5s5gqhexrducakjrey48kp7qjqocth95j47r36k7rgc4nzwutekxjxuhog.1- lbl8.mai X-HE-Tag: scene63_56160ed272f8 X-Filterd-Recvd-Size: 4749 Received: from mail-lf1-f73.google.com (mail-lf1-f73.google.com [209.85.167.73]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:20:42 +0000 (UTC) Received: by mail-lf1-f73.google.com with SMTP id 64so78650lfk.15 for ; Tue, 10 Nov 2020 14:20:42 -0800 (PST) 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=iclGPRxOEu/Y72cezYx1VmP9mDKpdmhcr9SlAN2oUkA=; b=anCq4EdnMSfYibAYpKrbP8hc679KEJvqPcdaN5/ex3VCos1k3cAadzjksNjGffBqyb 9lgrUg03iHa8hf4SaVEeE+mhD1mCHcljJ1Z7Ec/ZghnpiPfwDV4+tZOz03wyyuzCkWN9 T4v3wHx6wv0e4wpOUdjnOJR7SC5EgpvpDGy+L1000n3KvhEK62jVSzkseAUDrGlOW3r0 g8ZvAhT1g1U4eFHzE8Pxdb2eONP3u7u7CYSfsjuF0yjCdSWIeOtzbawwk3RpvEMvyPf3 Z/XsxkAcX/vePoc584Itp3epvSDKWY3tEZhC9BFnXQ7YFDQwHJPCHiGaCKIKNknphdDi D6Ww== 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=iclGPRxOEu/Y72cezYx1VmP9mDKpdmhcr9SlAN2oUkA=; b=OiVQxxPWyqjl7RpphZatmogxL8fQ5qmlwG+g+n+aVMvEtSZhrxTGDsdMBbiA2/Yu3N P1CnZt0tKySj6qz8QmY+KNp4EK31u+5jEG/1CY+ePgdxMdeiHWvxPGc8bwjFdUOMwn/G dZUcDKxijJLMP5OWLcwmxR+ZhncupKnkvGjsU9Okj1xEhVUl036ShCxlTA4Y5KIvty0m lRNLaMVNB+R1ev44c1oMXl2vdnPzDp6k/e30ZbCKND8qsb+6AEITv/liTCBe3mV71Ab8 t1NXrgpY/XmMumI3TZNo3D7+tZUnFaRPkEshazjMsP6Ny7rtwLYyABjKDKMLo+0N4qhT OAGA== X-Gm-Message-State: AOAM531p+EOPAcDCQvBSG1repYqyq2vtq0JkOiRpjpVIujGX0WZDVsZI EO6Qajxt2PC4g+r9aOPKZ7Fj1DDjTYOV1dbe X-Google-Smtp-Source: ABdhPJz/vW2PmB5nvPRSNdQS5v8e1QIaJCbChgmywQIwIw3qCBt2wYADSNx1GYS36rwbNkkvrKv/2+gFZwdZs5i0 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a2e:320c:: with SMTP id y12mr9612197ljy.362.1605046840773; Tue, 10 Nov 2020 14:20:40 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:09 +0100 In-Reply-To: Message-Id: <3443e106c40799e5dc3981dec2011379f3cbbb0c.1605046662.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 05/20] kasan: allow VMAP_STACK for HW_TAGS mode From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: Even though hardware tag-based mode currently doesn't support checking vmalloc allocations, it doesn't use shadow memory and works with VMAP_STACK as is. Change VMAP_STACK definition accordingly. Signed-off-by: Andrey Konovalov Link: https://linux-review.googlesource.com/id/I3552cbc12321dec82cd7372676e9372a2eb452ac Reviewed-by: Marco Elver Acked-by: Catalin Marinas --- arch/Kconfig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 56b6ccc0e32d..7e7d14fae568 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -914,16 +914,16 @@ config VMAP_STACK default y bool "Use a virtually-mapped stack" depends on HAVE_ARCH_VMAP_STACK - depends on !KASAN || KASAN_VMALLOC + depends on !KASAN || KASAN_HW_TAGS || KASAN_VMALLOC help Enable this if you want the use virtually-mapped kernel stacks with guard pages. This causes kernel stack overflows to be caught immediately rather than causing difficult-to-diagnose corruption. - To use this with KASAN, the architecture must support backing - virtual mappings with real shadow memory, and KASAN_VMALLOC must - be enabled. + To use this with software KASAN modes, the architecture must support + backing virtual mappings with real shadow memory, and KASAN_VMALLOC + must be enabled. config ARCH_OPTIONAL_KERNEL_RWX def_bool n From patchwork Tue Nov 10 22:20: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: 11895649 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 8C57B1391 for ; Tue, 10 Nov 2020 22:20:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 412A220674 for ; Tue, 10 Nov 2020 22:20: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="ljjlpu85" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 412A220674 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 C522C6B0083; Tue, 10 Nov 2020 17:20:45 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B3CD66B0085; Tue, 10 Nov 2020 17:20:45 -0500 (EST) 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 964DA6B0087; Tue, 10 Nov 2020 17:20:45 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0196.hostedemail.com [216.40.44.196]) by kanga.kvack.org (Postfix) with ESMTP id 57E866B0083 for ; Tue, 10 Nov 2020 17:20:45 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 0825B8249980 for ; Tue, 10 Nov 2020 22:20:45 +0000 (UTC) X-FDA: 77469929250.13.house01_1d16fa3272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id DA8D018140B69 for ; Tue, 10 Nov 2020 22:20:44 +0000 (UTC) X-Spam-Summary: 1,0,0,258e49479b9218f8,d41d8cd98f00b204,3oxkrxwokcbaq3t7ue03b1w44w1u.s421y3ad-220bqs0.47w@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:1534:1541:1593:1594:1711:1730:1747:1777:1792:1981:2194:2199:2393:2525:2559:2563:2682:2685:2859:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3352:3865:3870:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4425:5007:6261:6653:6742:7875:7903:8603:9025:9592:9969:10004:10400:11026:11473:11658:11914:12043:12114:12296:12297:12438:12555:12679:12895:12986:13069:13161:13229:13311:13357:14096:14097:14181:14394:14659:14721:14877:21080:21365:21444:21451:21627:21939:21990:30054,0,RBL:209.85.221.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yrx91gcpxgwsmaobx9kfqmpi543ycq1mfhrg3k4x4mcfx3ja1r11ktk4bzumf.g691bmcs3j19ey3estfi7wqrxk1ydqz1879cn4sd53hukq1kdpni m7g6p5cm X-HE-Tag: house01_1d16fa3272f8 X-Filterd-Recvd-Size: 4671 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:20:44 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id r15so1112576wrn.15 for ; Tue, 10 Nov 2020 14:20:44 -0800 (PST) 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=gyGUZGx6qFH2jkAU5L1Nk+VZLXl2e4B3h6WrDO5AJuc=; b=ljjlpu8510giM6ompwxwC9fW/XdFC8qbLxu53fZ6U03b6EYiKpJWB0pnDuMqHGR+jN r5TObzaeFfHiWBeyCqwixdqdi5C/59498RU2S9dfH8AcpG/uescXFFAI4vk1MFIFdUxs aKXAW+Igl/dpH9QlRqyELk9F5/tXGDupazh551//E9tyUg+sj67imZtPjKwh90Ayg1OS vnltrTuRHfB3/tkF78B29cR78uIqwsQ9sGY6GIW8WBL94NHckeVhPN4/F3EutOAkS+Ln 5/kQaGmI93yINQy4OgjBA4Oz+orNqVJURp3LVEBZBzBxMrSgh386MQ6eowcq/tXep6fs h8og== 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=gyGUZGx6qFH2jkAU5L1Nk+VZLXl2e4B3h6WrDO5AJuc=; b=PjfkHFm+Ej58+Flpu3yfJgAycPimfk7p8J40jF+/+NlluNYOExGLdFLfF99D3V/eAx /VuStZzQV18+ISpi8bIsNpc0t+bVhqK7aefhaulfUIz1Fkb2CcaVLd2Q67HfMzzJl/// oZMb0BwWcyeycBeT5u36utyYnYAdu6Dd8Hb2MVO2X2SAfUvKeszh8mEyzlvhDssSc7Tq IDEvgMtDk2CbulNsNBhxI5e5/Sj20Z0YxBsAHiMf424t9TO0pZ6hAWFsysfN3lurMwa+ aNlwanQ5gETkfeHnv73Cz8qo0WBUsSluFqzAQ2QjEUkX/fwTnHvY+UeUtFU6d/BKpdgD QO5Q== X-Gm-Message-State: AOAM532aiohhT0/MnuIinrRUvHqNsBPnUtO8c8EPXicimB8Y5I0MpxEG XglUJKnjqtYieRDf76yyzcp5lcRTMFgAOfid X-Google-Smtp-Source: ABdhPJwekepriFSyzIoCXRNKCGpvFiq2NnAR4bAyn052jaQHzEPlcFfRQSyz8Y0DdueqyddIpnCAMwTZ+WqCAiQP X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a5d:630b:: with SMTP id i11mr5840517wru.404.1605046843285; Tue, 10 Nov 2020 14:20:43 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:10 +0100 In-Reply-To: Message-Id: <462c375f39ba8c4c105b3a9bf3b5db17f3720159.1605046662.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 06/20] kasan: remove __kasan_unpoison_stack From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: There's no need for __kasan_unpoison_stack() helper, as it's only currently used in a single place. Removing it also removes unneeded arithmetic. No functional changes. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/Ie5ba549d445292fe629b4a96735e4034957bcc50 Reviewed-by: Marco Elver --- mm/kasan/common.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index a3e67d49b893..9008fc6b0810 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -59,18 +59,12 @@ void kasan_disable_current(void) #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ #if CONFIG_KASAN_STACK -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_memory(base, size); -} - /* Unpoison the entire stack for a task. */ void kasan_unpoison_task_stack(struct task_struct *task) { - __kasan_unpoison_stack(task, task_stack_page(task) + THREAD_SIZE); + void *base = task_stack_page(task); + + kasan_unpoison_memory(base, THREAD_SIZE); } /* Unpoison the stack for the current task beyond a watermark sp value. */ From patchwork Tue Nov 10 22:20: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: 11895651 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 EC38B138B for ; Tue, 10 Nov 2020 22:20:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 97C4A206B2 for ; Tue, 10 Nov 2020 22:20: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="blIC1ANB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 97C4A206B2 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 1F17B6B0088; Tue, 10 Nov 2020 17:20:48 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 153AA6B0089; Tue, 10 Nov 2020 17:20:48 -0500 (EST) 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 EBD0F6B008A; Tue, 10 Nov 2020 17:20:47 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0125.hostedemail.com [216.40.44.125]) by kanga.kvack.org (Postfix) with ESMTP id B38EA6B0088 for ; Tue, 10 Nov 2020 17:20:47 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 6504D180AD807 for ; Tue, 10 Nov 2020 22:20:47 +0000 (UTC) X-FDA: 77469929334.05.value23_320c22b272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id 4403B18016695 for ; Tue, 10 Nov 2020 22:20:47 +0000 (UTC) X-Spam-Summary: 1,0,0,046bd13c44594a2f,d41d8cd98f00b204,3prkrxwokcbis5v9wg25d3y66y3w.u64305cf-442dsu2.69y@flex--andreyknvl.bounces.google.com,,RULES_HIT:1:2:41:152:355:379:541:800:960:966:967:968:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1593:1594:1605:1730:1747:1777:1792:2196:2199:2393:2525:2559:2563:2682:2685:2859:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3865:3866:3867:3868:3870:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4051:4250:4321:4385:4425:4605:5007:6261:6653:6742:7904:8603:8660:8957:9025:9592:9969:10004:11026:11473:11657:11658:11914:12043:12296:12297:12438:12555:12679:12895:12986:13148:13230:14096:14097:14394:14659:21067:21080:21324:21365:21444:21451:21611:21627:21796:21939:21990:30003:30012:30036:30045:30054:30055:30075,0,RBL:209.85.128.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yfssykwdy98zco6dojjws7wj4buocym3z35r5qntq1baoxtwygjyd55q4h188.efzs1u 44ibcj1e X-HE-Tag: value23_320c22b272f8 X-Filterd-Recvd-Size: 11460 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:20:46 +0000 (UTC) Received: by mail-wm1-f73.google.com with SMTP id o19so1873280wme.2 for ; Tue, 10 Nov 2020 14:20:46 -0800 (PST) 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=syFMy85hNfCVsv9zzw9k8mLn//1pQqq/P081Jgl6REI=; b=blIC1ANBVNd6EZzMzsRlw3d4rt6B2ipZm892/MrZ7S1nhqnNWiOA7JvDTY6AMSh02M BaJg3PuQURSenuj+wfR6ssW9FkwcQYO8Bhz4ora+aWSAu2niRzurqnxkfhFeYyK3J1sx OUU+UGqUoiZj02mRPHxnU87w0tZwOz1ThhGd/L9AhjpdD+Y6HbrDz6zGAGcDgoyAbyqH VkiZY8f5IVx43dKCVdn+K+DOFwhCdfSNxSWATQocZECaN2AE7QOaWvyTt4Tbao9PL1yC Ill13wq+v6ZjomJNuAjfAriY8SteAWp9M5/wp68psNH5GzRU0n8ecJFQr4fffIhLEYGH F6uA== 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=syFMy85hNfCVsv9zzw9k8mLn//1pQqq/P081Jgl6REI=; b=i6pyMIh4Nu13Get77XZXkJCBb+7lEO78SZe+miwjyKV0bvO9fwfR2hNe6uGB4Wobmp vkTg2w+MCS12/Z775fyi33JSsRT33UYM/RuDx0HE1sgmRWQQLTWzJOViqTmFjNSlWyha p/LFhC81oj1SYm+aeT8EyEFSuO5MRwVNbViEO/Wj6zX7Q3k2jwLkRValrrhEN+5IqEYk wLfiKsT7ScaQQqHt+mEoIDWJ5KaZlgoAUIs81P0XB/ndb8nTdW60NZ3sdwS8G9uTheau ZA3jps3KscW7kvE6bvjkK9MifaQ+WdgO5FLlY9KeaEUj3gJ1wEHhFVRHl8+4YY+PV7fM Zltw== X-Gm-Message-State: AOAM531QXD8XzQSKRhO7DGAXwNw2IdDSzZmLN6Wr304QV4AXAG4MEa0R LWVU5NeVNZ+vvHooIhfTEM1vOejCbuUKnEah X-Google-Smtp-Source: ABdhPJyjyI1u9TfjaCaGRNEf+0oiJ6LkqtM1n6xNaRSxKrLTlg5Z8+icNw9Kwhx+L+60LftELeAmSKSqIcXD2xjN X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a5d:4ac1:: with SMTP id y1mr26982536wrs.27.1605046845650; Tue, 10 Nov 2020 14:20:45 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:11 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 07/20] kasan: inline kasan_reset_tag for tag-based modes From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: Using kasan_reset_tag() currently results in a function call. As it's called quite often from the allocator code, this leads to a noticeable slowdown. Move it to include/linux/kasan.h and turn it into a static inline function. Also remove the now unneeded reset_tag() internal KASAN macro and use kasan_reset_tag() instead. Signed-off-by: Andrey Konovalov Link: https://linux-review.googlesource.com/id/I4d2061acfe91d480a75df00b07c22d8494ef14b5 Reviewed-by: Marco Elver --- include/linux/kasan.h | 5 ++++- mm/kasan/common.c | 6 +++--- mm/kasan/hw_tags.c | 9 ++------- mm/kasan/kasan.h | 4 ---- mm/kasan/report.c | 4 ++-- mm/kasan/report_hw_tags.c | 2 +- mm/kasan/report_sw_tags.c | 4 ++-- mm/kasan/shadow.c | 4 ++-- mm/kasan/sw_tags.c | 9 ++------- 9 files changed, 18 insertions(+), 29 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index b9b9db335d87..53c8e8b12fbc 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -193,7 +193,10 @@ static inline void kasan_record_aux_stack(void *ptr) {} #if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) -void *kasan_reset_tag(const void *addr); +static inline void *kasan_reset_tag(const void *addr) +{ + return (void *)arch_kasan_reset_tag(addr); +} bool kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip); diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 9008fc6b0810..a266b90636a1 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -174,14 +174,14 @@ size_t kasan_metadata_size(struct kmem_cache *cache) struct kasan_alloc_meta *kasan_get_alloc_meta(struct kmem_cache *cache, const void *object) { - return (void *)reset_tag(object) + cache->kasan_info.alloc_meta_offset; + return kasan_reset_tag(object) + cache->kasan_info.alloc_meta_offset; } struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache, const void *object) { BUILD_BUG_ON(sizeof(struct kasan_free_meta) > 32); - return (void *)reset_tag(object) + cache->kasan_info.free_meta_offset; + return kasan_reset_tag(object) + cache->kasan_info.free_meta_offset; } void kasan_poison_slab(struct page *page) @@ -278,7 +278,7 @@ static bool __kasan_slab_free(struct kmem_cache *cache, void *object, tag = get_tag(object); tagged_object = object; - object = reset_tag(object); + object = kasan_reset_tag(object); if (unlikely(nearest_obj(cache, virt_to_head_page(object), object) != object)) { diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 70b88dd40cd8..49ea5f5c5643 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -30,20 +30,15 @@ void kasan_init_hw_tags(void) pr_info("KernelAddressSanitizer initialized\n"); } -void *kasan_reset_tag(const void *addr) -{ - return reset_tag(addr); -} - void kasan_poison_memory(const void *address, size_t size, u8 value) { - hw_set_mem_tag_range(reset_tag(address), + hw_set_mem_tag_range(kasan_reset_tag(address), round_up(size, KASAN_GRANULE_SIZE), value); } void kasan_unpoison_memory(const void *address, size_t size) { - hw_set_mem_tag_range(reset_tag(address), + hw_set_mem_tag_range(kasan_reset_tag(address), round_up(size, KASAN_GRANULE_SIZE), get_tag(address)); } diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index db8a7a508121..8a5501ef2339 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -246,15 +246,11 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) return addr; } #endif -#ifndef arch_kasan_reset_tag -#define arch_kasan_reset_tag(addr) ((void *)(addr)) -#endif #ifndef arch_kasan_get_tag #define arch_kasan_get_tag(addr) 0 #endif #define set_tag(addr, tag) ((void *)arch_kasan_set_tag((addr), (tag))) -#define reset_tag(addr) ((void *)arch_kasan_reset_tag(addr)) #define get_tag(addr) arch_kasan_get_tag(addr) #ifdef CONFIG_KASAN_HW_TAGS diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 0cac53a57c14..25ca66c99e48 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -328,7 +328,7 @@ void kasan_report_invalid_free(void *object, unsigned long ip) unsigned long flags; u8 tag = get_tag(object); - object = reset_tag(object); + object = kasan_reset_tag(object); #if IS_ENABLED(CONFIG_KUNIT) if (current->kunit_test) @@ -361,7 +361,7 @@ static void __kasan_report(unsigned long addr, size_t size, bool is_write, disable_trace_on_warning(); tagged_addr = (void *)addr; - untagged_addr = reset_tag(tagged_addr); + untagged_addr = kasan_reset_tag(tagged_addr); info.access_addr = tagged_addr; if (addr_has_metadata(untagged_addr)) diff --git a/mm/kasan/report_hw_tags.c b/mm/kasan/report_hw_tags.c index da543eb832cd..57114f0e14d1 100644 --- a/mm/kasan/report_hw_tags.c +++ b/mm/kasan/report_hw_tags.c @@ -22,7 +22,7 @@ const char *get_bug_type(struct kasan_access_info *info) void *find_first_bad_addr(void *addr, size_t size) { - return reset_tag(addr); + return kasan_reset_tag(addr); } void metadata_fetch_row(char *buffer, void *row) diff --git a/mm/kasan/report_sw_tags.c b/mm/kasan/report_sw_tags.c index 317100fd95b9..7604b46239d4 100644 --- a/mm/kasan/report_sw_tags.c +++ b/mm/kasan/report_sw_tags.c @@ -41,7 +41,7 @@ const char *get_bug_type(struct kasan_access_info *info) int i; tag = get_tag(info->access_addr); - addr = reset_tag(info->access_addr); + addr = kasan_reset_tag(info->access_addr); page = kasan_addr_to_page(addr); if (page && PageSlab(page)) { cache = page->slab_cache; @@ -72,7 +72,7 @@ const char *get_bug_type(struct kasan_access_info *info) void *find_first_bad_addr(void *addr, size_t size) { u8 tag = get_tag(addr); - void *p = reset_tag(addr); + void *p = kasan_reset_tag(addr); void *end = p + size; while (p < end && tag == *(u8 *)kasan_mem_to_shadow(p)) diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index 616ac64c4a21..8e4fa9157a0b 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -81,7 +81,7 @@ void kasan_poison_memory(const void *address, size_t size, u8 value) * some of the callers (e.g. kasan_poison_object_data) pass tagged * addresses to this function. */ - address = reset_tag(address); + address = kasan_reset_tag(address); shadow_start = kasan_mem_to_shadow(address); shadow_end = kasan_mem_to_shadow(address + size); @@ -98,7 +98,7 @@ void kasan_unpoison_memory(const void *address, size_t size) * some of the callers (e.g. kasan_unpoison_object_data) pass tagged * addresses to this function. */ - address = reset_tag(address); + address = kasan_reset_tag(address); kasan_poison_memory(address, size, tag); diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c index 3bffb489b144..d1af6f6c6d12 100644 --- a/mm/kasan/sw_tags.c +++ b/mm/kasan/sw_tags.c @@ -67,11 +67,6 @@ u8 random_tag(void) return (u8)(state % (KASAN_TAG_MAX + 1)); } -void *kasan_reset_tag(const void *addr) -{ - return reset_tag(addr); -} - bool check_memory_region(unsigned long addr, size_t size, bool write, unsigned long ret_ip) { @@ -107,7 +102,7 @@ bool check_memory_region(unsigned long addr, size_t size, bool write, if (tag == KASAN_TAG_KERNEL) return true; - untagged_addr = reset_tag((const void *)addr); + untagged_addr = kasan_reset_tag((const void *)addr); if (unlikely(untagged_addr < kasan_shadow_to_mem((void *)KASAN_SHADOW_START))) { return !kasan_report(addr, size, write, ret_ip); @@ -126,7 +121,7 @@ bool check_memory_region(unsigned long addr, size_t size, bool write, bool check_invalid_free(void *addr) { u8 tag = get_tag(addr); - u8 shadow_byte = READ_ONCE(*(u8 *)kasan_mem_to_shadow(reset_tag(addr))); + u8 shadow_byte = READ_ONCE(*(u8 *)kasan_mem_to_shadow(kasan_reset_tag(addr))); return (shadow_byte == KASAN_TAG_INVALID) || (tag != KASAN_TAG_KERNEL && tag != shadow_byte); From patchwork Tue Nov 10 22:20: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: 11895653 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 3C744138B for ; Tue, 10 Nov 2020 22:20:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id F111B20870 for ; Tue, 10 Nov 2020 22:20: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="X/G1FHBp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F111B20870 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 9DD306B008C; Tue, 10 Nov 2020 17:20:50 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 93DC76B0092; Tue, 10 Nov 2020 17:20:50 -0500 (EST) 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 790A26B0093; Tue, 10 Nov 2020 17:20:50 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0171.hostedemail.com [216.40.44.171]) by kanga.kvack.org (Postfix) with ESMTP id 3CC666B008C for ; Tue, 10 Nov 2020 17:20:50 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id DFB01362C for ; Tue, 10 Nov 2020 22:20:49 +0000 (UTC) X-FDA: 77469929418.20.pot18_2d0ce2e272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id C1E05180C07AF for ; Tue, 10 Nov 2020 22:20:49 +0000 (UTC) X-Spam-Summary: 1,0,0,5377d9cd9daa20d3,d41d8cd98f00b204,3qbkrxwokcbuv8yczj58g619916z.x97638fi-775gvx5.9c1@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:69:152:355:379:541:800:960:966:967:968:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:1981:2194:2196:2199:2200:2393:2525:2559:2563:2682:2685:2859:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3353:3867:3868:3870:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4385:4425:5007:6261:6653:6742:8603:8660:9025:9592:9969:10004:10400:11026:11473:11658:11914:12043:12296:12297:12438:12555:12679:12683:12895:12986:13148:13230:14096:14097:14181:14394:14659:14721:21080:21324:21365:21444:21451:21627:21939:21990:30003:30012:30054,0,RBL:209.85.221.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yfebobxjhh9nii8xos5oo75cdddypxn5y4riykzjxwb8p81857khnkt7oqfcb.j69n9doj4t46kun7sahek7jfsymrdsez1fxm nomqp3ua X-HE-Tag: pot18_2d0ce2e272f8 X-Filterd-Recvd-Size: 5960 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:20:49 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id r16so6159524wrw.22 for ; Tue, 10 Nov 2020 14:20:49 -0800 (PST) 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=/rSFl10DA/GX54GBDw6zGUYBErxFDPI5QaAJ7Zds8ak=; b=X/G1FHBpaTNPbceckVWXnlaQTlozNeiCpeU7tMmREOJimTXkmCTjt6rRjgNPSeQ0pw q73UVtucfzggJP2pLLg0d8XHXT0ngy/FLNTkV+unC3tseUSKbxmMqR1RfIvjsfMbA2Eq fniu1B6bL+1GI15kaPYNzXCk/yeIk98ad1Jm+d8i/5KDIlsK5BgcmP/efX5QPF1s8Si/ 6NXEIxz4MDViC1Q1XgbEBgCSkG1swl6ak5j3v5axkuBmgM9UBfbh1fuNYORk8kWZXP9Q iGwaOfp4qXX5szQspMdAW9gYIF9nebgteHML8xT3tOJCbTT3oOXCOGM54M/KBM4bacSy YBMQ== 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=/rSFl10DA/GX54GBDw6zGUYBErxFDPI5QaAJ7Zds8ak=; b=uXUkV0+BkvZ/s36lvn6LVcthoPnNc0wgvMe4qvSJwDdlLrSLdN9OK9MVZ6w5yCfCwN WV4vYCHlWHmyLalkfBKpLF6m6kHCS69yGlycwPC0FFJDeB5HMM32CcncxF28qmaab6wQ uKoorBntiCAfUBhi5D3Xel+7RUSXHKT/hRlYCv2jteMHg6CINhx3w/Sn8VKsuMIBRDHc vPeTDBlmufuAldgKA0Mv+zS7pI3rEz3VVKxAvo1Eo+mD0AhHtN9xtSDVBLtdpUCQs+Qx OIMGqp+HTzZtuEDthVbhYn1gfXulHvw1Xcyhw73Ox6Zrc99zqVY4wmGmWdcpyF1JnNz2 3v7Q== X-Gm-Message-State: AOAM53289XOypyvOx7MUkCiDQ+wGNHMHNU5VYfTxd6giH/L+4aWCXt6m ayMV83TqnKBPEPhcXd2eIhDWRvsJSc39Y+Jq X-Google-Smtp-Source: ABdhPJyY/bBCadcyM/PRgjtzpu0TT6SQ1RzDsL0gjh3vrXFFiPqpWwP79w3xbEXBJdKIjt2rfzmw9gOcpXSqt2FT X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a5d:6692:: with SMTP id l18mr14959782wru.44.1605046848070; Tue, 10 Nov 2020 14:20:48 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:12 +0100 In-Reply-To: Message-Id: <73399d4c0644266d61ad81eb391f5ee10c09e098.1605046662.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 08/20] kasan: inline random_tag for HW_TAGS From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: Using random_tag() currently results in a function call. Move its definition to mm/kasan/kasan.h and turn it into a static inline function for hardware tag-based mode to avoid uneeded function calls. Signed-off-by: Andrey Konovalov Link: https://linux-review.googlesource.com/id/Iac5b2faf9a912900e16cca6834d621f5d4abf427 Reviewed-by: Marco Elver --- mm/kasan/hw_tags.c | 5 ----- mm/kasan/kasan.h | 34 +++++++++++++++++----------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 49ea5f5c5643..1476ac07666e 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -42,11 +42,6 @@ void kasan_unpoison_memory(const void *address, size_t size) round_up(size, KASAN_GRANULE_SIZE), get_tag(address)); } -u8 random_tag(void) -{ - return hw_get_random_tag(); -} - bool check_invalid_free(void *addr) { u8 ptr_tag = get_tag(addr); diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 8a5501ef2339..7498839a15d3 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -188,6 +188,12 @@ static inline bool addr_has_metadata(const void *addr) #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ +#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) +void print_tags(u8 addr_tag, const void *addr); +#else +static inline void print_tags(u8 addr_tag, const void *addr) { } +#endif + bool check_invalid_free(void *addr); void *find_first_bad_addr(void *addr, size_t size); @@ -223,23 +229,6 @@ static inline void quarantine_reduce(void) { } static inline void quarantine_remove_cache(struct kmem_cache *cache) { } #endif -#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) - -void print_tags(u8 addr_tag, const void *addr); - -u8 random_tag(void); - -#else - -static inline void print_tags(u8 addr_tag, const void *addr) { } - -static inline u8 random_tag(void) -{ - return 0; -} - -#endif - #ifndef arch_kasan_set_tag static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) { @@ -279,6 +268,17 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) #endif /* CONFIG_KASAN_HW_TAGS */ +#ifdef CONFIG_KASAN_SW_TAGS +u8 random_tag(void); +#elif defined(CONFIG_KASAN_HW_TAGS) +#define random_tag() hw_get_random_tag() +#else +static inline u8 random_tag(void) +{ + return 0; +} +#endif + /* * Exported functions for interfaces called from assembly or from generated * code. Declarations here to avoid warning about missing declarations. From patchwork Tue Nov 10 22:20: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: 11895655 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 A411B138B for ; Tue, 10 Nov 2020 22:20:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4ED2D20674 for ; Tue, 10 Nov 2020 22:20: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="HbmemqL7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4ED2D20674 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 8F4E46B0095; Tue, 10 Nov 2020 17:20:52 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8A25C6B0096; Tue, 10 Nov 2020 17:20:52 -0500 (EST) 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 71D456B0098; Tue, 10 Nov 2020 17:20:52 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0170.hostedemail.com [216.40.44.170]) by kanga.kvack.org (Postfix) with ESMTP id 346E16B0095 for ; Tue, 10 Nov 2020 17:20:52 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id CFCD5180AD802 for ; Tue, 10 Nov 2020 22:20:51 +0000 (UTC) X-FDA: 77469929502.26.kite64_4e04738272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin26.hostedemail.com (Postfix) with ESMTP id A9E041804B647 for ; Tue, 10 Nov 2020 22:20:51 +0000 (UTC) X-Spam-Summary: 1,0,0,840e84f54e9dcf2f,d41d8cd98f00b204,3qhkrxwokcbcxa0e1l7ai83bb381.zb985ahk-997ixz7.be3@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:69:152:355:379:541:800:960:965:966:967:973:988:989: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:2525:2559:2563:2682:2685:2859:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3354:3867:3868:3870:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4117:4321:4385:4390:4395:4425:5007:6261:6653:6742:8603:8957:9025:9592:9969:10004:10400:11026:11473:11658:11914:12043:12291:12296:12297:12438:12555:12679:12895:12986:14096:14097:14181:14394:14659:14721:21080:21324:21365:21444:21451:21627:21939:21990:30003:30012:30054:30075,0,RBL:209.85.222.202:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yrtxhph15xkhx679skskd5dspryypt3ak41kkquxemcrwhrdxgzbkf57haqid.ntyxycc8racux9n9oabxr4xtti6fft9 57x6xwxd X-HE-Tag: kite64_4e04738272f8 X-Filterd-Recvd-Size: 6714 Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) by imf09.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:20:51 +0000 (UTC) Received: by mail-qk1-f202.google.com with SMTP id w189so215391qkd.6 for ; Tue, 10 Nov 2020 14:20:50 -0800 (PST) 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=WOMasW4WeK4i4aCbvBDhnou95P0GnHEsdPLivTBemP4=; b=HbmemqL7hGON1dZUtHAIO/Ny5Z5yXZ4JDxyVyJy817JkkYWiD/QtbND8oC8ab7jCnI 5Wbp10QDuzYLJu6lNMQ/cilMKfhcOQKdxLo2b2RlUEr9KAST0GqOKpk56Qy0CPfK5YuM QKo9+lLsoO9x4ILXIt3sKjhcJ8pdIqjOatB0zmydqRDWzWGHfAAw6YSENtb7o5FoF2si lv2RAbcm26eD/cbihEmRP5cwTzv9aHIH9H1rKOeKMG6R8p0oNMZ/gBRAvVBPI42BEMDc psc8VI/Zf64SE7/LFloA+ZdjypcKgOsrKstJM34+FhTA1A+KoSlI7qAqvqmoxKnZxc2h Df1g== 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=WOMasW4WeK4i4aCbvBDhnou95P0GnHEsdPLivTBemP4=; b=XXjBeNMF74vYBFGUKmO7lOoHJUKhMf5f2syuycn7KII5blWMlY14TjJB/IQfTf1YHS JV49L84iZxt3MA3Yr7ko0G0TT/je929IdEHqlGeGnR2vgPvoRb0sbsyzAHpa1W0hKNuJ k9OKyzI+p7EZzX8JzAmGgp8sGmFCX4mc6k/9SvoTsBtz3lsttpI5K/EQF4SwXLdFX5O/ zBFdQbKzUSniAfZZHx3v6rqZiLN4IDPzmJi0rZPKFHG1PLyDNZEAm2jZG89YOE3Nvbky ez1ui9iCfiFJ6DnIUxbkVXlk8tNLyfowzZEnSV6e2CjOT+NJqp1cykAYoxxwOeIbsWd2 n2mQ== X-Gm-Message-State: AOAM5333xeFcWD3PbkeLZy358NyCoDnujumCDW+9XyNsq9ZHLaiecohZ GYzUm8Ko9kba5p6PkW/4ZlxLyjvukvBuBEMF X-Google-Smtp-Source: ABdhPJxV3RzH8+DI2bYMl115wXV/xV/YUfiel/zd2PCNwgEqHTxxwM0dmmBMZ8TRZ+cgt1xGGP23OM9y5Oi9AE76 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:9e2f:: with SMTP id p47mr14534879qve.11.1605046850374; Tue, 10 Nov 2020 14:20:50 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:13 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 09/20] kasan: inline kasan_poison_memory and check_invalid_free From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: Using kasan_poison_memory() or check_invalid_free() currently results in function calls. Move their definitions to mm/kasan/kasan.h and turn them into static inline functions for hardware tag-based mode to avoid unneeded function calls. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/Ia9d8191024a12d1374675b3d27197f10193f50bb Reviewed-by: Marco Elver --- mm/kasan/hw_tags.c | 15 --------------- mm/kasan/kasan.h | 28 ++++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 1476ac07666e..0303e49904b4 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -30,27 +30,12 @@ void kasan_init_hw_tags(void) pr_info("KernelAddressSanitizer initialized\n"); } -void kasan_poison_memory(const void *address, size_t size, u8 value) -{ - hw_set_mem_tag_range(kasan_reset_tag(address), - round_up(size, KASAN_GRANULE_SIZE), value); -} - void kasan_unpoison_memory(const void *address, size_t size) { hw_set_mem_tag_range(kasan_reset_tag(address), round_up(size, KASAN_GRANULE_SIZE), get_tag(address)); } -bool check_invalid_free(void *addr) -{ - u8 ptr_tag = get_tag(addr); - u8 mem_tag = hw_get_mem_tag(addr); - - return (mem_tag == KASAN_TAG_INVALID) || - (ptr_tag != KASAN_TAG_KERNEL && ptr_tag != mem_tag); -} - void kasan_set_free_info(struct kmem_cache *cache, void *object, u8 tag) { diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 7498839a15d3..ab7314418604 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -153,8 +153,6 @@ struct kasan_alloc_meta *kasan_get_alloc_meta(struct kmem_cache *cache, struct kasan_free_meta *kasan_get_free_meta(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) @@ -194,8 +192,6 @@ void print_tags(u8 addr_tag, const void *addr); static inline void print_tags(u8 addr_tag, const void *addr) { } #endif -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); @@ -279,6 +275,30 @@ static inline u8 random_tag(void) } #endif +#ifdef CONFIG_KASAN_HW_TAGS + +static inline void kasan_poison_memory(const void *address, size_t size, u8 value) +{ + hw_set_mem_tag_range(kasan_reset_tag(address), + round_up(size, KASAN_GRANULE_SIZE), value); +} + +static inline bool check_invalid_free(void *addr) +{ + u8 ptr_tag = get_tag(addr); + u8 mem_tag = hw_get_mem_tag(addr); + + return (mem_tag == KASAN_TAG_INVALID) || + (ptr_tag != KASAN_TAG_KERNEL && ptr_tag != mem_tag); +} + +#else /* CONFIG_KASAN_HW_TAGS */ + +void kasan_poison_memory(const void *address, size_t size, u8 value); +bool check_invalid_free(void *addr); + +#endif /* CONFIG_KASAN_HW_TAGS */ + /* * Exported functions for interfaces called from assembly or from generated * code. Declarations here to avoid warning about missing declarations. From patchwork Tue Nov 10 22:20: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: 11895657 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 0C753138B for ; Tue, 10 Nov 2020 22:20:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id AB6F520674 for ; Tue, 10 Nov 2020 22:20: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="tjOoGMIf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AB6F520674 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 484C26B0099; Tue, 10 Nov 2020 17:20:55 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 437DB6B009A; Tue, 10 Nov 2020 17:20:55 -0500 (EST) 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 2B30A6B009B; Tue, 10 Nov 2020 17:20:55 -0500 (EST) 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 E025B6B0099 for ; Tue, 10 Nov 2020 17:20:54 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 7FFA8181AEF10 for ; Tue, 10 Nov 2020 22:20:54 +0000 (UTC) X-FDA: 77469929628.24.time70_1015229272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin24.hostedemail.com (Postfix) with ESMTP id 6C8871A4A5 for ; Tue, 10 Nov 2020 22:20:54 +0000 (UTC) X-Spam-Summary: 1,0,0,3d17f85e5fc32bb7,d41d8cd98f00b204,3rbkrxwokcbkzc2g3n9cka5dd5a3.1dba7cjm-bb9kz19.dg5@flex--andreyknvl.bounces.google.com,,RULES_HIT:2:41:69:152:355:379:541:800:960:966:967:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1593:1594:1605:1730:1747:1777:1792:2196:2198:2199:2200:2393:2525:2559:2563:2682:2685:2731:2859:2898:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3865:3866:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4049:4120:4321:4385:4425:4605:5007:6261:6653:6742:8603:8660:8957:9025:9592:9969:10004:11026:11473:11658:11914:12043:12114:12296:12297:12438:12555:12679:12895:12986:13148:13161:13229:13230:14096:14097:14394:14659:14877:21080:21365:21444:21451:21627:21939:21990:30003:30034:30054:30070,0,RBL:209.85.221.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yfnggp8eb8u4h7tuo9mcmw8e9pqopqfdrybq66b8dskek4n1pisqtyxkbeutj.dpf om836884 X-HE-Tag: time70_1015229272f8 X-Filterd-Recvd-Size: 9594 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf42.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:20:53 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id w17so5440479wrp.11 for ; Tue, 10 Nov 2020 14:20:53 -0800 (PST) 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=tuOEp1iVth583MBjSMMuaXP+cup9Jpeadd/jLYbzv5o=; b=tjOoGMIfi1Gy2x6aR7moxABHWyMdUQ9vFeQAZjlOfMm28OF0UgUGZZCPOYiyrWRuhp Zvfv6lWIXOW8Qhgx/K5jP91DGmLRB1FDX+2dINo9CsLqWdwLa/qTm5toRnoVWB6TgXCe 9vdlGqXBFqgVzxUOwRyn4y9EVlt5WJDMAId3+JtmEXPcHm65v4Q3UGdFLTKZyscgUFiH 5/tbS8FhH3SEYuHH4FYln33WWUmUTTwywFL50omBB/idcdGGItMwcrqRfMcvcWPfvIU1 Z5WBIbk0dyF4xuunIyE2hOWre7Qwjxc0UCO5kNa7aXBPIwh7vv3mMCzJhyvyTDoNSjXL y0SA== 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=tuOEp1iVth583MBjSMMuaXP+cup9Jpeadd/jLYbzv5o=; b=kEIUO5B+DYeUdjKvgZ7io5+62RAbEwgTZ2SMjO7OkiSNL147ZK2zfqL2ok3YCXst6H FlOTAGOGdXGyceWr96uoF0AH8KEkDpTOZhCLuMT/qXLSGOJicKvCkAMmnndfS5Dpvlyj Cs7TCwb+hzFXqtRR3L5wj99yRmeqcjzEaEH6zpf/67ayxXnmV+qQGsgqZjrmrqa7ERIT KGoB+WUao7yGVRvUAs4pJPvfqIwmXHBtjC+1+GrNhy76zc1JWUYQy814W6lZeBD8tIn4 i2ohO2uxgiN+4Z1D8CRe2XF0hDsLN3vDz8Hrg1m8iC899KVL7piXEBlueYAXEeCyBfGB P7Jw== X-Gm-Message-State: AOAM533pBUZLDGRZOzetlvSrVjyGqM96WD06LQ2vWeu4QF6eA8/PQo9y RPiwrr606/a4KPwDvss33/q8wHxZ9ze+8sqW X-Google-Smtp-Source: ABdhPJxtiBqyG4xwe2EmyTCmp+GdZ0f2gBwn+LXwUoSWPlDe2zEXDIKB2AYn330Kqc9Cuu2p95cOSOPMIUl2u6W+ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:c458:: with SMTP id l24mr281240wmi.136.1605046852883; Tue, 10 Nov 2020 14:20:52 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:14 +0100 In-Reply-To: Message-Id: <0a9b63bff116734ab63d99ebd09c244332d71958.1605046662.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 10/20] kasan: inline and rename kasan_unpoison_memory From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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 kasan_unpoison_memory() is used as both an external annotation and as an internal memory poisoning helper. Rename external annotation to kasan_unpoison_data() and inline the internal helper for hardware tag-based mode to avoid undeeded function calls. There's the external annotation kasan_unpoison_slab() that is currently defined as static inline and uses kasan_unpoison_memory(). With this change it's turned into a function call. Overall, this results in the same number of calls for hardware tag-based mode as kasan_unpoison_memory() is now inlined. Signed-off-by: Andrey Konovalov Link: https://linux-review.googlesource.com/id/Ia7c8b659f79209935cbaab3913bf7f082cc43a0e --- include/linux/kasan.h | 16 ++++++---------- kernel/fork.c | 2 +- mm/kasan/common.c | 10 ++++++++++ mm/kasan/hw_tags.c | 6 ------ mm/kasan/kasan.h | 7 +++++++ mm/slab_common.c | 2 +- 6 files changed, 25 insertions(+), 18 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 53c8e8b12fbc..f1a5042ae4fc 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -74,14 +74,15 @@ static inline void kasan_disable_current(void) {} #ifdef CONFIG_KASAN -void kasan_unpoison_memory(const void *address, size_t size); - void kasan_alloc_pages(struct page *page, unsigned int order); void kasan_free_pages(struct page *page, unsigned int order); void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, slab_flags_t *flags); +void kasan_unpoison_data(const void *address, size_t size); +void kasan_unpoison_slab(const void *ptr); + void kasan_poison_slab(struct page *page); void kasan_unpoison_object_data(struct kmem_cache *cache, void *object); void kasan_poison_object_data(struct kmem_cache *cache, void *object); @@ -106,11 +107,6 @@ struct kasan_cache { int free_meta_offset; }; -size_t __ksize(const void *); -static inline void kasan_unpoison_slab(const void *ptr) -{ - kasan_unpoison_memory(ptr, __ksize(ptr)); -} size_t kasan_metadata_size(struct kmem_cache *cache); bool kasan_save_enable_multi_shot(void); @@ -118,8 +114,6 @@ void kasan_restore_multi_shot(bool enabled); #else /* CONFIG_KASAN */ -static inline void kasan_unpoison_memory(const void *address, size_t size) {} - static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} static inline void kasan_free_pages(struct page *page, unsigned int order) {} @@ -127,6 +121,9 @@ static inline void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, slab_flags_t *flags) {} +static inline void kasan_unpoison_data(const void *address, size_t size) { } +static inline void kasan_unpoison_slab(const void *ptr) { } + static inline void kasan_poison_slab(struct page *page) {} static inline void kasan_unpoison_object_data(struct kmem_cache *cache, void *object) {} @@ -166,7 +163,6 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, return false; } -static inline void kasan_unpoison_slab(const void *ptr) { } static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } #endif /* CONFIG_KASAN */ diff --git a/kernel/fork.c b/kernel/fork.c index 1c905e4290ab..883898487b3f 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -226,7 +226,7 @@ static unsigned long *alloc_thread_stack_node(struct task_struct *tsk, int node) continue; /* Mark stack accessible for KASAN. */ - kasan_unpoison_memory(s->addr, THREAD_SIZE); + kasan_unpoison_data(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 a266b90636a1..4598c1364f19 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -184,6 +184,16 @@ struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache, return kasan_reset_tag(object) + cache->kasan_info.free_meta_offset; } +void kasan_unpoison_data(const void *address, size_t size) +{ + kasan_unpoison_memory(address, size); +} + +void kasan_unpoison_slab(const void *ptr) +{ + kasan_unpoison_memory(ptr, __ksize(ptr)); +} + void kasan_poison_slab(struct page *page) { unsigned long i; diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 0303e49904b4..838b29e44e32 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -30,12 +30,6 @@ void kasan_init_hw_tags(void) pr_info("KernelAddressSanitizer initialized\n"); } -void kasan_unpoison_memory(const void *address, size_t size) -{ - hw_set_mem_tag_range(kasan_reset_tag(address), - round_up(size, KASAN_GRANULE_SIZE), get_tag(address)); -} - void kasan_set_free_info(struct kmem_cache *cache, void *object, u8 tag) { diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index ab7314418604..2d3c99125996 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -283,6 +283,12 @@ static inline void kasan_poison_memory(const void *address, size_t size, u8 valu round_up(size, KASAN_GRANULE_SIZE), value); } +static inline void kasan_unpoison_memory(const void *address, size_t size) +{ + hw_set_mem_tag_range(kasan_reset_tag(address), + round_up(size, KASAN_GRANULE_SIZE), get_tag(address)); +} + static inline bool check_invalid_free(void *addr) { u8 ptr_tag = get_tag(addr); @@ -295,6 +301,7 @@ static inline bool check_invalid_free(void *addr) #else /* CONFIG_KASAN_HW_TAGS */ void kasan_poison_memory(const void *address, size_t size, u8 value); +void kasan_unpoison_memory(const void *address, size_t size); bool check_invalid_free(void *addr); #endif /* CONFIG_KASAN_HW_TAGS */ diff --git a/mm/slab_common.c b/mm/slab_common.c index 53d0f8bb57ea..f1b0c4a22f08 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_memory(objp, size); + kasan_unpoison_data(objp, size); return size; } EXPORT_SYMBOL(ksize); From patchwork Tue Nov 10 22:20: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: 11895659 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 AC163138B for ; Tue, 10 Nov 2020 22:20:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 42FA720674 for ; Tue, 10 Nov 2020 22:20:59 +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="gvbp41Wo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 42FA720674 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 807736B009C; Tue, 10 Nov 2020 17:20:57 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 792236B009D; Tue, 10 Nov 2020 17:20:57 -0500 (EST) 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 5E4206B009E; Tue, 10 Nov 2020 17:20:57 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0139.hostedemail.com [216.40.44.139]) by kanga.kvack.org (Postfix) with ESMTP id 233DC6B009C for ; Tue, 10 Nov 2020 17:20:57 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id BBE471EE6 for ; Tue, 10 Nov 2020 22:20:56 +0000 (UTC) X-FDA: 77469929712.23.jewel17_4404847272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 98ACD37608 for ; Tue, 10 Nov 2020 22:20:56 +0000 (UTC) X-Spam-Summary: 1,0,0,7345b0bc604e8e5c,d41d8cd98f00b204,3rxkrxwokcbw2f5j6qcfnd8gg8d6.4gedafmp-eecn24c.gj8@flex--andreyknvl.bounces.google.com,,RULES_HIT:1:41:152:355:379:541:800:960:966:967:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1593:1594:1605:1730:1747:1777:1792:1801:1981:2194:2196:2199:2200:2393:2525:2559:2564:2636:2682:2685:2859:2894:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3865:3866:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4385:4425:4605:5007:6119:6261:6653:6742:7875:8603:8957:9025:9969:10004:11026:11473:11658:11914:12043:12291:12296:12297:12438:12555:12663:12679:12683:12895:12986:13053:13141:13161:13229:13230:14096:14097:14394:14659:21080:21325:21365:21444:21451:21627:21939:21966:21990:30054:30070,0,RBL:209.85.222.201:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04y8hz5yyzam7ndusr94ci3rcbsyuop7w7fb7a7xwdwrygau5kzhcgihf 4x15ps.c X-HE-Tag: jewel17_4404847272f8 X-Filterd-Recvd-Size: 14219 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf31.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:20:55 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id z68so220520qkc.4 for ; Tue, 10 Nov 2020 14:20:55 -0800 (PST) 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=C1AHhA2JiIvkEyQnY3sopRuy3W9NzHQWsdv6OutYhlM=; b=gvbp41WoAzww8TYRMkKnNegELr+4/Y7ni0aHb9h9e2Ek6BRCEc8wNmGcSuLXFrDdju 8HFuejYaUD5zzx3ycw8T9elfW5ANAXirMImZOqD/oLXj2HVCz1N+dvi6nzg7Myeom8qF oOZF84RbQOqOFCChHPxL2C9Kv2NiHuBbkcZR0NRfazYmTWAYEXJi2p8kpQi/cHe8EVed DCIt1qRmzd0sV/2tF7FAS3pmWCL+sTMRTblqS0nTQeWXc5hqnMTNDeFFFsurS6+KxYhI 7v2Sg3o9W2+dQYcGdjjASONR6vn+tDZdwD1OYziEKxKg/WI6riY39Z6vo/ae7LBj+tGb 5yoQ== 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=C1AHhA2JiIvkEyQnY3sopRuy3W9NzHQWsdv6OutYhlM=; b=W1sNGGO01gabfOegJpc6HCTG5PMmdPP6+TBmFJQ0p/38V513vBDGI0N+/O5amrOGbf e9mt19wpFuVcYGeL+fhZeb5ISVr5LocsBSD1sbd67ZhO+Qeq5ZBkjPmdcs5kb2rUV1Ht n/yjOSp81RH1eEWduWBDb/67UsIgdbuPYc+GhMk/Yki5/C2+h8IJEpKSQ4MSwALd7JUG v5K4C/dS8Q7vYAdUrZVx2R+HXi0E8pHucRA5Dih4t+Wo/NwGEd5d9yB6KCwsMwu523Xg 2+QTODUdXPSBvdC80Uq36bMATwdjgosgx4VlrnzTr6l4o0mlS4XXm0+Z6598nX0fWJJR wehA== X-Gm-Message-State: AOAM533NnQAM7NqsRD54ZnNFGn377FPGR/3KXMfTXxxDDA1etMKl8TTz Sfx6pkPzcmVJWvmXOxzP/3W+szroWKnMR134 X-Google-Smtp-Source: ABdhPJzULwIjhucxHMEL1ve5N+U+spPW+S0asJ3yxR73Odh5s887/rzw9Q2Ud8xCU6UwkQF11IYxomADZ/OybFc8 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6214:1541:: with SMTP id t1mr21263869qvw.61.1605046855110; Tue, 10 Nov 2020 14:20:55 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:15 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 11/20] kasan: add and integrate kasan boot parameters From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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 mode is intended to eventually be used in production as a security mitigation. Therefore there's a need for finer control over KASAN features and for an existence of a kill switch. This change adds a few boot parameters for hardware tag-based KASAN that allow to disable or otherwise control particular KASAN features. The features that can be controlled are: 1. Whether KASAN is enabled at all. 2. Whether KASAN collects and saves alloc/free stacks. 3. Whether KASAN panics on a detected bug or not. With this change a new boot parameter kasan.mode allows to choose one of three main modes: - kasan.mode=off - KASAN is disabled, no tag checks are performed - kasan.mode=prod - only essential production features are enabled - kasan.mode=full - all KASAN features are enabled The chosen mode provides default control values for the features mentioned above. However it's also possible to override the default values by providing: - kasan.stacktrace=off/on - enable alloc/free stack collection (default: on for mode=full, otherwise off) - kasan.fault=report/panic - only report tag fault or also panic (default: report) If kasan.mode parameter is not provided, it defaults to full when CONFIG_DEBUG_KERNEL is enabled, and to prod otherwise. It is essential that switching between these modes doesn't require rebuilding the kernel with different configs, as this is required by the Android GKI (Generic Kernel Image) initiative [1]. [1] https://source.android.com/devices/architecture/kernel/generic-kernel-image Signed-off-by: Andrey Konovalov Link: https://linux-review.googlesource.com/id/If7d37003875b2ed3e0935702c8015c223d6416a4 Acked-by: Catalin Marinas --- mm/kasan/common.c | 22 +++++-- mm/kasan/hw_tags.c | 152 +++++++++++++++++++++++++++++++++++++++++++++ mm/kasan/kasan.h | 16 +++++ mm/kasan/report.c | 14 ++++- 4 files changed, 197 insertions(+), 7 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 4598c1364f19..efad5ed6a3bd 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -129,6 +129,11 @@ void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, unsigned int redzone_size; int redzone_adjust; + if (!kasan_stack_collection_enabled()) { + *flags |= SLAB_KASAN; + return; + } + /* Add alloc meta. */ cache->kasan_info.alloc_meta_offset = *size; *size += sizeof(struct kasan_alloc_meta); @@ -165,6 +170,8 @@ void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, size_t kasan_metadata_size(struct kmem_cache *cache) { + if (!kasan_stack_collection_enabled()) + return 0; return (cache->kasan_info.alloc_meta_offset ? sizeof(struct kasan_alloc_meta) : 0) + (cache->kasan_info.free_meta_offset ? @@ -267,11 +274,13 @@ void * __must_check kasan_init_slab_obj(struct kmem_cache *cache, { struct kasan_alloc_meta *alloc_meta; - if (!(cache->flags & SLAB_KASAN)) - return (void *)object; + if (kasan_stack_collection_enabled()) { + if (!(cache->flags & SLAB_KASAN)) + return (void *)object; - alloc_meta = kasan_get_alloc_meta(cache, object); - __memset(alloc_meta, 0, sizeof(*alloc_meta)); + alloc_meta = kasan_get_alloc_meta(cache, object); + __memset(alloc_meta, 0, sizeof(*alloc_meta)); + } if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) || IS_ENABLED(CONFIG_KASAN_HW_TAGS)) object = set_tag(object, assign_tag(cache, object, true, false)); @@ -308,6 +317,9 @@ static bool __kasan_slab_free(struct kmem_cache *cache, void *object, rounded_up_size = round_up(cache->object_size, KASAN_GRANULE_SIZE); kasan_poison_memory(object, rounded_up_size, KASAN_KMALLOC_FREE); + if (!kasan_stack_collection_enabled()) + return false; + if ((IS_ENABLED(CONFIG_KASAN_GENERIC) && !quarantine) || unlikely(!(cache->flags & SLAB_KASAN))) return false; @@ -355,7 +367,7 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, kasan_poison_memory((void *)redzone_start, redzone_end - redzone_start, KASAN_KMALLOC_REDZONE); - if (cache->flags & SLAB_KASAN) + if (kasan_stack_collection_enabled() && (cache->flags & SLAB_KASAN)) set_alloc_info(cache, (void *)object, flags); return set_tag(object, tag); diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 838b29e44e32..2f6f0261af8c 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -8,6 +8,8 @@ #define pr_fmt(fmt) "kasan: " fmt +#include +#include #include #include #include @@ -17,9 +19,104 @@ #include "kasan.h" +enum kasan_arg_mode { + KASAN_ARG_MODE_DEFAULT, + KASAN_ARG_MODE_OFF, + KASAN_ARG_MODE_PROD, + KASAN_ARG_MODE_FULL, +}; + +enum kasan_arg_stacktrace { + KASAN_ARG_STACKTRACE_DEFAULT, + KASAN_ARG_STACKTRACE_OFF, + KASAN_ARG_STACKTRACE_ON, +}; + +enum kasan_arg_fault { + KASAN_ARG_FAULT_DEFAULT, + KASAN_ARG_FAULT_REPORT, + KASAN_ARG_FAULT_PANIC, +}; + +static enum kasan_arg_mode kasan_arg_mode __ro_after_init; +static enum kasan_arg_stacktrace kasan_arg_stacktrace __ro_after_init; +static enum kasan_arg_fault kasan_arg_fault __ro_after_init; + +/* Whether KASAN is enabled at all. */ +DEFINE_STATIC_KEY_FALSE_RO(kasan_flag_enabled); +EXPORT_SYMBOL(kasan_flag_enabled); + +/* Whether to collect alloc/free stack traces. */ +DEFINE_STATIC_KEY_FALSE_RO(kasan_flag_stacktrace); + +/* Whether panic or disable tag checking on fault. */ +bool kasan_flag_panic __ro_after_init; + +/* kasan.mode=off/prod/full */ +static int __init early_kasan_mode(char *arg) +{ + if (!arg) + return -EINVAL; + + if (!strcmp(arg, "off")) + kasan_arg_mode = KASAN_ARG_MODE_OFF; + else if (!strcmp(arg, "prod")) + kasan_arg_mode = KASAN_ARG_MODE_PROD; + else if (!strcmp(arg, "full")) + kasan_arg_mode = KASAN_ARG_MODE_FULL; + else + return -EINVAL; + + return 0; +} +early_param("kasan.mode", early_kasan_mode); + +/* kasan.stack=off/on */ +static int __init early_kasan_flag_stacktrace(char *arg) +{ + if (!arg) + return -EINVAL; + + if (!strcmp(arg, "off")) + kasan_arg_stacktrace = KASAN_ARG_STACKTRACE_OFF; + else if (!strcmp(arg, "on")) + kasan_arg_stacktrace = KASAN_ARG_STACKTRACE_ON; + else + return -EINVAL; + + return 0; +} +early_param("kasan.stacktrace", early_kasan_flag_stacktrace); + +/* kasan.fault=report/panic */ +static int __init early_kasan_fault(char *arg) +{ + if (!arg) + return -EINVAL; + + if (!strcmp(arg, "report")) + kasan_arg_fault = KASAN_ARG_FAULT_REPORT; + else if (!strcmp(arg, "panic")) + kasan_arg_fault = KASAN_ARG_FAULT_PANIC; + else + return -EINVAL; + + return 0; +} +early_param("kasan.fault", early_kasan_fault); + /* kasan_init_hw_tags_cpu() is called for each CPU. */ void kasan_init_hw_tags_cpu(void) { + /* + * There's no need to check that the hardware is MTE-capable here, + * as this function is only called for MTE-capable hardware. + */ + + /* If KASAN is disabled, do nothing. */ + if (kasan_arg_mode == KASAN_ARG_MODE_OFF) + return; + hw_init_tags(KASAN_TAG_MAX); hw_enable_tagging(); } @@ -27,6 +124,61 @@ void kasan_init_hw_tags_cpu(void) /* kasan_init_hw_tags() is called once on boot CPU. */ void kasan_init_hw_tags(void) { + /* If hardware doesn't support MTE, do nothing. */ + if (!system_supports_mte()) + return; + + /* If KASAN is disabled, do nothing. */ + if (kasan_arg_mode == KASAN_ARG_MODE_OFF) + return; + + /* Choose KASAN mode if kasan boot parameter is not provided. */ + if (kasan_arg_mode == KASAN_ARG_MODE_DEFAULT) { + if (IS_ENABLED(CONFIG_DEBUG_KERNEL)) + kasan_arg_mode = KASAN_ARG_MODE_FULL; + else + kasan_arg_mode = KASAN_ARG_MODE_PROD; + } + + /* Preset parameter values based on the mode. */ + switch (kasan_arg_mode) { + case KASAN_ARG_MODE_OFF: + return; + case KASAN_ARG_MODE_PROD: + static_branch_enable(&kasan_flag_enabled); + break; + case KASAN_ARG_MODE_FULL: + static_branch_enable(&kasan_flag_enabled); + static_branch_enable(&kasan_flag_stacktrace); + break; + default: + break; + } + + /* Now, optionally override the presets. */ + + switch (kasan_arg_stacktrace) { + case KASAN_ARG_STACKTRACE_OFF: + static_branch_disable(&kasan_flag_stacktrace); + break; + case KASAN_ARG_STACKTRACE_ON: + static_branch_enable(&kasan_flag_stacktrace); + break; + default: + break; + } + + switch (kasan_arg_fault) { + case KASAN_ARG_FAULT_REPORT: + kasan_flag_panic = false; + break; + case KASAN_ARG_FAULT_PANIC: + kasan_flag_panic = true; + break; + default: + break; + } + pr_info("KernelAddressSanitizer initialized\n"); } diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 2d3c99125996..5eff3d9f624e 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -5,6 +5,22 @@ #include #include +#ifdef CONFIG_KASAN_HW_TAGS +#include +DECLARE_STATIC_KEY_FALSE(kasan_flag_stacktrace); +static inline bool kasan_stack_collection_enabled(void) +{ + return static_branch_unlikely(&kasan_flag_stacktrace); +} +#else +static inline bool kasan_stack_collection_enabled(void) +{ + return true; +} +#endif + +extern bool kasan_flag_panic __ro_after_init; + #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) #define KASAN_GRANULE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT) #else diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 25ca66c99e48..7d86af340148 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -99,6 +99,10 @@ static void end_report(unsigned long *flags) panic_on_warn = 0; panic("panic_on_warn set ...\n"); } +#ifdef CONFIG_KASAN_HW_TAGS + if (kasan_flag_panic) + panic("kasan.fault=panic set ...\n"); +#endif kasan_enable_current(); } @@ -161,8 +165,8 @@ static void describe_object_addr(struct kmem_cache *cache, void *object, (void *)(object_addr + cache->object_size)); } -static void describe_object(struct kmem_cache *cache, void *object, - const void *addr, u8 tag) +static void describe_object_stacks(struct kmem_cache *cache, void *object, + const void *addr, u8 tag) { struct kasan_alloc_meta *alloc_meta = kasan_get_alloc_meta(cache, object); @@ -190,7 +194,13 @@ static void describe_object(struct kmem_cache *cache, void *object, } #endif } +} +static void describe_object(struct kmem_cache *cache, void *object, + const void *addr, u8 tag) +{ + if (kasan_stack_collection_enabled()) + describe_object_stacks(cache, object, addr, tag); describe_object_addr(cache, object, addr); } From patchwork Tue Nov 10 22:20: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: 11895661 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 2F8211391 for ; Tue, 10 Nov 2020 22:21:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C0FF320674 for ; Tue, 10 Nov 2020 22:21: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="pkAAotds" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C0FF320674 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 19E5D6B009F; Tue, 10 Nov 2020 17:21:00 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 127E76B00A0; Tue, 10 Nov 2020 17:21:00 -0500 (EST) 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 EBD686B00A1; Tue, 10 Nov 2020 17:20:59 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0212.hostedemail.com [216.40.44.212]) by kanga.kvack.org (Postfix) with ESMTP id AC47F6B009F for ; Tue, 10 Nov 2020 17:20:59 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 5A9C08249980 for ; Tue, 10 Nov 2020 22:20:59 +0000 (UTC) X-FDA: 77469929838.13.eggs82_2115bfa272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 3E2D618140B69 for ; Tue, 10 Nov 2020 22:20:59 +0000 (UTC) X-Spam-Summary: 1,0,0,1eea6c7b40e40408,d41d8cd98f00b204,3srkrxwokcb44h7l8sehpfaiiaf8.6igfchor-ggep46e.ila@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:69:152:327:355:379:541:800:960:966:967: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:2525:2559:2563:2682:2685:2731:2859:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3740:3865:3867:3868:3870:3871:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4385:4425:4605:5007:6119:6261:6653:6742:7903:8603:8957:9025:9036:9592:9969:10004:10954:11026:11473:11658:11914:12043:12291:12295:12296:12297:12438:12555:12679:12683:12895:12986:14096:14097:14394:14659:21080:21365:21444:21451:21627:21939:21966:21990:30003:30054:30070,0,RBL:209.85.128.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yfqqsfywwf76f9qhka7k6uwkhwdypd9p1i8pfi4fkxmz77hhk67cd8ichktor.oyi33t788ifju hp1dfooi X-HE-Tag: eggs82_2115bfa272f8 X-Filterd-Recvd-Size: 21498 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:20:58 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id u207so1866615wmu.4 for ; Tue, 10 Nov 2020 14:20:58 -0800 (PST) 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=o1/1nos0zFZPL9mIFzV6FCy+ZXGKjAVVVyDw35QavK4=; b=pkAAotdsfAMsRZfaOpyxx7Rz2i5IkNySqQ7JPwm6WoXvf8tTRT3Q89WWzscOmM4lDh 1KGi706m82ncxB6mVp4FBO1UcMmWP8Gb0P8957QptILHOywu1qNMwfuKYw3HLwJ9BIMN WNTnXdEzAFWj/LpZ/WJjlmW5C8Hyetp98G3fl0GF/uO7ZxWVbMSnZNzJngYMewened/U 8ELme7jBq1mJS2gzSdgGD8AqztiMTRgJDxQbGuOpP/ukvKwuWvZDTgQrTDnnTg0IZYvm 0uC0bb03Tj4o97c1kQQIztRVIJcUsn4FyB+PpcD9AtSK1NOnzl4c5/8ycTVhjFz1ZQAz fHkg== 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=o1/1nos0zFZPL9mIFzV6FCy+ZXGKjAVVVyDw35QavK4=; b=CDd6BpzPevAAbIwBk1SdT0hamPVjk7ZZxTggWOS1b7dKn7yQH5pE5r1Rtc1Lz1V/Up GvWw/pCorjSzcssgz8T1VyPlAVflK47oHkS3nn58dKWNXvUkUZae26YvsCWdCNZkD2o6 LhsgZkFbIxtThtd1Ka+O/Al11ri72a9lPCCURsahFqonxEqWJ+RODQadQM+GC4AizcRB /vYd+Dd6wzpCY6sf3bGuHitwMDVHoXKZIr+XZps1eLn3r4zzLdvh6tEEXtst9oJgMmbD H2TFFYv1Pv7cOZ53D8/Gnc3hyIkpN5rdz/tA18oo/WlszIfe3/9gIlZIp21lPWvmwXNA 2lRg== X-Gm-Message-State: AOAM5301C1LaOlTaLzGi2CgsYQLOA8N5qnd0PuYYmuk9/n1W3f0HMMSY qctWIx7VU6NxMorCsF3ZIMX7yxORgUyFe6Rr X-Google-Smtp-Source: ABdhPJzmqSrplyUCQ4ds7REpp9Bb8+zoLNTCA47/0SwzZE9WT287XXOluXwd62ndMzbeEtx/MmT/5J+W8mDSzLx6 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6000:10e:: with SMTP id o14mr26646190wrx.225.1605046857657; Tue, 10 Nov 2020 14:20:57 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:16 +0100 In-Reply-To: Message-Id: <22c1a837d4d0c0b241a700c88f180f5e831a1953.1605046662.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 12/20] kasan, mm: check kasan_enabled in annotations From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: Declare the kasan_enabled static key in include/linux/kasan.h and in include/linux/mm.h and check it in all kasan annotations. This allows to avoid any slowdown caused by function calls when kasan_enabled is disabled. Signed-off-by: Andrey Konovalov Link: https://linux-review.googlesource.com/id/I2589451d3c96c97abbcbf714baabe6161c6f153e --- include/linux/kasan.h | 220 ++++++++++++++++++++++++++++++++---------- include/linux/mm.h | 22 +++-- mm/kasan/common.c | 60 ++++++------ 3 files changed, 216 insertions(+), 86 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index f1a5042ae4fc..779f8e703982 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -2,6 +2,7 @@ #ifndef _LINUX_KASAN_H #define _LINUX_KASAN_H +#include #include struct kmem_cache; @@ -74,56 +75,179 @@ static inline void kasan_disable_current(void) {} #ifdef CONFIG_KASAN -void kasan_alloc_pages(struct page *page, unsigned int order); -void kasan_free_pages(struct page *page, unsigned int order); +struct kasan_cache { + int alloc_meta_offset; + int free_meta_offset; +}; -void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, - slab_flags_t *flags); +#ifdef CONFIG_KASAN_HW_TAGS +DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled); +static inline kasan_enabled(void) +{ + return static_branch_likely(&kasan_flag_enabled); +} +#else +static inline kasan_enabled(void) +{ + return true; +} +#endif -void kasan_unpoison_data(const void *address, size_t size); -void kasan_unpoison_slab(const void *ptr); +void __kasan_alloc_pages(struct page *page, unsigned int order); +static inline void kasan_alloc_pages(struct page *page, unsigned int order) +{ + if (kasan_enabled()) + __kasan_alloc_pages(page, order); +} -void kasan_poison_slab(struct page *page); -void kasan_unpoison_object_data(struct kmem_cache *cache, void *object); -void kasan_poison_object_data(struct kmem_cache *cache, void *object); -void * __must_check kasan_init_slab_obj(struct kmem_cache *cache, - const void *object); +void __kasan_free_pages(struct page *page, unsigned int order); +static inline void kasan_free_pages(struct page *page, unsigned int order) +{ + if (kasan_enabled()) + __kasan_free_pages(page, order); +} -void * __must_check kasan_kmalloc_large(const void *ptr, size_t size, - gfp_t flags); -void kasan_kfree_large(void *ptr, unsigned long ip); -void kasan_poison_kfree(void *ptr, unsigned long ip); -void * __must_check kasan_kmalloc(struct kmem_cache *s, const void *object, - size_t size, gfp_t flags); -void * __must_check kasan_krealloc(const void *object, size_t new_size, - gfp_t flags); +void __kasan_cache_create(struct kmem_cache *cache, unsigned int *size, + slab_flags_t *flags); +static inline void kasan_cache_create(struct kmem_cache *cache, + unsigned int *size, slab_flags_t *flags) +{ + if (kasan_enabled()) + __kasan_cache_create(cache, size, flags); +} -void * __must_check kasan_slab_alloc(struct kmem_cache *s, void *object, - gfp_t flags); -bool kasan_slab_free(struct kmem_cache *s, void *object, unsigned long ip); +size_t __kasan_metadata_size(struct kmem_cache *cache); +static inline size_t kasan_metadata_size(struct kmem_cache *cache) +{ + if (kasan_enabled()) + return __kasan_metadata_size(cache); + return 0; +} -struct kasan_cache { - int alloc_meta_offset; - int free_meta_offset; -}; +void __kasan_unpoison_data(const void *addr, size_t size); +static inline void kasan_unpoison_data(const void *addr, size_t size) +{ + if (kasan_enabled()) + __kasan_unpoison_data(addr, size); +} + +void __kasan_unpoison_slab(const void *ptr); +static inline void kasan_unpoison_slab(const void *ptr) +{ + if (kasan_enabled()) + __kasan_unpoison_slab(ptr); +} + +void __kasan_poison_slab(struct page *page); +static inline void kasan_poison_slab(struct page *page) +{ + if (kasan_enabled()) + return __kasan_poison_slab(page); +} + +void __kasan_unpoison_object_data(struct kmem_cache *cache, void *object); +static inline void kasan_unpoison_object_data(struct kmem_cache *cache, void *object) +{ + if (kasan_enabled()) + return __kasan_unpoison_object_data(cache, object); +} + +void __kasan_poison_object_data(struct kmem_cache *cache, void *object); +static inline void kasan_poison_object_data(struct kmem_cache *cache, void *object) +{ + if (kasan_enabled()) + __kasan_poison_object_data(cache, object); +} + +void * __must_check __kasan_init_slab_obj(struct kmem_cache *cache, + const void *object); +static inline void * __must_check kasan_init_slab_obj(struct kmem_cache *cache, + const void *object) +{ + if (kasan_enabled()) + return __kasan_init_slab_obj(cache, object); + return (void *)object; +} + +bool __kasan_slab_free(struct kmem_cache *s, void *object, unsigned long ip); +static inline bool kasan_slab_free(struct kmem_cache *s, void *object, unsigned long ip) +{ + if (kasan_enabled()) + return __kasan_slab_free(s, object, ip); + return false; +} + +void * __must_check __kasan_slab_alloc(struct kmem_cache *s, + void *object, gfp_t flags); +static inline void * __must_check kasan_slab_alloc(struct kmem_cache *s, + void *object, gfp_t flags) +{ + if (kasan_enabled()) + return __kasan_slab_alloc(s, object, flags); + return object; +} -size_t kasan_metadata_size(struct kmem_cache *cache); +void * __must_check __kasan_kmalloc(struct kmem_cache *s, const void *object, + size_t size, gfp_t flags); +static inline void * __must_check kasan_kmalloc(struct kmem_cache *s, const void *object, + size_t size, gfp_t flags) +{ + if (kasan_enabled()) + return __kasan_kmalloc(s, object, size, flags); + return (void *)object; +} + +void * __must_check __kasan_kmalloc_large(const void *ptr, + size_t size, gfp_t flags); +static inline void * __must_check kasan_kmalloc_large(const void *ptr, + size_t size, gfp_t flags) +{ + if (kasan_enabled()) + return __kasan_kmalloc_large(ptr, size, flags); + return (void *)ptr; +} + +void * __must_check __kasan_krealloc(const void *object, + size_t new_size, gfp_t flags); +static inline void * __must_check kasan_krealloc(const void *object, + size_t new_size, gfp_t flags) +{ + if (kasan_enabled()) + return __kasan_krealloc(object, new_size, flags); + return (void *)object; +} + +void __kasan_poison_kfree(void *ptr, unsigned long ip); +static inline void kasan_poison_kfree(void *ptr, unsigned long ip) +{ + if (kasan_enabled()) + __kasan_poison_kfree(ptr, ip); +} + +void __kasan_kfree_large(void *ptr, unsigned long ip); +static inline void kasan_kfree_large(void *ptr, unsigned long ip) +{ + if (kasan_enabled()) + __kasan_kfree_large(ptr, ip); +} bool kasan_save_enable_multi_shot(void); void kasan_restore_multi_shot(bool enabled); #else /* CONFIG_KASAN */ +static inline kasan_enabled(void) +{ + return false; +} static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} static inline void kasan_free_pages(struct page *page, unsigned int order) {} - static inline void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, slab_flags_t *flags) {} - -static inline void kasan_unpoison_data(const void *address, size_t size) { } -static inline void kasan_unpoison_slab(const void *ptr) { } - +static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } +static inline void kasan_unpoison_data(const void *address, size_t size) {} +static inline void kasan_unpoison_slab(const void *ptr) {} static inline void kasan_poison_slab(struct page *page) {} static inline void kasan_unpoison_object_data(struct kmem_cache *cache, void *object) {} @@ -134,36 +258,32 @@ static inline void *kasan_init_slab_obj(struct kmem_cache *cache, { return (void *)object; } - -static inline void *kasan_kmalloc_large(void *ptr, size_t size, gfp_t flags) +static inline bool kasan_slab_free(struct kmem_cache *s, void *object, + unsigned long ip) { - return ptr; + return false; +} +static inline void *kasan_slab_alloc(struct kmem_cache *s, void *object, + gfp_t flags) +{ + return object; } -static inline void kasan_kfree_large(void *ptr, unsigned long ip) {} -static inline void kasan_poison_kfree(void *ptr, unsigned long ip) {} static inline void *kasan_kmalloc(struct kmem_cache *s, const void *object, size_t size, gfp_t flags) { return (void *)object; } +static inline void *kasan_kmalloc_large(const void *ptr, size_t size, gfp_t flags) +{ + return (void *)ptr; +} static inline void *kasan_krealloc(const void *object, size_t new_size, gfp_t flags) { return (void *)object; } - -static inline void *kasan_slab_alloc(struct kmem_cache *s, void *object, - gfp_t flags) -{ - return object; -} -static inline bool kasan_slab_free(struct kmem_cache *s, void *object, - unsigned long ip) -{ - return false; -} - -static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } +static inline void kasan_poison_kfree(void *ptr, unsigned long ip) {} +static inline void kasan_kfree_large(void *ptr, unsigned long ip) {} #endif /* CONFIG_KASAN */ diff --git a/include/linux/mm.h b/include/linux/mm.h index 0793d03a4183..8d84a6b2fa3c 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -31,6 +31,7 @@ #include #include #include +#include struct mempolicy; struct anon_vma; @@ -1414,22 +1415,30 @@ static inline bool cpupid_match_pid(struct task_struct *task, int cpupid) #endif /* CONFIG_NUMA_BALANCING */ #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; + if (kasan_enabled()) + return (page->flags >> KASAN_TAG_PGSHIFT) & KASAN_TAG_MASK; + return 0xff; } static inline void page_kasan_tag_set(struct page *page, u8 tag) { - page->flags &= ~(KASAN_TAG_MASK << KASAN_TAG_PGSHIFT); - page->flags |= (tag & KASAN_TAG_MASK) << KASAN_TAG_PGSHIFT; + if (kasan_enabled()) { + page->flags &= ~(KASAN_TAG_MASK << KASAN_TAG_PGSHIFT); + page->flags |= (tag & KASAN_TAG_MASK) << KASAN_TAG_PGSHIFT; + } } static inline void page_kasan_tag_reset(struct page *page) { - page_kasan_tag_set(page, 0xff); + if (kasan_enabled()) + page_kasan_tag_set(page, 0xff); } -#else + +#else /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS */ + static inline u8 page_kasan_tag(const struct page *page) { return 0xff; @@ -1437,7 +1446,8 @@ static inline u8 page_kasan_tag(const struct page *page) static inline void page_kasan_tag_set(struct page *page, u8 tag) { } static inline void page_kasan_tag_reset(struct page *page) { } -#endif + +#endif /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS */ static inline struct zone *page_zone(const struct page *page) { diff --git a/mm/kasan/common.c b/mm/kasan/common.c index efad5ed6a3bd..385863eaec2c 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -81,7 +81,7 @@ asmlinkage void kasan_unpoison_task_stack_below(const void *watermark) } #endif /* CONFIG_KASAN_STACK */ -void kasan_alloc_pages(struct page *page, unsigned int order) +void __kasan_alloc_pages(struct page *page, unsigned int order) { u8 tag; unsigned long i; @@ -95,7 +95,7 @@ void kasan_alloc_pages(struct page *page, unsigned int order) kasan_unpoison_memory(page_address(page), PAGE_SIZE << order); } -void kasan_free_pages(struct page *page, unsigned int order) +void __kasan_free_pages(struct page *page, unsigned int order) { if (likely(!PageHighMem(page))) kasan_poison_memory(page_address(page), @@ -122,8 +122,8 @@ static inline unsigned int optimal_redzone(unsigned int object_size) object_size <= (1 << 16) - 1024 ? 1024 : 2048; } -void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, - slab_flags_t *flags) +void __kasan_cache_create(struct kmem_cache *cache, unsigned int *size, + slab_flags_t *flags) { unsigned int orig_size = *size; unsigned int redzone_size; @@ -168,7 +168,7 @@ void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, *flags |= SLAB_KASAN; } -size_t kasan_metadata_size(struct kmem_cache *cache) +size_t __kasan_metadata_size(struct kmem_cache *cache) { if (!kasan_stack_collection_enabled()) return 0; @@ -191,17 +191,17 @@ struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache, return kasan_reset_tag(object) + cache->kasan_info.free_meta_offset; } -void kasan_unpoison_data(const void *address, size_t size) +void __kasan_unpoison_data(const void *addr, size_t size) { - kasan_unpoison_memory(address, size); + kasan_unpoison_memory(addr, size); } -void kasan_unpoison_slab(const void *ptr) +void __kasan_unpoison_slab(const void *ptr) { kasan_unpoison_memory(ptr, __ksize(ptr)); } -void kasan_poison_slab(struct page *page) +void __kasan_poison_slab(struct page *page) { unsigned long i; @@ -211,12 +211,12 @@ void kasan_poison_slab(struct page *page) KASAN_KMALLOC_REDZONE); } -void kasan_unpoison_object_data(struct kmem_cache *cache, void *object) +void __kasan_unpoison_object_data(struct kmem_cache *cache, void *object) { kasan_unpoison_memory(object, cache->object_size); } -void kasan_poison_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_GRANULE_SIZE), @@ -269,7 +269,7 @@ static u8 assign_tag(struct kmem_cache *cache, const void *object, #endif } -void * __must_check kasan_init_slab_obj(struct kmem_cache *cache, +void * __must_check __kasan_init_slab_obj(struct kmem_cache *cache, const void *object) { struct kasan_alloc_meta *alloc_meta; @@ -288,7 +288,7 @@ void * __must_check kasan_init_slab_obj(struct kmem_cache *cache, return (void *)object; } -static bool __kasan_slab_free(struct kmem_cache *cache, void *object, +static bool ____kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip, bool quarantine) { u8 tag; @@ -331,9 +331,9 @@ static bool __kasan_slab_free(struct kmem_cache *cache, void *object, return IS_ENABLED(CONFIG_KASAN_GENERIC); } -bool kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip) +bool __kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip) { - return __kasan_slab_free(cache, object, ip, true); + return ____kasan_slab_free(cache, object, ip, true); } static void set_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) @@ -341,7 +341,7 @@ static void set_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) kasan_set_track(&kasan_get_alloc_meta(cache, object)->alloc_track, flags); } -static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, +static void *____kasan_kmalloc(struct kmem_cache *cache, const void *object, size_t size, gfp_t flags, bool keep_tag) { unsigned long redzone_start; @@ -373,20 +373,20 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, return set_tag(object, tag); } -void * __must_check kasan_slab_alloc(struct kmem_cache *cache, void *object, - gfp_t flags) +void * __must_check __kasan_slab_alloc(struct kmem_cache *cache, + void *object, gfp_t flags) { - return __kasan_kmalloc(cache, object, cache->object_size, flags, false); + return ____kasan_kmalloc(cache, object, cache->object_size, flags, false); } -void * __must_check kasan_kmalloc(struct kmem_cache *cache, const void *object, - size_t size, gfp_t flags) +void * __must_check __kasan_kmalloc(struct kmem_cache *cache, const void *object, + size_t size, gfp_t flags) { - return __kasan_kmalloc(cache, object, size, flags, true); + return ____kasan_kmalloc(cache, object, size, flags, true); } -EXPORT_SYMBOL(kasan_kmalloc); +EXPORT_SYMBOL(__kasan_kmalloc); -void * __must_check kasan_kmalloc_large(const void *ptr, size_t size, +void * __must_check __kasan_kmalloc_large(const void *ptr, size_t size, gfp_t flags) { struct page *page; @@ -411,7 +411,7 @@ void * __must_check kasan_kmalloc_large(const void *ptr, size_t size, return (void *)ptr; } -void * __must_check kasan_krealloc(const void *object, size_t size, gfp_t flags) +void * __must_check __kasan_krealloc(const void *object, size_t size, gfp_t flags) { struct page *page; @@ -421,13 +421,13 @@ void * __must_check kasan_krealloc(const void *object, size_t size, gfp_t flags) page = virt_to_head_page(object); if (unlikely(!PageSlab(page))) - return kasan_kmalloc_large(object, size, flags); + return __kasan_kmalloc_large(object, size, flags); else - return __kasan_kmalloc(page->slab_cache, object, size, + return ____kasan_kmalloc(page->slab_cache, object, size, flags, true); } -void kasan_poison_kfree(void *ptr, unsigned long ip) +void __kasan_poison_kfree(void *ptr, unsigned long ip) { struct page *page; @@ -440,11 +440,11 @@ void kasan_poison_kfree(void *ptr, unsigned long ip) } kasan_poison_memory(ptr, page_size(page), KASAN_FREE_PAGE); } else { - __kasan_slab_free(page->slab_cache, ptr, ip, false); + ____kasan_slab_free(page->slab_cache, ptr, ip, false); } } -void kasan_kfree_large(void *ptr, unsigned long ip) +void __kasan_kfree_large(void *ptr, unsigned long ip) { if (ptr != page_address(virt_to_head_page(ptr))) kasan_report_invalid_free(ptr, ip); From patchwork Tue Nov 10 22:20: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: 11895663 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 7758B138B for ; Tue, 10 Nov 2020 22:21:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2B30720674 for ; Tue, 10 Nov 2020 22:21:04 +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="Sorzbxjl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2B30720674 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 548B06B00A2; Tue, 10 Nov 2020 17:21:02 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4D4896B00A3; Tue, 10 Nov 2020 17:21:02 -0500 (EST) 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 260BF6B00A4; Tue, 10 Nov 2020 17:21:02 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0048.hostedemail.com [216.40.44.48]) by kanga.kvack.org (Postfix) with ESMTP id DB75C6B00A2 for ; Tue, 10 Nov 2020 17:21:01 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8C7391EE6 for ; Tue, 10 Nov 2020 22:21:01 +0000 (UTC) X-FDA: 77469929922.22.nail72_5302286272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 546E718038E6B for ; Tue, 10 Nov 2020 22:21:01 +0000 (UTC) X-Spam-Summary: 1,0,0,c3a7cc29e404982e,d41d8cd98f00b204,3sxkrxwokcca6j9naugjrhckkcha.8kihejqt-iigr68g.knc@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:69:152:355:379:541:800:960:965:966:967:968:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2525:2559:2563:2682:2685:2859:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3352:3865:3867:3868:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4385:4390:4395:4425:5007:6119:6261:6653:6742:7903:8957:9025:9592:9969:10004:10400:11026:11473:11658:11914:12043:12297:12438:12555:12679:12895:12986:13069:13311:13357:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:21939:21990:30054:30070,0,RBL:209.85.222.201:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yr5ekij3444aepxy8893pn5bgrjypkzdbb3zmfkkkmdmn941amb5zamrqhb3y.ouqxubqdwy3r3x4uiojz3p5ersoprp4r347wam9 oidd6ggw X-HE-Tag: nail72_5302286272f8 X-Filterd-Recvd-Size: 4592 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:21:00 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id x85so200414qka.14 for ; Tue, 10 Nov 2020 14:21:00 -0800 (PST) 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=JVfCx5YoVAhsMAMzq5Ib4xNDNXTPugCAXEdF/9ZfK1c=; b=Sorzbxjl434teafjW3faZG7zFZzfm93UE5ni1XpfIncUp10ibp8jpLYD70flrD0+2/ /ZaY5ksYh6XtmAQzE15CeAKLXWStbYLxHdCNnUebaCqUpyj9z4JlZq4J3u8IfE10A5Lq Zr3qjbG+frRqzlU2wYjRNGXaopuLOQnurA51QAgFYIIrikpen/tETHXDcodSPHKR/9By HM+aXQXai3muVVFES7+dvfTZwk3Q1hnpbedVcj8nRXP8nq6OW22Mr8dJd3a/ILVJSdD3 So1MJMa8xAODLMxUsWoHgul0P/PCAhB0ZKwHZbNh8Nu2VglU+Jp9Lss9YGFtCDcHEgIE Xc4w== 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=JVfCx5YoVAhsMAMzq5Ib4xNDNXTPugCAXEdF/9ZfK1c=; b=Z93qo6PM7pEhFd/BkuQkO3+d9tSfWGwDSZwPLa7SSL0TM73j3DUWYJRL17sHbIKXnw JBZUjGQaLNbNFuTxltFqdKKuNlmZuHIqh7Cz5YUxG+CdJ0twmcWR2X+FAZ8QN+Po7Nw1 lli1ioFPp/hv3f0DpgqI0sjupvemKqeHPA+nZAFwphF+2h64KdwI+zutS4cxDa1O/QK2 od/+3PODSJB3EMz0lO8R5oJeXOOEfI501bsM1UQH+KgWlsavX/Y37ToZ2mO5STjszy6L GrAoiW3Mcvpy/ymiDEHOlDbm8Ouq83iZT5nDwATaDO/ozBQXbNSpJri7k4UnkG8UrAOT ahjA== X-Gm-Message-State: AOAM531a7AEF8Roj+Nzmom+Pj7mMbg4JHy2CKIuVzq/Lyz7nis5XskKt HKgyaws1lQM2rWdvFXWXCnfuMxyjMCtlNScZ X-Google-Smtp-Source: ABdhPJz9X4I0fQKQ6rAPw02HsIflV/nkdacrsdfDSd0mERCmB5vYjtdDNjyd6StrpyBIrGYzVfJD2gDIvmTN5dGg X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:e790:: with SMTP id x16mr12244792qvn.21.1605046859712; Tue, 10 Nov 2020 14:20:59 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:17 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 13/20] kasan: simplify kasan_poison_kfree From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: kasan_poison_kfree() is currently only called for mempool allocations that are backed by either kmem_cache_alloc() or kmalloc(). Therefore, the page passed to kasan_poison_kfree() is always PageSlab() and there's no need to do the check. Remove it. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/If31f88726745da8744c6bea96fb32584e6c2778c Reviewed-by: Marco Elver --- mm/kasan/common.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 385863eaec2c..819403548f2e 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -432,16 +432,7 @@ void __kasan_poison_kfree(void *ptr, unsigned long ip) struct page *page; page = virt_to_head_page(ptr); - - if (unlikely(!PageSlab(page))) { - if (ptr != page_address(page)) { - kasan_report_invalid_free(ptr, ip); - return; - } - kasan_poison_memory(ptr, page_size(page), KASAN_FREE_PAGE); - } else { - ____kasan_slab_free(page->slab_cache, ptr, ip, false); - } + ____kasan_slab_free(page->slab_cache, ptr, ip, false); } void __kasan_kfree_large(void *ptr, unsigned long ip) From patchwork Tue Nov 10 22:20: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: 11895665 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 B306F138B for ; Tue, 10 Nov 2020 22:21:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7924920781 for ; Tue, 10 Nov 2020 22:21: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="nWOy4NUD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7924920781 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 B8C506B00A5; Tue, 10 Nov 2020 17:21:04 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AEB586B00A6; Tue, 10 Nov 2020 17:21:04 -0500 (EST) 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 963476B00A7; Tue, 10 Nov 2020 17:21:04 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0177.hostedemail.com [216.40.44.177]) by kanga.kvack.org (Postfix) with ESMTP id 626896B00A5 for ; Tue, 10 Nov 2020 17:21:04 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 09D26181AEF10 for ; Tue, 10 Nov 2020 22:21:04 +0000 (UTC) X-FDA: 77469930048.27.air89_5515f20272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id DD8743D663 for ; Tue, 10 Nov 2020 22:21:03 +0000 (UTC) X-Spam-Summary: 1,0,0,374d744fb6f11a13,d41d8cd98f00b204,3thkrxwokccm9mcqdxjmukfnnfkd.bnlkhmtw-llju9bj.nqf@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:965:966:967:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2525:2559:2563:2682:2685:2859:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3355:3867:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4118:4321:4385:4390:4395:4425:4605:5007:6119:6261:6653:6742:8603:9025:9592:9969:10004:10400:11026:11658:11914:12043:12296:12297:12438:12555:12679:12895:12986:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:21939:21990:30054,0,RBL:209.85.128.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04y8eiig8qhzi9wzzpw4583msf7hkocogxz69frsqq7nnfajmuos97hjpx67ewh.t3eca1f8iqkkmcss5q76adze5po7we4exmch531twi5nr7a4nn43cit6jg7strj.h-lbl8.mailshell.net-2 23.238.2 X-HE-Tag: air89_5515f20272f8 X-Filterd-Recvd-Size: 7278 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:21:03 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id u207so1866708wmu.4 for ; Tue, 10 Nov 2020 14:21:03 -0800 (PST) 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=GOGJv8k49mZ7izGKRKf2lz4nE5+QAATrVFhHt9hU4vk=; b=nWOy4NUDHFOJEkxt4HeQuuF7ItikIUR8FEDsoSuy97fbvULA7lagn7eN3aC6vpstwF xnpFycGGrQwC8h/x/TXHWw0CW+G4Fjd4Slr9kUN2ThO1uqV1a17ThYYrVviz2QzvLoEO oWgn9eARxtVrIcMhHtbgK5vf157PytkMdr0TozM3dqyYiXD2fg1TZOmiSH2tfoQNyg/p JnBT4n1XAgbGk9xq5rgIyLRbUehOrg15Syn4bQ069qKNf+WaK4exp2ytMFY2Ps2HZxgG ZfB1I1UrMfNw1Gz86u3BfC24ZC1yd4ha4aaLaa9otfPc1GMwphpeAJEn2q3FmZCaeW05 uz7w== 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=GOGJv8k49mZ7izGKRKf2lz4nE5+QAATrVFhHt9hU4vk=; b=QfKsbeKZZQkGWEmwgoVyxkMwyCUwL1Fy37NJd7EM+KuEGiyXCPCgEmSJMlZuf4msww h8S5WNW0fgzYwZalGc8tMfjYg5Gx3e8+Zg7lUW1QMqbSOdC3tMCuOoxiEgPcTqlTkA2i R7DlxWLPo2TGjhrzRd91SDjcjriDM7LrjiASEee4jV8bmR631kcr9D+T1bljVz+Hl114 Etbi8ng7uYvZVEyEihOTyb7g/UvR7C+TxxC2c4TxbU7gyg2oeKoDyqOWuq75XX+FNjAe QE2zytgA3O2Kj1PJ5utscKCerNse7N/dlaKRn3Dqqh02uIaQqiWPFbyMegQsVYVIJ5qD xalw== X-Gm-Message-State: AOAM531mfwjxJpUFtyECBcnMcHfdqdjdkAlSOOoQQ621wExojhDfUqGi SAdb76cGy72u5yPyXC0ur2Ekj06zu50+fg8a X-Google-Smtp-Source: ABdhPJye7812Tl8RDG0JMOImadD+I+Ef01WcUzHZ3QitQU3NwVahUAiU8MWUn0N3DMR/yxe7K7D4GjlglR/6liPr X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:cbd7:: with SMTP id n23mr302280wmi.142.1605046862286; Tue, 10 Nov 2020 14:21:02 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:18 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 14/20] kasan, mm: rename kasan_poison_kfree From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: Rename kasan_poison_kfree() to kasan_slab_free_mempool() as it better reflects what this annotation does. No functional changes. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/I5026f87364e556b506ef1baee725144bb04b8810 --- include/linux/kasan.h | 16 ++++++++-------- mm/kasan/common.c | 16 ++++++++-------- mm/mempool.c | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 779f8e703982..534ab3e2935a 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -177,6 +177,13 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, unsigned return false; } +void __kasan_slab_free_mempool(void *ptr, unsigned long ip); +static inline void kasan_slab_free_mempool(void *ptr, unsigned long ip) +{ + if (kasan_enabled()) + __kasan_slab_free_mempool(ptr, ip); +} + void * __must_check __kasan_slab_alloc(struct kmem_cache *s, void *object, gfp_t flags); static inline void * __must_check kasan_slab_alloc(struct kmem_cache *s, @@ -217,13 +224,6 @@ static inline void * __must_check kasan_krealloc(const void *object, return (void *)object; } -void __kasan_poison_kfree(void *ptr, unsigned long ip); -static inline void kasan_poison_kfree(void *ptr, unsigned long ip) -{ - if (kasan_enabled()) - __kasan_poison_kfree(ptr, ip); -} - void __kasan_kfree_large(void *ptr, unsigned long ip); static inline void kasan_kfree_large(void *ptr, unsigned long ip) { @@ -263,6 +263,7 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, { return false; } +static inline void kasan_slab_free_mempool(void *ptr, unsigned long ip) {} static inline void *kasan_slab_alloc(struct kmem_cache *s, void *object, gfp_t flags) { @@ -282,7 +283,6 @@ static inline void *kasan_krealloc(const void *object, size_t new_size, { return (void *)object; } -static inline void kasan_poison_kfree(void *ptr, unsigned long ip) {} static inline void kasan_kfree_large(void *ptr, unsigned long ip) {} #endif /* CONFIG_KASAN */ diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 819403548f2e..60793f8695a8 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -336,6 +336,14 @@ bool __kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip) return ____kasan_slab_free(cache, object, ip, true); } +void __kasan_slab_free_mempool(void *ptr, unsigned long ip) +{ + struct page *page; + + page = virt_to_head_page(ptr); + ____kasan_slab_free(page->slab_cache, ptr, ip, false); +} + static void set_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) { kasan_set_track(&kasan_get_alloc_meta(cache, object)->alloc_track, flags); @@ -427,14 +435,6 @@ void * __must_check __kasan_krealloc(const void *object, size_t size, gfp_t flag flags, true); } -void __kasan_poison_kfree(void *ptr, unsigned long ip) -{ - struct page *page; - - page = virt_to_head_page(ptr); - ____kasan_slab_free(page->slab_cache, ptr, ip, false); -} - void __kasan_kfree_large(void *ptr, unsigned long ip) { if (ptr != page_address(virt_to_head_page(ptr))) diff --git a/mm/mempool.c b/mm/mempool.c index f473cdddaff0..b1f39fa75ade 100644 --- a/mm/mempool.c +++ b/mm/mempool.c @@ -104,7 +104,7 @@ static inline void poison_element(mempool_t *pool, void *element) static __always_inline void kasan_poison_element(mempool_t *pool, void *element) { if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc) - kasan_poison_kfree(element, _RET_IP_); + kasan_slab_free_mempool(element, _RET_IP_); else if (pool->alloc == mempool_alloc_pages) kasan_free_pages(element, (unsigned long)pool->pool_data); } From patchwork Tue Nov 10 22:20: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: 11895667 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 30E7C138B for ; Tue, 10 Nov 2020 22:21:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E9DCF20674 for ; Tue, 10 Nov 2020 22:21:08 +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="uANlXR3C" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E9DCF20674 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 742E66B00A8; Tue, 10 Nov 2020 17:21:07 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6A9AF6B00A9; Tue, 10 Nov 2020 17:21:07 -0500 (EST) 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 4D0306B00AA; Tue, 10 Nov 2020 17:21:07 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0063.hostedemail.com [216.40.44.63]) by kanga.kvack.org (Postfix) with ESMTP id 120BF6B00A8 for ; Tue, 10 Nov 2020 17:21:07 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id AA45A1EE6 for ; Tue, 10 Nov 2020 22:21:06 +0000 (UTC) X-FDA: 77469930132.16.jar00_3e0e5a2272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 8ACAE100E6917 for ; Tue, 10 Nov 2020 22:21:06 +0000 (UTC) X-Spam-Summary: 1,0,0,e9b11e1637f05155,d41d8cd98f00b204,3ubkrxwokccuboesfzlowmhpphmf.dpnmjovy-nnlwbdl.psh@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:966:967:968:973:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2525:2559:2563:2682:2685:2859:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3352:3865:3867:3868:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4385:4425:5007:6261:6653:6742:8603:9025:9969:10004:10400:10429:10430:10431:11026:11232:11473:11658:11914:12043:12296:12297:12438:12555:12679:12895:12986:14096:14097:14181:14394:14659:14721:19903:19997:21080:21365:21444:21451:21627:21772:21939:21990:30003:30012:30054,0,RBL:209.85.128.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yrhcsb3ek91jub3p1wcf4j6ogh4ocy7e1ffiypuhu1o8tbxfineegxwafqqob.1so75qhhj5dsejuhcyoqkuwafncmy184o1a69rf6ro3y9i hdp1ttq8 X-HE-Tag: jar00_3e0e5a2272f8 X-Filterd-Recvd-Size: 5431 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:21:05 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id k128so1862001wme.7 for ; Tue, 10 Nov 2020 14:21:05 -0800 (PST) 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=pq+zpW/Hw4XDGIR7N3eqf6sjflzq5qp4Op5FmJmOOa8=; b=uANlXR3CSpy0OVPmNQ73PxY92qov20UVaMIwXUyPX+fAIprSkZe9uSPL4bQVMEC/m/ t6wBvgClC8i+jwTY287EzT22FDgFPZZShu17Fwwgr+vWpgadpDkWYTs9vdSp0HV+9VZq Kx+M2yf4bagD7qpj2zf7ge0r5Zz+1FN0ycJy5Vu0t8QfpOdv9cijYOOLD8Vq/+Peju7k u3843665kwiM52RAxyenrbPXVhQuJ48TUwhSG4+Wo05tfFV9dEDRxFmFk0olCq4CS7+H zj5ZcfrDTG76qZOUCtww5kQJxsH6bWa0hEpqDIpxqTvvTx3BnIhmBpX9ELGPzultfHVR wsDA== 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=pq+zpW/Hw4XDGIR7N3eqf6sjflzq5qp4Op5FmJmOOa8=; b=VJz9RtdEZouiLZYF26YYoeCGGvCvJJQ2EDYzxKFWl1StZmOCVkeyD6gklJVPIJVJ2t vNfRS4yVL7KjrwFY4zXv1h4G2kqSEPh/h2eFsNGPwLX2o5TEy8Op5G9vopUG5vYcCZmH 071veHTwPpZXjN44Lt5rmiAXiYePFECM/a/lSzBklA1KicbcIKJx3yN4S1ea9/PYyvXB c44hfmRNB5jUfQGJMNShNiv4y1b/PJmybLpLhc304sdbH/g8w7wIJNDbA0aZaLXkN5uJ TGf8+BsSJQXMKYbNUI4t1aBHe2TvvyMW9vI94FIW+a6m7YWMP5LaXEFwgOwxnxIh1VYQ C1pg== X-Gm-Message-State: AOAM5311hTKGlZNb3W6so/bBezAD8VeyRSaabCYIYO6pslcYX7fqsLVs 72J21uHlvLU1WJJgvU7p/9PhRbWZvb4bwQjM X-Google-Smtp-Source: ABdhPJww9dm2MDRGqKJLg0tAFFPdHdF+3n5YlkqvRFYDl3KYCnu7Zb3EA2VEUW1wWZgN/7f9Jq+e6O9RKx82b94E X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:b387:: with SMTP id c129mr303876wmf.58.1605046864904; Tue, 10 Nov 2020 14:21:04 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:19 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 15/20] kasan: don't round_up too much From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: For hardware tag-based mode kasan_poison_memory() already rounds up the size. Do the same for software modes and remove round_up() from the common code. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/Ib397128fac6eba874008662b4964d65352db4aa4 Reviewed-by: Marco Elver --- mm/kasan/common.c | 8 ++------ mm/kasan/shadow.c | 1 + 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 60793f8695a8..69ab880abacc 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -218,9 +218,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_GRANULE_SIZE), - KASAN_KMALLOC_REDZONE); + kasan_poison_memory(object, cache->object_size, KASAN_KMALLOC_REDZONE); } /* @@ -293,7 +291,6 @@ static bool ____kasan_slab_free(struct kmem_cache *cache, void *object, { u8 tag; void *tagged_object; - unsigned long rounded_up_size; tag = get_tag(object); tagged_object = object; @@ -314,8 +311,7 @@ static bool ____kasan_slab_free(struct kmem_cache *cache, void *object, return true; } - rounded_up_size = round_up(cache->object_size, KASAN_GRANULE_SIZE); - kasan_poison_memory(object, rounded_up_size, KASAN_KMALLOC_FREE); + kasan_poison_memory(object, cache->object_size, KASAN_KMALLOC_FREE); if (!kasan_stack_collection_enabled()) return false; diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index 8e4fa9157a0b..3f64c9ecbcc0 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -82,6 +82,7 @@ void kasan_poison_memory(const void *address, size_t size, u8 value) * addresses to this function. */ address = kasan_reset_tag(address); + size = round_up(size, KASAN_GRANULE_SIZE); shadow_start = kasan_mem_to_shadow(address); shadow_end = kasan_mem_to_shadow(address + size); From patchwork Tue Nov 10 22:20:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11895669 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 E589B138B for ; Tue, 10 Nov 2020 22:21:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9F58220674 for ; Tue, 10 Nov 2020 22:21: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="QP7TuVPx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F58220674 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 482FC6B00AB; Tue, 10 Nov 2020 17:21:10 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 40B836B00AC; Tue, 10 Nov 2020 17:21:10 -0500 (EST) 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 2FC326B00AD; Tue, 10 Nov 2020 17:21:10 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id E3E356B00AB for ; Tue, 10 Nov 2020 17:21:09 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 93460181AEF10 for ; Tue, 10 Nov 2020 22:21:09 +0000 (UTC) X-FDA: 77469930258.14.nerve01_170b600272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 6FE2D18229818 for ; Tue, 10 Nov 2020 22:21:09 +0000 (UTC) X-Spam-Summary: 1,0,0,65fbca173ab84dfb,d41d8cd98f00b204,3uxkrxwokccgerhvicorzpksskpi.gsqpmryb-qqozego.svk@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:967:973: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:2525:2559:2563:2682:2685:2859:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3353:3865:3867:3868:3870:3871:3872:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4425:5007:6261:6653:6742:8603:8660:9025:9592:9969:10004:10400:11026:11473:11658:11914:12043:12296:12297:12438:12555:12679:12895:12986:13148:13230:14096:14097:14181:14394:14659:14721:21080:21212:21365:21444:21451:21627:21939:21990:30054:30070,0,RBL:209.85.218.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yg6wbjihc9twrt1wtcft6r9rjamyppgs1446rzw4p8zqpgps36b6cmchpwyxa.kzg7rudo5ujzijwnpux5micy6nhpi4d36mjbmhxn9n5u6ogoo6usogw3ybr3eic. o-lbl8.m X-HE-Tag: nerve01_170b600272f8 X-Filterd-Recvd-Size: 5382 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:21:08 +0000 (UTC) Received: by mail-ej1-f74.google.com with SMTP id gj4so33252ejb.13 for ; Tue, 10 Nov 2020 14:21:08 -0800 (PST) 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=UUb16eez1SBPDEo4INNWK7vyjFOxlmk1eUi1izfNnGk=; b=QP7TuVPxCEiWmmHgnEKJnNoGay3AQqR5W+nqoq/mV5uvCvY6CbJgGKtXz82KEG4kId KNMjnlvqyunp1Kqhwt3peDe0Vg4O+DQxvkw+MnRVzCq5Nvf0Ou/xBeqbAPV2XSIrqswu 9aKboBYNZGPP5klIdn8CMN07pjj/wj34ufercro9wLmyR/w6wCqGr66F7ztDXO4P9Y5P QoahP92EwMw+TLRC0EtcxvwFqReTRl6Xn1duRONdFajcKPyltvk3QlSDJFIhoKFiJo9K an+ewDBQH6xWC/JrFoJ/Z1WbXQtbEDByyh/6FVx/JJ1FMmIHAZ+hzFOiqtvuORTqVwpA AXpQ== 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=UUb16eez1SBPDEo4INNWK7vyjFOxlmk1eUi1izfNnGk=; b=FjrysP/jyyHiU5UOGBioX3gRjCF0tJS+SK4j1mLEgBKoeN5VyEIDmCuwowKdlVEx6Q pcsMiPskWllvCZRT69v2UQ3q/91TeS6DWDy29M7HYVtKHpcZqWtHII2oF8JCcxjPYNkJ yUR5Wq6H0LYEELK7kGgyCejXXhuPWQsmLcME9RuTPx8RHU0rNkb0RYjIeal9YMmxnwlQ hI/jZS8EWt0Q03VQRHxBOyWw8jwXRJXvRr/0N8UfnGeb1huO9TR9kq+fb3tAxZt4Ma1S nGdGQYI8mMOBUmZjvDNr2OTPwG3a5OgEZGgi1A+wMQtSRaATfhq9l5aiFVpw+7zkLsX0 +odQ== X-Gm-Message-State: AOAM533/aA/fC+44GOE+3VW6P57WBXyB2agwWWMsnBRhdWFanhVyR/J8 1Kd/GHvZh8yNCHUTMyJy/1egi/rG4EAEI0ZZ X-Google-Smtp-Source: ABdhPJy1APWb8IPIno5fyCxmFvAiY4V9ib3nnVEVsGk5gNukRVXnCQVuL8cF06lZdJfE+QXxRpZDFZp+aOWcujy4 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a17:906:b043:: with SMTP id bj3mr21951070ejb.543.1605046867367; Tue, 10 Nov 2020 14:21:07 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:20 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 16/20] kasan: simplify assign_tag and set_tag calls From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: set_tag() already ignores the tag for the generic mode, so just call it as is. Add a check for the generic mode to assign_tag(), and simplify its call in ____kasan_kmalloc(). Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/I18905ca78fb4a3d60e1a34a4ca00247272480438 Reviewed-by: Marco Elver --- mm/kasan/common.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 69ab880abacc..40ff3ce07a76 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -238,6 +238,9 @@ void __kasan_poison_object_data(struct kmem_cache *cache, void *object) static u8 assign_tag(struct kmem_cache *cache, const void *object, bool init, bool keep_tag) { + if (IS_ENABLED(CONFIG_KASAN_GENERIC)) + return 0xff; + /* * 1. When an object is kmalloc()'ed, two hooks are called: * kasan_slab_alloc() and kasan_kmalloc(). We assign the @@ -280,8 +283,8 @@ void * __must_check __kasan_init_slab_obj(struct kmem_cache *cache, __memset(alloc_meta, 0, sizeof(*alloc_meta)); } - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) || IS_ENABLED(CONFIG_KASAN_HW_TAGS)) - object = set_tag(object, assign_tag(cache, object, true, false)); + /* Tag is ignored in set_tag() without CONFIG_KASAN_SW/HW_TAGS */ + object = set_tag(object, assign_tag(cache, object, true, false)); return (void *)object; } @@ -362,9 +365,7 @@ static void *____kasan_kmalloc(struct kmem_cache *cache, const void *object, KASAN_GRANULE_SIZE); redzone_end = round_up((unsigned long)object + cache->object_size, KASAN_GRANULE_SIZE); - - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) || IS_ENABLED(CONFIG_KASAN_HW_TAGS)) - tag = assign_tag(cache, object, false, keep_tag); + tag = assign_tag(cache, object, false, keep_tag); /* Tag is ignored in set_tag without CONFIG_KASAN_SW/HW_TAGS */ kasan_unpoison_memory(set_tag(object, tag), size); From patchwork Tue Nov 10 22:20:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11895671 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 68DC9138B for ; Tue, 10 Nov 2020 22:21:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3030D20674 for ; Tue, 10 Nov 2020 22:21:14 +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="wL8k50M1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3030D20674 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 C02146B00AE; Tue, 10 Nov 2020 17:21:12 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AA1836B00AF; Tue, 10 Nov 2020 17:21:12 -0500 (EST) 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 82AAB6B00B0; Tue, 10 Nov 2020 17:21:12 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0225.hostedemail.com [216.40.44.225]) by kanga.kvack.org (Postfix) with ESMTP id 535026B00AE for ; Tue, 10 Nov 2020 17:21:12 -0500 (EST) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id F1CFA8249980 for ; Tue, 10 Nov 2020 22:21:11 +0000 (UTC) X-FDA: 77469930342.04.milk95_1c0c397272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id CB6E18006433 for ; Tue, 10 Nov 2020 22:21:11 +0000 (UTC) X-Spam-Summary: 1,0,0,0f5c7bff46d7c171,d41d8cd98f00b204,3vhkrxwokccshukylfrucsnvvnsl.jvtspube-ttrchjr.vyn@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:965:966:967:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1534:1540:1593:1594:1711:1714:1730:1747:1777:1792:2196:2199:2393:2525:2559:2563:2682:2685:2693:2859:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3351:3865:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4321:4385:4390:4395:4425:5007:6119:6261:6653:6742:7903:9025:9969:10004:10400:11026:11658:11914:12043:12296:12297:12438:12555:12679:12895:13069:13311:13357:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:21939:30012:30054,0,RBL:209.85.221.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04y8uf1g7isozejj1dguafut8sh4bopcq6tp6bjk9i88dur6e3j45f1bptqboxe.3drfjjtqu9mrpdumycsqjq4muqwmge9dz1e466sbyqgeupc8t8wne4wssz6d9xk.y-lbl8.mai lshell.n X-HE-Tag: milk95_1c0c397272f8 X-Filterd-Recvd-Size: 4235 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:21:11 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id w6so6201729wrk.1 for ; Tue, 10 Nov 2020 14:21:11 -0800 (PST) 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=MgiGs2FK0RQ4JNcJFnsxjsC4BWa7qeyNid6Uf5IWwBE=; b=wL8k50M1AQHx0VbQL3xi2XuIKzEGXDqvuUVrYzcIQ94olxXzgz0KX0q6k1f4qHRqNr llatx03+5CGH/foSZCzS8+mbo9AsyH1v/WHAAFQvSGtKVFIsW7M2JVSL/RY77Ni7+UKv FEqOLEs61nCxCIKEpESSzhVsL4LPWnOcrnfbp/V6bK7D8N8vSYSVH1Vn1WBuBPKz1Xto AJ3cdtZ2Uum98aAUASzeWGCdAOuYczsaP5Ke24OgbosVmgCMZ6eufONNfo/5pI4knmaW 5ez6cUJOUeYVfi5WRIAL3JvIxyUF+UP4ZCh+C3+BgUUsOc/4Liwv6fER/rLna14Yiuni 6Jfw== 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=MgiGs2FK0RQ4JNcJFnsxjsC4BWa7qeyNid6Uf5IWwBE=; b=KoelnWYs8RrThiqV201OYfZfAwaEfRuImJr8PQAHC+hNtfaYQwmZG59kwV4TPSfAgr oSSBtFTFc2jJEPzCjS5o0AS9H+oIksAAwcSckTWGtDdWzx5AVt/MHM2oSd7GWWjdjcV1 dEb3+SHhVu0FZQfD+cYXuRMMUWTC6fAdoIDGoMfFYack+GxLMfTcCWNUZnGG6ezmbiAj bZgxCq8z73MKCCvY5XFSMVXlvgSf4p5XVMeWqNWj4IMuFnCGbq9j2Fw5cY8v/uh00lBt gKSdEmXLWBYcnUGFAHAV3rj53s/z1qa6VZJnJCjQ62rrcSU4xp81xP5q6PJJ0HYxZoSC Bebw== X-Gm-Message-State: AOAM533q9d2I/bWxJlB2MR01RU6uDzXCHlfshuCo9aza9tEdQ7eqwdZV 0+N+98xGWZT/zRaBszi92hiZ7eIyMJWJd3VC X-Google-Smtp-Source: ABdhPJz8cb5hUXqbVxJ0PZ94Oo4nqDbSIaKQRp5eSLyEzi5Tgzn73vxMVKemqTEYC3dSSCt7/YBWoWzIAj4/5hyP X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:600c:210a:: with SMTP id u10mr304573wml.98.1605046870141; Tue, 10 Nov 2020 14:21:10 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:21 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 17/20] kasan: clarify comment in __kasan_kfree_large From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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 it says that the memory gets poisoned by page_alloc code. Clarify this by mentioning the specific callback that poisons the memory. Signed-off-by: Andrey Konovalov Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/I1334dffb69b87d7986fab88a1a039cc3ea764725 Reviewed-by: Marco Elver --- mm/kasan/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 40ff3ce07a76..4360292ad7f3 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -436,5 +436,5 @@ void __kasan_kfree_large(void *ptr, unsigned long ip) { if (ptr != page_address(virt_to_head_page(ptr))) kasan_report_invalid_free(ptr, ip); - /* The object will be poisoned by page_alloc. */ + /* The object will be poisoned by kasan_free_pages(). */ } From patchwork Tue Nov 10 22:20:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11895673 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 B949A1391 for ; Tue, 10 Nov 2020 22:21:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4DACA206B2 for ; Tue, 10 Nov 2020 22:21:17 +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="FOzDKlnS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4DACA206B2 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 D0FF96B00B1; Tue, 10 Nov 2020 17:21:15 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CC12E6B00B2; Tue, 10 Nov 2020 17:21:15 -0500 (EST) 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 AEF946B00B3; Tue, 10 Nov 2020 17:21:15 -0500 (EST) 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 6A6A96B00B1 for ; Tue, 10 Nov 2020 17:21:15 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id F05F9362B for ; Tue, 10 Nov 2020 22:21:14 +0000 (UTC) X-FDA: 77469930468.08.sea19_340b0b7272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id CCE951819E773 for ; Tue, 10 Nov 2020 22:21:14 +0000 (UTC) X-Spam-Summary: 1,0,0,2b7e32cf1aea1eb4,d41d8cd98f00b204,3wbkrxwokcc0jwmanhtweupxxpun.lxvurwdg-vvtejlt.xap@flex--andreyknvl.bounces.google.com,,RULES_HIT:4:41:69:152:355:379:541:800:960:966:967: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:2525:2559:2563:2682:2685:2731:2859:2898:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3865:3866:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4385:4425:4605:5007:6261:6653:6742:7875:8603:8660:9025:9592:9969:10004:11026:11473:11658:11914:12043:12291:12296:12297:12438:12555:12679:12683:12895:12986:13138:13148:13161:13229:13230:13231:14096:14097:14394:14659:21063:21080:21324:21365:21444:21451:21627:21740:21939:21966:21990:30012:30054:30070:30075,0,RBL:209.85.221.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yrr8jsnnh8rdfr719hqr y9ans3hy X-HE-Tag: sea19_340b0b7272f8 X-Filterd-Recvd-Size: 19033 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf37.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:21:14 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id k1so4868771wrg.12 for ; Tue, 10 Nov 2020 14:21:13 -0800 (PST) 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=2zUWPQplFymp9Hmc6hlFXFyiGUCdCRWGOE8USzzNHUI=; b=FOzDKlnSb1ljG+EB9YZK8MuDZK2QVgd+vEBRnNGIOsmByT0hZp/QxZV6N4gx4LwXJK 5bqmlJT0Ia2Z5GfrC2o5VNeOqhwMdDfBEK5I1e30ArlD3PqzxgilBWDRDZNSW3wVe13g hH4eXpXNXFuyyG+Dyes1ZPj7n+X9GJ8Ont3iQGNAfFku5e3CHFS8NgDUJgsKA44VgJUN NJX0T32+oNuqqt2pHbILme31X+iXy2f9LTYP5wT+2D0j3UXcH4AK0aTE9GAd9k/FiXti 25LGAFGL6fGj/J/KTejxXNuuZ9DEncV/6PiM0x3n570H6xpmiKr5+umAvXLXQ++Ok6LY Y5QQ== 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=2zUWPQplFymp9Hmc6hlFXFyiGUCdCRWGOE8USzzNHUI=; b=EF55lGEZQZycU4SfvYNjXIKev8+mtD64FpE89LuzBXV3aYx5wy/UAvNuB39/XI4aP9 DQHUD6aMj1YW08uW9rbMbR1Ubl5BVQtkRNAZ0m6ZA0eEpXPZjegcKvSS0AegK8QNeEE2 vJR+nPkz9hlJ3br2lycQEo1wnCe/f4r38UINg9epocx/KqejHcOkNiey5tPCyHTpYxSF P3bYei3lQuyZTH6Mpx1Jmt56o+XwodVhEngB8r+wAschzR7noqsZ2FQjVnnKWOMNaFJX H0WgHgsgqmrEceMDq7fRgXIiMOq6OMIXjyjlybw8FDrqEA3OTuiQoOPo7Qz76cz8ov/Q kPpQ== X-Gm-Message-State: AOAM533UOhCt5Q4Zqx/6/gVltZuvHCbwNA9astiGk6Vk+o0Qjmd4xph7 xfMoJGxmeKfUUDW2gCiMHXu0LnkHzPmP8Yhb X-Google-Smtp-Source: ABdhPJx6NSCyprfzCnoG3Bu9L/e53v6n3157momnnnlvzOzEvt/D47UjDjWZMq8vbeLYznH/vm0QqoXPT8slgNqO X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a5d:6310:: with SMTP id i16mr26060595wru.284.1605046872700; Tue, 10 Nov 2020 14:21:12 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:22 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 18/20] kasan: clean up metadata allocation and usage From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: KASAN marks caches that are sanitized with the SLAB_KASAN cache flag. Currently if the metadata that is appended after the object (stores e.g. stack trace ids) doesn't fit into KMALLOC_MAX_SIZE (can only happen with SLAB, see the comment in the patch), KASAN turns off sanitization completely. With this change sanitization of the object data is always enabled. However the metadata is only stored when it fits. Instead of checking for SLAB_KASAN flag accross the code to find out whether the metadata is there, use cache->kasan_info.alloc/free_meta_offset. As 0 can be a valid value for free_meta_offset, introduce KASAN_NO_FREE_META as an indicator that the free metadata is missing. Along the way rework __kasan_cache_create() and add claryfying comments. Signed-off-by: Andrey Konovalov Link: https://linux-review.googlesource.com/id/Icd947e2bea054cb5cfbdc6cf6652227d97032dcb --- mm/kasan/common.c | 112 +++++++++++++++++++++++++------------- mm/kasan/generic.c | 15 ++--- mm/kasan/hw_tags.c | 6 +- mm/kasan/kasan.h | 13 ++++- mm/kasan/quarantine.c | 8 +++ mm/kasan/report.c | 43 ++++++++------- mm/kasan/report_sw_tags.c | 7 ++- mm/kasan/sw_tags.c | 4 ++ 8 files changed, 138 insertions(+), 70 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 4360292ad7f3..940b42231069 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -109,9 +109,6 @@ 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_GENERIC)) - return 0; - return object_size <= 64 - 16 ? 16 : object_size <= 128 - 32 ? 32 : @@ -125,47 +122,79 @@ static inline unsigned int optimal_redzone(unsigned int object_size) void __kasan_cache_create(struct kmem_cache *cache, unsigned int *size, slab_flags_t *flags) { - unsigned int orig_size = *size; + unsigned int ok_size; unsigned int redzone_size; - int redzone_adjust; + unsigned int optimal_size; + + /* + * SLAB_KASAN is used to mark caches as ones that are sanitized by + * KASAN. Currently this is used in two places: + * 1. In slab_ksize() when calculating the size of the accessible + * memory within the object. + * 2. In slab_common.c to prevent merging of sanitized caches. + */ + *flags |= SLAB_KASAN; - if (!kasan_stack_collection_enabled()) { - *flags |= SLAB_KASAN; + if (!kasan_stack_collection_enabled()) return; - } - /* Add alloc meta. */ + ok_size = *size; + + /* Add alloc meta into redzone. */ cache->kasan_info.alloc_meta_offset = *size; *size += sizeof(struct kasan_alloc_meta); - /* Add free meta. */ - if (IS_ENABLED(CONFIG_KASAN_GENERIC) && - (cache->flags & SLAB_TYPESAFE_BY_RCU || cache->ctor || - cache->object_size < sizeof(struct kasan_free_meta))) { - cache->kasan_info.free_meta_offset = *size; - *size += sizeof(struct kasan_free_meta); + /* + * If alloc meta doesn't fit, don't add it. + * This can only happen with SLAB, as it has KMALLOC_MAX_SIZE equal + * to KMALLOC_MAX_CACHE_SIZE and doesn't fall back to page_alloc for + * larger sizes. + */ + if (*size > KMALLOC_MAX_SIZE) { + cache->kasan_info.alloc_meta_offset = 0; + *size = ok_size; + /* Continue, since free meta might still fit. */ } - redzone_size = optimal_redzone(cache->object_size); - redzone_adjust = redzone_size - (*size - cache->object_size); - if (redzone_adjust > 0) - *size += redzone_adjust; - - *size = min_t(unsigned int, KMALLOC_MAX_SIZE, - max(*size, cache->object_size + redzone_size)); + /* Only the generic mode uses free meta or flexible redzones. */ + if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) { + cache->kasan_info.free_meta_offset = KASAN_NO_FREE_META; + return; + } /* - * If the metadata doesn't fit, don't enable KASAN at all. + * Add free meta into redzone when it's not possible to store + * it in the object. This is the case when: + * 1. Object is SLAB_TYPESAFE_BY_RCU, which means that is can + * be touched after it was freed, or + * 2. Object has a constructor, which means it's expected to + * retain its content until the next allocation, or + * 3. Object is too small. + * Otherwise cache->kasan_info.free_meta_offset = 0 is implied. */ - if (*size <= cache->kasan_info.alloc_meta_offset || - *size <= cache->kasan_info.free_meta_offset) { - cache->kasan_info.alloc_meta_offset = 0; - cache->kasan_info.free_meta_offset = 0; - *size = orig_size; - return; + if (cache->flags & SLAB_TYPESAFE_BY_RCU || cache->ctor || + cache->object_size < sizeof(struct kasan_free_meta)) { + ok_size = *size; + + cache->kasan_info.free_meta_offset = *size; + *size += sizeof(struct kasan_free_meta); + + /* If free meta doesn't fit, don't add it. */ + if (*size > KMALLOC_MAX_SIZE) { + cache->kasan_info.free_meta_offset = KASAN_NO_FREE_META; + *size = ok_size; + } } - *flags |= SLAB_KASAN; + redzone_size = optimal_redzone(cache->object_size); + /* Calculate size with optimal redzone. */ + optimal_size = cache->object_size + redzone_size; + /* Limit it with KMALLOC_MAX_SIZE (relevant for SLAB only). */ + if (optimal_size > KMALLOC_MAX_SIZE) + optimal_size = KMALLOC_MAX_SIZE; + /* Use optimal size if the size with added metas is not large enough. */ + if (*size < optimal_size) + *size = optimal_size; } size_t __kasan_metadata_size(struct kmem_cache *cache) @@ -181,15 +210,21 @@ size_t __kasan_metadata_size(struct kmem_cache *cache) struct kasan_alloc_meta *kasan_get_alloc_meta(struct kmem_cache *cache, const void *object) { + if (!cache->kasan_info.alloc_meta_offset) + return NULL; return kasan_reset_tag(object) + cache->kasan_info.alloc_meta_offset; } +#ifdef CONFIG_KASAN_GENERIC struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache, const void *object) { BUILD_BUG_ON(sizeof(struct kasan_free_meta) > 32); + if (cache->kasan_info.free_meta_offset == KASAN_NO_FREE_META) + return NULL; return kasan_reset_tag(object) + cache->kasan_info.free_meta_offset; } +#endif void __kasan_unpoison_data(const void *addr, size_t size) { @@ -276,11 +311,9 @@ void * __must_check __kasan_init_slab_obj(struct kmem_cache *cache, struct kasan_alloc_meta *alloc_meta; if (kasan_stack_collection_enabled()) { - if (!(cache->flags & SLAB_KASAN)) - return (void *)object; - alloc_meta = kasan_get_alloc_meta(cache, object); - __memset(alloc_meta, 0, sizeof(*alloc_meta)); + if (alloc_meta) + __memset(alloc_meta, 0, sizeof(*alloc_meta)); } /* Tag is ignored in set_tag() without CONFIG_KASAN_SW/HW_TAGS */ @@ -319,8 +352,7 @@ static bool ____kasan_slab_free(struct kmem_cache *cache, void *object, if (!kasan_stack_collection_enabled()) return false; - if ((IS_ENABLED(CONFIG_KASAN_GENERIC) && !quarantine) || - unlikely(!(cache->flags & SLAB_KASAN))) + if ((IS_ENABLED(CONFIG_KASAN_GENERIC) && !quarantine)) return false; kasan_set_free_info(cache, object, tag); @@ -345,7 +377,11 @@ void __kasan_slab_free_mempool(void *ptr, unsigned long ip) static void set_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) { - kasan_set_track(&kasan_get_alloc_meta(cache, object)->alloc_track, flags); + struct kasan_alloc_meta *alloc_meta; + + alloc_meta = kasan_get_alloc_meta(cache, object); + if (alloc_meta) + kasan_set_track(&alloc_meta->alloc_track, flags); } static void *____kasan_kmalloc(struct kmem_cache *cache, const void *object, @@ -372,7 +408,7 @@ static void *____kasan_kmalloc(struct kmem_cache *cache, const void *object, kasan_poison_memory((void *)redzone_start, redzone_end - redzone_start, KASAN_KMALLOC_REDZONE); - if (kasan_stack_collection_enabled() && (cache->flags & SLAB_KASAN)) + if (kasan_stack_collection_enabled()) set_alloc_info(cache, (void *)object, flags); return set_tag(object, tag); diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index d259e4c3aefd..97e39516f8fe 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -338,10 +338,10 @@ void kasan_record_aux_stack(void *addr) cache = page->slab_cache; object = nearest_obj(cache, page, addr); alloc_meta = kasan_get_alloc_meta(cache, object); + if (!alloc_meta) + return; - /* - * record the last two call_rcu() call stacks. - */ + /* Record the last two call_rcu() call stacks. */ alloc_meta->aux_stack[1] = alloc_meta->aux_stack[0]; alloc_meta->aux_stack[0] = kasan_save_stack(GFP_NOWAIT); } @@ -352,11 +352,11 @@ void kasan_set_free_info(struct kmem_cache *cache, struct kasan_free_meta *free_meta; free_meta = kasan_get_free_meta(cache, object); - kasan_set_track(&free_meta->free_track, GFP_NOWAIT); + if (!free_meta) + return; - /* - * the object was freed and has free track set - */ + kasan_set_track(&free_meta->free_track, GFP_NOWAIT); + /* The object was freed and has free track set. */ *(u8 *)kasan_mem_to_shadow(object) = KASAN_KMALLOC_FREETRACK; } @@ -365,5 +365,6 @@ struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, { if (*(u8 *)kasan_mem_to_shadow(object) != KASAN_KMALLOC_FREETRACK) return NULL; + /* Free meta must be present with KASAN_KMALLOC_FREETRACK. */ return &kasan_get_free_meta(cache, object)->free_track; } diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 2f6f0261af8c..c3d2a21d925d 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -188,7 +188,8 @@ void kasan_set_free_info(struct kmem_cache *cache, struct kasan_alloc_meta *alloc_meta; alloc_meta = kasan_get_alloc_meta(cache, object); - kasan_set_track(&alloc_meta->free_track[0], GFP_NOWAIT); + if (alloc_meta) + kasan_set_track(&alloc_meta->free_track[0], GFP_NOWAIT); } struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, @@ -197,5 +198,8 @@ struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, struct kasan_alloc_meta *alloc_meta; alloc_meta = kasan_get_alloc_meta(cache, object); + if (!alloc_meta) + return NULL; + return &alloc_meta->free_track[0]; } diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 5eff3d9f624e..88892c05eb7d 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -154,20 +154,31 @@ struct kasan_alloc_meta { struct qlist_node { struct qlist_node *next; }; + +/* + * Generic mode either stores free meta in the object itself or in the redzone + * after the object. In the former case free meta offset is 0, in the latter + * case it has some sane value smaller than INT_MAX. Use INT_MAX as free meta + * offset when free meta isn't present. + */ +#define KASAN_NO_FREE_META (INT_MAX) + struct kasan_free_meta { +#ifdef CONFIG_KASAN_GENERIC /* This field is used while the object is in the quarantine. * Otherwise it might be used for the allocator freelist. */ struct qlist_node quarantine_link; -#ifdef CONFIG_KASAN_GENERIC struct kasan_track free_track; #endif }; struct kasan_alloc_meta *kasan_get_alloc_meta(struct kmem_cache *cache, const void *object); +#ifdef CONFIG_KASAN_GENERIC struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache, const void *object); +#endif #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c index 0da3d37e1589..23f6bfb1e73f 100644 --- a/mm/kasan/quarantine.c +++ b/mm/kasan/quarantine.c @@ -135,7 +135,12 @@ static void qlink_free(struct qlist_node *qlink, struct kmem_cache *cache) if (IS_ENABLED(CONFIG_SLAB)) local_irq_save(flags); + /* + * As the object now gets freed from the quaratine, assume that its + * free track is now longer valid. + */ *(u8 *)kasan_mem_to_shadow(object) = KASAN_KMALLOC_FREE; + ___cache_free(cache, object, _THIS_IP_); if (IS_ENABLED(CONFIG_SLAB)) @@ -168,6 +173,9 @@ void quarantine_put(struct kmem_cache *cache, void *object) struct qlist_head temp = QLIST_INIT; struct kasan_free_meta *meta = kasan_get_free_meta(cache, object); + if (!meta) + return; + /* * Note: irq must be disabled until after we move the batch to the * global quarantine. Otherwise quarantine_remove_cache() can miss diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 7d86af340148..6a95ad2dee91 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -168,32 +168,35 @@ static void describe_object_addr(struct kmem_cache *cache, void *object, static void describe_object_stacks(struct kmem_cache *cache, void *object, const void *addr, u8 tag) { - struct kasan_alloc_meta *alloc_meta = kasan_get_alloc_meta(cache, object); - - if (cache->flags & SLAB_KASAN) { - struct kasan_track *free_track; + struct kasan_alloc_meta *alloc_meta; + struct kasan_track *free_track; + alloc_meta = kasan_get_alloc_meta(cache, object); + if (alloc_meta) { print_track(&alloc_meta->alloc_track, "Allocated"); pr_err("\n"); - free_track = kasan_get_free_track(cache, object, tag); - if (free_track) { - print_track(free_track, "Freed"); - pr_err("\n"); - } + } + + free_track = kasan_get_free_track(cache, object, tag); + if (free_track) { + print_track(free_track, "Freed"); + pr_err("\n"); + } #ifdef CONFIG_KASAN_GENERIC - if (alloc_meta->aux_stack[0]) { - pr_err("Last call_rcu():\n"); - print_stack(alloc_meta->aux_stack[0]); - pr_err("\n"); - } - if (alloc_meta->aux_stack[1]) { - pr_err("Second to last call_rcu():\n"); - print_stack(alloc_meta->aux_stack[1]); - pr_err("\n"); - } -#endif + if (!alloc_meta) + return; + if (alloc_meta->aux_stack[0]) { + pr_err("Last call_rcu():\n"); + print_stack(alloc_meta->aux_stack[0]); + pr_err("\n"); } + if (alloc_meta->aux_stack[1]) { + pr_err("Second to last call_rcu():\n"); + print_stack(alloc_meta->aux_stack[1]); + pr_err("\n"); + } +#endif } static void describe_object(struct kmem_cache *cache, void *object, diff --git a/mm/kasan/report_sw_tags.c b/mm/kasan/report_sw_tags.c index 7604b46239d4..11dc8739e500 100644 --- a/mm/kasan/report_sw_tags.c +++ b/mm/kasan/report_sw_tags.c @@ -48,9 +48,10 @@ const char *get_bug_type(struct kasan_access_info *info) object = nearest_obj(cache, page, (void *)addr); alloc_meta = kasan_get_alloc_meta(cache, object); - for (i = 0; i < KASAN_NR_FREE_STACKS; i++) - if (alloc_meta->free_pointer_tag[i] == tag) - return "use-after-free"; + if (alloc_meta) + for (i = 0; i < KASAN_NR_FREE_STACKS; i++) + if (alloc_meta->free_pointer_tag[i] == tag) + return "use-after-free"; return "out-of-bounds"; } diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c index d1af6f6c6d12..be10d16bd129 100644 --- a/mm/kasan/sw_tags.c +++ b/mm/kasan/sw_tags.c @@ -170,6 +170,8 @@ void kasan_set_free_info(struct kmem_cache *cache, u8 idx = 0; alloc_meta = kasan_get_alloc_meta(cache, object); + if (!alloc_meta) + return; #ifdef CONFIG_KASAN_SW_TAGS_IDENTIFY idx = alloc_meta->free_track_idx; @@ -187,6 +189,8 @@ struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, int i = 0; alloc_meta = kasan_get_alloc_meta(cache, object); + if (!alloc_meta) + return NULL; #ifdef CONFIG_KASAN_SW_TAGS_IDENTIFY for (i = 0; i < KASAN_NR_FREE_STACKS; i++) { From patchwork Tue Nov 10 22:20:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11895675 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 338DE1391 for ; Tue, 10 Nov 2020 22:21:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D785C20679 for ; Tue, 10 Nov 2020 22:21:19 +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="MvPjJraT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D785C20679 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 3739B6B00B4; Tue, 10 Nov 2020 17:21:18 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 323406B00B5; Tue, 10 Nov 2020 17:21:18 -0500 (EST) 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 0DB6B6B00B6; Tue, 10 Nov 2020 17:21:18 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0237.hostedemail.com [216.40.44.237]) by kanga.kvack.org (Postfix) with ESMTP id C710A6B00B4 for ; Tue, 10 Nov 2020 17:21:17 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6C3A1362B for ; Tue, 10 Nov 2020 22:21:17 +0000 (UTC) X-FDA: 77469930594.11.edge19_0d0d5dc272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id 3F8F2180F8B81 for ; Tue, 10 Nov 2020 22:21:17 +0000 (UTC) X-Spam-Summary: 1,0,0,c106a0d75060d62f,d41d8cd98f00b204,3wxkrxwokcdamzpdqkwzhxsaasxq.oayxuzgj-yywhmow.ads@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:966:967:968:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1544:1593:1594:1605:1711:1730:1747:1777:1792:2194:2196:2198:2199:2200:2201:2393:2525:2559:2563:2682:2685:2693:2731:2859:2902:2911:2933:2937:2939:2942:2945:2947:2951:2954:3022:3138:3139:3140:3141:3142:3152:3355:3865:3866:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4118:4250:4321:4385:4425:4605:5007:6261:6653:6742:8603:9010:9025:9969:10004:11026:11473:11658:11914:12043:12291:12295:12296:12297:12438:12555:12679:12701:12737:12895:12986:13161:13229:14181:14394:14659:14721:21063:21080:21324:21365:21444:21450:21451:21627:21740:21939:21966:21990:30012:30029:30054:30070,0,RBL:209.85.221.73:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yrjd1z8jdue8yzzsug51f jt3zijyc X-HE-Tag: edge19_0d0d5dc272f8 X-Filterd-Recvd-Size: 7946 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:21:16 +0000 (UTC) Received: by mail-wr1-f73.google.com with SMTP id e11so6224265wrw.14 for ; Tue, 10 Nov 2020 14:21:16 -0800 (PST) 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=NSEnP5/Ymw2+CzfuUjUL3yzFjWGlVw3jfopzq6nBhYw=; b=MvPjJraTvvciMCrmEVBHJf7JZffHC8y5WsKXsz7dKaBKOd+ahVD8jotAMioOOY+Zy8 +oIjs5zBxjMN13SJYSVufJUR8ZSJRp8wcFRg6ysEbVOpnOQ5vU6igGKyRCAtUMHR205f 7QyvhDr6wwOcsOkI4zxzz6jcwQtJl0AqqctzgvATGiNPeP/sVqQ+6ox1fbYOYABAYPvk 7DaxX13UIIfsr9P6vPscgt+nvmJbOlQRSXO/sZhZ6Ht3GxlE3kgYYtamuzZF9LJ/Pvpz BQVuFuMfR8gf1A4I0Rij0OHDKjK8tIBD4Mhw3LvAXhWqwcwJRbF96SPZigccwisHP0Br nfyw== 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=NSEnP5/Ymw2+CzfuUjUL3yzFjWGlVw3jfopzq6nBhYw=; b=l13PNu0nPR5vSWDPQFfx3/SFn1q/IFT1ruCADCYyGoCHaWrUsfG44l999ZiozjTp58 K5U9MUin9IvLVh1wuO9kZhO/OCLrk9DBCFkoQUjARn7bRMsW0ByPa2ue3PDuR+nM1j0V cH1gMGdHMijhWldJ/IIYp+kGTEcBkEOV/HaEEHdQl2LeIGpqSGRZmRht4Bk3vsURy4Bd NygkwFFrf49bxtS7Py231FnSjWCwpjO/QnvwqgB3+6EE2UTg4Dcah0lbGeu9W6to30Ui yBT/Ze8/W9z1wvc1yQAqzpa3Qp3zrDqmQL9/SW9JvL8DmVQbnA/WgNzlrjsb7b7q0BZ+ CVfg== X-Gm-Message-State: AOAM532qZrLi8i4d8IUnkdCTIDSUoKJhWCA42ky7vzlEzYnFnGwNDGp2 5gMDeBon9Yvz4rC6Yg/OIsnAOLjcF8czDqTg X-Google-Smtp-Source: ABdhPJx5R9Lwi7vyMEdhZoBWGFA+5/tY8OWnRDBKQTuXeI+HTirxH7sptEemR57Y7sCa/FhiaUQSY6Jezq4w1pp+ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:c772:: with SMTP id x18mr262720wmk.185.1605046875625; Tue, 10 Nov 2020 14:21:15 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:23 +0100 In-Reply-To: Message-Id: <936c0c198145b663e031527c49a6895bd21ac3a0.1605046662.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 19/20] kasan, mm: allow cache merging with no metadata From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: The reason cache merging is disabled with KASAN is because KASAN puts its metadata right after the allocated object. When the merged caches have slightly different sizes, the metadata ends up in different places, which KASAN doesn't support. It might be possible to adjust the metadata allocation algorithm and make it friendly to the cache merging code. Instead this change takes a simpler approach and allows merging caches when no metadata is present. Which is the case for hardware tag-based KASAN with kasan.mode=prod. Signed-off-by: Andrey Konovalov Link: https://linux-review.googlesource.com/id/Ia114847dfb2244f297d2cb82d592bf6a07455dba --- include/linux/kasan.h | 26 ++++++++++++++++++++++++-- mm/kasan/common.c | 11 +++++++++++ mm/slab_common.c | 11 ++++++++--- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 534ab3e2935a..c754eca356f7 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -81,17 +81,35 @@ struct kasan_cache { }; #ifdef CONFIG_KASAN_HW_TAGS + DECLARE_STATIC_KEY_FALSE(kasan_flag_enabled); + static inline kasan_enabled(void) { return static_branch_likely(&kasan_flag_enabled); } -#else + +slab_flags_t __kasan_never_merge(slab_flags_t flags); +static inline slab_flags_t kasan_never_merge(slab_flags_t flags) +{ + if (kasan_enabled()) + return __kasan_never_merge(flags); + return flags; +} + +#else /* CONFIG_KASAN_HW_TAGS */ + static inline kasan_enabled(void) { return true; } -#endif + +static inline slab_flags_t kasan_never_merge(slab_flags_t flags) +{ + return flags; +} + +#endif /* CONFIG_KASAN_HW_TAGS */ void __kasan_alloc_pages(struct page *page, unsigned int order); static inline void kasan_alloc_pages(struct page *page, unsigned int order) @@ -240,6 +258,10 @@ static inline kasan_enabled(void) { return false; } +static inline slab_flags_t kasan_never_merge(slab_flags_t flags) +{ + return flags; +} static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} static inline void kasan_free_pages(struct page *page, unsigned int order) {} static inline void kasan_cache_create(struct kmem_cache *cache, diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 940b42231069..25b18c145b06 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -81,6 +81,17 @@ asmlinkage void kasan_unpoison_task_stack_below(const void *watermark) } #endif /* CONFIG_KASAN_STACK */ +/* + * Only allow cache merging when stack collection is disabled and no metadata + * is present. + */ +slab_flags_t __kasan_never_merge(slab_flags_t flags) +{ + if (kasan_stack_collection_enabled()) + return flags; + return flags & ~SLAB_KASAN; +} + void __kasan_alloc_pages(struct page *page, unsigned int order) { u8 tag; diff --git a/mm/slab_common.c b/mm/slab_common.c index f1b0c4a22f08..3042ee8ea9ce 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -49,12 +50,16 @@ static DECLARE_WORK(slab_caches_to_rcu_destroy_work, slab_caches_to_rcu_destroy_workfn); /* - * Set of flags that will prevent slab merging + * Set of flags that will prevent slab merging. + * Use slab_never_merge() instead. */ #define SLAB_NEVER_MERGE (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \ SLAB_TRACE | SLAB_TYPESAFE_BY_RCU | SLAB_NOLEAKTRACE | \ SLAB_FAILSLAB | SLAB_KASAN) +/* KASAN allows merging in some configurations and will remove SLAB_KASAN. */ +#define slab_never_merge() (kasan_never_merge(SLAB_NEVER_MERGE)) + #define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | \ SLAB_CACHE_DMA32 | SLAB_ACCOUNT) @@ -164,7 +169,7 @@ static unsigned int calculate_alignment(slab_flags_t flags, */ int slab_unmergeable(struct kmem_cache *s) { - if (slab_nomerge || (s->flags & SLAB_NEVER_MERGE)) + if (slab_nomerge || (s->flags & slab_never_merge())) return 1; if (s->ctor) @@ -198,7 +203,7 @@ struct kmem_cache *find_mergeable(unsigned int size, unsigned int align, size = ALIGN(size, align); flags = kmem_cache_flags(size, flags, name, NULL); - if (flags & SLAB_NEVER_MERGE) + if (flags & slab_never_merge()) return NULL; list_for_each_entry_reverse(s, &slab_caches, list) { From patchwork Tue Nov 10 22:20:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11895677 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 013D1138B for ; Tue, 10 Nov 2020 22:21:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8204E2074B for ; Tue, 10 Nov 2020 22:21: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="NtqZsgjs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8204E2074B 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 1C43C6B00B6; Tue, 10 Nov 2020 17:21:20 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 178B66B00B8; Tue, 10 Nov 2020 17:21:20 -0500 (EST) 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 EBEF76B00B9; Tue, 10 Nov 2020 17:21:19 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0106.hostedemail.com [216.40.44.106]) by kanga.kvack.org (Postfix) with ESMTP id AC2A66B00B6 for ; Tue, 10 Nov 2020 17:21:19 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 556C9180AD802 for ; Tue, 10 Nov 2020 22:21:19 +0000 (UTC) X-FDA: 77469930678.01.doll90_2c0dcea272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin01.hostedemail.com (Postfix) with ESMTP id 2FFF3100483E7 for ; Tue, 10 Nov 2020 22:21:19 +0000 (UTC) X-Spam-Summary: 1,0,0,48e8ec00edfb3e0c,d41d8cd98f00b204,3xrkrxwokcdiobrfsmybjzuccuzs.qcazwbil-aayjoqy.cfu@flex--andreyknvl.bounces.google.com,,RULES_HIT:4:41:69:152:355:379:541:800:960:966:967:973:982:988:989:1042:1260:1277:1313:1314:1345:1431:1437:1516:1518:1593:1594:1605:1730:1747:1777:1792:1801:2194:2196:2198:2199:2200:2201:2393:2525:2559:2565:2570:2639:2682:2685:2693:2703:2859:2892:2894:2901:2903:2918:2933:2937:2939:2942:2945:2947:2951:2954:3022:3152:3865:3866:3867:3868:3870:3871:3872:3874:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4385:4605:5007:6117:6119:6261:7875:7903:7904:8603:8660:8957:9025:9121:9969:10004:11658:12219:13148:13230:30056,0,RBL:209.85.160.201:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yfy8jiawnif4i5o5y6k5wnxi7qtocnixf5dzdpepm38s9txbg95ofjew9brj9.7oadepd97usy1rs5wcsqbfho34ensys4nwmojh9rrruqadfrh9xni3zi1nfghux.g-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,Do mainCach X-HE-Tag: doll90_2c0dcea272f8 X-Filterd-Recvd-Size: 16650 Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:21:18 +0000 (UTC) Received: by mail-qt1-f201.google.com with SMTP id w88so8555247qtd.4 for ; Tue, 10 Nov 2020 14:21:18 -0800 (PST) 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=hhAVeCS4JTcfsOdyr55ktLnnnel/q5W+4IYGph2ifVQ=; b=NtqZsgjsLakRDBLENq4QMY0X9HIgXySW03WWmgVqGyEYFqKXkjIr1dEai5KtjCKEW3 7K2btai6v2nhe+5GvDMjBlpzdb+L+gFrW0dsbOE3XONOKvcmOP84oxhz669e/Xv9pema AuFjujh/ijtNIT6DJ/yWdkkj6fZlw+UOPnNyLXJ48oiP2FBrAyyAJepdIaIb7X23kmcQ gGiLq8nwuid0DGkV9GC3ezMJdnVkK/gKzPZYVCyvbc7Uxuj45Uwy46M3IAVTYdpb/GQo RpYViBibwA69YuCVWHp62UdWt3CgA5Eym+yKlD5Ar4VDr7xMgH1UOG4msMzpsOHEPAHV n9nw== 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=hhAVeCS4JTcfsOdyr55ktLnnnel/q5W+4IYGph2ifVQ=; b=EJQYWf/2gKlbgd61kyUqPBwM1YTDgmqIhwhtnNM+Lz2vRs/2YJoQC5I+EyTu4R+8on SxCoiofQ1S7kw82zcV6Pum/w8jKmsDSL/nVbP+wRrJ3TO2fb5W07fhOtVrtO9jEXlPJD rdRFZqxRXIZQBg9FpDFy2D2+p+3ukEQ7yoH2Z9IOvqxcqOX4nqXYal45x1Bp73ubVFdz DKDOvQZpthy2YOPrp9oETw4CKByGoxsPvvs11BrG86SyBmD/wDNdSCKNKniwwgO7iXm0 qMgFc5Jb5WFlTfxkNNbf6L5yXwK4uVnnxU3iEEOdhilpF2yB78o61k+dqJ6S06cIXhng D72Q== X-Gm-Message-State: AOAM5300wC5Zerds87hHnkH33UrEyGN41/D4dO3QTKDVlUpUP7qpcW/5 FOkMESR5nb7YwMBCCqQbKL5Cq7HVG8ShigJ6 X-Google-Smtp-Source: ABdhPJxdW7ElRQssXr8ri/yytQPlY79pRGXXiR3orScqYpcHOLCE1EbY/q0D4TfAlEFaD8Q8q9+owBaUWU1bDOJV X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:4673:: with SMTP id z19mr9694086qvv.60.1605046877787; Tue, 10 Nov 2020 14:21:17 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:24 +0100 In-Reply-To: Message-Id: <6103d1aaacea96a94ca4632f78bcd801e4fbc9c4.1605046662.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 20/20] kasan: update documentation From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Evgenii Stepanov , Andrey Ryabinin , Branislav Rankov , Kevin Brodsky , Andrew Morton , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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 change updates KASAN documentation to reflect the addition of boot parameters and also reworks and clarifies some of the existing sections, in particular: defines what a memory granule is, mentions quarantine, makes Kunit section more readable. Signed-off-by: Andrey Konovalov --- Documentation/dev-tools/kasan.rst | 180 +++++++++++++++++++----------- 1 file changed, 113 insertions(+), 67 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index 422f8ee1bb17..f2da2b09e5c7 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -6,6 +6,7 @@ Overview KernelAddressSANitizer (KASAN) is a dynamic memory error detector designed to 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). @@ -39,23 +40,13 @@ 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 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. +while the hardware tag-based KASAN currently only support SLUB. + +For better error reports that include stack traces, enable CONFIG_STACKTRACE. To augment reports with last allocation and freeing stack of the physical page, it is recommended to enable also CONFIG_PAGE_OWNER and boot with page_owner=on. -To disable instrumentation for specific files or directories, add a line -similar to the following to the respective kernel Makefile: - -- For a single file (e.g. main.o):: - - KASAN_SANITIZE_main.o := n - -- For all files in one directory:: - - KASAN_SANITIZE := n - Error reports ~~~~~~~~~~~~~ @@ -140,16 +131,20 @@ freed (in case of a use-after-free bug report). Next comes a description of the accessed slab object and information about the accessed memory page. In the last section the report shows memory state around the accessed address. -Reading this part requires some understanding of how KASAN works. - -The state of each 8 aligned bytes of memory is encoded in one shadow byte. -Those 8 bytes can be accessible, partially accessible, freed or be a redzone. -We use the following encoding for each shadow byte: 0 means that all 8 bytes -of the corresponding memory region are accessible; number N (1 <= N <= 7) means -that the first N bytes are accessible, and other (8 - N) bytes are not; -any negative value indicates that the entire 8-byte word is inaccessible. -We use different negative values to distinguish between different kinds of -inaccessible memory like redzones or freed memory (see mm/kasan/kasan.h). +Internally KASAN tracks memory state separately for each memory granule, which +is either 8 or 16 aligned bytes depending on KASAN mode. Each number in the +memory state section of the report shows the state of one of the memory +granules that surround the accessed address. + +For generic KASAN the size of each memory granule is 8. The state of each +granule is encoded in one shadow byte. Those 8 bytes can be accessible, +partially accessible, freed or be a part of a redzone. KASAN uses the following +encoding for each shadow byte: 0 means that all 8 bytes of the corresponding +memory region are accessible; number N (1 <= N <= 7) means that the first N +bytes are accessible, and other (8 - N) bytes are not; any negative value +indicates that the entire 8-byte word is inaccessible. KASAN uses different +negative values to distinguish between different kinds of inaccessible memory +like redzones or freed memory (see mm/kasan/kasan.h). In the report above the arrows point to the shadow byte 03, which means that the accessed address is partially accessible. @@ -157,6 +152,55 @@ the accessed address is partially accessible. For tag-based KASAN this last report section shows the memory tags around the accessed address (see Implementation details section). +Boot parameters +~~~~~~~~~~~~~~~ + +Hardware tag-based KASAN mode (see the section about different mode below) is +intended for use in production as a security mitigation. Therefore it supports +boot parameters that allow to disable KASAN competely or otherwise control +particular KASAN features. + +The things that can be controlled are: + +1. Whether KASAN is enabled at all. +2. Whether KASAN collects and saves alloc/free stacks. +3. Whether KASAN panics on a detected bug or not. + +The ``kasam.mode`` boot parameter allows to choose one of three main modes: + +- ``kasan.mode=off`` - KASAN is disabled, no tag checks are performed +- ``kasan.mode=prod`` - only essential production features are enabled +- ``kasan.mode=full`` - all KASAN features are enabled + +The chosen mode provides default control values for the features mentioned +above. However it's also possible to override the default values by providing: + +- ``kasan.stacktrace=off`` or ``=on`` - enable alloc/free stack collection + (default: ``on`` for ``mode=full``, + otherwise ``off``) +- ``kasan.fault=report`` or ``=panic`` - only print KASAN report or also panic + (default: ``report``) + +If ``kasan.mode parameter`` is not provided, it defaults to ``full`` when +``CONFIG_DEBUG_KERNEL`` is enabled, and to ``prod`` otherwise. + +For developers +~~~~~~~~~~~~~~ + +Software KASAN modes use compiler instrumentation to insert validity checks. +Such instrumentation might be incompatible with some part of the kernel, and +therefore needs to be disabled. To disable instrumentation for specific files +or directories, add a line similar to the following to the respective kernel +Makefile: + +- For a single file (e.g. main.o):: + + KASAN_SANITIZE_main.o := n + +- For all files in one directory:: + + KASAN_SANITIZE := n + Implementation details ---------------------- @@ -164,10 +208,10 @@ Implementation details Generic KASAN ~~~~~~~~~~~~~ -From a high level, our approach to memory error detection is similar to that -of kmemcheck: use shadow memory to record whether each byte of memory is safe -to access, and use compile-time instrumentation to insert checks of shadow -memory on each memory access. +From a high level perspective, KASAN's approach to memory error detection is +similar to that of kmemcheck: use shadow memory to record whether each byte of +memory is safe to access, and use compile-time instrumentation to insert checks +of shadow memory on each memory access. Generic KASAN dedicates 1/8th of kernel memory to its shadow memory (e.g. 16TB to cover 128TB on x86_64) and uses direct mapping with a scale and offset to @@ -194,7 +238,10 @@ function calls GCC directly inserts the code to check the shadow memory. This option significantly enlarges kernel but it gives x1.1-x2 performance boost over outline instrumented kernel. -Generic KASAN prints up to 2 call_rcu() call stacks in reports, the last one +Generic KASAN is the only mode that delays the reuse of freed object via +quarantine (see mm/kasan/quarantine.c for implementation). + +Generic KASAN prints up to two call_rcu() call stacks in reports, the last one and the second to last. Software tag-based KASAN @@ -302,15 +349,15 @@ therefore be wasteful. Furthermore, to ensure that different mappings use different shadow pages, mappings would have to be aligned to ``KASAN_GRANULE_SIZE * PAGE_SIZE``. -Instead, we share backing space across multiple mappings. We allocate +Instead, KASAN shares backing space across multiple mappings. It allocates a backing page when a mapping in vmalloc space uses a particular page of the shadow region. This page can be shared by other vmalloc mappings later on. -We hook in to the vmap infrastructure to lazily clean up unused shadow +KASAN hooks in to the vmap infrastructure to lazily clean up unused shadow memory. -To avoid the difficulties around swapping mappings around, we expect +To avoid the difficulties around swapping mappings around, KASAN expects that the part of the shadow region that covers the vmalloc space will not be covered by the early shadow page, but will be left unmapped. This will require changes in arch-specific code. @@ -321,24 +368,31 @@ architectures that do not have a fixed module region. CONFIG_KASAN_KUNIT_TEST & CONFIG_TEST_KASAN_MODULE -------------------------------------------------- -``CONFIG_KASAN_KUNIT_TEST`` utilizes the KUnit Test Framework for testing. -This means each test focuses on a small unit of functionality and -there are a few ways these tests can be run. +KASAN tests consist on two parts: + +1. Tests that are integrated with the KUnit Test Framework. Enabled with +``CONFIG_KASAN_KUNIT_TEST``. These tests can be run and partially verified +automatically in a few different ways, see the instructions below. -Each test will print the KASAN report if an error is detected and then -print the number of the test and the status of the test: +2. Tests that are currently incompatible with Kunit. Enabled with +``CONFIG_TEST_KASAN_MODULE`` and can only be run as a module. These tests can +only be verified manually, by loading the kernel module and inspecting the +kernel log for KASAN reports. -pass:: +Each KUNIT-compatible KASAN test prints a KASAN report if an error is detected. +Then the test prints its number and status. + +When a test passes:: ok 28 - kmalloc_double_kzfree -or, if kmalloc failed:: +When a test fails due to a failed ``kmalloc``:: # kmalloc_large_oob_right: ASSERTION FAILED at lib/test_kasan.c:163 Expected ptr is not null, but is not ok 4 - kmalloc_large_oob_right -or, if a KASAN report was expected, but not found:: +When a test fails due to a missing KASAN report:: # kmalloc_double_kzfree: EXPECTATION FAILED at lib/test_kasan.c:629 Expected kasan_data->report_expected == kasan_data->report_found, but @@ -346,46 +400,38 @@ or, if a KASAN report was expected, but not found:: kasan_data->report_found == 0 not ok 28 - kmalloc_double_kzfree -All test statuses are tracked as they run and an overall status will -be printed at the end:: +At the end the cumulative status of all KASAN tests is printed. On success:: ok 1 - kasan -or:: +Or, if one of the tests failed:: not ok 1 - kasan -(1) Loadable Module -~~~~~~~~~~~~~~~~~~~~ + +There are a few ways to run Kunit-compatible KASAN tests. + +1. Loadable module +~~~~~~~~~~~~~~~~~~ With ``CONFIG_KUNIT`` enabled, ``CONFIG_KASAN_KUNIT_TEST`` can be built as -a loadable module and run on any architecture that supports KASAN -using something like insmod or modprobe. The module is called ``test_kasan``. +a loadable module and run on any architecture that supports KASAN by loading +the module with insmod or modprobe. The module is called ``test_kasan``. -(2) Built-In -~~~~~~~~~~~~~ +2. Built-In +~~~~~~~~~~~ With ``CONFIG_KUNIT`` built-in, ``CONFIG_KASAN_KUNIT_TEST`` can be built-in -on any architecure that supports KASAN. These and any other KUnit -tests enabled will run and print the results at boot as a late-init -call. +on any architecure that supports KASAN. These and any other KUnit tests enabled +will run and print the results at boot as a late-init call. -(3) Using kunit_tool -~~~~~~~~~~~~~~~~~~~~~ +3. Using kunit_tool +~~~~~~~~~~~~~~~~~~~ -With ``CONFIG_KUNIT`` and ``CONFIG_KASAN_KUNIT_TEST`` built-in, we can also -use kunit_tool to see the results of these along with other KUnit -tests in a more readable way. This will not print the KASAN reports -of tests that passed. Use `KUnit documentation `_ for more up-to-date -information on kunit_tool. +With ``CONFIG_KUNIT`` and ``CONFIG_KASAN_KUNIT_TEST`` built-in, it's also +possible use ``kunit_tool`` to see the results of these and other KUnit tests +in a more readable way. This will not print the KASAN reports of the tests that +passed. Use `KUnit documentation `_ +for more up-to-date information on ``kunit_tool``. .. _KUnit: https://www.kernel.org/doc/html/latest/dev-tools/kunit/index.html - -``CONFIG_TEST_KASAN_MODULE`` is a set of KASAN tests that could not be -converted to KUnit. These tests can be run only as a module with -``CONFIG_TEST_KASAN_MODULE`` built as a loadable module and -``CONFIG_KASAN`` built-in. The type of error expected and the -function being run is printed before the expression expected to give -an error. Then the error is printed, if found, and that test -should be interpretted to pass only if the error was the one expected -by the test.