From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5C9AC43381 for ; Wed, 20 Feb 2019 18:27:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BE75B21841 for ; Wed, 20 Feb 2019 18:27:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726120AbfBTS16 (ORCPT ); Wed, 20 Feb 2019 13:27:58 -0500 Received: from www62.your-server.de ([213.133.104.62]:44580 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725798AbfBTS16 (ORCPT ); Wed, 20 Feb 2019 13:27:58 -0500 Received: from [88.198.220.130] (helo=sslproxy01.your-server.de) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1gwWb6-0005qL-0y; Wed, 20 Feb 2019 19:27:56 +0100 Received: from [178.197.248.36] (helo=linux.home) by sslproxy01.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1gwWb5-0002qz-Ko; Wed, 20 Feb 2019 19:27:55 +0100 Subject: Re: [PATCH bpf-next] bpf, seccomp: fix false positive preemption splat for cbpf->ebpf progs To: Alexei Starovoitov Cc: ast@kernel.org, netdev@vger.kernel.org References: <20190220110629.21646-1-daniel@iogearbox.net> <20190220170723.bbcj7bipsa6r7oy6@ast-mbp> From: Daniel Borkmann Message-ID: <15b7c010-0635-35e4-dac8-0d811a496cd7@iogearbox.net> Date: Wed, 20 Feb 2019 19:27:54 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20190220170723.bbcj7bipsa6r7oy6@ast-mbp> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.100.2/25366/Wed Feb 20 12:52:59 2019) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 02/20/2019 06:07 PM, Alexei Starovoitov wrote: > On Wed, Feb 20, 2019 at 12:06:29PM +0100, Daniel Borkmann wrote: >> In 568f196756ad ("bpf: check that BPF programs run with preemption disabled") >> a check was added for BPF_PROG_RUN() that for every invocation preemption has >> to be disabled to not break eBPF assumptions (e.g. per-cpu map). Of course this >> does not count for seccomp because only cBPF -> eBPF is loaded here and it does >> not make use of any functionality that would require this assertion. Fix this >> false positive by adding and using __BPF_PROG_RUN() variant that does not have >> the cant_sleep(); check. >> >> Fixes: 568f196756ad ("bpf: check that BPF programs run with preemption disabled") >> Reported-by: syzbot+8bf19ee2aa580de7a2a7@syzkaller.appspotmail.com >> Signed-off-by: Daniel Borkmann >> --- >> include/linux/filter.h | 9 ++++++++- >> kernel/seccomp.c | 2 +- >> 2 files changed, 9 insertions(+), 2 deletions(-) >> >> diff --git a/include/linux/filter.h b/include/linux/filter.h >> index f32b3ec..2648fd7 100644 >> --- a/include/linux/filter.h >> +++ b/include/linux/filter.h >> @@ -533,7 +533,14 @@ struct sk_filter { >> struct bpf_prog *prog; >> }; >> >> -#define BPF_PROG_RUN(filter, ctx) ({ cant_sleep(); (*(filter)->bpf_func)(ctx, (filter)->insnsi); }) >> +#define bpf_prog_run__non_preempt(prog, ctx) \ >> + ({ cant_sleep(); __BPF_PROG_RUN(prog, ctx); }) >> +/* Native eBPF or cBPF -> eBPF transitions. Preemption must be disabled. */ >> +#define BPF_PROG_RUN(prog, ctx) \ >> + bpf_prog_run__non_preempt(prog, ctx) >> +/* Direct use for cBPF -> eBPF only, but not for native eBPF. */ > > I think the comment is too abstract. > May be it should say that this is seccomp cBPF only ? > And macro name should be explicit as well ? I think macro naming is probably okay imho as used internally as well from BPF_PROG_RUN(), but I'll improve the comment to state seccomp specifically as an example there and providing some more background. >> +#define __BPF_PROG_RUN(prog, ctx) \ >> + (*(prog)->bpf_func)(ctx, (prog)->insnsi) >> >> #define BPF_SKB_CB_LEN QDISC_CB_PRIV_LEN >> >> diff --git a/kernel/seccomp.c b/kernel/seccomp.c >> index e815781..826d4e4 100644 >> --- a/kernel/seccomp.c >> +++ b/kernel/seccomp.c >> @@ -268,7 +268,7 @@ static u32 seccomp_run_filters(const struct seccomp_data *sd, >> * value always takes priority (ignoring the DATA). >> */ >> for (; f; f = f->prev) { >> - u32 cur_ret = BPF_PROG_RUN(f->prog, sd); >> + u32 cur_ret = __BPF_PROG_RUN(f->prog, sd); >> >> if (ACTION_ONLY(cur_ret) < ACTION_ONLY(ret)) { >> ret = cur_ret; >> -- >> 2.9.5 >>