Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp66984pxb; Wed, 4 Nov 2020 14:48:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJyUbIenyXtOF1F3LVRPHEhlJOwjrBaOmYvy+fcWZEbVtgdkbuU3QBOsxso80xx0z3QWw0BM X-Received: by 2002:a17:907:262d:: with SMTP id aq13mr315399ejc.484.1604530115950; Wed, 04 Nov 2020 14:48:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604530115; cv=none; d=google.com; s=arc-20160816; b=juvY+28fn/2jUswRm5wnXg8XiHh69xtp1QrNp+aj2+cmBuIJTAgy6qquxgef9LHJsz DeNrkNWYo8oAMoljQPf9yhMxHQ6FUKVNu2sCQbMfcPgbEgJsuBh07Jc9ZD1M28yKpJXY fdv8ooG7frAoVT9z2alWwM+S8PzmE6zRhWvXG0vpE/uiCLTp0xsZdoFTL+Z8ochEb0iH HVBV32Gjz/NlnHOB2nM+1qzCe4t4si6za9NJLXZM/SDeQ+zShmD47kGyVLd3wf+MyZ/L Ae/g+PqCt8FdhW2s/IKG4xQQfi74UMrcs0aeYKy8cvr4vDurVsDccYe98GqvKX2x+S8M 77IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ktpmn2NX0J5OPT7QN9c8op6gbH7kVw1jxv9tLBj7cuc=; b=FYTO+ZBMdFy25mdxZqnKRCgXT+5I02ZituxplR7MWOOnSVHlPyMMfxAjsL8wZfLgNf L9LSqBVgbYR0sGtyfaUtog1TurFySyOCTfTu/+tbz44FCIZxzyR3Poz2nuk1ZyqAPI+D jT5UAC/WAd0WX/6Lo6zPVj7mRYaWH6uu+NCdAjgwaHl9uHmbmqihdmIPFw9Z0ZvVuUae cwJHC/LvI/z9RF+Z9kBiYJVMhNCARgccycwJI+a0HoMNjzeIC+vN9SLldZ2EtlLWTs+0 1e2hdqQw0+RHTW7Q1JC91WWYE59noCa3U5vcPkz9UiURGmIg3qwWDEYOtLewz4aNunhQ DNHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IFzi+wpr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w22si2141932edl.537.2020.11.04.14.47.49; Wed, 04 Nov 2020 14:48:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=IFzi+wpr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732535AbgKDWoh (ORCPT + 99 others); Wed, 4 Nov 2020 17:44:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732515AbgKDWod (ORCPT ); Wed, 4 Nov 2020 17:44:33 -0500 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E6F2C0613CF for ; Wed, 4 Nov 2020 14:44:31 -0800 (PST) Received: by mail-lj1-x243.google.com with SMTP id y16so204049ljk.1 for ; Wed, 04 Nov 2020 14:44:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ktpmn2NX0J5OPT7QN9c8op6gbH7kVw1jxv9tLBj7cuc=; b=IFzi+wpry5wW+UcbEC2QWIKhQYjtR1ggicBVKASHjN2NV+62ExLtw0CYZFhffyZaXL 4wTGZ6IFAYjBXdxC509EJd1UuJfOZjza4SMu0WCgKRO5+PLp6Z3oo3u+GOMeeADnqSx+ E53VmeaTZqtXGiTWQogT9aH06dJf/lXRuON2c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ktpmn2NX0J5OPT7QN9c8op6gbH7kVw1jxv9tLBj7cuc=; b=k1wGg/xt8nhiIVcBC38TnGe4ZmVV7xEb2eb78gxRNApIQ1d0HX5FdVWu/JUST3HvfM MLTnqiOmbD83nkiL5eQbVEZO023L82oSdoBOP9eFwZ3y4Lvd9A6lYw3cyFQpx0oSzvo6 lOf99A9y1ZSXg82XsRBaRrE6ZfLYf1sXRI/DYD+cWQ2NowH0f5ubwto3Yhriv6vBglZT Yt7mHjZkCc7V2G7/H6pZj5KG/J20FciXOZZwieM06/hgF8oDGcsZj7YrpjRi+6bWfs1F keGJPT8k+ZseDZFunj8ZMX+pK/vSibpnqVinFNPnVkpaoQ844XWMpiUD7OaFbp9IAyKr gfdQ== X-Gm-Message-State: AOAM532knmHtVPx1UKsTkQrOI3AtKnUE5yVtvSP7Hf8rD92nYpGJmELw ylZHDY/TjQRF6wRo4wvUcweyzDVdzIL0kV54ofx0XA== X-Received: by 2002:a2e:1517:: with SMTP id s23mr71620ljd.83.1604529869714; Wed, 04 Nov 2020 14:44:29 -0800 (PST) MIME-Version: 1.0 References: <20201104164453.74390-1-kpsingh@chromium.org> <20201104164453.74390-6-kpsingh@chromium.org> <20201104223539.pwtwnx6penoqm37j@kafai-mbp.dhcp.thefacebook.com> In-Reply-To: <20201104223539.pwtwnx6penoqm37j@kafai-mbp.dhcp.thefacebook.com> From: KP Singh Date: Wed, 4 Nov 2020 23:44:19 +0100 Message-ID: Subject: Re: [PATCH bpf-next v3 5/9] bpf: Allow LSM programs to use bpf spin locks To: Martin KaFai Lau Cc: open list , bpf , Alexei Starovoitov , Daniel Borkmann , Song Liu , Paul Turner , Jann Horn , Hao Luo Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 4, 2020 at 11:35 PM Martin KaFai Lau wrote: > > On Wed, Nov 04, 2020 at 05:44:49PM +0100, KP Singh wrote: > > From: KP Singh > > > > Usage of spin locks was not allowed for tracing programs due to > > insufficient preemption checks. The verifier does not currently prevent > > LSM programs from using spin locks, but the helpers are not exposed > > via bpf_lsm_func_proto. > This could be the first patch but don't feel strongly about it. > > > > > Based on the discussion in [1], non-sleepable LSM programs should be > > able to use bpf_spin_{lock, unlock}. > > > > Sleepable LSM programs can be preempted which means that allowng spin > > locks will need more work (disabling preemption and the verifier > > ensuring that no sleepable helpers are called when a spin lock is held). > > > > [1]: https://lore.kernel.org/bpf/20201103153132.2717326-1-kpsingh@chromium.org/T/#md601a053229287659071600d3483523f752cd2fb > > > > Signed-off-by: KP Singh > > --- > > kernel/bpf/bpf_lsm.c | 4 ++++ > > kernel/bpf/verifier.c | 17 +++++++++++++++++ > > 2 files changed, 21 insertions(+) > > > > diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c > > index 61f8cc52fd5b..93383df2140b 100644 > > --- a/kernel/bpf/bpf_lsm.c > > +++ b/kernel/bpf/bpf_lsm.c > > @@ -63,6 +63,10 @@ bpf_lsm_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) > > return &bpf_task_storage_get_proto; > > case BPF_FUNC_task_storage_delete: > > return &bpf_task_storage_delete_proto; > > + case BPF_FUNC_spin_lock: > > + return &bpf_spin_lock_proto; > > + case BPF_FUNC_spin_unlock: > > + return &bpf_spin_unlock_proto; > > default: > > return tracing_prog_func_proto(func_id, prog); > > } > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > > index 314018e8fc12..7c6c246077cf 100644 > > --- a/kernel/bpf/verifier.c > > +++ b/kernel/bpf/verifier.c > > @@ -9739,6 +9739,23 @@ static int check_map_prog_compatibility(struct bpf_verifier_env *env, > > return -EINVAL; > > } > > > > + if (map_value_has_spin_lock(map)) { > > + if (prog_type == BPF_PROG_TYPE_SOCKET_FILTER) { > > + verbose(env, "socket filter progs cannot use bpf_spin_lock yet\n"); > > + return -EINVAL; > > + } > > + > > + if (is_tracing_prog_type(prog_type)) { > > + verbose(env, "tracing progs cannot use bpf_spin_lock yet\n"); > > + return -EINVAL; > > + } > It is good to have a more specific verifier log. However, > these are duplicated checks (a few lines above in the same function). > They should at least be removed. > Thanks, I fixed this up and will move this as the first patch. > > + > > + if (prog->aux->sleepable) { > > + verbose(env, "sleepable progs cannot use bpf_spin_lock yet\n"); > > + return -EINVAL; > > + } > > + } > > + > > if ((bpf_prog_is_dev_bound(prog->aux) || bpf_map_is_dev_bound(map)) && > > !bpf_offload_prog_map_match(prog, map)) { > > verbose(env, "offload device mismatch between prog and map\n"); > > -- > > 2.29.1.341.ge80a0c044ae-goog > >