From: Kees Cook <keescook@chromium.org>
To: Jarmo Tiitto <jarmo.tiitto@gmail.com>
Cc: Sami Tolvanen <samitolvanen@google.com>,
Bill Wendling <wcw@google.com>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>,
clang-built-linux@googlegroups.com, linux-kernel@vger.kernel.org,
morbo@google.com
Subject: Re: [PATCH 1/1] pgo: Fix allocate_node() handling of non-vmlinux nodes.
Date: Wed, 2 Jun 2021 10:41:28 -0700 [thread overview]
Message-ID: <202106021037.09943A41@keescook> (raw)
In-Reply-To: <20210602005702.9650-2-jarmo.tiitto@gmail.com>
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
next prev parent reply other threads:[~2021-06-02 17:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-02 0:57 [PATCH 0/1] pgo: Fix allocate_node() handling of non-vmlinux nodes Jarmo Tiitto
2021-06-02 0:57 ` [PATCH 1/1] " Jarmo Tiitto
2021-06-02 17:41 ` Kees Cook [this message]
2021-06-02 18:52 ` jarmo.tiitto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202106021037.09943A41@keescook \
--to=keescook@chromium.org \
--cc=clang-built-linux@googlegroups.com \
--cc=jarmo.tiitto@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=samitolvanen@google.com \
--cc=wcw@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.