Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1468084rwd; Sun, 14 May 2023 20:54:22 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5OLiDai37fx5l5SBlEdjJdfLycUSSirj890s//Je6jpM++5Vl9Z22inyv4Z4ANP6Jx2iqF X-Received: by 2002:a05:6a20:7f9d:b0:105:66a1:5d05 with SMTP id d29-20020a056a207f9d00b0010566a15d05mr6105196pzj.55.1684122862088; Sun, 14 May 2023 20:54:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684122862; cv=none; d=google.com; s=arc-20160816; b=ztBnJnVcPpuB399LKLe3NlGit3NVC+d9c81Ewlq9g58eOeisc0iufr3LzDDz/prkZJ SxZY58BNDzfF3C+R21rCTLHmGJ4GOy7Ve25sV2r67T8QjtCqP95ATan6ZzVO3O0NQTVl jE7uHsEquICm6IwzlSIKLcdP1mqmwgX087318J6iDh9ePnCYmvtMhKISG0Mruxa8CKAE SZYgsKOItbrO8j2vI0r9uqpwJPedbayJkm1U710tF8GeIO05Sc2jEY4mCdSh19oE/gAG cixPhVQ+pKpnr23ngMaZznli87yOUWPEovx82DGDtnvwTkwEQ/sqnYKTbOnEauJ0FtXn jUpA== 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=0f9x1Dk/cfHW3blxJhShtrm1AB0yRuYcOeZhmIyzLQ9leACZLu3CC7tKfMuCKZD+pD IoSNowpfmCQgJ/t2bibV3J3S1rpgmFexDUXozv/6eKlVla2qB6fqzx4tSBzLJrECTehp 72FDiJJGilGGXr6IDVEUSoZIAxwCUNot1o0MVc/bx09rlGX0oPH+PjOx9QCh/LcFHw0F OdjGHy7J4JDskKBP7I3v7AD9BTnQUOgHn0RcTwxsH01+sMNQ3L8LTFxmMTkXewkBnbvG p8YcugmTct2mda4tNVGLBhIGOxgswQ6/OUJp+VL2pezX4IgUMn/IozY26vQCpWUiNX3b uGWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=aq2446Ts; 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 x24-20020a63db58000000b00524cf947601si15480898pgi.23.2023.05.14.20.54.10; Sun, 14 May 2023 20:54:22 -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=aq2446Ts; 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 S238197AbjEOD1P (ORCPT + 99 others); Sun, 14 May 2023 23:27:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229701AbjEOD1L (ORCPT ); Sun, 14 May 2023 23:27:11 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E898819BE; Sun, 14 May 2023 20:27:09 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-24dea6d5ce8so11363511a91.2; Sun, 14 May 2023 20:27:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684121229; x=1686713229; 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=aq2446TsX1Ld9+p66vC4YJ1ME7o1BG1TAYj2c/1PsW+2SjkODlqrO+giTcyvd1epTe KogHvLh033R2cIiXHqpGnJ9IltV/aXGYGkO0v1lc6aai2yysg/1r3sYX0tftiNlYKQja KFxC1LbVFDp6Q/K3rZovzXTg5P+fS4iI7ilPipDoid9MLdSQn5Ux8RJJZ/CpiN1mLQNW py4pZ++8XB7NDzxEPxHocZCz3Opi59bIo6w/gEf3KVUMRdYk+zSgkmFMX9RRpvDnocmv Mcib1fWSXc04nH6Qt8+3kF0chdPUsJI4uwOf5LEApurHqKMViXvQmHu4izxq5xutVvAN /kxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684121229; x=1686713229; 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=Z1jO0nZr8M1gkmzm2DV+D+BKbqMMO0sMtLnXtR9Z+DHzDQ8UHRfq5owJWfGcod67Qy 5rNbXoYtsRRZ0IOd+o6SnRXJ2uS8hCptfC7dBZi/yddxmCaQk76aNpcYde9GgBZTkjp1 0ZyfUjoead1Kes6CH/Aw+lrVaFvzVjlp7Hu/BA9W1teN6q6r0mwM1buPcada/f+OF6X9 sRHP0xLP2pWr1syYQJ38s7uMSx+PR1K1ee4DnK4gvvRUKuCDUZA37FsbO8a3zHj42GnJ hsrDlwwAlkrMAP3yeS0htC4pTtXO3CSgJ5s6wkHiyn5wVMBG09SxYGz0RZxhBSyYPlcH vdkA== X-Gm-Message-State: AC+VfDzOt8G+CD3jPvhLbDBIGUpWlxzuvGLOezVzhLAF0JNBRIi+SxKs FR2ZajioY/uKrqDmAYNklbM= X-Received: by 2002:a17:90a:ea82:b0:22b:b832:d32 with SMTP id h2-20020a17090aea8200b0022bb8320d32mr33674815pjz.9.1684121229377; Sun, 14 May 2023 20:27:09 -0700 (PDT) Received: from localhost.localdomain ([43.132.98.42]) by smtp.googlemail.com with ESMTPSA id s6-20020a632146000000b0051416609fb7sm10363825pgm.61.2023.05.14.20.27.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 May 2023 20:27:09 -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:26:40 +0800 Message-Id: <5f8081030f6f5d5af56c93fff95f0a7fadde04ad.1684120990.git.zegao@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: 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