Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2894639rwd; Mon, 29 May 2023 02:30:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ74qx8hnF6F04VaJogccnmT/gAsHMDOftbQ6z0TWJ2VhqRdrT7ec7fVwvlbxjFn/jlSZNAO X-Received: by 2002:a17:903:25cd:b0:1b0:3a74:7fd6 with SMTP id jc13-20020a17090325cd00b001b03a747fd6mr3197192plb.52.1685352657637; Mon, 29 May 2023 02:30:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685352657; cv=none; d=google.com; s=arc-20160816; b=KQO56L9ef7w5eJKoouHUjmdsOZDmktA1MZJswQYn2CmJY4NA0aAGJbs7C01XztzCo0 swVipxPdmvgmW+c94Kwd9HpeWERR0AWC/gyuScfYwxGr1TbcRxxm6dglG9bCI2DybzxL fNQ2zkwg0zshN6oHotfplHVksDPloGLBRcNLxA6pywz72Y/aUXmRiRrfOkZvdfHflBIe yEfFLZb9VwngpyKhGaJlJOY7Wf1sC0C1g6IEVSZns0x+dIo6PaqwDgaCq3rz/yyiOOON PsJhhciVW1sF7LlLYQ7FnBVzE2lZIbJBK3BqQfe4dZFcvhE3UnACrVE1xt49uT5fmwGd F1Gg== 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=D6JIsB1SR5Ul5Gk2UKco86ee2S/ldMlyJ9kribm25SM=; b=TqDrKSzsYFFYl97fu1x8JB4GAbUmj2Ed//fPNHh4f5lt9d9vOq/jFjqwt9LU9Dqmvw gfrIvAMam1JQQ8iz7UGhR5k357Uo2Yj9v6H18axjb0YN+M2XWXLR5K0pmKMxyrQR8qkt 6yhl2QC+llXqQ3CD0eR3B3rZ+ITwiU7+wGl/JZTCyVjmeyIe5N5WRtXc0yuSvvoQWAjM fCxbHlnBqp/jVc2W2PK+dD/nQMc6oD9Zqok5sXtCBv4DnB3KOCWpcYuZwRU7y0xSBtoA 40aC8WZh9uIrI+j+1lY4zR5yDr5/ne2IlTKsE5nhmmVzCT0NLY/os9uo/Wa3yfjb+eFs aZfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="dIOU/xaG"; 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 e4-20020a17090301c400b001b04c325d66si330428plh.565.2023.05.29.02.30.45; Mon, 29 May 2023 02:30:57 -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="dIOU/xaG"; 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 S231469AbjE2JXZ (ORCPT + 99 others); Mon, 29 May 2023 05:23:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229572AbjE2JXX (ORCPT ); Mon, 29 May 2023 05:23:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6DFEAC; Mon, 29 May 2023 02:23:22 -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 7402162247; Mon, 29 May 2023 09:23:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02F23C4339B; Mon, 29 May 2023 09:23:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685352201; bh=GWbhfro7mScT3pUdsUQtz4ZAPeagy5Rb6k2c8ZAI6OQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=dIOU/xaGwkDyKcwyDocIkiVQbENBQUi7g8WqE5qVwhsQEKDXoKJAnOaqRk5026r0M 6oyFDRIKaqfaBYUw5znjcIqLKg5YqJ7kQG15fkIxk29lHxmPMgWriZOU1HpjRvc1xP K1Ieza6rVH1Q9zHLYYzJeQ+pcW5U1cpYDq6KtrH45561axeaGeA7l6d1Jn4P4flXoh g8PvuHzoF6Agw4qkKi1ijOvsDhq57VDhV6atWntw/7r6SU2zWDcX28ARQWofVWdB0p 3LahSss88sxsVsd2diXJijydgrAi6UZFgzu3pzXw30uPOKtqzRlIDjUgoyTUlH3HSA w78SZsz40txaA== Date: Mon, 29 May 2023 18:23:19 +0900 From: Masami Hiramatsu (Google) To: sunliming Cc: rostedt@goodmis.org, beaub@linux.microsoft.com, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH V3] tracing/user_events: Prevent same name but different args event Message-Id: <20230529182319.5b3dff8afcf50922eb46099f@kernel.org> In-Reply-To: <20230529032100.286534-1-sunliming@kylinos.cn> References: <20230529032100.286534-1-sunliming@kylinos.cn> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; 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=-7.4 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 On Mon, 29 May 2023 11:21:00 +0800 sunliming wrote: > User processes register name_args for events. If the same name but different > args event are registered. The trace outputs of second event are printed > as the first event. This is incorrect. > > Return EADDRINUSE back to the user process if the same name but different args > event has being registered. > > Signed-off-by: sunliming Looks good to me. Reviewed-by: Masami Hiramatsu (Google) Thank you, > --- > kernel/trace/trace_events_user.c | 36 +++++++++++++++---- > .../selftests/user_events/ftrace_test.c | 6 ++++ > 2 files changed, 36 insertions(+), 6 deletions(-) > > diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c > index b1ecd7677642..e90161294698 100644 > --- a/kernel/trace/trace_events_user.c > +++ b/kernel/trace/trace_events_user.c > @@ -1753,6 +1753,8 @@ static int user_event_parse(struct user_event_group *group, char *name, > int ret; > u32 key; > struct user_event *user; > + int argc = 0; > + char **argv; > > /* Prevent dyn_event from racing */ > mutex_lock(&event_mutex); > @@ -1760,13 +1762,35 @@ static int user_event_parse(struct user_event_group *group, char *name, > mutex_unlock(&event_mutex); > > if (user) { > - *newuser = user; > - /* > - * Name is allocated by caller, free it since it already exists. > - * Caller only worries about failure cases for freeing. > - */ > - kfree(name); > + if (args) { > + argv = argv_split(GFP_KERNEL, args, &argc); > + if (!argv) { > + ret = -ENOMEM; > + goto error; > + } > + > + ret = user_fields_match(user, argc, (const char **)argv); > + argv_free(argv); > + > + } else > + ret = list_empty(&user->fields); > + > + if (ret) { > + *newuser = user; > + /* > + * Name is allocated by caller, free it since it already exists. > + * Caller only worries about failure cases for freeing. > + */ > + kfree(name); > + } else { > + ret = -EADDRINUSE; > + goto error; > + } > + > return 0; > +error: > + refcount_dec(&user->refcnt); > + return ret; > } > > user = kzalloc(sizeof(*user), GFP_KERNEL_ACCOUNT); > diff --git a/tools/testing/selftests/user_events/ftrace_test.c b/tools/testing/selftests/user_events/ftrace_test.c > index 7c99cef94a65..6e8c4b47281c 100644 > --- a/tools/testing/selftests/user_events/ftrace_test.c > +++ b/tools/testing/selftests/user_events/ftrace_test.c > @@ -228,6 +228,12 @@ TEST_F(user, register_events) { > ASSERT_EQ(0, ioctl(self->data_fd, DIAG_IOCSREG, ®)); > ASSERT_EQ(0, reg.write_index); > > + /* Multiple registers to same name but different args should fail */ > + reg.enable_bit = 29; > + reg.name_args = (__u64)"__test_event u32 field1;"; > + ASSERT_EQ(-1, ioctl(self->data_fd, DIAG_IOCSREG, ®)); > + ASSERT_EQ(EADDRINUSE, errno); > + > /* Ensure disabled */ > self->enable_fd = open(enable_file, O_RDWR); > ASSERT_NE(-1, self->enable_fd); > -- > 2.25.1 > -- Masami Hiramatsu (Google)