Message ID | a17a14abfb81cb0eea77c2ee10d7fc98d5d5a73e.1684120990.git.zegao@tencent.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6653116vqo; Sun, 14 May 2023 21:15:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6NY2UXVBBiA5N8PtP2NZRBcHrwaESoodusWPbiy5WwW2x2EG4tPASTBiG/hqnzcL18MIsU X-Received: by 2002:a17:902:bc83:b0:1ad:fcdc:2a9f with SMTP id bb3-20020a170902bc8300b001adfcdc2a9fmr6034717plb.51.1684124108100; Sun, 14 May 2023 21:15:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684124108; cv=none; d=google.com; s=arc-20160816; b=EYvYpiNhF8EciBgR+gVFGVW26rw+u0oR5UM24Fn+WvA8RjxowU9WVwTaI6Yr7uA26b ZbECCoor8vHwNcHEdU9g8NkosGRzAoUssjnKxBFJe77COhFPhmTocFCBYkerCq+ItmDp Rz7REDi5hNybRlWWf1Y2Ne78bq9uLQxSlN00ogiUc6DOPC2I0JLnmElRnLXOCXzgB21C RZAz2gVKnrkz2jKUasV0G2XrrZXU8co/8c5MwdzyH5RljmTnLJ1E2sKHSWAU492PDQAK PjMxsWd6Xz7jNAQmQOzLKvmakU7vc748oSo9E/H0cRi7Bo9NxNU8tVI4Q84+ZL5uQcIL fuLA== 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=HfO0FQe7LL8tpwg2PdMURaHU+jV7nrgpfKB4jccXJDQ=; b=j2mcAurm/gphpqv8WBM18nNkA72yR9rx/mHBet57VLWear/TcynWR8jJmzQ9PPW81a rzQnlhSm01enciPMdeoomS87ik9MNTTDgVBHPNWZp0ZL2fEzDxbTiciDe3/+VQLF4SEi swEYjU0TncOEQTqmBKSbZBcA0nDqVltnUXlk1N6JEakkoJ/zv4XMtSUvQGl3zQLwGXPQ 976H+Zb8Ct8KuVTOu3BwE8l7y4YeyT+HfdkO2EssvQXDKioGeoS16lUMaonsrgGB5/Sj bgSBaYluxeo+dBrdAIMnwwvscXLwy2jXibWSjlkpQzUdP1q/EOFxV7VrplMd1GC7V+J4 SCLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=WVB3C+5o; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x13-20020a170902ec8d00b001a1ad6fabdesi16377557plg.228.2023.05.14.21.14.53; Sun, 14 May 2023 21:15:08 -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=WVB3C+5o; 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 S238097AbjEOD1I (ORCPT <rfc822;peekingduck44@gmail.com> + 99 others); Sun, 14 May 2023 23:27:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36418 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232128AbjEOD1F (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 14 May 2023 23:27:05 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C7F01997; Sun, 14 May 2023 20:27:04 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6434e263962so8954157b3a.2; Sun, 14 May 2023 20:27:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684121224; x=1686713224; 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=HfO0FQe7LL8tpwg2PdMURaHU+jV7nrgpfKB4jccXJDQ=; b=WVB3C+5of4uMP7ScO4Yvn60WFDYoZNDWLC01FoZNuZamSGzinFIhL1w/yn5LeSaHsf 2mLOOVY3Edk9fekV4079ljH4DU4Iqdw7lhLf6R6cmjsLGHOhoRbBglRCi3DFwZ5jTP7C GrbVATSZ3VdzrORZcPMoHtC94RWmOjbHrb/jRlj2Urt07DFAmnUl+GeWurCUYg/tdbU0 b9M7fiY9FzWmDsK2/OAEWmMQAeuftDNcl7Y2GYAIR/iUnLRUriLPTEoDCeCwgT7m3iwY KG4kbm1vSDeHkz/PUOiXUGZJsTlGVSQwjg0AdRpxH/Baih5krASD17n4VZxKuzWlL0rz E4kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684121224; x=1686713224; 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=HfO0FQe7LL8tpwg2PdMURaHU+jV7nrgpfKB4jccXJDQ=; b=VI8pyGag1JXpGFppzjhRBEsy8D9nctXuUW1cncuwLrskLgYn+AqhFUxfYDXkfKpFMp aVPm25iOBdY4MaynVxE+AXGHLCr2noMClUbNPj9u7dCLRVujw3f2pNRVbguXBtJEcpjd 2fREDSya3zsx/l5s3Gfg+chof0irn1e6ZmhybviQhAc2wchXgSXoRKQFx2jP9RwS3lP7 MZZ+Sfnkt1bF95xRR8TxlUbEZ/aIfVA+Hbe5L7dOHAluBT94t67AKJtPym07ML56j67K WYQS38NJbW+LSuO078wAKHjJO1INNJFDiwIDR+1sQXdEKN5Gff0GSmGSewZCYdzjBxyj QKXw== X-Gm-Message-State: AC+VfDyJGD03mtPjFNLBT0iDUoiQDos8TbOkKt97bg/UHUFZZqQbQFwr hfz/tl95rrh/QZtnH9+n8Vg= X-Received: by 2002:a05:6a20:4291:b0:100:efa1:eab0 with SMTP id o17-20020a056a20429100b00100efa1eab0mr31177918pzj.2.1684121223711; Sun, 14 May 2023 20:27:03 -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.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 May 2023 20:27:03 -0700 (PDT) From: Ze Gao <zegao2021@gmail.com> X-Google-Original-From: Ze Gao <zegao@tencent.com> To: Steven Rostedt <rostedt@goodmis.org>, Masami Hiramatsu <mhiramat@kernel.org> Cc: Ze Gao <zegao@tencent.com>, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH 1/4] rethook: use preempt_{disable, enable}_notrace in rethook_trampoline_handler Date: Mon, 15 May 2023 11:26:38 +0800 Message-Id: <a17a14abfb81cb0eea77c2ee10d7fc98d5d5a73e.1684120990.git.zegao@tencent.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <cover.1684120990.git.zegao@tencent.com> References: <cover.1684120990.git.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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765932120842597319?= X-GMAIL-MSGID: =?utf-8?q?1765932120842597319?= |
Series |
Make fpobe + rethook immune to recursion
|
|
Commit Message
Ze Gao
May 15, 2023, 3:26 a.m. UTC
This patch replace preempt_{disable, enable} with its corresponding
notrace version in rethook_trampoline_handler so no worries about stack
recursion or overflow introduced by preempt_count_{add, sub} under
fprobe + rethook context.
Signed-off-by: Ze Gao <zegao@tencent.com>
---
kernel/trace/rethook.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
Hi Ze Gao, Thanks for the patch. On Mon, 15 May 2023 11:26:38 +0800 Ze Gao <zegao2021@gmail.com> wrote: > This patch replace preempt_{disable, enable} with its corresponding > notrace version in rethook_trampoline_handler so no worries about stack > recursion or overflow introduced by preempt_count_{add, sub} under > fprobe + rethook context. So, have you ever see that recursion of preempt_count overflow case? I intended to use the normal preempt_disable() here because it does NOT prohibit any function-trace call (Note that both kprobes and fprobe checks recursive call by itself) but it is used for preempt_onoff tracer. Thanks, > > Signed-off-by: Ze Gao <zegao@tencent.com> > --- > kernel/trace/rethook.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c > index 32c3dfdb4d6a..60f6cb2b486b 100644 > --- a/kernel/trace/rethook.c > +++ b/kernel/trace/rethook.c > @@ -288,7 +288,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs, > * These loops must be protected from rethook_free_rcu() because those > * are accessing 'rhn->rethook'. > */ > - preempt_disable(); > + preempt_disable_notrace(); > > /* > * Run the handler on the shadow stack. Do not unlink the list here because > @@ -321,7 +321,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs, > first = first->next; > rethook_recycle(rhn); > } > - preempt_enable(); > + preempt_enable_notrace(); > > return correct_ret_addr; > } > -- > 2.40.1 >
On Tue, 16 May 2023 13:25:02 +0900 Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote: > Hi Ze Gao, > > Thanks for the patch. > > On Mon, 15 May 2023 11:26:38 +0800 > Ze Gao <zegao2021@gmail.com> wrote: > > > This patch replace preempt_{disable, enable} with its corresponding > > notrace version in rethook_trampoline_handler so no worries about stack > > recursion or overflow introduced by preempt_count_{add, sub} under > > fprobe + rethook context. > > So, have you ever see that recursion of preempt_count overflow case? > > I intended to use the normal preempt_disable() here because it does NOT > prohibit any function-trace call (Note that both kprobes and > fprobe checks recursive call by itself) but it is used for preempt_onoff > tracer. OK, I got the point. rethook_trampoline_handler() { preempt_disable() { preempt_count_add() { => fprobe and set rethook } => rethook_trampoline_handler() { preempt_disable() { ... So the problem is that the preempt_disable() macro calls preempt_count_add() which can be tracable. So, let's make it notrace. Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> and Fixes: 54ecbe6f1ed5 ("rethook: Add a generic return hook") Cc: stable@vger.kernel.org Thank you, > > Thanks, > > > > > Signed-off-by: Ze Gao <zegao@tencent.com> > > --- > > kernel/trace/rethook.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c > > index 32c3dfdb4d6a..60f6cb2b486b 100644 > > --- a/kernel/trace/rethook.c > > +++ b/kernel/trace/rethook.c > > @@ -288,7 +288,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs, > > * These loops must be protected from rethook_free_rcu() because those > > * are accessing 'rhn->rethook'. > > */ > > - preempt_disable(); > > + preempt_disable_notrace(); > > > > /* > > * Run the handler on the shadow stack. Do not unlink the list here because > > @@ -321,7 +321,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs, > > first = first->next; > > rethook_recycle(rhn); > > } > > - preempt_enable(); > > + preempt_enable_notrace(); > > > > return correct_ret_addr; > > } > > -- > > 2.40.1 > > > > > -- > Masami Hiramatsu (Google) <mhiramat@kernel.org>
diff --git a/kernel/trace/rethook.c b/kernel/trace/rethook.c index 32c3dfdb4d6a..60f6cb2b486b 100644 --- a/kernel/trace/rethook.c +++ b/kernel/trace/rethook.c @@ -288,7 +288,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs, * These loops must be protected from rethook_free_rcu() because those * are accessing 'rhn->rethook'. */ - preempt_disable(); + preempt_disable_notrace(); /* * Run the handler on the shadow stack. Do not unlink the list here because @@ -321,7 +321,7 @@ unsigned long rethook_trampoline_handler(struct pt_regs *regs, first = first->next; rethook_recycle(rhn); } - preempt_enable(); + preempt_enable_notrace(); return correct_ret_addr; }