Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1213747pxb; Wed, 4 Nov 2020 03:06:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJwwzhWygf6ZgA+NG+NVbATqk8p9cLW+0fQo/YNq4eQGusIRION5yBybYtpHlzyOoQmvG9qi X-Received: by 2002:a17:906:3a97:: with SMTP id y23mr24406859ejd.250.1604487969519; Wed, 04 Nov 2020 03:06:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604487969; cv=none; d=google.com; s=arc-20160816; b=y4prjVB6djFBsiaxcU2pxidT1c3Ad4G8YCep1Ij0NEwIGN5UV29pqEEcLkcX2qG6B+ Dqd6l6CuXt/JJbyXnD5uIEic4O10Bt0LvX2IIG9T5M6AptwruLHzkM+HbNg/2fsCFONZ nYrigxZ0hf07eHiamoM4o3v/s8WjEgELBn986HSNy9sSkeWYe2c8NLd9VmKPKIwPNkc4 FV4klxPYc4HYmV+OqZeHSQa6QfJIEP8AarkXlG0+Q9X2YjMH4bFOXmR8C7rjkbnS0Vsz lrC5UB+TMdKqGGlRlDwXDpnrBsoihpG2V0PWcDQh9OrQzHytJ70GBBuSCGL3trRoA25q m7uw== 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=xEKEC0YlSgaEOnt38rltuqrha4RV8MJOHNAt5plznLs=; b=zNc5eBc021aNhgrA7Hzzeqmgi4ukpkXizFVKB8tPMuCs8LYWMDuMADnUiYcl8U8Zog DbHiEbpQy/ygTemg3gNULHl7FUgOSyla2G9ypYOZ10dEIsuUvKDzesAc6CigiJGugzhh EVoEXBuxuV6yFjmafoXXAXtbw+1/iNeAGY2zE6KNVNbj4ha+J0mN4M46xfNnZcLOMM7C s3+hW5EScPbChpMCiRh069n10QnPA2bVjIY09xyGA3CabszAcDuUhsbfLpkTkpc5CVqW UrHginJ5JfIyfD6TzRxUMQjoZrb/3yn8PEW6yY/Z0VyckgsvqaXkgQZeAqYrRSk0V5T1 1i8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nIjqSgqz; 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 i14si1062684edl.282.2020.11.04.03.05.45; Wed, 04 Nov 2020 03:06:09 -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=nIjqSgqz; 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 S1728287AbgKDLDy (ORCPT + 99 others); Wed, 4 Nov 2020 06:03:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727001AbgKDLDy (ORCPT ); Wed, 4 Nov 2020 06:03:54 -0500 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96689C061A4A for ; Wed, 4 Nov 2020 03:03:53 -0800 (PST) Received: by mail-lj1-x242.google.com with SMTP id k25so22501095lji.9 for ; Wed, 04 Nov 2020 03:03:53 -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=xEKEC0YlSgaEOnt38rltuqrha4RV8MJOHNAt5plznLs=; b=nIjqSgqzowbObFnifreTIMOTeoAVRfxRwndC6H73URjJbyOcvPONZ9sx7rJo1OtWEE YF9hjqvtZohF4FV3Ru1FdQv2v6Js21CnpaR/848bMrva15z64H85s3kUgfVV40eU6rlh w6fs/q8ZB4JPod/IG+iJljGM/vGFfFiMFklt4= 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=xEKEC0YlSgaEOnt38rltuqrha4RV8MJOHNAt5plznLs=; b=mpjXdJ31uTuudzfcs4aVhb+8SkgR5QCd71mqJQTWKI9Y1Pv+VMpJMVuMCfplqoBEJj +HdympU+Wjet88e0EJHprXRHbklGcSTnASbBOED7o7/WzX6dgil1izrwki3hOXZ7ajdU FB91W5Cf8eVH3Y3A4cHiOzIb4Zyhh2NMApA0qloWAeZgpUA2WaL5+PX/Ty6DtMCTPvAY np/qz8PGne3u+SOOc1MZx24iLqdNo1t7pfqP5xkl1xMA3AHPkmm6T2O4XKlcF9WBefmm Ql9Kwg0twFz8Z/SA/V1U2K+6pNY6jSmpa5p+VcxTr1Ts6X1DMJjgnMZPLi6ekyfRRLug /Vpw== X-Gm-Message-State: AOAM531Nxkfuyhyy6knLcQREsqNzV1EOHwBo6uKmydwKU5uLaJVeLpdF YrUR0LuOxyOB2Sl7LV/373TPk4tKg4O/oHilyZUahQ== X-Received: by 2002:a05:651c:1345:: with SMTP id j5mr11016574ljb.430.1604487832066; Wed, 04 Nov 2020 03:03:52 -0800 (PST) MIME-Version: 1.0 References: <20201103153132.2717326-1-kpsingh@chromium.org> <20201103153132.2717326-8-kpsingh@chromium.org> <20201103184714.iukuqfw2byls3s4k@ast-mbp.dhcp.thefacebook.com> <5fa24f72dd48e_9fa0e20871@john-XPS-13-9370.notmuch> In-Reply-To: <5fa24f72dd48e_9fa0e20871@john-XPS-13-9370.notmuch> From: KP Singh Date: Wed, 4 Nov 2020 12:03:41 +0100 Message-ID: Subject: Re: [PATCH bpf-next v2 7/8] bpf: Add tests for task_local_storage To: John Fastabend Cc: Alexei Starovoitov , open list , bpf , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , 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 [...] > > Ahh. Yes. That should do it. Right now I don't see concerns with safety > > of the bpf_spin_lock in bpf_lsm progs. > > What about sleepable lsm hooks? Normally we wouldn't expect to sleep with > a spinlock held. Should we have a check to ensure programs bpf_spin_lock > are not also sleepable? Thanks. Yes, I added that to my patch: 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..8892f7ba2041 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; + } + + if (prog->aux->sleepable) { + verbose(env, "sleepable progs cannot use bpf_spin_lock\n"); + return -EINVAL; + } + } +