lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260106183815.33fa41f9@gandalf.local.home>
Date: Tue, 6 Jan 2026 18:38:15 -0500
From: Steven Rostedt <rostedt@...dmis.org>
To: Guenter Roeck <linux@...ck-us.net>
Cc: Masami Hiramatsu <mhiramat@...nel.org>, Mark Rutland
 <mark.rutland@....com>, Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
 linux-kernel@...r.kernel.org, linux-trace-kernel@...r.kernel.org
Subject: Re: [PATCH] ftrace: Do not over-allocate ftrace memory

On Tue, 6 Jan 2026 15:05:25 -0800
Guenter Roeck <linux@...ck-us.net> wrote:

> > > 	/*
> > > 	 * Use ftrace_number_of_pages to determine how many pages were
> > > 	 * allocated
> > > 	 */
> > > 	pages = ftrace_number_of_pages;
> > > 
> > > 	start_pg = ftrace_allocate_pages(count);
> > > 	if (!start_pg)
> > > 		return -ENOMEM;
> > > 
> > > 	/* ftrace_allocate_pages() increments ftrace_number_of_pages */
> > > 	pages = ftrace_number_of_pages - pages;
> > >   
> > 
> > That might work, assuming that the code updating ftrace_number_of_pages
> > is (mutex) protected. I don't immediately see that, and the
> > "mutex_lock(&ftrace_lock);" right after the above code makes me a bit
> > concerned.
> >   
> 
> One way to avoid the locking problem without potentially risky code changes
> would be to pass a pointer to pages to ftrace_allocate_pages() and to
> ftrace_allocate_records(), and to update it from there. I tested that and
> confirmed that it works.

I was originally going to suggest that, but when looking at the code, I
noticed that these variables could be useful. They are only updated on boot
up, module load, module unload and when module memory is freed.

But looking into the module code, these updates are done outside of the
module_mutex. This means these values need to be converted to atomics as
they are updated without any protection.

Yeah, better to just get the value from passing in a parameter to both
ftrace_allocate_pages() and to ftrace_allocate_records().

Something like:

	unsigend long pages = 0;

	[..]
	start_pg = ftrace_allocate_pages(count, &pages);

[..]
	ftrace_allocate_pages(unsigned long num_to_init, unsigned long *num_pages) {
		[..]
			cnt = ftrace_allocate_records(pg, num_to_init, num_pages);

And have ftrace_allocte_records() have:

	pages = 1 << order;
	*num_pages += pages;
	ftrace_number_of_pages += pages;

And I'll add another patch on top of this to make the variables atomic.

Thanks,

-- Steve

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ