Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1443472rwd; Sun, 14 May 2023 20:19:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5uG52jrHj8G4FsbpPAlITbO5vesDiftlV/RYsDBWjfqIrkxd/jtfhp3mJIhqMfW9Ycy1Go X-Received: by 2002:a17:90b:17d0:b0:246:f9f1:ad17 with SMTP id me16-20020a17090b17d000b00246f9f1ad17mr30898636pjb.40.1684120770570; Sun, 14 May 2023 20:19:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684120770; cv=none; d=google.com; s=arc-20160816; b=MI8+clX7EDAmJO4uRDDqdh3gM45hsoPPFizwMaplo34vSIp97EYJjmmRYo4BEhO02y pnBkyCvp0P3HAwlslk5hof4R7Enry5XKyCJDgMeXgFv6VawMIkgbtmaTNpRJg+lU+WuT oL41UWEeqF1729GSqfLD+kxP+XOPf/dTJi69mc6bNKlcavVu2anlEVnxBc4GxXQGOT1G ZQ71IS/IPL6pJBcpnKAnXf8bb/taioy3EyosK5aQyme+KXEEAqYBvN6S2btua96M8dqz 8+kwU6oinw+VN6NqPXAAP88mudS9U2rzOJZaDuA5IfQpKXFdE6k8hLg035BBSReMFwLZ 3GaQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JzkH4lQfb5ZOUjwqO+AdNbxgdgLDuSyyuCXzioTUQhE=; b=qcGplJ5jQZUo4EfWiqwpdVC3jrNGlHk/21DFxVAYR+Op4c9jYzbYlCYBWIm2sfxxvp 04AFTnrdtgEAoVZH8e9fLofzSn7mmFy0qKy1cZ3FvMQWb+u13TaZImlOvRDrV6ZHxR65 gibAVTThyB9ZDbn7JUuqkL6H1O9XvKhhWZlu99iHFXn7sGNJVVhSMOf/JrlELiypIBXo 4Hn2CNnAqzLO0Tk2kkiHeHoS3kE2rQ892CPTbsznT8tVU4aPdfg6JLhiK8LkjtSKGrek zV0vtY5A4R4OUtUTKVrNKTOoymT18AQFDWBHf6UTAi+tQU/5U/LcNCPrXhE38vwAnq1o 5zwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=enBaw82M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id il9-20020a17090b164900b0024df598ed11si22833866pjb.188.2023.05.14.20.19.15; Sun, 14 May 2023 20:19:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=enBaw82M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238150AbjEODOA (ORCPT + 99 others); Sun, 14 May 2023 23:14:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238101AbjEODNx (ORCPT ); Sun, 14 May 2023 23:13:53 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 405E719AE; Sun, 14 May 2023 20:13:52 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-24df6bbf765so10416294a91.0; Sun, 14 May 2023 20:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684120431; x=1686712431; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JzkH4lQfb5ZOUjwqO+AdNbxgdgLDuSyyuCXzioTUQhE=; b=enBaw82MMhF8WgmXnqu36qFSVY3hKbpo+op2O5MAGLA+GpkIJEl3vC1lBt3rERLk8L gRdcppCEuq/5D+3OQ0RfxKTGM6PKQGMJw3kTzsQvcBmKRjF/5dCFVVY86/f8EwCVFMFh gfFgegsBJXoMf5eyTbJWd7LqflGxj2HgBaapTA0wMctFtIPZ9gwkztpfL71uZ5QezH2t yllnfUII7mWYm0JTwyV8wKKJ2C6HQuf/+vk3uizyMMJPyIZ1t8I2aht/uDigW0kAQp42 1vdzBOYtzxIjhyWUSIjfXUopS486Ag1SwrAzvHCXAmDBigR9h3snNa4b3n+aaqAMps2u RWVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684120431; x=1686712431; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JzkH4lQfb5ZOUjwqO+AdNbxgdgLDuSyyuCXzioTUQhE=; b=It18kmxqVFfNTfoCapw1cBcHpuCB8TAdDRZ0dpn40lXD7OrcesZgFFfeNDZr9O7ZtQ cb7N78rgCWv02pnyrFNJ2sDceOWKCoGOU5GKJZBqHv3DDodVE23XgckQq88KOGBHPWlC kXZ12S9ms09Q61YxM/uIZxWv49n5qigS47Iz5MAeNwjcsb593UCgA5ga0CNqgiqNRE5U d//F93GbYCpRiCfnU0IxB0Inqf1MyF0SFh6bO4an1lFouCHxsmj/fyzZwc7o+SQWPp5d l9ZnYEteyBV5m2dwUie2hTj0OJPtQ1eWE/7NWuLmaSngjUbzssacQJKsoycG/XW5PuXO /Iqw== X-Gm-Message-State: AC+VfDxWzA7M6pQf1sJIKbejixWcxrIjThDdSzmwtCvPpWZwlalYfYiX U7m9ard1MkKj0sGEdmIK55s= X-Received: by 2002:a17:90b:a58:b0:23f:81c0:eadd with SMTP id gw24-20020a17090b0a5800b0023f81c0eaddmr31427720pjb.47.1684120431582; Sun, 14 May 2023 20:13:51 -0700 (PDT) Received: from localhost.localdomain ([43.132.98.42]) by smtp.googlemail.com with ESMTPSA id o4-20020a17090a744400b00252b3328ad8sm4943577pjk.0.2023.05.14.20.13.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 May 2023 20:13:51 -0700 (PDT) From: Ze Gao X-Google-Original-From: Ze Gao To: Steven Rostedt , Masami Hiramatsu Cc: Ze Gao , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH 3/4] fprobe: add recursion detection in fprobe_exit_handler Date: Mon, 15 May 2023 11:13:12 +0800 Message-Id: <20230515031314.7836-4-zegao@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230515031314.7836-1-zegao@tencent.com> References: <20230515031314.7836-1-zegao@tencent.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org fprobe_hander and fprobe_kprobe_handler has guarded ftrace recusion detection but fprobe_exit_handler has not, which possibly introduce recurive calls if the fprobe exit callback calls any traceable functions. Checking in fprobe_hander or fprobe_kprobe_handler is not enough and misses this case. So add recusion free guard the same way as fprobe_hander and also mark fprobe_exit_handler notrace. Since ftrace recursion check does not employ ips, so here use entry_ip and entry_parent_ip the same as fprobe_handler. Signed-off-by: Ze Gao --- kernel/trace/fprobe.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c index ad9a36c87ad9..cf982d4ab142 100644 --- a/kernel/trace/fprobe.c +++ b/kernel/trace/fprobe.c @@ -17,6 +17,7 @@ struct fprobe_rethook_node { struct rethook_node node; unsigned long entry_ip; + unsigned long entry_parent_ip; char data[]; }; @@ -39,6 +40,7 @@ static inline notrace void __fprobe_handler(unsigned long ip, unsigned long } fpr = container_of(rh, struct fprobe_rethook_node, node); fpr->entry_ip = ip; + fpr->entry_parent_ip = parent_ip; if (fp->entry_data_size) entry_data = fpr->data; } @@ -109,19 +111,30 @@ static void notrace fprobe_kprobe_handler(unsigned long ip, unsigned long parent ftrace_test_recursion_unlock(bit); } -static void fprobe_exit_handler(struct rethook_node *rh, void *data, +static void notrace fprobe_exit_handler(struct rethook_node *rh, void *data, struct pt_regs *regs) { struct fprobe *fp = (struct fprobe *)data; struct fprobe_rethook_node *fpr; + int bit; if (!fp || fprobe_disabled(fp)) return; fpr = container_of(rh, struct fprobe_rethook_node, node); + /* we need to assure no calls to traceable functions in-between the + * end of fprobe_handler and the beginning of fprobe_exit_handler. + */ + bit = ftrace_test_recursion_trylock(fpr->entry_ip, fpr->entry_parent_ip); + if (bit < 0) { + fp->nmissed++; + return; + } + fp->exit_handler(fp, fpr->entry_ip, regs, fp->entry_data_size ? (void *)fpr->data : NULL); + ftrace_test_recursion_unlock(bit); } NOKPROBE_SYMBOL(fprobe_exit_handler); -- 2.40.1