linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: Kees Cook <keescook@chromium.org>, Alexei Starovoitov <ast@kernel.org>
Cc: linux-kernel@vger.kernel.org, Martin KaFai Lau <kafai@fb.com>,
	Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
	Andrii Nakryiko <andriin@fb.com>,
	Sami Tolvanen <samitolvanen@google.com>,
	bpf@vger.kernel.org
Subject: Re: [PATCH] bpf: Avoid function casting when calculating immediate
Date: Mon, 17 Feb 2020 16:51:46 +0100	[thread overview]
Message-ID: <92bcfdab-79df-c3f4-bae8-00116b39e015@iogearbox.net> (raw)
In-Reply-To: <202001291335.31F425A198@keescook>

On 1/29/20 10:36 PM, Kees Cook wrote:
> In an effort to enable -Wcast-function-type in the top-level Makefile
> to support Control Flow Integrity builds, rework the BPF instruction
> immediate calculation macros to avoid mismatched function pointers. Since
> these calculations are only ever between function address (these are
> not function calls, just address calculations), they can be cast to u64
> instead, where the result will be assigned to the s32 insn->imm.
> 
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>   include/linux/filter.h |  6 +++---
>   kernel/bpf/hashtab.c   |  6 +++---
>   kernel/bpf/verifier.c  | 21 +++++++--------------
>   3 files changed, 13 insertions(+), 20 deletions(-)
> 
> diff --git a/include/linux/filter.h b/include/linux/filter.h
> index f349e2c0884c..b5beee7bf2ea 100644
> --- a/include/linux/filter.h
> +++ b/include/linux/filter.h
> @@ -340,8 +340,8 @@ static inline bool insn_is_zext(const struct bpf_insn *insn)
>   
>   /* Function call */
>   
> -#define BPF_CAST_CALL(x)					\
> -		((u64 (*)(u64, u64, u64, u64, u64))(x))
> +#define BPF_FUNC_IMM(FUNC)					\
> +		((u64)(FUNC) - (u64)__bpf_call_base)

Looks good to me in general. My only concern is compilation on 32bit archs: I think
the cast needs to be of '(u64)(unsigned long)' to avoid introducing new warnings a la
'cast from pointer to integer of different size'.

Thanks,
Daniel

  reply	other threads:[~2020-02-17 15:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-29 21:36 [PATCH] bpf: Avoid function casting when calculating immediate Kees Cook
2020-02-17 15:51 ` Daniel Borkmann [this message]
2020-02-17 18:25   ` Kees Cook

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=92bcfdab-79df-c3f4-bae8-00116b39e015@iogearbox.net \
    --to=daniel@iogearbox.net \
    --cc=andriin@fb.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=kafai@fb.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=samitolvanen@google.com \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).