From patchwork Mon Jul 29 18:19:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rik van Riel X-Patchwork-Id: 13745570 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57560C3DA61 for ; Mon, 29 Jul 2024 18:22:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A8D126B0095; Mon, 29 Jul 2024 14:22:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A3D2B6B0096; Mon, 29 Jul 2024 14:22:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92B536B0098; Mon, 29 Jul 2024 14:22:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 73DFF6B0095 for ; Mon, 29 Jul 2024 14:22:20 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E037D1C1BC6 for ; Mon, 29 Jul 2024 18:22:19 +0000 (UTC) X-FDA: 82393609998.04.075D64A Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) by imf04.hostedemail.com (Postfix) with ESMTP id 402BC40009 for ; Mon, 29 Jul 2024 18:22:17 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722277310; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=1jv0Yfvz9IAnSWlJLHXlUo40J5paVUUfceTFeHalVCs=; b=iaKYa7qwXrW1trnthKke0lXgLagARUoI7j03bIdpG64aIi5JJ9KDn5T2yWroGShsw5Gs2E y3dgNCcob3YH5hyT2N7F1S98xldpYzM1BVf8Gcj2G+dVzQrvi4nTpzDCPBKhBBqNyAUa34 deXwrPYj6eqGKRnnYZJ7qcWPTEBHagA= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of riel@shelob.surriel.com designates 96.67.55.147 as permitted sender) smtp.mailfrom=riel@shelob.surriel.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722277310; a=rsa-sha256; cv=none; b=crnWbPKc27xuLGQmW+40llj3Z2FbawuzFRgCG4ViH1+lRhM8udblHciv6HaEsxMIOKrELs wWiPvwvJE3HNB6FhB8L8HcbonqGuVTzCMFjoNd8X61VjpWnVKYmr878r2TMKQ9gnekKcVH hfcie1fZy9uCBwfWwlqtb1gphBSajrM= Received: from [2601:18c:9101:a8b6:6e0b:84ff:fee2:98bb] (helo=imladris.surriel.com) by shelob.surriel.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.97.1) (envelope-from ) id 1sYUy1-000000002Aa-1F2I; Mon, 29 Jul 2024 14:19:29 -0400 Date: Mon, 29 Jul 2024 14:19:28 -0400 From: Rik van Riel To: clm@meta.com Cc: Pekka Enberg , Christoph Lameter , Andrew Morton , Vlastimil Babka , kernel-team@meta.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Joonsoo Kim , David Rientjes Subject: [PATCH] mm,slub: do not call do_slab_free for kfence object Message-ID: <20240729141928.4545a093@imladris.surriel.com> X-Mailer: Claws Mail 4.3.0 (GTK 3.24.41; x86_64-redhat-linux-gnu) MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 402BC40009 X-Stat-Signature: 5och65mzrz3tc1r8xj3bfef5m6desspi X-HE-Tag: 1722277337-121684 X-HE-Meta: U2FsdGVkX19l//F3muUxMOd60hW2CibwZzzRG6QA7IQNrdLhZGLCZvLpzr0MtTNgRaEZYTd4mDMXDLQ8hNolIC097BtynfSSrliduPYMjBs+UeWWfysIH/+aMnVWCJnhKRMGhhkh68IhQohT8vqgkV/JZPqGi6KfemRSrzhOAw4MeuPyhGc2CeiEQcrALOUsqPN852CyHK1g5jBDaqgBBuIjM7nLuvsl59iq/a09wIB4y+oTpo8SrdLInaxSLzQJpidU4i8YuMh9beWYqNGitrbdYixlnHfZjGxFA8yG1bLaPsk3C9WcGbVIf3DIiWYcaqRb+D3DLnpTAZTbtj0a7R0QJ3CreWAET+9UO7Dt220/4/GkDybvpWz5HSKbWcChj/pL9cq7rqT+uRymis0t7YnB5pLoWbm2PpcL0CEnCmriGFtPUazt6khI9udEK9gKEGuB3hGOsoyqu+fw7wvPArXz7K52o/mgYrBT9wdPO9WgrYi+pjV0F+m6tldnutfuTMj5tnts6qEeWHW/Rvp2ukU1qO9Kdcnvy9c2Aa4eD+0H5rz3Lx1veNPLj7rxWuJVxgACabHWxrSJfhFTBhtnG+Pp+7LzjjX4we8ryNBqZJopP1ofFoAsnYPSm/9tNuL4yjKrk6T+QzdW6FTCK9nzjtaWoHEa87RCOHfqDxMkdNnjJY4CHfWjQLz3stapIueGb4XiVpOasg7CMuIYtOTmeUvKgcJg6WRz65gzbJz2dmsXIhNj7zNUmNv276L3JUlox4saQqkUnEC8BItLk0Xmyq47S1wF8TM8otAAvC2RcU5RukWrqr+uE/S5aKvR70Z2drp2lkf46NMUDhl+YDgxUF+mPiNln8Xnm5U51+Rl029xT7PN/tXBoAWLQ/M76KgNdBRIRk2hd8OG8ngIY1M3eG88DKXiHzLLzxKdDi48C5qoe08oVU44w8Crpl1kW+4fXb64J+VpOJ5rxVl3fkj h2qyoxjP 37EciMcF5FYCLd6C8BAzO9WJi6RuFxJFD6fycGtMVRlAneGvFCmePHHGILM7LpjwFELFZsi87aoIQi4H7y4CCbfrkfo+lqnRAEAlwsG4lS6Il+DoWj1Nku234cYuiCvksfrDDeZDY9PE/kXiQki4RpItQuGs8kThOxZ/4N/sHywhWmX27hIFDSIcy5xPhFB0GeXt56uTSb+EsOjFkg+36ccPjX+n/m2Qyj5J5u+cFVKvUvlEOTVD6qGnrpYzxB4PXOrFHDCQolB7ZlxYANDViMywgGQHLaP94PrON0ZTeub/55FUSVJcR92DaYs6wOmFy/tcbHu8utLmOopwdwyDmeY6rWgQVL0vr88Xa5q5cWl9xtdROJZrV5/nmfb3eoeLQjRqMOmlgDu6aX6Q09fIERNTT9Hhy62OxlM37CQOJdys4jxmqbAOrHMUcjvLU1LIZnEZz6sg5VPyHPMiep10runbrUeL0ELtP22Ky9A3fck0O/V8ZYo/PcjWUFcwYr1tRkw1ujlev/xKIfKY= 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: List-Subscribe: List-Unsubscribe: In 782f8906f805 the freeing of kfence objects was moved from deep inside do_free_slab to the wrapper functions outside. This is a nice change, but unfortunately it missed one spot in __kmem_cache_free_bulk. This results in a crash like this: BUG skbuff_head_cache (Tainted: G S B E ): Padding overwritten. 0xffff88907fea0f00-0xffff88907fea0fff @offset=3840 slab_err (mm/slub.c:1129) free_to_partial_list (mm/slub.c:? mm/slub.c:4036) slab_pad_check (mm/slub.c:864 mm/slub.c:1290) check_slab (mm/slub.c:?) free_to_partial_list (mm/slub.c:3171 mm/slub.c:4036) kmem_cache_alloc_bulk (mm/slub.c:? mm/slub.c:4495 mm/slub.c:4586 mm/slub.c:4635) napi_build_skb (net/core/skbuff.c:348 net/core/skbuff.c:527 net/core/skbuff.c:549) All the other callers to do_free_slab appear to be ok. Add a kfence_free check in __kmem_cache_free_bulk to avoid the crash. Reported-by: Chris Mason Fixes: 782f8906f805 ("mm/slub: free KFENCE objects in slab_free_hook()") Cc: stable@kernel.org Signed-off-by: Rik van Riel --- mm/slub.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/slub.c b/mm/slub.c index 3520acaf9afa..c9d8a2497fd6 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -4690,6 +4690,9 @@ static void __kmem_cache_free_bulk(struct kmem_cache *s, size_t size, void **p) if (!df.slab) continue; + if (kfence_free(df.freelist)) + continue; + do_slab_free(df.s, df.slab, df.freelist, df.tail, df.cnt, _RET_IP_); } while (likely(size));