From patchwork Sun May 26 23:06:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 13674432 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 17E7BC25B75 for ; Sun, 26 May 2024 23:06:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6937A6B0082; Sun, 26 May 2024 19:06:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6424D6B0083; Sun, 26 May 2024 19:06:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 531256B0085; Sun, 26 May 2024 19:06:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3532C6B0082 for ; Sun, 26 May 2024 19:06:56 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B48798028A for ; Sun, 26 May 2024 23:06:55 +0000 (UTC) X-FDA: 82162083990.29.A4AC8CB Received: from mail-il1-f173.google.com (mail-il1-f173.google.com [209.85.166.173]) by imf09.hostedemail.com (Postfix) with ESMTP id 1580314000C for ; Sun, 26 May 2024 23:06:53 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=cSnlavmy; spf=pass (imf09.hostedemail.com: domain of xiyou.wangcong@gmail.com designates 209.85.166.173 as permitted sender) smtp.mailfrom=xiyou.wangcong@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716764814; 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=zJqtAAqlFhCcDbb4ROnfcMhXZWMT8rTzCRv8aWFfHq8=; b=17RadrWaYyrXepjZ829PzMUrsfZqjGbdCtqDT5FLh7EWbe/pAGUK5uC0s/v09k1OqfvcaB Dz1XhvRpJkyGJdejN0UwqsDRuASp7pwvZL3dbYjkRguILrTxstkap92VWzBNZIHXiSZlJq NDwfb2IgOafEHNBxGzpiAOItu8fizqQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716764814; a=rsa-sha256; cv=none; b=LYnMTuMdSFmaCAIcKrEGrHrzH75IgXQSCs/D3vnyjVJTzikHu3++xCwd0zMNGJNhyoaeo8 FBr9euDBPzFppxPfdqUei4w7mxIhBhgpOTc7Ou33QtpMG+d+HHREN+Q08fVEXWokci59b4 w2uSEbkCGqbPvZh2ChJaZDpO0ZeUxlc= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=cSnlavmy; spf=pass (imf09.hostedemail.com: domain of xiyou.wangcong@gmail.com designates 209.85.166.173 as permitted sender) smtp.mailfrom=xiyou.wangcong@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-il1-f173.google.com with SMTP id e9e14a558f8ab-371c97913cdso23242895ab.3 for ; Sun, 26 May 2024 16:06:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716764813; x=1717369613; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=zJqtAAqlFhCcDbb4ROnfcMhXZWMT8rTzCRv8aWFfHq8=; b=cSnlavmy+Vg42JxCKSvEAK8D7KqyqrTl7PxeZJAB2oi/8VDPtQYbvX+MIoOZOHV8ZT Wj8Hf34GV9SCjg26UUGkvUMZfqthvgCTxLhXjhTKhXl0OXPqKosyc/13f47tjud1jPNs I0O6LFli2YkKc4KS7iCLjpWduy2qp+nMpeUWKeZjZF9jrhVVzrBOHmC2L4J2fdiA9yzZ 7uS4k2naGT8b6jQd86y6f/bt6JwkOC6rf8FZXl5eA0G8KkqSdjozIXjpkeaDEir8dW+c 8Q5ikDYyYjYVPoSHBEIPtmqFKNlY7aGmKxu4xkromZlHuSIzmF8iaEaIKFoNY+umfKcw ruLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716764813; x=1717369613; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zJqtAAqlFhCcDbb4ROnfcMhXZWMT8rTzCRv8aWFfHq8=; b=YLUogGgDfAJ2v0RbMGGIT8Li/jKGnLpySPfWO+hJ6Cg94MFWA1LLIWWe7Ht/19KXW5 gXaeRCUFtjeNshMZAMCPhZb+jSaizVYFIYiFwenFtmC93pspbftRq3YQJZgi+wZ1WXf9 bbYYXPMTVbe30w3/3EYZl+zbqnFLpe3leVbcfG/WPRUXZJFhWGueYZSNDOweZKx8Ahlu CKqmqcqWP8G2FfNtAuf63dhG52AtuwMlC6VDCjBsjoQgqtwu0WbWeQC4YcCjwI/f2zFo hsA0Y87+7wIHaoFMj2X6lP/pllJEBrXpPg7qj4bB8gi8i1N/zWFsoikNrRWqmwq6bd+L 0ZvA== X-Gm-Message-State: AOJu0YxCz5cABOKPJtqQzTslPhCkuxwwN3MoRzJ5RjdqoxqshNnZ9niU H4Isn98iyQ4yYx7iQa9CTooMvaIl3VSVVCdOFn7ubWZ08U/8izn+ X-Google-Smtp-Source: AGHT+IE201ttVYgZcyG2D3k1Vy2ZngvDdVtaBQx71rVja7N8HAXvNtKmfkWyaYbH3Fovx5pjX5yBiQ== X-Received: by 2002:a05:6e02:178d:b0:371:44f7:b9c0 with SMTP id e9e14a558f8ab-3737b2f8c57mr108095665ab.9.1716764813126; Sun, 26 May 2024 16:06:53 -0700 (PDT) Received: from pop-os.hsd1.ca.comcast.net ([2601:647:6881:9060:ea8b:d923:f46f:eef5]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-6822073f067sm4855338a12.5.2024.05.26.16.06.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 16:06:52 -0700 (PDT) From: Cong Wang To: netdev@vger.kernel.org Cc: linux-mm@kvack.org, Andrew Morton , bpf@vger.kernel.org, Cong Wang , Luis Chamberlain , Mike Rapoport Subject: [Patch bpf] vmalloc: relax is_vmalloc_or_module_addr() check Date: Sun, 26 May 2024 16:06:48 -0700 Message-Id: <20240526230648.188550-1-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 1580314000C X-Rspam-User: X-Stat-Signature: 97r7wrokhamcrj7u51kc1pcuxh3irgyd X-HE-Tag: 1716764813-367694 X-HE-Meta: U2FsdGVkX18pDI5sY2dTnkINXw5aGlN18JxAUyWOkw4rn4Oek+6EvxCZCT3Kikgq2eoYjFDiFQOxrPHSK/s+41ytxaHNMtFh6ocNBmtRkoZtjp3AIBGwqRgY7qL7LLRP3CLpNEU+o603cG/nvyuaO74FDh2sWkrtWLrfc3GPhBPQbpwhMjayMe0ZlKcs0bKIT1ovJNKIueHPxUUshy/wXOwBVOwiaypLI6hR0Was+2+EFHjNlXjI9qAz58Mp8gS1nELzYsAxnm3YIvpzuLtqQdEe9WFRL1nB7FWDBD64SqnLk9/ylbG/Rb4woN5nCgWf0/LzHto6K4bHlbntqUbRYut+U8k+gM+eq7RoF5i5kb8z0D7vfvp61gNR/thuEFSz8TNcWJeYG+aLIEOKBffKjRKJR+szJ7uPV0woy9N7WXp28tsJ8X3FwzPFkFG+0pdVK0lsmePCb7f+YMjOOyZBi9loNGAdtdwtFUyKwA19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nZyqwZoe4ApPUivHE6Rm5GuObzWSFJ/JOaPeiovFAFxc0WwrkOtBanZGMzqSYaIiByIHxa5A2gSp6lgRxh3wftvOqJdWcteClG/BlZaSzy 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: From: Cong Wang After commit 2c9e5d4a0082 ("bpf: remove CONFIG_BPF_JIT dependency on CONFIG_MODULES of") CONFIG_BPF_JIT does not depend on CONFIG_MODULES any more and bpf jit also uses the MODULES_VADDR ~ MODULES_END memory region. But is_vmalloc_or_module_addr() still checks CONFIG_MODULES, which then returns false for a bpf jit memory region when CONFIG_MODULES is not defined. It leads to the following kernel BUG: [ 1.567023] ------------[ cut here ]------------ [ 1.567883] kernel BUG at mm/vmalloc.c:745! [ 1.568477] Oops: invalid opcode: 0000 [#1] PREEMPT SMP KASAN NOPTI [ 1.569367] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.9.0+ #448 [ 1.570247] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.15.0-1 04/01/2014 [ 1.570786] RIP: 0010:vmalloc_to_page+0x48/0x1ec [ 1.570786] Code: 0f 00 00 e8 eb 1a 05 00 b8 37 00 00 00 48 ba fe ff ff ff ff 1f 00 00 4c 03 25 76 49 c6 02 48 c1 e0 28 48 01 e8 48 39 d0 76 02 <0f> 0b 4c 89 e7 e8 bf 1a 05 00 49 8b 04 24 48 a9 9f ff ff ff 0f 84 [ 1.570786] RSP: 0018:ffff888007787960 EFLAGS: 00010212 [ 1.570786] RAX: 000036ffa0000000 RBX: 0000000000000640 RCX: ffffffff8147e93c [ 1.570786] RDX: 00001ffffffffffe RSI: dffffc0000000000 RDI: ffffffff840e32c8 [ 1.570786] RBP: ffffffffa0000000 R08: 0000000000000000 R09: 0000000000000000 [ 1.570786] R10: ffff888007787a88 R11: ffffffff8475d8e7 R12: ffffffff83e80ff8 [ 1.570786] R13: 0000000000000640 R14: 0000000000000640 R15: 0000000000000640 [ 1.570786] FS: 0000000000000000(0000) GS:ffff88806cc00000(0000) knlGS:0000000000000000 [ 1.570786] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 1.570786] CR2: ffff888006a01000 CR3: 0000000003e80000 CR4: 0000000000350ef0 [ 1.570786] Call Trace: [ 1.570786] [ 1.570786] ? __die_body+0x1b/0x58 [ 1.570786] ? die+0x31/0x4b [ 1.570786] ? do_trap+0x9d/0x138 [ 1.570786] ? vmalloc_to_page+0x48/0x1ec [ 1.570786] ? do_error_trap+0xcd/0x102 [ 1.570786] ? vmalloc_to_page+0x48/0x1ec [ 1.570786] ? vmalloc_to_page+0x48/0x1ec [ 1.570786] ? handle_invalid_op+0x2f/0x38 [ 1.570786] ? vmalloc_to_page+0x48/0x1ec [ 1.570786] ? exc_invalid_op+0x2b/0x41 [ 1.570786] ? asm_exc_invalid_op+0x16/0x20 [ 1.570786] ? vmalloc_to_page+0x26/0x1ec [ 1.570786] ? vmalloc_to_page+0x48/0x1ec [ 1.570786] __text_poke+0xb6/0x458 [ 1.570786] ? __pfx_text_poke_memcpy+0x10/0x10 [ 1.570786] ? __pfx___mutex_lock+0x10/0x10 [ 1.570786] ? __pfx___text_poke+0x10/0x10 [ 1.570786] ? __pfx_get_random_u32+0x10/0x10 [ 1.570786] ? srso_return_thunk+0x5/0x5f [ 1.570786] text_poke_copy_locked+0x70/0x84 [ 1.570786] text_poke_copy+0x32/0x4f [ 1.570786] bpf_arch_text_copy+0xf/0x27 [ 1.570786] bpf_jit_binary_pack_finalize+0x26/0x5a [ 1.570786] bpf_int_jit_compile+0x576/0x8ad [ 1.570786] ? __pfx_bpf_int_jit_compile+0x10/0x10 [ 1.570786] ? srso_return_thunk+0x5/0x5f [ 1.570786] ? __kmalloc_node_track_caller+0x2b5/0x2e0 [ 1.570786] bpf_prog_select_runtime+0x7c/0x199 [ 1.570786] bpf_prepare_filter+0x1e9/0x25b [ 1.570786] ? __pfx_bpf_prepare_filter+0x10/0x10 [ 1.570786] ? srso_return_thunk+0x5/0x5f [ 1.570786] ? _find_next_bit+0x29/0x7e [ 1.570786] bpf_prog_create+0xb8/0xe0 [ 1.570786] ptp_classifier_init+0x75/0xa1 [ 1.570786] ? __pfx_ptp_classifier_init+0x10/0x10 [ 1.570786] ? srso_return_thunk+0x5/0x5f [ 1.570786] ? register_pernet_subsys+0x36/0x42 [ 1.570786] ? srso_return_thunk+0x5/0x5f [ 1.570786] sock_init+0x99/0xa3 [ 1.570786] ? __pfx_sock_init+0x10/0x10 [ 1.570786] do_one_initcall+0x104/0x2c4 [ 1.570786] ? __pfx_do_one_initcall+0x10/0x10 [ 1.570786] ? parameq+0x25/0x2d [ 1.570786] ? rcu_is_watching+0x1c/0x3c [ 1.570786] ? trace_kmalloc+0x81/0xb2 [ 1.570786] ? srso_return_thunk+0x5/0x5f [ 1.570786] ? __kmalloc+0x29c/0x2c7 [ 1.570786] ? srso_return_thunk+0x5/0x5f [ 1.570786] do_initcalls+0xf9/0x123 [ 1.570786] kernel_init_freeable+0x24f/0x289 [ 1.570786] ? __pfx_kernel_init+0x10/0x10 [ 1.570786] kernel_init+0x19/0x13a [ 1.570786] ret_from_fork+0x24/0x41 [ 1.570786] ? __pfx_kernel_init+0x10/0x10 [ 1.570786] ret_from_fork_asm+0x1a/0x30 [ 1.570786] [ 1.570819] ---[ end trace 0000000000000000 ]--- [ 1.571463] RIP: 0010:vmalloc_to_page+0x48/0x1ec [ 1.572111] Code: 0f 00 00 e8 eb 1a 05 00 b8 37 00 00 00 48 ba fe ff ff ff ff 1f 00 00 4c 03 25 76 49 c6 02 48 c1 e0 28 48 01 e8 48 39 d0 76 02 <0f> 0b 4c 89 e7 e8 bf 1a 05 00 49 8b 04 24 48 a9 9f ff ff ff 0f 84 [ 1.574632] RSP: 0018:ffff888007787960 EFLAGS: 00010212 [ 1.575129] RAX: 000036ffa0000000 RBX: 0000000000000640 RCX: ffffffff8147e93c [ 1.576097] RDX: 00001ffffffffffe RSI: dffffc0000000000 RDI: ffffffff840e32c8 [ 1.577084] RBP: ffffffffa0000000 R08: 0000000000000000 R09: 0000000000000000 [ 1.578077] R10: ffff888007787a88 R11: ffffffff8475d8e7 R12: ffffffff83e80ff8 [ 1.578810] R13: 0000000000000640 R14: 0000000000000640 R15: 0000000000000640 [ 1.579823] FS: 0000000000000000(0000) GS:ffff88806cc00000(0000) knlGS:0000000000000000 [ 1.580992] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 1.581869] CR2: ffff888006a01000 CR3: 0000000003e80000 CR4: 0000000000350ef0 [ 1.582800] Kernel panic - not syncing: Fatal exception [ 1.583765] ---[ end Kernel panic - not syncing: Fatal exception ]--- Fixes: 2c9e5d4a0082 ("bpf: remove CONFIG_BPF_JIT dependency on CONFIG_MODULES of") Cc: Luis Chamberlain Cc: Mike Rapoport (IBM) Signed-off-by: Cong Wang --- mm/vmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 125427cbdb87..168a5c7c2fdf 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -714,7 +714,7 @@ int is_vmalloc_or_module_addr(const void *x) * and fall back on vmalloc() if that fails. Others * just put it in the vmalloc space. */ -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR) +#if defined(MODULES_VADDR) unsigned long addr = (unsigned long)kasan_reset_tag(x); if (addr >= MODULES_VADDR && addr < MODULES_END) return 1;