From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B54DC48BCF for ; Sat, 12 Jun 2021 15:51:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6CE73610FC for ; Sat, 12 Jun 2021 15:51:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6CE73610FC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C3D976B006C; Sat, 12 Jun 2021 11:51:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BEE406B006E; Sat, 12 Jun 2021 11:51:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A410F6B0070; Sat, 12 Jun 2021 11:51:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0214.hostedemail.com [216.40.44.214]) by kanga.kvack.org (Postfix) with ESMTP id 7291F6B006C for ; Sat, 12 Jun 2021 11:51:19 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0A506DDFB for ; Sat, 12 Jun 2021 15:51:19 +0000 (UTC) X-FDA: 78245511078.14.C3E1365 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by imf03.hostedemail.com (Postfix) with ESMTP id 9BA60C0042C0 for ; Sat, 12 Jun 2021 15:51:11 +0000 (UTC) Received: by mail-pg1-f172.google.com with SMTP id t9so5013162pgn.4 for ; Sat, 12 Jun 2021 08:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=13vDzbI957CXDNEDtcZR2S0juOb9uGtVIdJ1VlmUGxM=; b=lSSHhbMP8v2VoHlvUXfUyX1msYdK7i2l/zphFT4PyuG6HNDDYT7KiMHSr+ZKTXJ+ZD Ndi49LNJchotWTey+CTKsNH85bVpK8k9wwDCVzktEJ5RWA24oh9JeD30R43ZCcvGWpKY x1qazk4LiLegvrSvt4spLvV21NcAvab+bFblAOe//kPF88REVhEasBVmTMO93jr4Vpo0 Jkloz2JkdajqyvQCapu54ifOePJx4ip0XezVq6XDZdi2xwBboQsmuvTWRBHWGz4f/Ioi IR0cAtU1T0if8ElcFdCsCRSY9v9AlPk/8h/oYlQhDLAv9yOpIa2OdDnsQA+NGF3Gif6A OHhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=13vDzbI957CXDNEDtcZR2S0juOb9uGtVIdJ1VlmUGxM=; b=cWeTfVdEm2ByqH8bGkL7sgdwMz5KZ7tZJMIoFs4/m7ZW4s6Gf//HmqygqTY01j9xCF I73irpHfaqUNgGOenkpbzasyt4o2LEamf38rJgPD8bmgRWvDnPFSnApmt2DG/tRd0S34 tr4vP2KA9GJPfgjfBYmAR4nH+Cm1Ib6PmEhOgyOc7ARE+hhT4ToiJuZDFHuCPerE/Cet T0KXJLr10+C87cyQqRerlJBkxTr7E9A7cjHK8eGtIH2NB3wO6ZZuKviu8aQAREBpdyQZ A1lnYx2JBgxBO9iC/wvUXVVeND9lq4Z5r/wmiYqSuO/S4BlvAmSzyzYcZUNpJ8kM50OM tQVQ== X-Gm-Message-State: AOAM531mHEwPFqDwPISd5RIYZLaQ6MIRSgHbFYfMnur+mRUhjA/g+uFV /uAUbxxk19tVUY+AALvCrgQ= X-Google-Smtp-Source: ABdhPJxeofGXExwLsfdM4964kd2TTSRR4vEi6CmJptlxHOf0tP4ANhG+X8CoDPWU3VZL6Nwlpi+b3g== X-Received: by 2002:a63:b043:: with SMTP id z3mr9161280pgo.89.1623513077639; Sat, 12 Jun 2021 08:51:17 -0700 (PDT) Received: from DESKTOP-PJLD54P.localdomain (122-116-74-98.HINET-IP.hinet.net. [122.116.74.98]) by smtp.gmail.com with ESMTPSA id t19sm12891513pjq.44.2021.06.12.08.51.14 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 12 Jun 2021 08:51:17 -0700 (PDT) Date: Sat, 12 Jun 2021 23:51:08 +0800 From: Kuan-Ying Lee To: Marco Elver Cc: Greg Kroah-Hartman , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Andrew Morton , kasan-dev , LKML , Linux Memory Management List Subject: Re: [PATCH v2 2/3] kasan: integrate the common part of two KASAN tag-based modes Message-ID: <20210612155108.GA68@DESKTOP-PJLD54P.localdomain> References: <20210612045156.44763-1-kylee0686026@gmail.com> <20210612045156.44763-3-kylee0686026@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=lSSHhbMP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of kylee0686026@gmail.com designates 209.85.215.172 as permitted sender) smtp.mailfrom=kylee0686026@gmail.com X-Rspamd-Server: rspam02 X-Stat-Signature: mzhgbrdffxe8qa73s1btrj1o3tywts5m X-Rspamd-Queue-Id: 9BA60C0042C0 X-HE-Tag: 1623513071-753616 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: On Sat, Jun 12, 2021 at 04:42:44PM +0200, Marco Elver wrote: > On Sat, 12 Jun 2021 at 06:52, Kuan-Ying Lee wrote: > > 1. Move kasan_get_free_track() and kasan_set_free_info() > > into tags.c > > 2. Move kasan_get_bug_type() to header file > > > > Signed-off-by: Kuan-Ying Lee > > Suggested-by: Marco Elver > > Cc: Andrey Ryabinin > > Cc: Alexander Potapenko > > Cc: Andrey Konovalov > > Cc: Dmitry Vyukov > > Cc: Andrew Morton > > --- > > mm/kasan/Makefile | 4 +-- > > mm/kasan/hw_tags.c | 22 --------------- > > mm/kasan/report_hw_tags.c | 6 +--- > > mm/kasan/report_sw_tags.c | 46 +------------------------------ > > mm/kasan/report_tags.h | 56 +++++++++++++++++++++++++++++++++++++ > > mm/kasan/sw_tags.c | 41 --------------------------- > > mm/kasan/tags.c | 58 +++++++++++++++++++++++++++++++++++++++ > > 7 files changed, 118 insertions(+), 115 deletions(-) > > create mode 100644 mm/kasan/report_tags.h > > create mode 100644 mm/kasan/tags.c > [...] > > diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c > > index ed5e5b833d61..4ea8c368b5b8 100644 > > --- a/mm/kasan/hw_tags.c > > +++ b/mm/kasan/hw_tags.c > > @@ -216,28 +216,6 @@ void __init kasan_init_hw_tags(void) > > pr_info("KernelAddressSanitizer initialized\n"); > > } > > > > -void kasan_set_free_info(struct kmem_cache *cache, > > - void *object, u8 tag) > > -{ > > - struct kasan_alloc_meta *alloc_meta; > > - > > - alloc_meta = kasan_get_alloc_meta(cache, object); > > - if (alloc_meta) > > - kasan_set_track(&alloc_meta->free_track[0], GFP_NOWAIT); > > -} > > - > > -struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, > > - void *object, u8 tag) > > -{ > > - struct kasan_alloc_meta *alloc_meta; > > - > > - alloc_meta = kasan_get_alloc_meta(cache, object); > > - if (!alloc_meta) > > - return NULL; > > - > > - return &alloc_meta->free_track[0]; > > -} > > - > > void kasan_alloc_pages(struct page *page, unsigned int order, gfp_t flags) > > { > > /* > > diff --git a/mm/kasan/report_hw_tags.c b/mm/kasan/report_hw_tags.c > > index 42b2168755d6..ef5e7378f3aa 100644 > > --- a/mm/kasan/report_hw_tags.c > > +++ b/mm/kasan/report_hw_tags.c > > @@ -14,11 +14,7 @@ > > #include > > > > #include "kasan.h" > > - > > -const char *kasan_get_bug_type(struct kasan_access_info *info) > > -{ > > - return "invalid-access"; > > -} > > +#include "report_tags.h" > > > > void *kasan_find_first_bad_addr(void *addr, size_t size) > > { > > diff --git a/mm/kasan/report_sw_tags.c b/mm/kasan/report_sw_tags.c > > index 821a14a19a92..d965a170083e 100644 > > --- a/mm/kasan/report_sw_tags.c > > +++ b/mm/kasan/report_sw_tags.c > > @@ -26,51 +26,7 @@ > > > > #include > > > > -#include "kasan.h" > > -#include "../slab.h" > > - > > -const char *kasan_get_bug_type(struct kasan_access_info *info) > > -{ > > -#ifdef CONFIG_KASAN_TAGS_IDENTIFY > > - struct kasan_alloc_meta *alloc_meta; > > - struct kmem_cache *cache; > > - struct page *page; > > - const void *addr; > > - void *object; > > - u8 tag; > > - int i; > > - > > - tag = get_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; > > - object = nearest_obj(cache, page, (void *)addr); > > - alloc_meta = kasan_get_alloc_meta(cache, object); > > - > > - 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"; > > - } > > - > > -#endif > > - /* > > - * If access_size is a negative number, then it has reason to be > > - * defined as out-of-bounds bug type. > > - * > > - * Casting negative numbers to size_t would indeed turn up as > > - * a large size_t and its value will be larger than ULONG_MAX/2, > > - * so that this can qualify as out-of-bounds. > > - */ > > - if (info->access_addr + info->access_size < info->access_addr) > > - return "out-of-bounds"; > > - > > - return "invalid-access"; > > -} > > +#include "report_tags.h" > > > > void *kasan_find_first_bad_addr(void *addr, size_t size) > > { > > diff --git a/mm/kasan/report_tags.h b/mm/kasan/report_tags.h > > new file mode 100644 > > index 000000000000..4f740d4d99ee > > --- /dev/null > > +++ b/mm/kasan/report_tags.h > > @@ -0,0 +1,56 @@ > > +/* SPDX-License-Identifier: GPL-2.0 */ > > +#ifndef __MM_KASAN_REPORT_TAGS_H > > +#define __MM_KASAN_REPORT_TAGS_H > > + > > +#include "kasan.h" > > +#include "../slab.h" > > + > > +#ifdef CONFIG_KASAN_TAGS_IDENTIFY > > +const char *kasan_get_bug_type(struct kasan_access_info *info) > > +{ > [...] > > + /* > > + * If access_size is a negative number, then it has reason to be > > + * defined as out-of-bounds bug type. > > + * > > + * Casting negative numbers to size_t would indeed turn up as > > + * a large size_t and its value will be larger than ULONG_MAX/2, > > + * so that this can qualify as out-of-bounds. > > + */ > > + if (info->access_addr + info->access_size < info->access_addr) > > + return "out-of-bounds"; > > This seems to change behaviour for SW_TAGS because it was there even > if !CONFIG_KASAN_TAGS_IDENTIFY. Does it still work as before? > You are right. It will change the behavior. However, I think that if !CONFIG_KASAN_TAG_IDENTIFY, it should be reported "invalid-access". Or is it better to keep it in both conditions? > > + > > + return "invalid-access"; > > +} > > +#else > > +const char *kasan_get_bug_type(struct kasan_access_info *info) > > +{ > > + return "invalid-access"; > > +} > > +#endif > > + > > +#endif > > diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c > > index dd05e6c801fa..bd3f540feb47 100644 > > --- a/mm/kasan/sw_tags.c > > +++ b/mm/kasan/sw_tags.c > > @@ -167,47 +167,6 @@ void __hwasan_tag_memory(unsigned long addr, u8 tag, unsigned long size) > > } > > EXPORT_SYMBOL(__hwasan_tag_memory); > > > > -void kasan_set_free_info(struct kmem_cache *cache, > > - void *object, u8 tag) > > -{ > > - struct kasan_alloc_meta *alloc_meta; > > - u8 idx = 0; > > - > > - alloc_meta = kasan_get_alloc_meta(cache, object); > > - if (!alloc_meta) > > - return; > > - > > -#ifdef CONFIG_KASAN_TAGS_IDENTIFY > > - idx = alloc_meta->free_track_idx; > > - alloc_meta->free_pointer_tag[idx] = tag; > > - alloc_meta->free_track_idx = (idx + 1) % KASAN_NR_FREE_STACKS; > > -#endif > > - > > - kasan_set_track(&alloc_meta->free_track[idx], GFP_NOWAIT); > > -} > > - > > -struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, > > - void *object, u8 tag) > > -{ > > - struct kasan_alloc_meta *alloc_meta; > > - int i = 0; > > - > > - alloc_meta = kasan_get_alloc_meta(cache, object); > > - if (!alloc_meta) > > - return NULL; > > - > > -#ifdef CONFIG_KASAN_TAGS_IDENTIFY > > - for (i = 0; i < KASAN_NR_FREE_STACKS; i++) { > > - if (alloc_meta->free_pointer_tag[i] == tag) > > - break; > > - } > > - if (i == KASAN_NR_FREE_STACKS) > > - i = alloc_meta->free_track_idx; > > -#endif > > - > > - return &alloc_meta->free_track[i]; > > -} > > - > > void kasan_tag_mismatch(unsigned long addr, unsigned long access_info, > > unsigned long ret_ip) > > { > > diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c > > new file mode 100644 > > index 000000000000..9c33c0ebe1d1 > > --- /dev/null > > +++ b/mm/kasan/tags.c > > @@ -0,0 +1,58 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * This file contains common tag-based KASAN code. > > + * > > + * Author: Kuan-Ying Lee > > We appreciate your work on this, but this is misleading. Because you > merely copied/moved the code, have a look what sw_tags.c says -- that > should either be preserved, or we add nothing here. > > I prefer to add nothing or the bare minimum (e.g. if the company > requires a Copyright line) for non-substantial additions because this > stuff becomes out-of-date fast and just isn't useful at all. 'git log' > is the source of truth. This was my first time to upload a new file. Thanks for the suggestions. :) I will remove this author tag and wait for Greg's process advice. > > Cc'ing Greg for process advice. For moved code, does it have to > preserve the original Copyright line if there was one? > > Thanks, > -- Marco