Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3988175pxt; Tue, 10 Aug 2021 16:52:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGm9WF5e9/dFAbsBoBvRg75gQLk/S4pTokstmrJOdlH2wA1KYbJMYI1KfLJKNbTzcP45ob X-Received: by 2002:a05:6402:b2a:: with SMTP id bo10mr7855062edb.215.1628639521433; Tue, 10 Aug 2021 16:52:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628639521; cv=none; d=google.com; s=arc-20160816; b=wAcAcA9BOMywHl61l/NcAmvFuXTvpr6VGYCSvvwuL82W/QGVOxCT3Lnb+VLnnVOIrH zca4FuOLRcdRabWcY5Qa6rSWGlABDGtZta3j6p3aiX9JFwpuM5bX9Qu10lpXCA/zU8vn l6g6aDAURyiWn4Yul+LMUeqr+SUZj72wtZ9SVtFhAkymhzFdZ0y4JgcgDWcMTZEHLGGM WbZVv/uJQOATMOpZrCRoAbXHOn43OCIvwgtBtJvGima6ewhVo7yLgMKc80/EA0lEsj9R 6jvcx8k/7B4ghCiNfkmLzTw8fBI34Bu9LlSMIvXHFwytf2P3cS9GtFqwheHLIXHObqRq IrNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ggLsS7yz1kOGaLQ3EmXt3GWbT2jgyKyTzpDsbhnW9U4=; b=NL73HSFNya8osdzsCcIj60k68ey0owmWKu/dB3pXbnqeHCbDPqEbd9XznVZs129FrA QVMOf4OsFnBH7BmtvjxhutvR0/ACnL4XZMQuBPlOPKAP0MDty25EC7Q6MtsOBzvK0lBq PhMb+ebRrSZQkx/Ub19tup3Dio6ar7RrjHcsQVUB/iHkLewm+57ryPIe3EQiwGNxhHCn fJmUb1D/psM0B1nQ1dH/xS/MMxE2+TcxtYQA4SYFA7pihh8rS4Afy3U/4F/p7NEn/jb+ iSqyGlFxd3/qCNyVMxUX1p5bsHXPehwOsVy8FisI0Hn67wwo7PR31UyZHAoarJwTUBxw DeLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=XF1pS+k7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y15si7425916edu.593.2021.08.10.16.51.37; Tue, 10 Aug 2021 16:52:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=XF1pS+k7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235592AbhHJXrg (ORCPT + 99 others); Tue, 10 Aug 2021 19:47:36 -0400 Received: from out0.migadu.com ([94.23.1.103]:39516 "EHLO out0.migadu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235501AbhHJXrf (ORCPT ); Tue, 10 Aug 2021 19:47:35 -0400 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 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: andrey.konovalov@linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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_); -- 2.25.1