Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp285212rwd; Tue, 16 May 2023 00:40:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ47I1fE7eqZody6jpbqnDl0miOyl44qBKR/9cn8TAEYiLBtpDJwtiZ7x7p7d15DCRlxO8VS X-Received: by 2002:a05:6a20:914f:b0:106:ff3c:be9b with SMTP id x15-20020a056a20914f00b00106ff3cbe9bmr1165322pzc.7.1684222813042; Tue, 16 May 2023 00:40:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684222813; cv=none; d=google.com; s=arc-20160816; b=VMaItbKAqC4b2BCPK9QheFitqRJ+nklEN38I7D5x1wx7yGBkAAoVg2I3r9d8+T1h6P G9dVR3HbCX3NkxLn6Hd0kYommAiD05A2qqgS2EUcaAEaxmXynYn9kC25MNO0Byzi9nQN nz0Ri107kebf2jvUcH8yyJNo8jn3a4WZ9o96aPf+P6CATY9pLrQeXha0Gwy51Ms6GDCX 6vnRwl3f9KaXedXekwhLz1JHp3mTrtObf9vMZz2/OQkyN+ddOHDeQcq9QURHRrU5/gXx GpPjZo0qPvegWPMh9KOZRlln9Zn/3dUkKZn/Fv44ksXXs6qeYHUwKUXiPqtXvJRLWdFL jeSQ== 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=BaoLZ/dBLXvTx6mYn8gtFpoeO4MZOVPTvDmN/MOLVfI=; b=LGpJ6bCpteFUb88o6VIc2QHbKhoF7wr6m4dZryUYj0ckTaQ3Aeb6k0xbJibGqRRBJf vQeIY7P91NR0SUlzb5pXm2ujrmHWHcQUKXgYfkv0PD/pLVWKsIE/rBtCxfqRW5+FOYKx 7LfYC2iBojJFXQAEthqN73cmTh/lSDbKV6l1JVTypDHOvcMps1fTDDUgMdc4nZV8wtkG rrLcGRQb6mAzp1oFf42agctCSVo7rP6rzFpNmPZNa8wcx86EahWeBFoPX6swSvYUGsPk BLBGNT9+bGHWx8hes6F+D6YGMeiuQxcVk+177t3Ln2HSo8+NEk09ne93BjRKIUth93zd 6jUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="elodM/SN"; 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 b201-20020a621bd2000000b00643a695e976si18765167pfb.291.2023.05.16.00.39.59; Tue, 16 May 2023 00:40:13 -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="elodM/SN"; 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 S231256AbjEPHTf (ORCPT + 99 others); Tue, 16 May 2023 03:19:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231253AbjEPHT1 (ORCPT ); Tue, 16 May 2023 03:19:27 -0400 Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C03C4421F; Tue, 16 May 2023 00:19:25 -0700 (PDT) Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-517c840f181so7415884a12.3; Tue, 16 May 2023 00:19:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684221565; x=1686813565; 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=BaoLZ/dBLXvTx6mYn8gtFpoeO4MZOVPTvDmN/MOLVfI=; b=elodM/SNoJ9U0KRWKOkpJzY7sFOiiAwcySNutlxkuaECCMGs57bNTYUgGLf7apLnmF mU/pSRkqEVZ+7rPyRZ8YnO5x6wQkUTqvaRf83bRRsM+c240BE9sqFwEfNXNWfv/FNwJA Abife5G2U8Ob1Vo7SKvledXlBqRahn+vDQEt128UyR/hVyMcaCWGJ9fEZW2nu06zUDc0 mWDQhiS8sp9WifrjGN17a5aB1CK9y9Xn+g2KbKBlwWt6GeKGgh/BvMhR11+zQ/z+XWCm PJ6B9ImSBH/O+DzeIXV5HWmld40h6QxUu5PlUm4lP7A2N1biHL1brTeyyC47cMr4CWJ/ Nj7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684221565; x=1686813565; 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=BaoLZ/dBLXvTx6mYn8gtFpoeO4MZOVPTvDmN/MOLVfI=; b=iB1TFAn/AF/zBkbmguFL3okx7V8A2xvaIqRkMCtbZnyHnQGbVPyWJp+dfDZFcCGbms NT2v/XOsu1jRUV5rTnzhy/RQVnYrnm2vgjuxrQZ05q6PB2DpWE3kfbVVPGu3Pz8z5La2 mxp7kMKkOrBkzsDVC0Ma8ujkjWxH5dL7K2iHgKm/gkUG43Rl96UgpCGrCcZdB4gjgteI DHEhLm1KhLHTsHLgDUtysTa0x/3lPjQzOvg5GIpU05SZvDrarRoqcctOfH3189GhO97W gHaZQTavb4qODEdYjiFrJY1MXxOlldR3VrV1G2OLfyYM4unG2P+t+6jgOfZjs5c/HqRe j7Xw== X-Gm-Message-State: AC+VfDwI8W+YxVg3pdg9KEbxQC2YEtzCfFuUl7HmnZBoMtArjrwhe83i B3LviwNvyFZlp/8nmRv3mFPSlDR8z/eK5Q== X-Received: by 2002:a05:6a20:8f10:b0:102:345f:593b with SMTP id b16-20020a056a208f1000b00102345f593bmr28960762pzk.4.1684221565221; Tue, 16 May 2023 00:19:25 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.15]) by smtp.googlemail.com with ESMTPSA id 17-20020aa79251000000b006468222af91sm12849830pfp.48.2023.05.16.00.19.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 00:19:24 -0700 (PDT) From: Ze Gao X-Google-Original-From: Ze Gao To: Steven Rostedt , Masami Hiramatsu Cc: Albert Ou , Alexander Gordeev , Alexei Starovoitov , Borislav Petkov , Christian Borntraeger , Dave Hansen , Heiko Carstens , "H. Peter Anvin" , Ingo Molnar , Palmer Dabbelt , Paul Walmsley , Sven Schnelle , Thomas Gleixner , Vasily Gorbik , x86@kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org, Conor Dooley , Jiri Olsa , Yonghong Song , Ze Gao , stable@vger.kernel.org Subject: [PATCH v2 3/4] fprobe: add recursion detection in fprobe_exit_handler Date: Tue, 16 May 2023 15:18:29 +0800 Message-Id: <20230516071830.8190-4-zegao@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230516071830.8190-1-zegao@tencent.com> References: <20230516071830.8190-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 recursion detection but fprobe_exit_handler has not, which possibly introduce recursive 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 recursion free guard the same way as fprobe_hander. Since ftrace recursion check does not employ ip(s), so here use entry_ip and entry_parent_ip the same as fprobe_handler. Fixes: 5b0ab78998e3 ("fprobe: Add exit_handler support") Signed-off-by: Ze Gao Cc: stable@vger.kernel.org Acked-by: Masami Hiramatsu (Google) --- kernel/trace/fprobe.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c index 097c740799ba..a9580a88cc15 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 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; } @@ -114,14 +116,25 @@ static void fprobe_exit_handler(struct rethook_node *rh, void *data, { 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