From patchwork Tue Jul 11 14:06:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 118553 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp514607vqm; Tue, 11 Jul 2023 07:18:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlElwkq3++QF75NwWLVFvCfYzTV/VXHX/VVoEJelMsG2clnnvJ78Vw7iDZZX5u8gpNcgPqY+ X-Received: by 2002:a17:907:cc9a:b0:992:b3a3:81f4 with SMTP id up26-20020a170907cc9a00b00992b3a381f4mr16972497ejc.50.1689085115782; Tue, 11 Jul 2023 07:18:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689085115; cv=none; d=google.com; s=arc-20160816; b=ojwJ/mh1N9Rejmzz03oa7BHmRM3ReEedjt+rUOv15QzjJmahIitQICH49Rdah8gKKP sVAhO3Ec01IFDVpgJIx1p3kwtN694zWvLJDsycokTMWoWgZv+lT1AWStfQOD+gHm/AxL XRs8TYvtet0isdwsulS0SkPcN2sUBDF0RPiy7Gds2vAYXZcvOYkH/6lZBWRjwF4sYAji kIBW2olKVUser30bA6V429XxkaXVFbw1FAyFHzaoAnTLr3AsqhUKExD2esW/EKkO0Jhy KFonLXioOvYTDI9LzNWmHRe+MCgqDwpl8YaVsQb0klVs801QzuYyUyReCT9PSyoizeLF Y+IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=RsXEfdadTjrTJTAH6+qe15wBEGGF9CsgPrVdqrTRn4M=; fh=TaaQLnbGWiKu3/HwIKiA70emPjplBVeR5ymaX4dVUCg=; b=bDTZr/QJbI2CuCrna3pQ2o730MUaopgb0bujxrIqBpI+GoOhawrRZvBhDzDfHzUAWz JCyc//CH6mfEbtMS6SP+R2Npko353s8f78CJxIeJm0HKmnX5i/oC3+s2o1gtbHtZn9DP dX1+P3T0iG2zd9DTFiSX5iJLz9IkP8TwkI5IfopNuIrlJo/KwSO5YRgHtfztCGVOVsUH XPdlky9WYKuSRfDofxv3JLJhnqSdXggFYI4R/Ctg/SDKRBh9mDLE/RPjxUaPHYMMfCgO PNtB7RmXmEPpTKpmgYuVFFuHHbS5dfUCwspFYYXTzvdIw1VekUe3mWx2RXplHSO4hBsc EUUg== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xa17-20020a170907b9d100b0099351214a94si2286025ejc.648.2023.07.11.07.18.11; Tue, 11 Jul 2023 07:18:35 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233303AbjGKOH2 (ORCPT + 99 others); Tue, 11 Jul 2023 10:07:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233313AbjGKOHT (ORCPT ); Tue, 11 Jul 2023 10:07:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 081B8BC; Tue, 11 Jul 2023 07:07:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4ABC861519; Tue, 11 Jul 2023 14:07:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5057C433C7; Tue, 11 Jul 2023 14:07:17 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.96) (envelope-from ) id 1qJE1M-0007nN-2Q; Tue, 11 Jul 2023 10:07:16 -0400 Message-ID: <20230711140716.561714719@goodmis.org> User-Agent: quilt/0.66 Date: Tue, 11 Jul 2023 10:06:57 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Andrew Morton , stable@vger.kernel.org, Beau Belgrave Subject: [for-linus][PATCH 5/5] tracing/user_events: Fix struct arg size match check References: <20230711140652.217008556@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771134114482096601 X-GMAIL-MSGID: 1771134114482096601 From: Beau Belgrave When users register an event the name of the event and it's argument are checked to ensure they match if the event already exists. Normally all arguments are in the form of "type name", except for when the type starts with "struct ". In those cases, the size of the struct is passed in addition to the name, IE: "struct my_struct a 20" for an argument that is of type "struct my_struct" with a field name of "a" and has the size of 20 bytes. The current code does not honor the above case properly when comparing a match. This causes the event register to fail even when the same string was used for events that contain a struct argument within them. The example above "struct my_struct a 20" generates a match string of "struct my_struct a" omitting the size field. Add the struct size of the existing field when generating a comparison string for a struct field to ensure proper match checking. Link: https://lkml.kernel.org/r/20230629235049.581-2-beaub@linux.microsoft.com Cc: stable@vger.kernel.org Fixes: e6f89a149872 ("tracing/user_events: Ensure user provided strings are safely formatted") Signed-off-by: Beau Belgrave Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace_events_user.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c index dbb14705d0d3..83c0536ff41c 100644 --- a/kernel/trace/trace_events_user.c +++ b/kernel/trace/trace_events_user.c @@ -1223,6 +1223,9 @@ static int user_field_set_string(struct ftrace_event_field *field, pos += snprintf(buf + pos, LEN_OR_ZERO, " "); pos += snprintf(buf + pos, LEN_OR_ZERO, "%s", field->name); + if (str_has_prefix(field->type, "struct ")) + pos += snprintf(buf + pos, LEN_OR_ZERO, " %d", field->size); + if (colon) pos += snprintf(buf + pos, LEN_OR_ZERO, ";");