From nobody Tue Feb 10 19:16:17 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 9C54B3C1FCC for ; Thu, 15 Jan 2026 17:29:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498169; cv=none; b=AxV7ApXu4LE9ygkNwPrH77/gXyfx+zr4ArCzk/7bHd9RamectBXp0M/pSFGT/vor41JTZG4wb+0hSgryeL6RZAvErhzgU8FMVskxlWDeViH/L5e0biRfr6HZ4TymF7KhRS4kcg6684KS3kVehK6trXWaHkIzxNAw27J668THoZo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768498169; c=relaxed/simple; bh=/8OuF00pp6FFiPuSw3AMppL0kz8wKPiLAYLFZ1Ivp8E=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HN2Fi2R6iAt/i8/Wm61VhZo7cTLRr5Z1rzejQsGViIhRZx4syydwyyzsQJ9XrQ/9tafULG7rVxaeOWOZ5zCCiXllF8kr6h4mo4GtIPXtia2GKKoSZXbMH0pkKLePXu6ukzo7cqQUsPIQLDNpdE4F1BpvjcR3dB8oq8fvrR2g7Hw= 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=Xm+4k2PS; arc=none smtp.client-ip=170.10.129.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="Xm+4k2PS" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768498167; 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=KbxiRjdWmA02eWzJj/JqfOkUupAYpZjuI15c7UU19T8=; b=Xm+4k2PSsEWfCgiX2mLiHgjN1SE6exXarf5X8gtqCxvjNkSFrxdmnA2PxW1oCrv9O64cy3 pRyTb5pm+NiW20yRJDukykQ+WErAUxYKJp8YFnXwuFiBvlwmOyKLn7QEgP4fBmIMqGxQYK oQBStNwXPdVZ8ZMSclVdTdeuDMvxsTY= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-461-uGbfuLnvMPe36yLhCBSY2w-1; Thu, 15 Jan 2026 12:29:24 -0500 X-MC-Unique: uGbfuLnvMPe36yLhCBSY2w-1 X-Mimecast-MFC-AGG-ID: uGbfuLnvMPe36yLhCBSY2w_1768498160 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3B94B180045C; Thu, 15 Jan 2026 17:29:20 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.64.87]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 677AC1800285; Thu, 15 Jan 2026 17:29:15 +0000 (UTC) From: Wander Lairson Costa To: Steven Rostedt , Tomas Glozar , Wander Lairson Costa , Crystal Wood , Ivan Pravdin , Costa Shulyupin , John Kacur , Haiyong Sun , Tiezhu Yang , Daniel Wagner , Daniel Bristot de Oliveira , 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 v3 15/18] rtla/trace: Fix write loop in trace_event_save_hist() Date: Thu, 15 Jan 2026 13:31:58 -0300 Message-ID: <20260115163650.118910-16-wander@redhat.com> In-Reply-To: <20260115163650.118910-1-wander@redhat.com> References: <20260115163650.118910-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" The write loop in trace_event_save_hist() does not correctly handle errors from the write() system call. If write() returns -1, this value is added to the loop index, leading to an incorrect memory access on the next iteration and potentially an infinite loop. The loop also fails to handle EINTR. Fix the write loop by introducing proper error handling. The return value of write() is now stored in a ssize_t variable and checked for errors. The loop retries the call if interrupted by a signal and breaks on any other error after logging it with strerror(). Additionally, change the index variable type from int to size_t to match the type used for buffer sizes and by strlen(), improving type safety. Signed-off-by: Wander Lairson Costa --- tools/tracing/rtla/src/trace.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/tracing/rtla/src/trace.c b/tools/tracing/rtla/src/trace.c index ed7db5f4115ce..fed3362527b08 100644 --- a/tools/tracing/rtla/src/trace.c +++ b/tools/tracing/rtla/src/trace.c @@ -342,11 +342,11 @@ static void trace_event_disable_filter(struct trace_i= nstance *instance, static void trace_event_save_hist(struct trace_instance *instance, struct trace_events *tevent) { - int index, out_fd; + size_t index, hist_len; mode_t mode =3D 0644; char path[MAX_PATH]; char *hist; - size_t hist_len; + int out_fd; =20 if (!tevent) return; @@ -378,7 +378,15 @@ static void trace_event_save_hist(struct trace_instanc= e *instance, index =3D 0; hist_len =3D strlen(hist); do { - index +=3D write(out_fd, &hist[index], hist_len - index); + const ssize_t written =3D write(out_fd, &hist[index], hist_len - index); + + if (written < 0) { + if (errno =3D=3D EINTR) + continue; + err_msg(" Error writing hist file: %s\n", strerror(errno)); + break; + } + index +=3D written; } while (index < hist_len); =20 free(hist); --=20 2.52.0