From patchwork Mon Oct 21 06:59:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: xiaopeitux@foxmail.com X-Patchwork-Id: 13843679 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 2A1C5D3DEA1 for ; Mon, 21 Oct 2024 07:00:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6B996B007B; Mon, 21 Oct 2024 03:00:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A1BE06B0082; Mon, 21 Oct 2024 03:00:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E3C66B0083; Mon, 21 Oct 2024 03:00:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 700796B007B for ; Mon, 21 Oct 2024 03:00:06 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E7B8781592 for ; Mon, 21 Oct 2024 06:59:52 +0000 (UTC) X-FDA: 82696709634.05.6F4FB0A Received: from out203-205-221-155.mail.qq.com (out203-205-221-155.mail.qq.com [203.205.221.155]) by imf24.hostedemail.com (Postfix) with ESMTP id BEF82180015 for ; Mon, 21 Oct 2024 07:00:00 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=foxmail.com header.s=s201512 header.b="wkRONGB/"; dmarc=pass (policy=none) header.from=foxmail.com; spf=pass (imf24.hostedemail.com: domain of xiaopeitux@foxmail.com designates 203.205.221.155 as permitted sender) smtp.mailfrom=xiaopeitux@foxmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729493882; a=rsa-sha256; cv=none; b=fCMqP2NvQAdRXS/mH7VVd7EfuRwCoGrr70fcGxhwhKaxoIif7uBRaWsdNF9uXddshenoyu oT1ocAkhq9mMWhaLd3S0KOavHlw/uR3Z0cfhbRNshv7gvRwXiuNGSJLHpHcBbvX3bptuLQ LedzSrW7nJ9mrZtDMXo/BVHyCsNeskw= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=foxmail.com header.s=s201512 header.b="wkRONGB/"; dmarc=pass (policy=none) header.from=foxmail.com; spf=pass (imf24.hostedemail.com: domain of xiaopeitux@foxmail.com designates 203.205.221.155 as permitted sender) smtp.mailfrom=xiaopeitux@foxmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729493882; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=144/N2ZzvXSuwNAqNOt4nx8XXQ2rHmaeMBaqchMXVdA=; b=fG8NqtYUChjGTTO+fldpQQPKtH0Z8kCgKBo/M2u/wCw4kJj7Te5Xw8hz4gn6+R+Sq+8KJJ rhXi9zE7JgRfQHs2BUylAAsJdWf77f69bMJmzxAr3AKxEfCIOIzL1opyoxFTfwo8JMjyqD wvnTzpZZIdWrPpHCYUe5dI9iMJxDThs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1729493988; bh=144/N2ZzvXSuwNAqNOt4nx8XXQ2rHmaeMBaqchMXVdA=; h=From:To:Cc:Subject:Date; b=wkRONGB/bV01UhZ33+QuTLHREskDPCgNj99F/jrYHYhq8grD9LilYbU1DELrr2HCI Q1FqZgND1XOtqcYJ+VQBH2x2ier/jZdvH9WdGtj/GFT7kDN1BCz1wueoVeESaVwFq9 K5OIM13hd3fTAY1ecv2XxRrPMcUcMwyHfda1UhC0= Received: from xiaopei-pc.. ([111.48.58.13]) by newxmesmtplogicsvrszgpuc1-0.qq.com (NewEsmtp) with SMTP id EEE8CCD0; Mon, 21 Oct 2024 14:59:46 +0800 X-QQ-mid: xmsmtpt1729493986t433b4fs9 Message-ID: X-QQ-XMAILINFO: MmCmH9jyqHC2n4gG4e7gexqW8tzjEJFq8/qXrF9Q5PcqxZ/kkEeOXdO0dcFAcp j+u/BFL5N2Hv2NVoVLOa4z+Qu24vEpC4ifFoKFQFWs31RoYGfEnBkCxz5A1bIuvcHWSdEi3Ow9HR S9hST+dKsS5JE2tL/UAoob/GjjVmmDQlfMHYPUc91XBgbFpk74znjCk5nC9fFYcRILVp5xHC8j6E zntgtOlmeufc542czi9/QZwIRAV+clfazkXQCUtX1hOtgCJCVY+UlZpRnawpuAPxEM5Ss1ntaHda oerT/EjpvTQfrJr/Lx9BFPvMWMdRLg5FSv6/wsrLelY7w9IbvGKITVPMyUj85NkZp/4CBnMpqeyg 0LCXv6GEA00iZCQpEbxW0UChafHTzlwCMuTu4PCg7bacYxrL4KOGhEvlNI/ovrevpnT85wVIwdaZ bTa9Lb4VOSv6jLusnuilKKihauFWjwg8bk/M8fcvvsVX11smEGGOQG9uWYj9rtRCBAOe3IEOBGzh zS1iownnWooBR2aSXfMq6OjCqe4cXgX9s2L/vrGORdZmg6ZriAnEnBt71tnQcHyxcxjZ1eQUDp6X db4vSeeEtbxLTtQRQee++pHbh5k92pAtJjHO9T6IWs8lPAznDML0jUtAbdj0KcHWBQhpSIWsz383 syU+xgFmVzRWrdkZK+UC9KxypdRgcRDwVEbd59WjNl9mN/G0y+psLgo/4gh2OkzU+YUcmlYsV10b bmr6izkA7ot5YIwFZcgOHFwiGdEPWGtlP8G4Gg26wrdQBZm2zMn1yfHOkGR48u7P6V/LHzNTaGIo NmxU5xofKRcRWs0IUbethWbNARqUPcba+8MhlefES1Q+bjYOj8D8rjMh3iIf36Xmn+jWLyJkvhBQ Cl+mb+MEUCwoJ6iG3BqCXAwZUYg0yfT73nwdqiVNvGiU/3hXjoluIaymfiX2+fnYhelwJPIF5SQ5 QRprkaHNUoxrC3/HUYpBvBwBbtHEv19CGKGBxEAMQPeFp4oAmVhKtsc1UIaB6gGZiWcd86UsNK2z rLRa9H4ofITwD9skK4yrsmUIBwU2WaGRrzA2JS2oUJbsV9CqtvfKjjftDOfXx9gtlvjpSpB3R5OO Et8aNv X-QQ-XMRINFO: NI4Ajvh11aEj8Xl/2s1/T8w= From: xiaopeitux@foxmail.com To: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, surenb@google.com, yuzhao@google.com Cc: xiaopei01@kylinos.cn, gehao@kylinso.cn, xiongxin@kylinos.cn Subject: [PATCH] slub/slub_kunit:fix a panic due to __kmalloc_cache_noprof incorretly use Date: Mon, 21 Oct 2024 14:59:42 +0800 X-OQ-MSGID: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: BEF82180015 X-Stat-Signature: 7t6no6y5uzwyqtpefcubn6pzywonfjrn X-Rspam-User: X-HE-Tag: 1729494000-222536 X-HE-Meta: U2FsdGVkX18l8O5lAZ1YDjXHQx/OsHa8ZbwU2LLAA7xgNR3nIXzm2LXz2AvbJFqBO1+O5HFTzIY4mVTyYkUC/bCPyeOrFHCwDS1QOIuS2nb8rn7m1EVoP82jpGQ/Pkxj2MVGxwWXkxJ2Q9rAqLr4bmBhdwt83ANKurwLw2UjMkcBoiVc412GB1KRr2bUnab3AfFeezyT4zxEW0w+/oUu/eE9/hcPvK4+Xu8Pg1K3QwPLwzqsl6HzWrfhuRw7Svm1328qHb+XnhFMnVcY4xUtnJzzWxZI+6c/ZPUN7GslFO5M92TsMlvmp1w/efos/t6GO5eHfAAe2lm7hyDj/ryeQ0tn3cCkq6nzGJZMGNgfel3Mbs8eCTPO3y/HOeZaAMtQKaKaEW3kYjbilSZHKTQ8vsjSVRNni8QVKSVn4jsoLilTjSmlk6EpFciEA0z0kj6K1RoDqAHff11w2dFGWEaL8KveQ2VZFRvcwyMxa/1m66Y7WK0/8Kvf4A8Wr3bvg/5lnzYwZnJ2/khPcm+Cq1YMA6oC5kJthKgKKpd7ARO9r/dqRHUBvlKYsQxGQTFrqWc6uBfAOAAj1W4SPe21+OC+soQamP9aWpkjkOL0Me6UwJRS5jkoskTeLOD2gQIiqi/4mskDKtUFyGI+laiUjPPvo+EC8uDlLx53J6WFL/MNIkAP0Xdyr26/APnZkwX+DrPrPniXExu7ecndvVOjngsS1OZAhVwvM2a2Nn75Pw1cz+R5LEh/b+wEumZGHfu0K3tHESh2D+LsaqVuCOos3+5NZoMcI0LPzzqU4Bp3unqSDwcyzBZo2RKJ62peqlBitzQSvwl3OUwT4BghgON24G6obkDmVwqqioMwMJPT/se11pYmi/JyVKMQrtbGtMKUs6JJi0hx7SanP3Jtx2mc5IhtGQcmHbkmDWRrvByh3Z0AehysgiFB1gj81TpTKe0cJ2QS+GOGSqywm2hPHnjEntk HE7zqyWl a6ZuiB/LnQOZx7Dr+bpTL0W1COTd0cU0+ob5Bdwy3ZVdio24u34u9uu33JMuD9LTJuSQ+aeMadwB8rIFDxabVqGA0T44B/pbAzsJEptnCLlde4JXhhRBchCvrry+z0Xy5ND+PeK2lQ34nrrVOIZZB3La8GldCUndfP75GxviOf2OObburAd/mlNRM8wZhoAkfsDc5gCAxhknDNbUz5+Nqmt82b8/1VSSs7Axz X-Bogosity: Ham, tests=bogofilter, spamicity=0.000011, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Pei Xiao 'modprobe slub_kunit',will have a panic.The root cause is that __kmalloc_cache_noprof was directly ,which resulted in no alloc_tag being allocated.This caused current->alloc_tag to be null,leading to a null pointer dereference in alloc_tag_ref_set. Here is the log for the panic: [ 74.779373][ T2158] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000020 [ 74.780130][ T2158] Mem abort info: [ 74.780406][ T2158] ESR = 0x0000000096000004 [ 74.780756][ T2158] EC = 0x25: DABT (current EL), IL = 32 bits [ 74.781225][ T2158] SET = 0, FnV = 0 [ 74.781529][ T2158] EA = 0, S1PTW = 0 [ 74.781836][ T2158] FSC = 0x04: level 0 translation fault [ 74.782288][ T2158] Data abort info: [ 74.782577][ T2158] ISV = 0, ISS = 0x00000004, ISS2 = 0x00000000 [ 74.783068][ T2158] CM = 0, WnR = 0, TnD = 0, TagAccess = 0 [ 74.783533][ T2158] GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0 [ 74.784010][ T2158] user pgtable: 4k pages, 48-bit VAs, pgdp=0000000105f34000 [ 74.784586][ T2158] [0000000000000020] pgd=0000000000000000, p4d=0000000000000000 [ 74.785293][ T2158] Internal error: Oops: 0000000096000004 [#1] SMP [ 74.785805][ T2158] Modules linked in: slub_kunit kunit ip6t_rpfilter ip6t_REJECT nf_reject_ipv6 ipt_REJECT nf_reject_ipv4 xt_conntrack ebtable_nat ebtable_broute ip6table_nat ip6table_mangle 4 [ 74.790661][ T2158] CPU: 0 UID: 0 PID: 2158 Comm: kunit_try_catch Kdump: loaded Tainted: G W N 6.12.0-rc3+ #2 [ 74.791535][ T2158] Tainted: [W]=WARN, [N]=TEST [ 74.791889][ T2158] Hardware name: QEMU KVM Virtual Machine, BIOS 0.0.0 02/06/2015 [ 74.792479][ T2158] pstate: 40400005 (nZcv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 74.793101][ T2158] pc : alloc_tagging_slab_alloc_hook+0x120/0x270 [ 74.793607][ T2158] lr : alloc_tagging_slab_alloc_hook+0x120/0x270 [ 74.794095][ T2158] sp : ffff800084d33cd0 [ 74.794418][ T2158] x29: ffff800084d33cd0 x28: 0000000000000000 x27: 0000000000000000 [ 74.795095][ T2158] x26: 0000000000000000 x25: 0000000000000012 x24: ffff80007b30e314 [ 74.795822][ T2158] x23: ffff000390ff6f10 x22: 0000000000000000 x21: 0000000000000088 [ 74.796555][ T2158] x20: ffff000390285840 x19: fffffd7fc3ef7830 x18: ffffffffffffffff [ 74.797283][ T2158] x17: ffff8000800e63b4 x16: ffff80007b33afc4 x15: ffff800081654c00 [ 74.798011][ T2158] x14: 0000000000000000 x13: 205d383531325420 x12: 5b5d383734363537 [ 74.798744][ T2158] x11: ffff800084d337e0 x10: 000000000000005d x9 : 00000000ffffffd0 [ 74.799476][ T2158] x8 : 7f7f7f7f7f7f7f7f x7 : ffff80008219d188 x6 : c0000000ffff7fff [ 74.800206][ T2158] x5 : ffff0003fdbc9208 x4 : ffff800081edd188 x3 : 0000000000000001 [ 74.800932][ T2158] x2 : 0beaa6dee1ac5a00 x1 : 0beaa6dee1ac5a00 x0 : ffff80037c2cb000 [ 74.801656][ T2158] Call trace: [ 74.801954][ T2158] alloc_tagging_slab_alloc_hook+0x120/0x270 [ 74.802494][ T2158] __kmalloc_cache_noprof+0x148/0x33c [ 74.802976][ T2158] test_kmalloc_redzone_access+0x4c/0x104 [slub_kunit] [ 74.803607][ T2158] kunit_try_run_case+0x70/0x17c [kunit] [ 74.804124][ T2158] kunit_generic_run_threadfn_adapter+0x2c/0x4c [kunit] [ 74.804768][ T2158] kthread+0x10c/0x118 [ 74.805141][ T2158] ret_from_fork+0x10/0x20 [ 74.805540][ T2158] Code: b9400a80 11000400 b9000a80 97ffd858 (f94012d3) [ 74.806176][ T2158] SMP: stopping secondary CPUs [ 74.808130][ T2158] Starting crashdump kernel... Signed-off-by: Pei Xiao --- include/linux/slab.h | 1 + lib/slub_kunit.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index 10a971c2bde3..0149d36cd311 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -827,6 +827,7 @@ void *__kmalloc_cache_noprof(struct kmem_cache *s, gfp_t flags, size_t size) void *__kmalloc_cache_node_noprof(struct kmem_cache *s, gfp_t gfpflags, int node, size_t size) __assume_kmalloc_alignment __alloc_size(4); +#define kmalloc_cache(...) alloc_hooks(__kmalloc_cache_noprof(__VA_ARGS__)) void *__kmalloc_large_noprof(size_t size, gfp_t flags) __assume_page_alignment __alloc_size(1); diff --git a/lib/slub_kunit.c b/lib/slub_kunit.c index 80e39f003344..4bf38f52dbbd 100644 --- a/lib/slub_kunit.c +++ b/lib/slub_kunit.c @@ -141,7 +141,7 @@ static void test_kmalloc_redzone_access(struct kunit *test) { struct kmem_cache *s = test_kmem_cache_create("TestSlub_RZ_kmalloc", 32, SLAB_KMALLOC|SLAB_STORE_USER|SLAB_RED_ZONE); - u8 *p = __kmalloc_cache_noprof(s, GFP_KERNEL, 18); + u8 *p = kmalloc_cache(s, GFP_KERNEL, 18); kasan_disable_current();