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]
Date: Thu, 15 Feb 2024 08:45:52 +0900
From: Masami Hiramatsu (Google) <mhiramat@...nel.org>
To: Steven Rostedt <rostedt@...dmis.org>
Cc: Alexei Starovoitov <alexei.starovoitov@...il.com>, Florent Revest
 <revest@...omium.org>, linux-trace-kernel@...r.kernel.org, LKML
 <linux-kernel@...r.kernel.org>, Martin KaFai Lau <martin.lau@...ux.dev>,
 bpf <bpf@...r.kernel.org>, Sven Schnelle <svens@...ux.ibm.com>, Alexei
 Starovoitov <ast@...nel.org>, Jiri Olsa <jolsa@...nel.org>, Arnaldo
 Carvalho de Melo <acme@...nel.org>, Daniel Borkmann <daniel@...earbox.net>,
 Alan Maguire <alan.maguire@...cle.com>, Mark Rutland
 <mark.rutland@....com>, Peter Zijlstra <peterz@...radead.org>, Thomas
 Gleixner <tglx@...utronix.de>, Guo Ren <guoren@...nel.org>
Subject: Re: [PATCH v7 19/36] function_graph: Implement
 fgraph_reserve_data() and fgraph_retrieve_data()

On Wed, 14 Feb 2024 13:59:58 -0500
Steven Rostedt <rostedt@...dmis.org> wrote:

> On Wed,  7 Feb 2024 00:11:01 +0900
> "Masami Hiramatsu (Google)" <mhiramat@...nel.org> wrote:
> 
> > From: Ste
> > +/**
> > + * fgraph_reserve_data - Reserve storage on the task's ret_stack
> > + * @idx:	The index of fgraph_array
> > + * @size_bytes: The size in bytes to reserve
> > + *
> > + * Reserves space of up to FGRAPH_MAX_DATA_SIZE bytes on the
> > + * task's ret_stack shadow stack, for a given fgraph_ops during
> > + * the entryfunc() call. If entryfunc() returns zero, the storage
> > + * is discarded. An entryfunc() can only call this once per iteration.
> > + * The fgraph_ops retfunc() can retrieve this stored data with
> > + * fgraph_retrieve_data().
> > + *
> > + * Returns: On success, a pointer to the data on the stack.
> > + *   Otherwise, NULL if there's not enough space left on the
> > + *   ret_stack for the data, or if fgraph_reserve_data() was called
> > + *   more than once for a single entryfunc() call.
> > + */
> > +void *fgraph_reserve_data(int idx, int size_bytes)
> > +{
> > +	unsigned long val;
> > +	void *data;
> > +	int curr_ret_stack = current->curr_ret_stack;
> > +	int data_size;
> > +
> > +	if (size_bytes > FGRAPH_MAX_DATA_SIZE)
> > +		return NULL;
> > +
> > +	/* Convert to number of longs + data word */
> > +	data_size = DIV_ROUND_UP(size_bytes, sizeof(long));
> 
> Hmm, the above is a fast path. I wonder if we should add a patch to make that into:
> 
> 	if (unlikely(size_bytes & (sizeof(long) - 1)))
> 		data_size = DIV_ROUND_UP(size_bytes, sizeof(long));
> 	else
> 		data_size = size_bytes >> (sizeof(long) == 4 ? 2 : 3);
> 
> to keep from doing the division.

OK, I thought DIV_ROUND_UP was not much cost. Since sizeof(long) is
fixed 4 or 8, so 

data_size = (size_bytes + sizeof(long) - 1) >> BITS_PER_LONG;

will this work?

Thanks,

> 
> -- Steve
> 
> > +
> > +	val = get_fgraph_entry(current, curr_ret_stack - 1);
> > +	data = &current->ret_stack[curr_ret_stack];
> > +
> > +	curr_ret_stack += data_size + 1;
> > +	if (unlikely(curr_ret_stack >= SHADOW_STACK_MAX_INDEX))
> > +		return NULL;
> > +
> > +	val = make_fgraph_data(idx, data_size, __get_index(val) + data_size + 1);
> > +
> > +	/* Set the last word to be reserved */
> > +	current->ret_stack[curr_ret_stack - 1] = val;
> > +
> > +	/* Make sure interrupts see this */
> > +	barrier();
> > +	current->curr_ret_stack = curr_ret_stack;
> > +	/* Again sync with interrupts, and reset reserve */
> > +	current->ret_stack[curr_ret_stack - 1] = val;
> > +
> > +	return data;
> > +}
> > +


-- 
Masami Hiramatsu (Google) <mhiramat@...nel.org>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ