From patchwork Thu Jun 29 23:50:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beau Belgrave X-Patchwork-Id: 114512 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10010431vqr; Thu, 29 Jun 2023 17:41:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlEnBT6Cf6A6tGo76/VagADGM2gbPdSbGFo/LFdE8adihrkUxf19CLuJEgp/b0fG2C9oMk5j X-Received: by 2002:aa7:980a:0:b0:677:bb4c:c321 with SMTP id e10-20020aa7980a000000b00677bb4cc321mr1582731pfl.0.1688085673293; Thu, 29 Jun 2023 17:41:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688085673; cv=none; d=google.com; s=arc-20160816; b=bIqbcS/trLiuRNWwRVGr6cmdMwUeaWSEtF+s4eRiS9JOPa8YeLny0Fosjf8IF7Grgn EZN/pRjaV+VEs41EyGNDdtkSzl+3VO5tfnpXgIJ9thSYAnPEj136p/NyZURSoZE2GDar wwGochMvF3H56ukjvyf6baVI56bxiG6V6X72hXYMpt+0rnEvemEaNWbOd8NFB2cwrlpY X4SbYQ7FdDuF+yO4K9eHYyPbaVZkhE3aQgHH4o6/GlFEU7wgr6WTvhD7kDiBFrjlkJfR dE+ZlBkKhbPZV1e/lLWLixc34WNxLqJtbZsRm+ZUNYqfk/D9LHgO4N+wLzI6LdXSbLG8 8oKA== 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:dkim-filter; bh=gCxckCcdhkcYSNpOGc+UHMmZw5sSgaEy+c0gjwxBW/Q=; fh=p4jcC6qPA5R6qIqhMXvm4Q5Zg5H5ZjhkM/jXdOBVsQs=; b=sSjGMzwm7klNJAXdHTjfYI6HF2yQjMCOrBsTmh0jqh13VnTBk1YnAxwvuMYDjLPIqV 8zc60rVZq7qolcq/7kWwZguTdeSAl5rd4UCJXP6H65krI07qeKveSxgs6PlTMeOh1NCs 3tcd5ma4TH0eBoQX8O8IGgFmmJG29SK6S7LRN8dBo77MmmRsqFZsVocJpiNmtr+S1a7w ZmUO7D+2hfhkDr4Yy7Ds3L77kODrxZLeBsR4n1bRpfvNyuQPcGiiYNluCEUjwz5vkLt/ Vd4vM8SR6Mfm+GV410rmykTJntqpukrcsaydq7aqes6HK89StuSC3Yyvr4VdHPb9oXlW fOyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=BZlKCwXe; 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=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p38-20020a634f66000000b0053ef158b0c3si11544650pgl.25.2023.06.29.17.41.00; Thu, 29 Jun 2023 17:41: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=@linux.microsoft.com header.s=default header.b=BZlKCwXe; 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=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230474AbjF2XvE (ORCPT + 99 others); Thu, 29 Jun 2023 19:51:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230286AbjF2Xu4 (ORCPT ); Thu, 29 Jun 2023 19:50:56 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 973D430F1; Thu, 29 Jun 2023 16:50:55 -0700 (PDT) Received: from CPC-beaub-VBQ1L.localdomain (unknown [4.155.48.123]) by linux.microsoft.com (Postfix) with ESMTPSA id AA4AD208396B; Thu, 29 Jun 2023 16:50:54 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AA4AD208396B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1688082654; bh=gCxckCcdhkcYSNpOGc+UHMmZw5sSgaEy+c0gjwxBW/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BZlKCwXeupqEmLSMFQsH4rfdDLmvfpxma01KBAaL01XCt0ehHvzVGlrOcbTYEuk9H LIPTkaXf0toboei85ZVGoBtPtrwvrozJKh2jpCgntl0E+uNdwwS3M65B3Fg31U5eg5 B8zZddU70CKUl6TYMkQM3i1mqVL+h4vEGKqM0XqQ= From: Beau Belgrave To: rostedt@goodmis.org, mhiramat@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH 1/2] tracing/user_events: Fix struct arg size match check Date: Thu, 29 Jun 2023 23:50:48 +0000 Message-Id: <20230629235049.581-2-beaub@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230629235049.581-1-beaub@linux.microsoft.com> References: <20230629235049.581-1-beaub@linux.microsoft.com> MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770085115241586654?= X-GMAIL-MSGID: =?utf-8?q?1770086122798685870?= 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. Fixes: e6f89a149872 ("tracing/user_events: Ensure user provided strings are safely formatted") Signed-off-by: Beau Belgrave --- 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 8df0550415e7..5c787fe48d53 100644 --- a/kernel/trace/trace_events_user.c +++ b/kernel/trace/trace_events_user.c @@ -1317,6 +1317,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, ";"); From patchwork Thu Jun 29 23:50:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beau Belgrave X-Patchwork-Id: 114515 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10011703vqr; Thu, 29 Jun 2023 17:44:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlF0PJHxloT5JQznGama5EmmnwK2Yr3cGguO7WGXdxfu7LADNPCcMx9vltCfbN7fZt88/KTN X-Received: by 2002:aa7:980a:0:b0:677:bb4c:c321 with SMTP id e10-20020aa7980a000000b00677bb4cc321mr1587742pfl.0.1688085884367; Thu, 29 Jun 2023 17:44:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688085884; cv=none; d=google.com; s=arc-20160816; b=xzhNy/h2pEXFW1RY6ktfhigagvl6CoGA3n/Yc/OrAlxIeslfDQeto4N7FHuZ55+crQ x3FZow7odvBzGLNHfWIAakGgKdIGe+hG+dVYN1KkBAR3qcdYdZDaee7koTqaXiTDsTX1 HiVYO6qnfhY5oYp7D5e3xjK7jE/YF7l+G3/6USdQ8ZV+Ufantu4a6D5ZJ37TOq1WH6sl SmOm7gyRucvJsBFWDHGx8WjL9Kv1gV66fyqYaGafeTz0DpY07Q0c4usY2uuvaAIXd7wz qvFml+BByQ3FqtiqJNTa3TT2H4FaOeYD6DPUWTNVvPvzlzurNPr/Iflb5InkGcq6C/XB c7Yw== 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:dkim-filter; bh=0aQD7w91qsRnUacHvqCqrLheZ0AfaxAuOy5KqQ12dw8=; fh=p4jcC6qPA5R6qIqhMXvm4Q5Zg5H5ZjhkM/jXdOBVsQs=; b=EEVIJfyfjZPYDffRvJKVNkJSCqfMkDtfMDTmPhTgRUmYlSFM1jTN7kiI/+ktEssW7L W4ozXdpqdNfbMDedZ/dpzKNiQ/bGplFiPMLYVRpOHjq8XiaC5peA6KwDUWxz7PxNn6bs 9od9WnqI/I5+O0M2U2wPLxRB6tQi7W+62d1DVRJmcGVvRWsLFZoxbIf0J+4v0dzEKu4H rLShTFMMJa6IofXODh7D0ZaE+kpRcS/uTM9YfzCBOJNnioyWhgEmXHIn6QFb3rGRsEaN 7g9jV+isdtOtIVVYWpg6x5S6RZvG0s+EUH7ewG8nPzAXOI9lnY88Xa3ZEzqywYtIpkGs k6zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Y3trTN8u; 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=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u12-20020a056a00124c00b006543a5c8fb7si11317103pfi.286.2023.06.29.17.44.30; Thu, 29 Jun 2023 17:44:44 -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=@linux.microsoft.com header.s=default header.b=Y3trTN8u; 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=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230462AbjF2XvB (ORCPT + 99 others); Thu, 29 Jun 2023 19:51:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230256AbjF2Xu4 (ORCPT ); Thu, 29 Jun 2023 19:50:56 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 966DA2D55; Thu, 29 Jun 2023 16:50:55 -0700 (PDT) Received: from CPC-beaub-VBQ1L.localdomain (unknown [4.155.48.123]) by linux.microsoft.com (Postfix) with ESMTPSA id C2F84208396C; Thu, 29 Jun 2023 16:50:54 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com C2F84208396C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1688082654; bh=0aQD7w91qsRnUacHvqCqrLheZ0AfaxAuOy5KqQ12dw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y3trTN8upge61n68tUauMvmEglojh7Eu6kcf56/khalzgWsTsroZzvWzaUKgLrdN/ +VVBUDDdlaaVYvB3tXU7DJyJwwPzOQnF9N438SsZY3IExQpDlZuAbzECcByTb4VA84 hJOXprKkVX4WLa6kbaWfgUv9lPttAuHsGFfHA2R0= From: Beau Belgrave To: rostedt@goodmis.org, mhiramat@kernel.org Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [PATCH 2/2] selftests/user_events: Test struct size match cases Date: Thu, 29 Jun 2023 23:50:49 +0000 Message-Id: <20230629235049.581-3-beaub@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230629235049.581-1-beaub@linux.microsoft.com> References: <20230629235049.581-1-beaub@linux.microsoft.com> MIME-Version: 1.0 X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770086344156864788?= X-GMAIL-MSGID: =?utf-8?q?1770086344156864788?= The self tests for user_events currently does not ensure that the edge case for struct types work properly with size differences. Add cases for mis-matching struct names and sizes to ensure they work properly. Signed-off-by: Beau Belgrave --- tools/testing/selftests/user_events/dyn_test.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/testing/selftests/user_events/dyn_test.c b/tools/testing/selftests/user_events/dyn_test.c index d6979a48478f..91a4444ad42b 100644 --- a/tools/testing/selftests/user_events/dyn_test.c +++ b/tools/testing/selftests/user_events/dyn_test.c @@ -217,6 +217,18 @@ TEST_F(user, matching) { /* Types don't match */ TEST_NMATCH("__test_event u64 a; u64 b", "__test_event u32 a; u32 b"); + + /* Struct name and size matches */ + TEST_MATCH("__test_event struct my_struct a 20", + "__test_event struct my_struct a 20"); + + /* Struct name don't match */ + TEST_NMATCH("__test_event struct my_struct a 20", + "__test_event struct my_struct b 20"); + + /* Struct size don't match */ + TEST_NMATCH("__test_event struct my_struct a 20", + "__test_event struct my_struct a 21"); } int main(int argc, char **argv)