From patchwork Thu Aug 5 15:43:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 492269 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:396:0:0:0:0 with SMTP id y22csp415207jap; Thu, 5 Aug 2021 08:49:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywLnh1J9S7RVFDxfK5Glwp/CE6mFFArv34svataG77pQNw12vb+WSnHlY6tN29qbtelnO+ X-Received: by 2002:a05:6402:31a4:: with SMTP id dj4mr7428111edb.350.1628178579869; Thu, 05 Aug 2021 08:49:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628178579; cv=none; d=google.com; s=arc-20160816; b=fJdKSnPI6gUjOxiWFfOqRwR20rg/kuChHa5PL8bjLPcQ44/A2HM3CC5MnS5gayqwK2 nfuBRPR9lfCVesqCqkortKriOsFaXkSg6XGrfqtAov01m09JFswXeOpu0NuY7xCBx12X inn0dkKWyb3YseIJWWv2dki1gMTwOF5aW6vGiOP7gtOCt8Q8ErumEwT+38sdpMlGMEqx fVFhD9UVBhAFw764PF8P5V/710HD5GSbfV1ykq4aZXL/jcCDGoCRCj4fvzhhPVOctxMI Z8PdTAiiLLFm5KZBC1QcrlwX/SB5wtF11kG1aVAyL8JKyFHMQPoyetps3LeHWi46WpT9 7q4A== 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=FhaIxqKTza347iLJRMfiDEP0SfIOkTmM0pBN+dmUkRw=; b=sQn4TfE7F1huBFLE2ssQ9JGZC5Yg4wTlh6qSCNkr9rrRsUPe+iQZ1JORX1NMEjq4IM YrPiedHWScpIdgLTgAjisxuX2gPA1Cf/4MErRZowx/naxuR5ipaYcNIAQBZgiVuzffaN Cpj3botHdGy+YAu0AQMlFTKkxSxJgvhvE5AFxpyEXl/yhQR59IUzsBUEK/za1Ezg8vlN oTSWW0kr0Ff1exsn9uU1BRe7tR08Nal4LmSUZyERd0uP1E8dCrnCHYq8ctGN8fvHlJPH ODnfOQqmEasbFQFFZvNxedPCwnxghNG34OgXgptmWH4hUMlgSu8Pl9dKW/C5guJ9NcS+ DO3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v29si6111719edb.576.2021.08.05.08.49.39; Thu, 05 Aug 2021 08:49:39 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242412AbhHEPtw (ORCPT + 12 others); Thu, 5 Aug 2021 11:49:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:51740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242359AbhHEPtv (ORCPT ); Thu, 5 Aug 2021 11:49:51 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1195561152; Thu, 5 Aug 2021 15:49:37 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.94.2) (envelope-from ) id 1mBfcm-0037wz-37; Thu, 05 Aug 2021 11:49:36 -0400 Message-ID: <20210805154935.938398701@goodmis.org> User-Agent: quilt/0.66 Date: Thu, 05 Aug 2021 11:43:39 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Ingo Molnar , Andrew Morton , stable@vger.kernel.org, Masami Hiramatsu Subject: [for-linus][PATCH 3/6] tracing: Reject string operand in the histogram expression References: <20210805154336.208362117@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Masami Hiramatsu Since the string type can not be the target of the addition / subtraction operation, it must be rejected. Without this fix, the string type silently converted to digits. Link: https://lkml.kernel.org/r/162742654278.290973.1523000673366456634.stgit@devnote2 Cc: stable@vger.kernel.org Fixes: 100719dcef447 ("tracing: Add simple expression support to hist triggers") Signed-off-by: Masami Hiramatsu Signed-off-by: Steven Rostedt (VMware) --- kernel/trace/trace_events_hist.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) -- 2.30.2 diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c index 362db9b81b8d..949ef09dc537 100644 --- a/kernel/trace/trace_events_hist.c +++ b/kernel/trace/trace_events_hist.c @@ -65,7 +65,8 @@ C(INVALID_SORT_MODIFIER,"Invalid sort modifier"), \ C(EMPTY_SORT_FIELD, "Empty sort field"), \ C(TOO_MANY_SORT_FIELDS, "Too many sort fields (Max = 2)"), \ - C(INVALID_SORT_FIELD, "Sort field must be a key or a val"), + C(INVALID_SORT_FIELD, "Sort field must be a key or a val"), \ + C(INVALID_STR_OPERAND, "String type can not be an operand in expression"), #undef C #define C(a, b) HIST_ERR_##a @@ -2156,6 +2157,13 @@ static struct hist_field *parse_unary(struct hist_trigger_data *hist_data, ret = PTR_ERR(operand1); goto free; } + if (operand1->flags & HIST_FIELD_FL_STRING) { + /* String type can not be the operand of unary operator. */ + hist_err(file->tr, HIST_ERR_INVALID_STR_OPERAND, errpos(str)); + destroy_hist_field(operand1, 0); + ret = -EINVAL; + goto free; + } expr->flags |= operand1->flags & (HIST_FIELD_FL_TIMESTAMP | HIST_FIELD_FL_TIMESTAMP_USECS); @@ -2257,6 +2265,11 @@ static struct hist_field *parse_expr(struct hist_trigger_data *hist_data, operand1 = NULL; goto free; } + if (operand1->flags & HIST_FIELD_FL_STRING) { + hist_err(file->tr, HIST_ERR_INVALID_STR_OPERAND, errpos(operand1_str)); + ret = -EINVAL; + goto free; + } /* rest of string could be another expression e.g. b+c in a+b+c */ operand_flags = 0; @@ -2266,6 +2279,11 @@ static struct hist_field *parse_expr(struct hist_trigger_data *hist_data, operand2 = NULL; goto free; } + if (operand2->flags & HIST_FIELD_FL_STRING) { + hist_err(file->tr, HIST_ERR_INVALID_STR_OPERAND, errpos(str)); + ret = -EINVAL; + goto free; + } ret = check_expr_operands(file->tr, operand1, operand2); if (ret)