From patchwork Mon Nov 23 20:14:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11929071 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=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,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 8DBD0C2D0E4 for ; Tue, 24 Nov 2020 13:50:39 +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 1A54120888 for ; Tue, 24 Nov 2020 13:50:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="YMIS76iH"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="iw9IgCY/"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="A+kpGAdD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1A54120888 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=Qxg4k3Uex81+y7F15RCoaRCope6PFeLXZ05asNkNe8I=; b=YMIS76iHSCout4hjfEst/vk/1 bXFlBrd3OW9upZ8FxR+YyDBVVE/D23YzwyAztyEsMjdVi7KGHCLO+rVHNabP0uge86O9zjb2TuvcO 5D6uAK6J5/D8kjO6SX47KyK1HSxqogPnzqAlQHY8HKq4NHyfJstmik/NLlWN7kCKsf45rAjnHSDHh gKScKD4ewrFuCLXWlMxyp+q1XuRKusdh9/JHYY6KljNw8wGj+KJtvwL62cOl1SQkw8sGp5LzwWu4q AdzgBqi3JeYmM2aerkzAs4D69ZNcloar5tDqU2uhL+DSugWXJV0j1ykHBNIqUZDc31m1WaK/urCEp qns4CjtWw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khYh9-0005dM-Ko; Tue, 24 Nov 2020 13:49:23 +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 1khIO9-0006KM-7A for linux-arm-kernel@merlin.infradead.org; Mon, 23 Nov 2020 20:24:41 +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=vCPSdYhuISEPMca4NzZzu0kqKTeEYaaZfMxe3jMvD/s=; b=iw9IgCY/sbFLc4cxpe3DV+DSkZ EIZ08ZvT84EFxQkOWQAXPdSmBrAnTiExQkecAQI6Wjs4ZbloLu35TbGklNv6XAUsJW3nBwPJjcEZG JQdQO6d729Rln5t0Uw/sP2DvCHect6rg3BkLdxKSdGws/e6iCyBUssIygeCU7gdS2vM2or/Ot6RXG 7/nhatchcu1SHQeNQvr4rulquRoZ5HQ6cFNfdwxEqGxsSUWoe7ZOvfeOQDFHNacIGIAkicBDD+VWr xph5H/emd+Hu+gbeiCFiZtYewKIk6eTvRsHkL1ZMk/kTv2nbnih/aSXqioiNGLBtnKPjmuET0cLQI E684oZPg==; Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIFC-0006Lz-Hh for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:30 +0000 Received: by mail-wr1-x44a.google.com with SMTP id x10so2158078wrs.2 for ; Mon, 23 Nov 2020 12:15:25 -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=vCPSdYhuISEPMca4NzZzu0kqKTeEYaaZfMxe3jMvD/s=; b=A+kpGAdDHR+xLc8BXfFeZuxuuUrerctxHRGgM41gvim7A7SXBS2BpSFAPSf5z+xzcE w6rQ703Pf9m4i65OsXJrLu449pBNv4pXNZeOvCOD8nzLXO3r5Zsa4nVbArsdgc4QZy/D ClV5Ear6f0SA4Jp/VjbffFIIf1cSZ6qO6dFN5ShhIVcvVxMoMbpLjthlfMNq75mF0WYA T7wypdNYQEmicmFseG6C87RZXk2XsHgsH8s1aqze4J+fIljx2mYVTU6+mkwSiOWQsfQD BnjTUyurg1MZW73nAmP1V+AeMyico/YJMF2zluj5MlPfXPwPp4qXLmUPA3Lavcv/PFIs URBQ== 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=vCPSdYhuISEPMca4NzZzu0kqKTeEYaaZfMxe3jMvD/s=; b=lVjvaMuEijpuXXnH86nD1OvU3N8slJivgy5vogYUo1LXImQbB/95f647DbjNzjYNJe Zrub0xP/zMoODB0Yf2HCCgvt7oUq8CmsO924EPHOiw7O0m3Bv0DJcf1AUho+v2DTpMxL 0bDcE7n7Ka6wX1YYNk2ERWfGdMDHSnGUsAbdefcpavhldGmix8PW1Uv9h65FzVHnofAb 9XwLWGl7qVwM3Ve/dfN+VNlIVpXDm7OjSG7PJsnvBcl/BpGt3MHa1Qh8VyqnHriUVEV/ GMH+x1qYCvFtmdMpWWJnhfKlG7V+enHkJhgrke5ffJ1Vg9cnvjfPwKMrbn4R7sclEMic E07w== X-Gm-Message-State: AOAM531Rv/xb3QDjjV1DwerPmC3plocEv8HsfYH5lx4CvEo7GLULqjmE mhNnOM15Eo5KrxWUtsCJg71w8V/xXESHrRQN X-Google-Smtp-Source: ABdhPJyImRIUxX0vdlPpQTNZOS8VnAdiwtBEG9ySXx3qFznfha0oetLY9Do8+WGjSwOiFt3ZSxe5XbJ3Qnga4at5 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:c343:: with SMTP id t64mr639600wmf.140.1606162524075; Mon, 23 Nov 2020 12:15:24 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:43 +0100 In-Reply-To: Message-Id: <141675fb493555e984c5dca555e9d9f768c7bbaa.1606162397.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 13/19] kasan, mm: rename kasan_poison_kfree From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_201526_915223_A71363AD X-CRM114-Status: GOOD ( 16.40 ) 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: linux-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Rename kasan_poison_kfree() to kasan_slab_free_mempool() as it better reflects what this annotation does. Also add a comment that explains the PageSlab() check. No functional changes. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver Link: https://linux-review.googlesource.com/id/I5026f87364e556b506ef1baee725144bb04b8810 --- include/linux/kasan.h | 16 ++++++++-------- mm/kasan/common.c | 40 +++++++++++++++++++++++----------------- mm/mempool.c | 2 +- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index f631f99aa4b4..2610438120ce 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -175,6 +175,13 @@ static __always_inline bool kasan_slab_free(struct kmem_cache *s, void *object, return false; } +void __kasan_slab_free_mempool(void *ptr, unsigned long ip); +static __always_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 __always_inline void * __must_check kasan_slab_alloc( @@ -215,13 +222,6 @@ static __always_inline void * __must_check kasan_krealloc(const void *object, return (void *)object; } -void __kasan_poison_kfree(void *ptr, unsigned long ip); -static __always_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 __always_inline void kasan_kfree_large(void *ptr, unsigned long ip) { @@ -260,6 +260,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) { @@ -279,7 +280,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 17918bd20ed9..1205faac90bd 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -335,6 +335,29 @@ 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); + + /* + * Even though this function is only called for kmem_cache_alloc and + * kmalloc backed mempool allocations, those allocations can still be + * !PageSlab() when the size provided to kmalloc is larger than + * KMALLOC_MAX_SIZE, and kmalloc falls back onto page_alloc. + */ + if (unlikely(!PageSlab(page))) { + if (ptr != page_address(page)) { + kasan_report_invalid_free(ptr, ip); + return; + } + poison_range(ptr, page_size(page), KASAN_FREE_PAGE); + } else { + ____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); @@ -429,23 +452,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); - - if (unlikely(!PageSlab(page))) { - if (ptr != page_address(page)) { - kasan_report_invalid_free(ptr, ip); - return; - } - poison_range(ptr, page_size(page), KASAN_FREE_PAGE); - } else { - ____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 583a9865b181..624ed51b060f 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); }