lkml.org 
[lkml]   [2021]   [Jun]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 1/1] pgo: Fix allocate_node() handling of non-vmlinux nodes.
On Wed, Jun 02, 2021 at 03:57:04AM +0300, Jarmo Tiitto wrote:
> Currently allocate_node() will reserve nodes even if *p
> doesn't point into __llvm_prf_data_start - __llvm_prf_data_end
> range.
>
> Fix it by checking if p points into vmlinux range
> and otherwise return NULL.
>
> Signed-off-by: Jarmo Tiitto <jarmo.tiitto@gmail.com>
> ---
> kernel/pgo/instrument.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/kernel/pgo/instrument.c b/kernel/pgo/instrument.c
> index 0e07ee1b17d9..9bca535dfa91 100644
> --- a/kernel/pgo/instrument.c
> +++ b/kernel/pgo/instrument.c
> @@ -55,6 +55,10 @@ void prf_unlock(unsigned long flags)
> static struct llvm_prf_value_node *allocate_node(struct llvm_prf_data *p,
> u32 index, u64 value)
> {
> + /* check if p points into vmlinux. If not, don't allocate. */
> + if (p < __llvm_prf_data_start || p >= __llvm_prf_data_end)
> + return NULL;

This should be a tighter check (struct llvm_prf_data has size, so just
checking for p < __llvm_prf_data_end isn't sufficient. I recommend using
the memory_contains() helper.

And I think this should be louder as it's entirely unexpected right
now. Perhaps:

if (WARN_ON_ONCE(!memory_contains(__llvm_prf_data_start,
__llvm_prf_data_end,
p, sizeof(*p))))
return NULL;

> +
> if (&__llvm_prf_vnds_start[current_node + 1] >= __llvm_prf_vnds_end)
> return NULL; /* Out of nodes */
>
> --
> 2.31.1
>

--
Kees Cook

\
 
 \ /
  Last update: 2021-06-02 19:44    [W:0.457 / U:0.092 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site