From patchwork Thu Nov 5 00:02: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: 11883277 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=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 67229C00A89 for ; Thu, 5 Nov 2020 05:16:07 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E223C2083B for ; Thu, 5 Nov 2020 05:16:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LxkULcBW"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="T1Qe8AH1"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="DWEvy7mM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E223C2083B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=q6KLPBcKUHPYR8Gx5ufaJ402QCKzjSG6/CaFneiAM20=; b=LxkULcBWvaHsYuZZWW2kwtwhD Oyl7vpoQ+XvZs2k/NHwqNuRMXWz/2lGV3hz1f+/FnRydeymO8dTrerzMbhMSK8Ob5HBEloIGsh084 JKKoO7xufE4BbZPxYT76Hg9uR0Nsa2f6oERuIMjaE4MP5BFTsAEo7LfdgDrvAnxVLnE/fWu/hsALy 0q2oLgwSWCJtyff31AzMxx8R9qCBs5CW5YgMapUdVY8vtYssQMV0j3lGLtmUy8zsh1YNM9NQ1lGzj z9UgybZ+mCWk97Rof5I04YugWbIhWWPcIdzh7bKXgi/ChJJZmnzSJhE0UkmUVzICiNCX5p/BuS9Yo ufIumfv0A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXcC-0000dS-Ee; Thu, 05 Nov 2020 05:15:16 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW3q-00016k-Pw for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:35:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=TVZ5KfDqV4sczuDDUV9gNsUWnBSctv8RhcIj1oMqFVo=; b=T1Qe8AH1OMF1S6rzPVhKcJK0/J R8PXYGTlf93trtIZ38ZiuM+MNfE8gLn5K74JFE+SRyHpB5Efcf53FZbbuCwgU3YIAnfW4LkfyOfSz Fykj9fL3qQNAufz/4jqRtCGEhlphpns0JTJES/jjFZ4B9qtbiRRrE6FaL0NmE2SyezcipfPXDF8+U kC1RjNnfoXbgKCZoXds+GVETqpD9XRSUzA8xXwybwQuX4pASTiwrXMYlS45pMDBN3bPUKxEyb07Xs OQgo8VY2xqddNXseT3sQXf8HPwKMiIC25/DdIg9RbqNYEiwgA+voST3tJgybetUpf215gL6GaI2Pp t5ZIVZtQ==; Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaSky-0000qO-IM for linux-arm-kernel@lists.infradead.org; Thu, 05 Nov 2020 00:04:03 +0000 Received: by mail-wm1-x34a.google.com with SMTP id c10so469wmh.6 for ; Wed, 04 Nov 2020 16:04: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=TVZ5KfDqV4sczuDDUV9gNsUWnBSctv8RhcIj1oMqFVo=; b=DWEvy7mMEfr+/axjvw6t2VjDZPS+lO0xs+0DiZYZF+nJ/ZsK5Vhqm1kX0FdXvUY7yG 7jCjsxmBJd4av9dmmVxOp0gRjRs2QCY5L3otIaMyH7pQ4nKoFxVscyQ9krNdoXU0alvh DhuBuZL5pei0BWn8T0hoN4WkbQNcs3/Rb0i/xpksyeduhrc5PXjjCgF0P/3A4mmuVE7V Gazmv0f/MfckBnt0ufqq6PUfKCFQTkU73BJsVkhUSWBmR1xBSsc52x/QycRA9GeNSXQZ hS0WV28RuFuQLkl6WpqfqAT0/gIyIKYt0um0SMwnhJGYhi5Qc34vqM0lhPtMDl383/Em hqXw== 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=TVZ5KfDqV4sczuDDUV9gNsUWnBSctv8RhcIj1oMqFVo=; b=Z7E3tXejE8p106Ue+uUissszpndtmTkRpCDqP0UJOapEma5LEPTyBojxdtrqGRITIY am/K5b8iV9A1cX+qdTb59wwgHcXIAnezKTlJw3HUV1KrJcKoh99Y1hCb+jPfGtOmJ8rS u+07aTOX6K3octYmDehT+8QqgPtxv+Nl95Ddo9F8eDU7Yfy+5C/zCU2f/fZrhpewOd6K VE34p9jYaRjFFpn904GLfo62YzidrbG8MFm0/6FRPjiIzgVAGFw3c/Stw2ZfAjM00VZf B56H36/KJWR/5GONi0RlbvWGGWVb0G/1E263L4aQhpLUu3Dyb7COJebJSt5nrbyBa1df xdIw== X-Gm-Message-State: AOAM5309p21+BmCnugYynR4Jg+8qR+vZYg8XIR9jpWJ0yNmZ8SWSAlfZ fYpoZmIJ0LMdnV6fGyc5X5yeEANthWultVAs X-Google-Smtp-Source: ABdhPJzWht9sgT8VGHbs3poE0UdD+kavb+Z/NCfdyaj2htoI0/JLAcuZvn5uAHlVsbj+IJFNKhvHkMoibdhWjIwx X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:4d05:: with SMTP id o5mr23559wmh.94.1604534576841; Wed, 04 Nov 2020 16:02:56 -0800 (PST) Date: Thu, 5 Nov 2020 01:02:19 +0100 In-Reply-To: Message-Id: <7a831f5b5876f468545d637775d5440d49d31400.1604534322.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH 09/20] kasan: inline kasan_poison_memory and check_invalid_free From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Marco Elver X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201105_000400_754550_9B7E15A5 X-CRM114-Status: GOOD ( 11.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Branislav Rankov , Andrey Konovalov , Kevin Brodsky , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Andrey Ryabinin , Andrew Morton , Evgenii Stepanov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- 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 d5824530fd15..9d7b1f1a2553 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -26,27 +26,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 d7a03eab5814..73364acf6ec8 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); @@ -275,6 +271,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.