From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796213799; b=RUbQEQygDDhlZTGbzBHdh3c1eyIwTZeGOEAzbemcdUJiDXySIyVoJtbdUtfSpzYJ58O+ 5Xd3c1f8WpFJCfabOHXH0lb8LD67kEuFZULuIdbzYzua2eQw9YFVy8p37RXRSXaQ89Fbq D/4YLjzV/AOo1YwWVWbfuRBHMTyQvcEKF32OVuE6SuphYm/YRPLnmAnCfBQTGcr0SoAWm /uu4vL57o3l1UgJ2IT1iHgFlYGgdAorJaOMlpTJ9tJkr74dBo+/+AkXVzeZtJqiMobqEO 5FGrvslv7wb7HatdgS7FpCeobhlbULtHYGDhq27313ocILyaMdQLkZwvLL/c7qDFJ4Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796213799; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=dwxmMyFj/Ny5zuFjW4mcInCCQzW9waupamSBEizJjaQ=; b=mnI8MRb2vJKxaJHAInEXvGBeHy332QuaPwORTh5trOStalxiMd0zW0qUKTWCHWpx8iYj mMhsePUWwL4sHm4gTJlHWEHb+1RW3D0hDi9nqAFYCtW+8x3C9su1q3WWx82A44UsOneHX HoIyrFz57+N8DtLawaZuO2v2Ts7mQYY+glIzMXQkE/THTWPgJ6SRpB2QwKDz1DML5juuk XdA4YzHVh53L5zb8VIpluEIrjAipJfpPqwSG7Oz7BDT9OhLotgIQ9JxZwCtsACvrL9C00 V2MQHBaMhF64NaTrTkayEsG32lEnxGrdXgnaX/cT5NaiieuyeMCXrzDdkFTKCGE/8lg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JswT76e5; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87838606A32F for ; Wed, 2 Dec 2026 12:16:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 87838606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=JswT76e5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796213798; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dwxmMyFj/Ny5zuFjW4mcInCCQzW9waupamSBEizJjaQ=; b=JswT76e5BTAx+H7fHDPu/Qu/blUssLMl/9Tpax1twcJnWyAGTqQk5rMvbGZsXBhDRofyj8 0I0mH83egrDTHfPT8eKAE7Rsyg52zZ5WzLpkYp/rqO4/h4VhNO/qUmT26On7/KA0mXn9d4 V3F46QdYZugxWPANVLDYrAB4CbJhduw= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-343-Sm8ViPz-PwqSLE4eepNncw-1; Wed, 2 Dec 2026 12:16:33 +0000 X-MC-Unique: Sm8ViPz-PwqSLE4eepNncw-1 X-Mimecast-MFC-AGG-ID: Sm8ViPz-PwqSLE4eepNncw_1796213792 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 127DE19775B2; Wed, 2 Dec 2026 12:16:32 +0000 (UTC) Received: from mpazur-thinkpadt14gen6.redhat.corp (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0D2331801438; Wed, 2 Dec 2026 12:16:29 +0000 (UTC) From: Marek Pazur To: Arnaldo Carvalho de Melo , Namhyung Kim Cc: Jiri Olsa , Ian Rogers , Adrian Hunter , Howard Chu , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] perf trace: Quote and escape augmented buffer contents Date: Wed, 2 Dec 2026 13:16:22 +0100 Message-ID: <20261202121622.30071-3-mpazur@redhat.com> In-Reply-To: <20261202121622.30071-1-mpazur@redhat.com> References: <20261202121622.30071-1-mpazur@redhat.com> X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 When using perf trace, syscall_arg__scnprintf_buf() pretty-prints augmented buf arguments without delimiters. Since the payload can contain arbitrary characters (such as commas, quotes or brackets), the resulting trace output is ambiguous to parse reliably in automated tests. Additionally, literal backslashes and escape sequences are not differentiated. Before: write(fd: 1, buf: 123, fake_argument: 456, count: 23) write(fd: 1, buf: 98171 write(fd: 13, buf: write(f, count: 33) write(fd: 1, buf: \0, count: 1) // buf = {0} write(fd: 1, buf: \0, count: 2) // buf = {'\\', '0'} write(fd: 1, buf: "Hello world!", count: 14) The quotes were present in the original submission (v2 used "\"%s\""), but got removed during the review process [1]. Enclose the buf contents in double quotes and backslash-escape '"' and '\', matching strace's formatting style: write(fd: 1, buf: "123, fake_argument: 456", count: 23) write(fd: 1, buf: "98171 write(fd: 13, buf: write(f", count: 33) write(fd: 1, buf: "\0", count: 1) // buf = {0} write(fd: 1, buf: "\\0", count: 2) // buf = {'\\', '0'} write(fd: 1, buf: "\"Hello world!\"", count: 14) Update the buffer augmentation shell tests to account for the new format. [1] https://lore.kernel.org/all/ZsiaBnd5KrkGbZ9w@x1/ Signed-off-by: Marek Pazur --- tools/perf/builtin-trace.c | 14 ++++++++++++-- tools/perf/tests/shell/trace_btf_general.sh | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index c08f2c3a8128..3b61bc895aa3 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -1964,26 +1964,36 @@ static size_t syscall_arg__scnprintf_buf(char *bf, size_t size, struct syscall_a struct augmented_arg *augmented_arg = arg->augmented.args; size_t printed = 0; unsigned char *orig; int consumed; if (!syscall_arg__augmented_args_valid(arg, 0)) return 0; orig = (unsigned char *)augmented_arg->value; + printed += scnprintf(bf + printed, size - printed, "\""); + for (int j = 0; j < augmented_arg->size; ++j) { bool control_char = orig[j] <= MAX_CONTROL_CHAR || orig[j] >= MAX_ASCII; - /* print control characters (0~31 and 127), and non-ascii characters in \(digits) */ - printed += scnprintf(bf + printed, size - printed, control_char ? "\\%d" : "%c", (int)orig[j]); + bool escaped = orig[j] == '"' || orig[j] == '\\'; + /* + * Print control characters (0~31 and 127), and non-ascii + * characters in \(digits). Escape '"' and '\'. + */ + printed += scnprintf(bf + printed, size - printed, + control_char ? "\\%d" : escaped ? "\\%c" : "%c", + (int)orig[j]); } + printed += scnprintf(bf + printed, size - printed, "\""); + consumed = sizeof(*augmented_arg) + augmented_arg->size; arg->augmented.args = ((void *)arg->augmented.args) + consumed; arg->augmented.size -= consumed; return printed; } static bool trace__filter_duration(struct trace *trace, double t) { return t < (trace->duration_filter * NSEC_PER_MSEC); diff --git a/tools/perf/tests/shell/trace_btf_general.sh b/tools/perf/tests/shell/trace_btf_general.sh index 0941459a7137..7784e93645d1 100755 --- a/tools/perf/tests/shell/trace_btf_general.sh +++ b/tools/perf/tests/shell/trace_btf_general.sh @@ -31,21 +31,21 @@ trace_test_string() { then printf "String augmentation test failed, output:\n%s\n" "$output" err=1 fi } trace_test_buffer() { echo "Testing perf trace's buffer augmentation" # echo will insert a newline (\10) at the end of the buffer output="$(perf trace --sort-events -e write -- echo "${buffer}" 2>&1)" - if ! echo "$output" | grep -q -E "^echo/[0-9]+ write\([0-9]+, ${buffer}.*, [0-9]+\) += +[0-9]+$" + if ! echo "$output" | grep -q -E "^echo/[0-9]+ write\([0-9]+, \"${buffer}.*\", [0-9]+\) += +[0-9]+$" then printf "Buffer augmentation test failed, output:\n%s\n" "$output" err=1 fi } trace_test_struct_btf() { echo "Testing perf trace's struct augmentation" output="$(perf trace --sort-events -e clock_nanosleep --force-btf -- sleep 1 2>&1)" if ! echo "$output" | grep -q -E "^sleep/[0-9]+ clock_nanosleep\(0, 0, \{1,.*\}, 0x[0-9a-f]+\) += +[0-9]+$" -- 2.55.0