Re: [PATCH v3] tracing: compare named histogram expressions recursively
From: Kyuwon Cho
Date: Fri Dec 04 2026 - 20:45:42 EST
On Fri, Dec 04, 2026 at 10:40:49AM -0500, Steven Rostedt wrote:
> Kernel stack size is a fixed limit and recursive functions must have a
> limiting field to make sure it can never exceed the expect call depth.
>
> How deep do you expect this to go? 2?
The reproducer is attached. It mounts tracefs at /trace, creates the two
named histogram triggers, and fires syscalls; it must be run as root.
parse_expr() limits expressions to three subexpressions, while modifiers and
aliases can add operand wrappers. I will add an explicit level argument in v4
and bound it using all operand-producing paths, with a test at the accepted
maximum and one beyond it.
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <sched.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
static void msg(const char *fmt, ...)
{
char buf[1024];
va_list ap;
int n;
va_start(ap, fmt);
n = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
if (n > 0)
write(STDOUT_FILENO, buf, n < (int)sizeof(buf) ? n : (int)sizeof(buf));
}
static int put(const char *path, const char *s)
{
int fd = open(path, O_WRONLY | O_CLOEXEC);
ssize_t n;
int e;
if (fd < 0) {
msg("open %s: %s\n", path, strerror(errno));
return -1;
}
n = write(fd, s, strlen(s));
e = errno;
msg("write %s => %zd/%zu errno=%d\n", path, n, strlen(s),
n < 0 ? e : 0);
close(fd);
errno = e;
return n == (ssize_t)strlen(s) ? 0 : -1;
}
int main(void)
{
char def[4096];
size_t off;
int i;
mkdir("/trace", 0700);
if (mount("tracefs", "/trace", "tracefs", 0, NULL) && errno != EBUSY) {
msg("mount tracefs: %s\n", strerror(errno));
return 1;
}
/* Put x far beyond an ordinary trace record, but within a valid
* synthetic event layout. Static strings occupy 256 bytes each. */
off = snprintf(def, sizeof(def), "s:histmatch_big ");
for (i = 0; i < 63; i++)
off += snprintf(def + off, sizeof(def) - off,
"char[256] p%d; ", i);
off += snprintf(def + off, sizeof(def) - off, "s64 x;\n");
msg("synthetic definition bytes=%zu\n", off);
if (put("/trace/dynamic_events", def))
return 2;
/* This trigger owns the named map and its expression tree. */
if (put("/trace/events/synthetic/histmatch_big/trigger",
"hist:name=histmatch_boom:keys=x+1\n"))
return 3;
/* id+2 has the same wrapper flags/size/signedness as x+1. The
* buggy matcher ignores both expression trees, accepts this as the
* same histogram, and installs the first tree on sys_enter. */
if (put("/trace/events/raw_syscalls/sys_enter/trigger",
"hist:name=histmatch_boom:keys=id+2\n"))
return 4;
msg("second trigger installed; issuing syscalls\n");
for (i = 0; i < 200000; i++) {
syscall(SYS_getpid);
if (!(i & 1023))
sched_yield();
}
msg("survived syscall firing\n");
return 0;
}