From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F6682054EF; Thu, 12 Dec 2024 16:56:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734022605; cv=none; b=hPTTF9DqREoOfPLzAzyCMWNjobZMAYus2WP2YrKYz8Y0J7KKT/sPnSGgZ+8wtN5DPk/a/UN0VrLicmaUqXpUzzykJYEnOhZlIYbioGLYic4ladPp+AHqN/JEsWZ8axWOQhpoL6GVmzmHDJbBKbG6gbJ+Z4bT2AC+iYc6LSblIY0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734022605; c=relaxed/simple; bh=WgQJS07Bs0dvQPAstjhfz5pF1n485jU3P/s+XyWMu3w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vz/zMmYpQDH0g+Tg+O2cwNZo0+7fbzoZml1xUO+tbv1SzzhFaA6lecali6uJqjqICUide/3eDTqPuZct8pM0mguiB4afO2wRMmfBXoSWlvfhQLvZc6sNz54htyxdyr28FWHmubYlKQCD9YQvuPZCKr5zrGUXwV+UQ9BJkJNA15U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=wllnFWcS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="wllnFWcS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A29C9C4CECE; Thu, 12 Dec 2024 16:56:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1734022605; bh=WgQJS07Bs0dvQPAstjhfz5pF1n485jU3P/s+XyWMu3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wllnFWcS0pAf89R19MUNeyI61bHRZo5cP+9m2JaNzilaaFZ9RpNNPLUVdQ9xPui1l 5K+WHUyaPc/xNPXEFuNSdRQrqRjpPsqjdwPAdxjTSkTzeuTMDDgN2WI0AVkC/yjZW/ tjoNGNdiJRe+EkuBLKokqGUAGez+L3U91D1WUJRo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Benjamin Peterson , Arnaldo Carvalho de Melo , Howard Chu , Adrian Hunter , Alexander Shishkin , Ian Rogers , Ingo Molnar , Jiri Olsa , Kan Liang , Mark Rutland , Namhyung Kim , Peter Zijlstra , Sasha Levin Subject: [PATCH 5.15 257/565] perf trace: Avoid garbage when not printing a syscalls arguments Date: Thu, 12 Dec 2024 15:57:32 +0100 Message-ID: <20241212144321.632684791@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241212144311.432886635@linuxfoundation.org> References: <20241212144311.432886635@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Benjamin Peterson [ Upstream commit 1302e352b26f34991b619b5d0b621b76d20a3883 ] syscall__scnprintf_args may not place anything in the output buffer (e.g., because the arguments are all zero). If that happened in trace__fprintf_sys_enter, its fprintf would receive an unitialized buffer leading to garbage output. Fix the problem by passing the (possibly zero) bounds of the argument buffer to the output fprintf. Fixes: a98392bb1e169a04 ("perf trace: Use beautifiers on syscalls:sys_enter_ handlers") Signed-off-by: Benjamin Peterson Tested-by: Arnaldo Carvalho de Melo Tested-by: Howard Chu Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ian Rogers Cc: Ingo Molnar Cc: Jiri Olsa Cc: Kan Liang Cc: Mark Rutland Cc: Namhyung Kim Cc: Peter Zijlstra Link: https://lore.kernel.org/r/20241107232128.108981-2-benjamin@engflow.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/builtin-trace.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c index 49a968bdd3a27..65f94597590ef 100644 --- a/tools/perf/builtin-trace.c +++ b/tools/perf/builtin-trace.c @@ -2379,6 +2379,7 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, char msg[1024]; void *args, *augmented_args = NULL; int augmented_args_size; + size_t printed = 0; if (sc == NULL) return -1; @@ -2394,8 +2395,8 @@ static int trace__fprintf_sys_enter(struct trace *trace, struct evsel *evsel, args = perf_evsel__sc_tp_ptr(evsel, args, sample); augmented_args = syscall__augmented_args(sc, sample, &augmented_args_size, trace->raw_augmented_syscalls_args_size); - syscall__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, thread); - fprintf(trace->output, "%s", msg); + printed += syscall__scnprintf_args(sc, msg, sizeof(msg), args, augmented_args, augmented_args_size, trace, thread); + fprintf(trace->output, "%.*s", (int)printed, msg); err = 0; out_put: thread__put(thread); -- 2.43.0