From nobody Sun Feb 8 15:57:50 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 6F300333431 for ; Tue, 6 Jan 2026 13:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767707270; cv=none; b=HPISXATqI26IIrjHAq2kHjjOJPis7hTKQEF9MJpR8udqM9kpxCv08S8h/FO1Myd2wYRjjGerboMoLTOfjZMM50CV/2PPI9InK1GFviyDcd+6VOBkF+g61rMEd2qxLyZ4IvGz1RresoupJz9jG3b6IVl+FJX0jWDkTziPPGBHksc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767707270; c=relaxed/simple; bh=X0mhfphzyzLPUFjrtvGZjqO0h8g5+dpKSw/dmcSM54k=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wa37nZ/3fjDtbW5OTX6hgXffdRrsA9pnY2lIRRTjCtbOSIBweodS221f7+MlIYOMWgvpMwoiDFjFYzBnTdPEq0SvYWN1sXapGtWC5pjwueFYVHTF/fMRIDri61KKjWmcKaqVg48/slSEXH6FIdi+E9oPRFwxIkN9358E3pezH64= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=KPPaAPma; arc=none smtp.client-ip=170.10.133.124 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.b="KPPaAPma" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767707267; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D2PckU0JC5Ea9d4GrF2OBPBlpYWIkdOC3Apu6J3z5gQ=; b=KPPaAPma2cqjIyvdqjKi1abyWQ/ZuYNHapwSOBjnBbJkqXapGx/Qq4r4L5s6DPYKskyfT3 uakOlQOnEl3MA6ivus+fn9G/aEhcqeTeAdw5/mr9woSdlOKpN5FJQhG1A+W0m7vKf0oS9c hoQhrnMSdCoCTmxXRnW9m39BZizjcIM= 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-354-oRXwTd-_OTqtkSl4qfStLA-1; Tue, 06 Jan 2026 08:47:44 -0500 X-MC-Unique: oRXwTd-_OTqtkSl4qfStLA-1 X-Mimecast-MFC-AGG-ID: oRXwTd-_OTqtkSl4qfStLA_1767707263 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 5D0191956068; Tue, 6 Jan 2026 13:47:43 +0000 (UTC) Received: from wcosta-thinkpadt14gen4.rmtbr.csb (unknown [10.22.89.23]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 42DE21800667; Tue, 6 Jan 2026 13:47:39 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Ivan Pravdin , Crystal Wood , Costa Shulyupin , John Kacur , Tiezhu Yang , linux-trace-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), linux-kernel@vger.kernel.org (open list:Real-time Linux Analysis (RTLA) tools), bpf@vger.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_)) Subject: [PATCH v2 16/18] rtla: Ensure null termination after read operations in utils.c Date: Tue, 6 Jan 2026 08:49:52 -0300 Message-ID: <20260106133655.249887-17-wander@redhat.com> In-Reply-To: <20260106133655.249887-1-wander@redhat.com> References: <20260106133655.249887-1-wander@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Content-Type: text/plain; charset="utf-8" Add explicit null termination and buffer initialization for read() operations in procfs_is_workload_pid() and get_self_cgroup() functions. The read() system call does not null-terminate the data it reads, and when the buffer is filled to capacity, subsequent string operations will read past the buffer boundary searching for a null terminator. In procfs_is_workload_pid(), explicitly set buffer[MAX_PATH-1] to '\0' to ensure the buffer is always null-terminated before passing it to strncmp(). In get_self_cgroup(), use memset() to zero the path buffer before reading, which ensures null termination when retval is less than MAX_PATH. Additionally, set path[MAX_PATH-1] to '\0' after the read to handle the case where the buffer is filled completely. These defensive buffer handling practices prevent potential buffer overruns and align with the ongoing buffer safety improvements across the rtla codebase. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/utils.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/tracing/rtla/src/utils.c b/tools/tracing/rtla/src/utils.c index e0f31e5cae844..508b8891acd86 100644 --- a/tools/tracing/rtla/src/utils.c +++ b/tools/tracing/rtla/src/utils.c @@ -317,6 +317,7 @@ static int procfs_is_workload_pid(const char *comm_pref= ix, struct dirent *proc_e if (retval <=3D 0) return 0; =20 + buffer[MAX_PATH-1] =3D '\0'; retval =3D strncmp(comm_prefix, buffer, strlen(comm_prefix)); if (retval) return 0; @@ -750,6 +751,7 @@ static int get_self_cgroup(char *self_cg, int sizeof_se= lf_cg) if (fd < 0) return 0; =20 + memset(path, 0, sizeof(path)); retval =3D read(fd, path, MAX_PATH); =20 close(fd); @@ -757,6 +759,7 @@ static int get_self_cgroup(char *self_cg, int sizeof_se= lf_cg) if (retval <=3D 0) return 0; =20 + path[MAX_PATH-1] =3D '\0'; start =3D path; =20 start =3D strstr(start, ":"); --=20 2.52.0