From patchwork Sun Mar 26 09:21:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 75027 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp840261vqo; Sun, 26 Mar 2023 02:23:24 -0700 (PDT) X-Google-Smtp-Source: AKy350Z6cnYEWqh56z1ZXtWNzU4gH2/nrw5aIxXvSbH8XLWnBx7T3CpWGxSaCLGxwqt6VAlw3NGI X-Received: by 2002:aa7:cb87:0:b0:501:d2eb:6b2c with SMTP id r7-20020aa7cb87000000b00501d2eb6b2cmr8720567edt.15.1679822604640; Sun, 26 Mar 2023 02:23:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679822604; cv=none; d=google.com; s=arc-20160816; b=afqh+xuXQuUI5oFjfB1PFyyrc7xLl/EqeQOgQ0k9/bwoc8l9zscPPUROuk1rQ+w2uM YHg0Ft7Dpx19x0qI5FxqZiqbur/CtOGB9+C5GbjIqCbwSEwsmtww7tuDHr9XaQnMwSde Ql/XMYwqQSMcYLR/EXNvL+d72xiUiEyFpyFxsVoSvUUolySxSVVs07yH7T96BaXcBM25 gfM2NF39QKpqqzGqbkWfi91Ao3x64FqVwr3105O1W0IqowCyizlZaenCi5rvaWprZ5FS WnfIMaGk0FJHpbspMb+VVOhMTJqw/0u7HO/0jTIfDwXWfEut+lN49MQpdmpWvNA6B2iR 7tBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TwHHUn2KJ1qVHrX1VAd8snE/lpVIPkRNAfXb0ctK8EA=; b=VTHpx3OR34PRSX6xhSft0lME3C+3uj+NB7VGjipCJHMhEhA/yla9PtmctXKBv7Jxbu ZSuQnMdOvuc6qEWp+XVN9CXkH5508Pgsu0USNH3bcb4Npsd3K6ZOyBRh1kJvHgAIlql/ Qc7x99NEMvQwieyap0fFsKZOYRqnfY7jd2ym0n008pF0i3cS00r1xnosP2zgTVctcGO9 +A4R6EzJfiTMwviY3DfxEo4BVUEwxRipVZkATNuGPGem9u4nssX3r6qg36eao6zWAMBC tLdWbE1UV3o2f1vd6wjapzEQSeUbGoCH4qEeK8H5UqleN2qZwjZbfIHtT7prcNSYXipI 5OoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VmnNzVvb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o9-20020a170906358900b0093084f268d0si23714124ejb.52.2023.03.26.02.23.00; Sun, 26 Mar 2023 02:23:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=VmnNzVvb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231820AbjCZJWW (ORCPT + 99 others); Sun, 26 Mar 2023 05:22:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbjCZJWT (ORCPT ); Sun, 26 Mar 2023 05:22:19 -0400 Received: from mail-qv1-xf29.google.com (mail-qv1-xf29.google.com [IPv6:2607:f8b0:4864:20::f29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D464540EE; Sun, 26 Mar 2023 02:22:18 -0700 (PDT) Received: by mail-qv1-xf29.google.com with SMTP id qh28so4870902qvb.7; Sun, 26 Mar 2023 02:22:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679822538; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TwHHUn2KJ1qVHrX1VAd8snE/lpVIPkRNAfXb0ctK8EA=; b=VmnNzVvbOE2xFNfHTtV8ssb2ax9uq2cUpvbAsBKyuOhvL/pKhQHH5D1N1paKdpk2pZ OrYkUh/mTYLLSE/Xc5KjyO1ELmj2oWzNAaiZCEJv3U6CYvBEwJ3iMsy20Z8r4pT/Hd8B 57KvlQz2ZAgauzaPME5YjeGKXdwLsAyK6i+rPGxCfOGdfuPqAfPQ4xootiof17ZxCdDE JVq+cfd0qguE9m5enVYLoD2qHmmeS081/qldllbut0vVaOsjHuKBvafUAL+zVdvoEpOY k55CWTKkJZ+BxKWDCZVTDVX8LwvomU+0kHNxuCrtbj5j36Np1AUgHHyUQxMeRpBxmykK efzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679822538; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TwHHUn2KJ1qVHrX1VAd8snE/lpVIPkRNAfXb0ctK8EA=; b=kxhx5/QutIxIiaCHeB6iif09i7bicAhwIVnQSU6dufEMkV9Y0dlnIjrWYiGkmi7tS6 oIyhXRmoKhkrMqhCS9GHNBv2n0TNJqv7Aza0n+nqmcwxDimSeldoR9vUmntVF98HF6BL QCF2VEWL2J3WoIXw0/1ELOocmtPvm/dMmY97B01/MfzsJFbnQLIqmKu/dcq3Kv38QxTD fZbsK6D1CrrGI96xieMLULqPsjUzBpLh0eazlUgBbAdkjLLURjvIGRrqNHQ0OS5uRq4O R52n1LMY0wbg05QtRBVWTl58YpWwi0JQbaC6gzOSsLeIkUk9HERvBF2jckdaNxErhpSx Peqw== X-Gm-Message-State: AAQBX9dJ0/8u59H0OYEwL3zAcNkVw1LV9FmCCJcMtFaLFyv2Zu2d5KF7 N+50vV/3NNjfnuVSJ5e64Ek= X-Received: by 2002:a05:6214:1c45:b0:5bd:14f9:650f with SMTP id if5-20020a0562141c4500b005bd14f9650fmr14305482qvb.45.1679822537938; Sun, 26 Mar 2023 02:22:17 -0700 (PDT) Received: from vultr.guest ([2001:19f0:1000:1a1f:5400:4ff:fe5e:1d32]) by smtp.gmail.com with ESMTPSA id y5-20020ac87085000000b003e014845d9esm10257987qto.74.2023.03.26.02.22.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Mar 2023 02:22:17 -0700 (PDT) From: Yafang Shao To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Yafang Shao Subject: [RFC PATCH bpf-next 01/13] fork: New clone3 flag for BPF namespace Date: Sun, 26 Mar 2023 09:21:56 +0000 Message-Id: <20230326092208.13613-2-laoar.shao@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230326092208.13613-1-laoar.shao@gmail.com> References: <20230326092208.13613-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761421667577838204?= X-GMAIL-MSGID: =?utf-8?q?1761421667577838204?= A new clone3 flag CLONE_NEWBPF is introduced to create a new BPF namespace. Signed-off-by: Yafang Shao --- include/uapi/linux/sched.h | 1 + kernel/fork.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h index 3bac0a8..ace31df 100644 --- a/include/uapi/linux/sched.h +++ b/include/uapi/linux/sched.h @@ -36,6 +36,7 @@ /* Flags for the clone3() syscall. */ #define CLONE_CLEAR_SIGHAND 0x100000000ULL /* Clear any signal handler and reset to SIG_DFL. */ #define CLONE_INTO_CGROUP 0x200000000ULL /* Clone into a specific cgroup given the right permissions. */ +#define CLONE_NEWBPF 0x400000000ULL /* New BPF namespace */ /* * cloning flags intersect with CSIGNAL so can be used with unshare and clone3 diff --git a/kernel/fork.c b/kernel/fork.c index f68954d..db0abd4 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2929,7 +2929,8 @@ static bool clone3_args_valid(struct kernel_clone_args *kargs) { /* Verify that no unknown flags are passed along. */ if (kargs->flags & - ~(CLONE_LEGACY_FLAGS | CLONE_CLEAR_SIGHAND | CLONE_INTO_CGROUP)) + ~(CLONE_LEGACY_FLAGS | CLONE_CLEAR_SIGHAND | CLONE_INTO_CGROUP | + CLONE_NEWBPF)) return false; /* @@ -3080,7 +3081,7 @@ static int check_unshare_flags(unsigned long unshare_flags) CLONE_VM|CLONE_FILES|CLONE_SYSVSEM| CLONE_NEWUTS|CLONE_NEWIPC|CLONE_NEWNET| CLONE_NEWUSER|CLONE_NEWPID|CLONE_NEWCGROUP| - CLONE_NEWTIME)) + CLONE_NEWTIME|CLONE_NEWBPF)) return -EINVAL; /* * Not implemented, but pretend it works if there is nothing