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=-8.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_NEOMUTT 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 2DB25C43381 for ; Wed, 20 Feb 2019 17:07:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F050F21841 for ; Wed, 20 Feb 2019 17:07:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RhCuUwb7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726013AbfBTRH2 (ORCPT ); Wed, 20 Feb 2019 12:07:28 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:42463 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725796AbfBTRH2 (ORCPT ); Wed, 20 Feb 2019 12:07:28 -0500 Received: by mail-pl1-f194.google.com with SMTP id s1so12512500plp.9 for ; Wed, 20 Feb 2019 09:07:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Ty0AjoKsNMecOYhB6VKoyaRpCH2xgmOsoCJ+ujmAj3k=; b=RhCuUwb7MRYPyAS2GBBZMz6W811J4hGJJtCMfV/06f//vXRTALpkf6mUhWNnXJ1cdm uxivehAfP9eByRNQCp6+v36dVL4ntJq4sePC5xNLGBlY/A4p8JB6htThlZxZcNtY8z6y wFqYC7XOZ3rUPKi+SE/GwtV66eYcUrtuxwdIgj39YaIGSVDbfEvi2W5NU98O2lr/NpXu 8kDRaRjn6Ow3POxtMdC7V6zJvvzi6Galj/C6O66lclUUGyTlenuF1GZ+Tde11n5wj73V WC7YujivO+R6CvP8hDA8kYDIBe4/FZ9uMri98P4x15bk/8C8i7lwJoW0eXrzEBdYYty5 lP8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Ty0AjoKsNMecOYhB6VKoyaRpCH2xgmOsoCJ+ujmAj3k=; b=hQfPn4nOkGOyF4ij9en+62X8FWiYpNXVA/5sZw0hUgc3kdCQRpglKG6Rb6dPWobKSx VUsyC6khkcuGrBwHCRIkZxPsehL5RyLlWf7EBp+ke/c9sbCRsN2xYJmsLMbBKvitemDE r1h4kV8FUXfmocjnTcwlNVHJpxirJMU6wcIxpLmW7h+TzhxXKDj4XDWWBaoZ3ENftwfc G+w4A87cyp3THLziPmWrXEQqlrMiLBnQDDGpuOkEuLwP7yh7i+4ITvuSHG1qBxBf27qa SPN+rpmSUbjiPS5J8qVvr1BMwPuxmd1R1ArPsld5bMXVSYaYfsS3bxo3tl1lUndLyFQ3 DNPA== X-Gm-Message-State: AHQUAuaLuHU3eNwEbnRRd4CT49baU7iirffI1i4jhTuxzbCQIAf//25m nx0Gohy7ZawoNeWJzOpizsw= X-Google-Smtp-Source: AHgI3IbEvU1WoKmxm2TBFE6Bw2eUsyJ3tBR3NuR2um2ZeUFCPH+RCoy8Zu6jbAEgE0edkp92c/3nIQ== X-Received: by 2002:a17:902:b187:: with SMTP id s7mr26208639plr.174.1550682447674; Wed, 20 Feb 2019 09:07:27 -0800 (PST) Received: from ast-mbp ([2620:10d:c090:180::1:2015]) by smtp.gmail.com with ESMTPSA id p6sm27854555pfp.15.2019.02.20.09.07.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Feb 2019 09:07:26 -0800 (PST) Date: Wed, 20 Feb 2019 09:07:25 -0800 From: Alexei Starovoitov To: Daniel Borkmann Cc: ast@kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH bpf-next] bpf, seccomp: fix false positive preemption splat for cbpf->ebpf progs Message-ID: <20190220170723.bbcj7bipsa6r7oy6@ast-mbp> References: <20190220110629.21646-1-daniel@iogearbox.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190220110629.21646-1-daniel@iogearbox.net> User-Agent: NeoMutt/20180223 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 ? > +#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 >