Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp218029rdb; Fri, 6 Oct 2023 00:59:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFCb760ZR7Ul4YA1MxIq+nX1mmAtCzsNUhuBJg7sjA0HlqK4oMmyuCP0+yP41ezrp4ltcc/ X-Received: by 2002:a05:6a20:4286:b0:159:e0b9:bd02 with SMTP id o6-20020a056a20428600b00159e0b9bd02mr8614658pzj.40.1696579145487; Fri, 06 Oct 2023 00:59:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696579145; cv=none; d=google.com; s=arc-20160816; b=y9lbPtF68CI18q7kzwXYbI+Fo5PEop0X9sL8z9PzI939gmVNZfUCCHkTDRXkc4DZOG dtbHvMk8zeUdsdk2JAlC/jnU1d1GJnUklJU2cee9juGRYeX5M4xUJWsrzOSLXEZf3AU1 +uyAR71/GUa7oe+H1oA3GJOoLk+45VYKcaU4Ha3C0xw6Qez6bZMRfo++TFLwCSJdaHwP R6+fk86VaeiBST1v0lTQnTZOXM26JZeHQRPaH7IcKI2ax9EnotJicHmz9/Br8pgo0qwk npIGcStmIpHkv6BRzBodZcIVVDFCB2XdJx0c8+O0fpSp5R5SVwO97I6p5C+9KvdfFWP2 t3KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=8dzmcoPg4c1fBky5mvbNlQevg6ir0Fo8DQjjuoUSzGc=; fh=mNJVb+1ZFYAh2IB7ThZsgocAx2bTQwD5d7wlj19eIzU=; b=qIuTL2WbHe7Wc2Yj8z9J/DpTYzf/DPNH+T43Vn7ixha9uzG0Pdx1tFFhQje3SVkFJI kEpXDLKz+lH0NY4O9bqfvuYrxXPzuLVbuhvONhD24nAc47V3myY52SlrSoZdr85br/nd Flw1d2D5oj2sE8PkNdPwL5f1r08bb5jM1onUmkmj3bUPJSRVFURymh7am+T6NLU02e5K Lff96BbrMTV0wcvwP8YLbLlh/qBjnR1ed0P0YRZImTB+HAXVdwH8jt13w5F06gKo8P21 Jb7oOKoJcobiPhXFav3o4+4+vPKrvn0MQ3hJ18N9EJ3RkHziiuX2SgpJZxjZw1CQ4U2R Sq6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fbvhbFyA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id p39-20020a056a0026e700b0068e47e5f221si906442pfw.195.2023.10.06.00.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 00:59:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fbvhbFyA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 29F3B8405309; Fri, 6 Oct 2023 00:59:03 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230361AbjJFH6z (ORCPT + 99 others); Fri, 6 Oct 2023 03:58:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230456AbjJFH6x (ORCPT ); Fri, 6 Oct 2023 03:58:53 -0400 Received: from mail-oa1-x2b.google.com (mail-oa1-x2b.google.com [IPv6:2001:4860:4864:20::2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D293CA; Fri, 6 Oct 2023 00:58:52 -0700 (PDT) Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-1dd1714b9b6so1208791fac.0; Fri, 06 Oct 2023 00:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696579131; x=1697183931; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=8dzmcoPg4c1fBky5mvbNlQevg6ir0Fo8DQjjuoUSzGc=; b=fbvhbFyAOSNc1SWwoyTBlEKcSgTQiZxJuMe+u3FAf+kjCn0OAxIj+PEIqN1ts+7/SR /9+ct27P7sFWuwLr9+62D84gk4Nc5H3XQGDhPzMziXsUsqtRDdxk2vW9uK2w0j4ey7Cs 1gCUjIhBpdKENoj+IoBRIWhoBw05vjemqeeRD/WIZDZ7o/A075rxxsEc746Sa9vo5h6z n7oVeFAtlSaC6dqzrfsxv4TCXiQ1bjrcdJ2c2YntGZsgdLqsZ8Wpsk9s3P5+T1+MB8H3 xB/Z0lsWb1GzbLesRqSBW0UmXC+1/xeI9upLaQjj9zbOj5KIyPAYYhKGydOGRGV4TXSc K6Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696579131; x=1697183931; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8dzmcoPg4c1fBky5mvbNlQevg6ir0Fo8DQjjuoUSzGc=; b=xRjnt9JejtvtCO8cFwNPOzADxh8Ya53Lx/fdelBlEpG/EqHyQtEvsPnej6I+nk1lZN x42QdqCIYd47g4+N4PbzQZsMwTxzu1xzD7kzDVuZE48FpXk9QohWmKFfxCMQTptchPce zq40vqGiPxR89sYYhzuH3SbyGUhgrDpBt/J3E0PTJPfmLJRYf+GnqOw4JLeU1mCVHUBR 6ZDJ78eWV5GtwVOPkZGFTl5jshM6rjOjYcRxVPBHZJwlVeew+k7rfVBTMLdFd9p5VExW M1IdoiWhnOXFs7rRN7mybMawVVOzkuVmoQEkHG93rrne6uy/bTW1oTr+Mg4G7axb3VH2 p5/Q== X-Gm-Message-State: AOJu0YyITuebWhVWDoqc0kMm6XKRdHRDxS8DQle4STk89A//17csy7Mj wsWkXcjDK9tznUW+Zf6Up+oQxIUD7WAPjKstebA50BzWJH8C/g== X-Received: by 2002:a05:6870:7196:b0:1d6:7f77:c922 with SMTP id d22-20020a056870719600b001d67f77c922mr8202007oah.28.1696579131492; Fri, 06 Oct 2023 00:58:51 -0700 (PDT) MIME-Version: 1.0 References: <20231003083836.100706-1-hengqi.chen@gmail.com> <202310031055.3F19F87@keescook> In-Reply-To: <202310031055.3F19F87@keescook> From: Hengqi Chen Date: Fri, 6 Oct 2023 15:58:40 +0800 Message-ID: Subject: Re: [RFC PATCH 0/2] seccomp: Split set filter into two steps To: Kees Cook , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, luto@amacapital.net, wad@chromium.org, alexyonghe@tencent.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,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 pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 06 Oct 2023 00:59:03 -0700 (PDT) + BPF maintainers On Wed, Oct 4, 2023 at 2:02=E2=80=AFAM Kees Cook wr= ote: > > On Tue, Oct 03, 2023 at 08:38:34AM +0000, Hengqi Chen wrote: > > This patchset introduces two new operations which essentially > > splits the SECCOMP_SET_MODE_FILTER process into two steps: > > SECCOMP_LOAD_FILTER and SECCOMP_ATTACH_FILTER. > > > > The SECCOMP_LOAD_FILTER loads the filter and returns a fd > > which can be pinned to bpffs. This extends the lifetime of the > > filter and thus can be reused by different processes. > > With this new operation, we can eliminate a hot path of JITing > > BPF program (the filter) where we apply the same seccomp filter > > to thousands of micro VMs on a bare metal instance. > > > > The SECCOMP_ATTACH_FILTER is used to attach a loaded filter. > > The filter is represented by a fd which is either returned > > from SECCOMP_LOAD_FILTER or obtained from bpffs using bpf syscall. > > Interesting! I like this idea, thanks for writing it up. > > Two design notes: > > - Can you reuse/refactor seccomp_prepare_filter() instead of duplicating > the logic into two new functions? > Sure, will do. > - Is there a way to make sure the BPF program coming from the fd is one > that was built via SECCOMP_LOAD_FILTER? (I want to make sure we can > never confuse a non-seccomp program into getting loaded into seccomp.) > Maybe we can add a new prog type enum like BPF_PROG_TYPE_SECCOMP for seccomp filter. > -Kees > > -- > Kees Cook > Cheers, -- Hengqi