Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp29069iog; Tue, 14 Jun 2022 18:06:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxqOAwmPEzrdoLjPnOYYT0NkSvxHew9bNFX8URdtj/3zwRdvYGTeOHa0b07zxwof9MklA0 X-Received: by 2002:a05:6402:518d:b0:431:5487:9606 with SMTP id q13-20020a056402518d00b0043154879606mr9631507edd.177.1655255205187; Tue, 14 Jun 2022 18:06:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655255205; cv=none; d=google.com; s=arc-20160816; b=FzsJqRDMJe9JmtX2t1jiWDNtV//3qlK/EqwTeVnZzXfBIbEm7/PoK5YjpO3ebAmzow 5UCHIhB+yz6wQkNJc6TLhuWgNcM+IaipHrPlJErsjCgIo7RvJm+ZQnkn78YEwEthrEJG LLIdh06g6okEEAXO1H+UXbQnAOoHghS/pIdnOsIiBBgEZcruSJ6k3S1uHFI4btDuE3n8 wcr+aVJNeG5WMCgxw6zqK3cBhywu9FPVrDnTX3Ia6YDBLC3sXQiXZUvor/dAwqbZUAZr BUwuHGHgqMeFwnpifw1VgPfzap5CaOP2aUYyCM0TQEypIAEbglSIWOMP90yhWEDLS04T Debg== 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:subject:cc:to:from:date :dkim-signature; bh=Ej43mxgsxzLNjw29OJqnaztPr1yWQVKIh70O8jlV9io=; b=YyH+2DXFFaXt71aH0u2oRGyGWIUJR+uEw3orbOAN6wPUauzMk9vkKVX6b7G4GI9SpL i+wfiSR5wotNxgNmBPz/vBECjrwzBR0p7kdiN+eRTj37qw5DVZqzZHoWb/yX8OpMgB6M Kt7uKqrczL2VtEuV8cIV2eUtpDvhRgzMyZUycjkJl9AO5n7zyHSBTzAnUHknJNORDCJI 0HHncFB8QhUL6Ry3FrLmNcXaKh0XVR6A7L9Mkul5w943eD+nibBjSvmWEI4Zv2QJU4Fb ZUNDqDd61XoyYW+P1a0Xpw/KnwjIRuT8dQiDDcAWbEllsbypcWZQSZh0BbR3rkejAVbK vL1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tmV7wIid; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j10-20020a05640211ca00b00423ed4c5c02si15675858edw.205.2022.06.14.18.06.20; Tue, 14 Jun 2022 18:06:45 -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=@kernel.org header.s=k20201202 header.b=tmV7wIid; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237710AbiFOAef (ORCPT + 99 others); Tue, 14 Jun 2022 20:34:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232753AbiFOAed (ORCPT ); Tue, 14 Jun 2022 20:34:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0889435DDF; Tue, 14 Jun 2022 17:34:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 615C461939; Wed, 15 Jun 2022 00:34:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5BB1AC3411B; Wed, 15 Jun 2022 00:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655253269; bh=Yz13IgKOC0iptK56o8LR0wiHGkxHflnnEptjcBA8JLw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=tmV7wIidivjbcMYZ1hU1aTj9NB/A1MRCBVya/3tpreqni8hYFTx913TzD1NS8JXzo 7yfglVwuTvYpw2EBONC4IqG7Qtnl28CanSp6+3xRhBnJG6By8uYCcvThL1H0kyaOIb Y1TG1oVICzZ69U54EejXLTINvPLTLZ0MhanhQosB3nppl1C96/A2bGlpoySXWo61s+ tdzeedOKE9kJl8OO1hWVBeLNBSntRl7/wS8d2mNyV2LezzrsgBr75Jd95vG4vKbrM/ KQ79GkATvcNvu3c3s6SUp9oEnpDqkpo4QUN4W5MVZ5cUtfx4xPmuUS8ERy9NG/KjHg Dh2sVTlY4r3Zg== Date: Wed, 15 Jun 2022 09:34:24 +0900 From: Masami Hiramatsu (Google) To: Chuang W Cc: stable@vger.kernel.org, "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu , Ingo Molnar , Jessica Yu , linux-kernel@vger.kernel.org Subject: Re: [PATCH] kprobes: Rollback post_handler on failed arm_kprobe() Message-Id: <20220615093424.961cfa58eae0a8ce601e7af6@kernel.org> In-Reply-To: <20220614090633.43832-1-nashuiliang@gmail.com> References: <20220614090633.43832-1-nashuiliang@gmail.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_HI,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 Hi Chuang, On Tue, 14 Jun 2022 17:06:33 +0800 Chuang W wrote: > In a scenario where livepatch and aggrprobe coexist, if arm_kprobe() > returns an error, ap.post_handler, while has been modified to > p.post_handler, is not rolled back. Would you mean 'coexist' on the same function? > > When ap.post_handler is not NULL (not rolled back), the caller (e.g. > register_kprobe/enable_kprobe) of arm_kprobe_ftrace() will always fail. It seems this explanation and the actual code does not match. Can you tell me what actually you observed? Thank you, > > Fixes: 12310e343755 ("kprobes: Propagate error from arm_kprobe_ftrace()") > Signed-off-by: Chuang W > Cc: > --- > kernel/kprobes.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index f214f8c088ed..0610b02a3a05 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > @@ -1300,6 +1300,7 @@ static int register_aggr_kprobe(struct kprobe *orig_p, struct kprobe *p) > { > int ret = 0; > struct kprobe *ap = orig_p; > + kprobe_post_handler_t old_post_handler = NULL; > > cpus_read_lock(); > > @@ -1351,6 +1352,9 @@ static int register_aggr_kprobe(struct kprobe *orig_p, struct kprobe *p) > > /* Copy the insn slot of 'p' to 'ap'. */ > copy_kprobe(ap, p); > + > + /* save the old post_handler */ > + old_post_handler = ap->post_handler; > ret = add_new_kprobe(ap, p); > > out: > @@ -1365,6 +1369,7 @@ static int register_aggr_kprobe(struct kprobe *orig_p, struct kprobe *p) > ret = arm_kprobe(ap); > if (ret) { > ap->flags |= KPROBE_FLAG_DISABLED; > + ap->post_handler = old_post_handler; > list_del_rcu(&p->list); > synchronize_rcu(); > } > -- > 2.34.1 > -- Masami Hiramatsu (Google)