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] [day] [month] [year] [list]
Message-ID: <202002171024.184D90B@keescook>
Date:   Mon, 17 Feb 2020 10:25:22 -0800
From:   Kees Cook <keescook@...omium.org>
To:     Daniel Borkmann <daniel@...earbox.net>
Cc:     Alexei Starovoitov <ast@...nel.org>, linux-kernel@...r.kernel.org,
        Martin KaFai Lau <kafai@...com>,
        Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
        Andrii Nakryiko <andriin@...com>,
        Sami Tolvanen <samitolvanen@...gle.com>, bpf@...r.kernel.org
Subject: Re: [PATCH] bpf: Avoid function casting when calculating immediate

On Mon, Feb 17, 2020 at 04:51:46PM +0100, Daniel Borkmann wrote:
> 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@...omium.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'.

Oh, good point. I'll double-check the 32-bit builds. (I also have
another related change that I found several days later.) I'll get this
adjusted/tested and resend the patch.

Thanks!

-Kees

-- 
Kees Cook

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ