From patchwork Tue Aug 10 23:46:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 12429615 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=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 0F79EC4338F for ; Tue, 10 Aug 2021 23:47:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8A2CB60FDA for ; Tue, 10 Aug 2021 23:47:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8A2CB60FDA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.dev Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id BF76A6B0071; Tue, 10 Aug 2021 19:47:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B810B6B0072; Tue, 10 Aug 2021 19:47:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A48888D0001; Tue, 10 Aug 2021 19:47:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0224.hostedemail.com [216.40.44.224]) by kanga.kvack.org (Postfix) with ESMTP id 8761C6B0071 for ; Tue, 10 Aug 2021 19:47:14 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2E3E522022 for ; Tue, 10 Aug 2021 23:47:14 +0000 (UTC) X-FDA: 78460809588.09.F455E84 Received: from out0.migadu.com (out0.migadu.com [94.23.1.103]) by imf29.hostedemail.com (Postfix) with ESMTP id B1E279008028 for ; Tue, 10 Aug 2021 23:47:12 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1628639230; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=ggLsS7yz1kOGaLQ3EmXt3GWbT2jgyKyTzpDsbhnW9U4=; b=XF1pS+k7eSAhin5XDAOYUApD2tBQV4RDKbjbW1fjqU0v4YgDWcMTfYtDbNECo7qgjvtZsb uziWUrqbgMq/hZ9QxNRhy0NqyBNmGUBmIIyrXKZlI1wQhyrFWbuLmYX+deUY6XjBlqwKyr NYaeoKy+xnNjW+8GQiqMsYedV9TPRps= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Shakeel Butt Subject: [PATCH] mm/slub, kasan: fix checking page_alloc allocations on free Date: Wed, 11 Aug 2021 01:46:51 +0200 Message-Id: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: andrey.konovalov@linux.dev Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=XF1pS+k7; spf=pass (imf29.hostedemail.com: domain of andrey.konovalov@linux.dev designates 94.23.1.103 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: B1E279008028 X-Stat-Signature: qsiujbtgq3p9jngbiq3m9h688motrjbc X-HE-Tag: 1628639232-560202 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov A fix for stat counters f227f0faf63b ("slub: fix unreclaimable slab stat for bulk free") used page_address(page) as kfree_hook() argument instead of object. While the change is technically correct, it breaks KASAN's ability to detect improper (unaligned) pointers passed to kfree() and causes the kmalloc_pagealloc_invalid_free test to fail. This patch changes free_nonslab_page() to pass object to kfree_hook() instead of page_address(page) as it was before the fix. Fixed: f227f0faf63b ("slub: fix unreclaimable slab stat for bulk free") Signed-off-by: Andrey Konovalov --- mm/slub.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/slub.c b/mm/slub.c index af984e4990e8..56079dd33c74 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -3236,12 +3236,12 @@ struct detached_freelist { struct kmem_cache *s; }; -static inline void free_nonslab_page(struct page *page) +static inline void free_nonslab_page(void *object, struct page *page) { unsigned int order = compound_order(page); VM_BUG_ON_PAGE(!PageCompound(page), page); - kfree_hook(page_address(page)); + kfree_hook(object); mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B, -(PAGE_SIZE << order)); __free_pages(page, order); } @@ -3282,7 +3282,7 @@ int build_detached_freelist(struct kmem_cache *s, size_t size, if (!s) { /* Handle kalloc'ed objects */ if (unlikely(!PageSlab(page))) { - free_nonslab_page(page); + free_nonslab_page(object, page); p[size] = NULL; /* mark object processed */ return size; } @@ -4258,7 +4258,7 @@ void kfree(const void *x) page = virt_to_head_page(x); if (unlikely(!PageSlab(page))) { - free_nonslab_page(page); + free_nonslab_page(object, page); return; } slab_free(page->slab_cache, page, object, NULL, 1, _RET_IP_);