[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20251118141350.50662edbdf0a788b70e40e53@kernel.org>
Date: Tue, 18 Nov 2025 14:13:50 +0900
From: Masami Hiramatsu (Google) <mhiramat@...nel.org>
To: Steven Rostedt <rostedt@...dmis.org>
Cc: Wander Lairson Costa <wander@...hat.com>, Tomas Glozar
<tglozar@...hat.com>, Ivan Pravdin <ipravdin.official@...il.com>, Crystal
Wood <crwood@...hat.com>, John Kacur <jkacur@...hat.com>, Costa Shulyupin
<costa.shul@...hat.com>, Tiezhu Yang <yangtiezhu@...ngson.cn>,
linux-trace-kernel@...r.kernel.org (open list:Real-time Linux Analysis
(RTLA) tools), linux-kernel@...r.kernel.org (open list),
bpf@...r.kernel.org (open list:BPF [MISC]:Keyword:(?:\b|_)bpf(?:\b|_))
Subject: Re: [rtla 01/13] rtla: Check for memory allocation failures
On Mon, 17 Nov 2025 22:06:15 -0500
Steven Rostedt <rostedt@...dmis.org> wrote:
> On Tue, 18 Nov 2025 11:09:46 +0900
> Masami Hiramatsu (Google) <mhiramat@...nel.org> wrote:
>
> > On Mon, 17 Nov 2025 15:41:08 -0300
> > Wander Lairson Costa <wander@...hat.com> wrote:
> >
> > > The actions_init() and actions_new() functions did not check the
> > > return value of calloc() and realloc() respectively. In a low
> > > memory situation, this could lead to a NULL pointer dereference.
> > >
> > > Add checks for the return value of memory allocation functions
> > > and return an error in case of failure. Update the callers to
> > > handle the error properly.
> > >
> > > Signed-off-by: Wander Lairson Costa <wander@...hat.com>
> > > ---
> > > tools/tracing/rtla/src/actions.c | 26 +++++++++++++++++++++++---
> > > tools/tracing/rtla/src/actions.h | 2 +-
> > > tools/tracing/rtla/src/timerlat_hist.c | 7 +++++--
> > > tools/tracing/rtla/src/timerlat_top.c | 7 +++++--
> > > 4 files changed, 34 insertions(+), 8 deletions(-)
> > >
> > > diff --git a/tools/tracing/rtla/src/actions.c b/tools/tracing/rtla/src/actions.c
> > > index 8945aee58d511..01648a1425c10 100644
> > > --- a/tools/tracing/rtla/src/actions.c
> > > +++ b/tools/tracing/rtla/src/actions.c
> > > @@ -11,11 +11,13 @@
> > > /*
> > > * actions_init - initialize struct actions
> > > */
> > > -void
> > > +int
> > > actions_init(struct actions *self)
> > > {
> > > self->size = action_default_size;
> > > self->list = calloc(self->size, sizeof(struct action));
> > > + if (!self->list)
> > > + return -1;
> >
> > Can you return -ENOMEM?
>
> Does it need to? This is user space not the kernel. Errno is already
> set by calloc() failing.
Ah, indeed! I agree to just return -1.
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@...nel.org>
Thank you,
>
> -- Steve
>
--
Masami Hiramatsu (Google) <mhiramat@...nel.org>
Powered by blists - more mailing lists