From: Peter Zijlstra <peterz@infradead.org>
To: Yonghong Song <yhs@fb.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
kernel-team@fb.com, x86@kernel.org, KP Singh <kpsingh@kernel.org>
Subject: Re: [PATCH bpf] x86/bpf: handle bpf-program-triggered exceptions properly
Date: Tue, 26 Jan 2021 10:15:22 +0100 [thread overview]
Message-ID: <YA/dqup/752hHBI4@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20210126001219.845816-1-yhs@fb.com>
On Mon, Jan 25, 2021 at 04:12:19PM -0800, Yonghong Song wrote:
> When the test is run normally after login prompt, cpu_feature_enabled(X86_FEATURE_SMAP)
> is true and bad_area_nosemaphore() is called and then fixup_exception() is called,
> where bpf specific handler is able to fixup the exception.
>
> But when the test is run at /sbin/init time, cpu_feature_enabled(X86_FEATURE_SMAP) is
> false, the control reaches
That makes no sense, cpu features should be set in stone long before we
reach userspace.
> To fix the issue, before the above mmap_read_trylock(), we will check
> whether fault ip can be served by bpf exception handler or not, if
> yes, the exception will be fixed up and return.
> diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
> index f1f1b5a0956a..e8182d30bf67 100644
> --- a/arch/x86/mm/fault.c
> +++ b/arch/x86/mm/fault.c
> @@ -1317,6 +1317,15 @@ void do_user_addr_fault(struct pt_regs *regs,
> if (emulate_vsyscall(hw_error_code, regs, address))
> return;
> }
> +
> +#ifdef CONFIG_BPF_JIT
> + /*
> + * Faults incurred by bpf program might need emulation, i.e.,
> + * clearing the dest register.
> + */
> + if (fixup_bpf_exception(regs, X86_TRAP_PF, hw_error_code, address))
> + return;
> +#endif
> #endif
NAK, this is broken. You're now disallowing faults that should've gone
through.
next prev parent reply other threads:[~2021-01-26 9:22 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-26 0:12 [PATCH bpf] x86/bpf: handle bpf-program-triggered exceptions properly Yonghong Song
2021-01-26 9:15 ` Peter Zijlstra [this message]
2021-01-26 19:21 ` Yonghong Song
2021-01-27 9:30 ` Peter Zijlstra
2021-01-27 21:07 ` Andrii Nakryiko
2021-01-27 21:47 ` Andy Lutomirski
2021-01-28 1:05 ` Yonghong Song
2021-01-28 23:51 ` Andy Lutomirski
2021-01-29 0:11 ` Alexei Starovoitov
2021-01-29 0:18 ` Andy Lutomirski
2021-01-29 0:26 ` Alexei Starovoitov
2021-01-29 0:29 ` Andy Lutomirski
2021-01-29 0:32 ` Andy Lutomirski
2021-01-29 0:41 ` Alexei Starovoitov
2021-01-29 0:45 ` Andy Lutomirski
2021-01-29 1:04 ` Alexei Starovoitov
2021-01-29 1:31 ` Andy Lutomirski
2021-01-29 1:53 ` Alexei Starovoitov
2021-01-29 2:18 ` Andy Lutomirski
2021-01-29 2:32 ` Alexei Starovoitov
2021-01-29 3:09 ` Andy Lutomirski
2021-01-29 3:26 ` Alexei Starovoitov
2021-01-29 0:35 ` Jann Horn
2021-01-29 0:43 ` Alexei Starovoitov
2021-01-29 1:03 ` Jann Horn
2021-01-29 1:08 ` Alexei Starovoitov
[not found] <YBPToXfWV1ekRo4q@hirez.programming.kicks-ass.net>
[not found] ` <97EF0157-F068-4234-B826-C08B7324F356@amacapital.net>
2021-01-29 23:11 ` Alexei Starovoitov
2021-01-29 23:30 ` Andy Lutomirski
2021-01-30 2:54 ` Alexei Starovoitov
2021-01-31 17:32 ` Andy Lutomirski
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=YA/dqup/752hHBI4@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=kpsingh@kernel.org \
--cc=x86@kernel.org \
--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