Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp694233pxb; Tue, 5 Apr 2022 19:04:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZal0BFJLYi4ER7eQnARBsYgb+NGjNuyjcsz7DQPRDiZdG2+Q8NNbOdDvMldqOv+GYLiFp X-Received: by 2002:a65:654f:0:b0:378:b8f6:ebe4 with SMTP id a15-20020a65654f000000b00378b8f6ebe4mr5132617pgw.399.1649210591561; Tue, 05 Apr 2022 19:03:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649210591; cv=none; d=google.com; s=arc-20160816; b=RjvDUQ9a0j36kufh0LverlkhIQ1qCyZWug8J0edttX2MK+GnUjsq1Z2dIcn+gZmj5P qGTdK+Vj67orSDmy6scOuZdMXmjf/s5KuyM92GXt8OQ5xp73AVqNEe0c8Z8qvwx4yp6c 9nAdN5DD/LSBPa2StcHxjwKpigsinJp++HQc2ifQ9B8dWb49LdgyWDQWVILlimp+4vs9 7sU8i2B1DoMizQuIJnzKcHdoHHCLP2LKaMxxpllJQR76C6aUGBBts5fnC3UFH9Lhy+k2 VFv+QY5y7MJMK1NmjgHHWE34Qy/7cadF5408lwQT/uNykTQ3h4SPnCipOL3gFse9z8Gq FB3g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TFyYXYKJZ5c4y3MbwS6JpO87MT9gaxyThtDaZhBB3DQ=; b=EZectOwFaE+qXuQX7GCqxpJc/51buxgMfVLKX0jVwn1XPBywuRQwz1cYYmtpyEXIBG CGkjc3qt9J5+bacTjemJaK3VXL9J1hdLQeZr5OcPTNnaEDhv6+6y90fQWVW9fKlgbn5b Q0xRJy2alKkX3lorYEDe6cLxjTwHX46KeMx7PhNJS2YhJLCzj4GSc+2bzm7zsFXsiRKl bHHeCXR7/sW7aV9QJtuedLipBQOWr33cQ01wQ0+JtdIS27U/AOV/pm576fRa5qR4VfNI Goh7V1kPuUsrWwX7cB4XkIn0fqmcyYJmaH8isS1pHQh3kH4JWUBIprE7zYtL35Rno7iK 4PZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=t1KDgrn0; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q4-20020a170902b10400b00153b2d16433si13627293plr.59.2022.04.05.19.02.53; Tue, 05 Apr 2022 19:03:11 -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=@linuxfoundation.org header.s=korg header.b=t1KDgrn0; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376319AbiDELVd (ORCPT + 99 others); Tue, 5 Apr 2022 07:21:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240913AbiDEIsL (ORCPT ); Tue, 5 Apr 2022 04:48:11 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE3B027B09; Tue, 5 Apr 2022 01:36:34 -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 ams.source.kernel.org (Postfix) with ESMTPS id 71EADB81BBF; Tue, 5 Apr 2022 08:36:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7865C385A0; Tue, 5 Apr 2022 08:36:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649147789; bh=WPAbJuu1jDixVIN1IUwnVaASv9TrrMbMCgWrVhN0jmw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t1KDgrn045LuAXBOKxi/3XEBJ6vWgzJwaNSGyk6hbyKzNtvk70tLD5EVvvijW0mXe 20eaQ7rWo7pIuJJ5BlyftDej3QaBwEYt/LeHKTbhWhIrgjBRnyBdBrHYGcY41dOBSg IxFwDV5MjsVVDe8a8MdWqzWIZC9IK5wOkTsKc6wk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Brian Foster , "Steven Rostedt (Google)" Subject: [PATCH 5.16 0123/1017] tracing: Have trace event string test handle zero length strings Date: Tue, 5 Apr 2022 09:17:16 +0200 Message-Id: <20220405070357.849805803@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 From: Steven Rostedt (Google) commit eca344a7362e0f34f179298fd8366bcd556eede1 upstream. If a trace event has in its TP_printk(): "%*.s", len, len ? __get_str(string) : NULL It is perfectly valid if len is zero and passing in the NULL. Unfortunately, the runtime string check at time of reading the trace sees the NULL and flags it as a bad string and produces a WARN_ON(). Handle this case by passing into the test function if the format has an asterisk (star) and if so, if the length is zero, then mark it as safe. Link: https://lore.kernel.org/all/YjsWzuw5FbWPrdqq@bfoster/ Cc: stable@vger.kernel.org Reported-by: Brian Foster Tested-by: Brian Foster Fixes: 9a6944fee68e2 ("tracing: Add a verifier to check string pointers for trace events") Signed-off-by: Steven Rostedt (Google) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -3654,12 +3654,17 @@ static char *trace_iter_expand_format(st } /* Returns true if the string is safe to dereference from an event */ -static bool trace_safe_str(struct trace_iterator *iter, const char *str) +static bool trace_safe_str(struct trace_iterator *iter, const char *str, + bool star, int len) { unsigned long addr = (unsigned long)str; struct trace_event *trace_event; struct trace_event_call *event; + /* Ignore strings with no length */ + if (star && !len) + return true; + /* OK if part of the event data */ if ((addr >= (unsigned long)iter->ent) && (addr < (unsigned long)iter->ent + iter->ent_size)) @@ -3845,7 +3850,7 @@ void trace_check_vprintf(struct trace_it * instead. See samples/trace_events/trace-events-sample.h * for reference. */ - if (WARN_ONCE(!trace_safe_str(iter, str), + if (WARN_ONCE(!trace_safe_str(iter, str, star, len), "fmt: '%s' current_buffer: '%s'", fmt, show_buffer(&iter->seq))) { int ret;