From patchwork Thu Jun 15 11:52:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Olsa X-Patchwork-Id: 13281096 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21BE312B69 for ; Thu, 15 Jun 2023 11:52:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F06B1C433C8; Thu, 15 Jun 2023 11:52:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686829960; bh=vzXaLtl6SzbvAGUpSSunsAgBa5POCxudf8Ga0otXJQU=; h=From:To:Cc:Subject:Date:From; b=ETYkAhwtp5kNnRtpjzuT4+P3vKvOR2SXhqd4Q8qIpLEGQl6dYfiqvReb117moKwM0 LdRSt8WIYArfD9xxw9VDPZkTSWuHYapMzGO0mAQIHYlfaZalEYEUIxzcXQNxfgplip HFSkXpe4WVm8vK1ciYLuagzQS77bEkvoRMS9V0DxIqX/IpuS3JOBRhOuDHK1QlOQJh ZuVKK4rULuoGZdXfT5urJ5l1fOfaOuLe7P14w9PSeSu6nEAocRDhXIdQXNFJTwFShi /wM/YDUZ9tDa5U3Zf3y+3cTlwxPE9hKOABGrBM2pcfjZYmcgPaBrZrQlZmxvcaKYkJ pRsGyu2GFtomA== From: Jiri Olsa To: Steven Rostedt , Masami Hiramatsu , Mark Rutland Cc: lkml , linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH] fprobe: Release rethook after the ftrace_ops is unregistered Date: Thu, 15 Jun 2023 13:52:36 +0200 Message-Id: <20230615115236.3476617-1-jolsa@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 While running bpf selftests it's possible to get following fault: general protection fault, probably for non-canonical address \ 0x6b6b6b6b6b6b6b6b: 0000 [#1] PREEMPT SMP DEBUG_PAGEALLOC NOPTI ... Call Trace: fprobe_handler+0xc1/0x270 ? __pfx_bpf_testmod_init+0x10/0x10 ? __pfx_bpf_testmod_init+0x10/0x10 ? bpf_fentry_test1+0x5/0x10 ? bpf_fentry_test1+0x5/0x10 ? bpf_testmod_init+0x22/0x80 ? do_one_initcall+0x63/0x2e0 ? rcu_is_watching+0xd/0x40 ? kmalloc_trace+0xaf/0xc0 ? do_init_module+0x60/0x250 ? __do_sys_finit_module+0xac/0x120 ? do_syscall_64+0x37/0x90 ? entry_SYSCALL_64_after_hwframe+0x72/0xdc In unregister_fprobe function we can't release fp->rethook while it's possible there are some of its users still running on another cpu. Moving rethook_free call after fp->ops is unregistered with unregister_ftrace_function call. Fixes: 5b0ab78998e3 ("fprobe: Add exit_handler support") Reviewed-by: Steven Rostedt (Google) Signed-off-by: Jiri Olsa Acked-by: Masami Hiramatsu (Google) --- kernel/trace/fprobe.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c index 18d36842faf5..0121e8c0d54e 100644 --- a/kernel/trace/fprobe.c +++ b/kernel/trace/fprobe.c @@ -364,19 +364,13 @@ int unregister_fprobe(struct fprobe *fp) fp->ops.saved_func != fprobe_kprobe_handler)) return -EINVAL; - /* - * rethook_free() starts disabling the rethook, but the rethook handlers - * may be running on other processors at this point. To make sure that all - * current running handlers are finished, call unregister_ftrace_function() - * after this. - */ - if (fp->rethook) - rethook_free(fp->rethook); - ret = unregister_ftrace_function(&fp->ops); if (ret < 0) return ret; + if (fp->rethook) + rethook_free(fp->rethook); + ftrace_free_filter(&fp->ops); return ret;