Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp495292rdg; Tue, 10 Oct 2023 17:28:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHNDMWS00x22Mj9mNCxmn5nGY2FA5/grsvwrRUxp+Ythhk5IJdF2WGBPzLuIM1yaOFcdrj5 X-Received: by 2002:a9d:7342:0:b0:6b9:9e4f:5f4c with SMTP id l2-20020a9d7342000000b006b99e4f5f4cmr19045673otk.29.1696984131374; Tue, 10 Oct 2023 17:28:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696984131; cv=none; d=google.com; s=arc-20160816; b=jIyHWTk3UkJhdn9leOKBuyoyHlSgDm06KWy1PGbXf5Mrm/k3010WuMJEV6S47tIk3K lF5KMJhwjj1xied4VQdLlcnPKcdvtOeqBOhqkZIEE8zKsUNgVsbeMddZFqaK6cc5SyAH ZKqQGFAhwI2d+BeFBT6kFQe7/qiBeaxI3yR+lnZyF+wnz48RcYA2n9PYJtvfOLcQlr1y 75JPxFGwVIffZp5x+pdiUZLZel6SR7USvUsGy2jJRz4iDI4LfXIeWdp556WGVJ0MueYi N94hjE5lbOdvVeCIHDzD7LB1jn0oMU9llgLFRI9QM3HizRA9uULZpCeriSc5SYnRQ4MW 9b9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=8mdeBYmV3Iz7hBYw8oNEhI6gNWC/shNZ9/fkqlI8Fj8=; fh=OP+7TAWqZCSpoz/llh4+/bsJ1XsL3oLSKO8+dmCeG84=; b=BNMRc7fV8PXA4hIfaNQGYSfhTY+sUEORW9+A07LmumZYRK8eqVezHpsz0f+agPKa/4 SqKeKgbEniObeCbKGpc+amyxJskovGQ55iZFbXJ0P+6uXb8bywW/1123mlMt69g8XiNa OKZHJQvX/AuINi07lorBNM6aHrUf93o42A9gIOL9l3/uSHWkz3HEAqBgxJT7X6ZxYjpN /GZh//tSPvoHPUJrEPISFX9CPHssjPy+ABjxXdMwyY+GeixKjmYCTpvvBbZgug72ehFV FEIcMxQX7fHc0w7MUAFXAJq8P1Rr/6glSn0yKmKbWXAC6GE3CVsg7pAuyfxS7DpW7ZPz sk9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bnV0DCKR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id 126-20020a630084000000b0057760853706si13657646pga.578.2023.10.10.17.28.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 17:28:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bnV0DCKR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id B1A1A8083AD9; Tue, 10 Oct 2023 17:28:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344387AbjJKA2f (ORCPT + 99 others); Tue, 10 Oct 2023 20:28:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344353AbjJKA2d (ORCPT ); Tue, 10 Oct 2023 20:28:33 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 048B2D48 for ; Tue, 10 Oct 2023 17:26:20 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-692b2bdfce9so5603544b3a.3 for ; Tue, 10 Oct 2023 17:26:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696983979; x=1697588779; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=8mdeBYmV3Iz7hBYw8oNEhI6gNWC/shNZ9/fkqlI8Fj8=; b=bnV0DCKRefmUflgQkyrxnItazRMUPu2M/q4DavlYFLSJpv4A6TY0xfGRZILJL4cEp0 hW+5uRIMxBve2WrifzvRT1uu7Pcx+B/GrgCK6ZuavfXuUvrHNYViwgJ3TeH0pM/+ZmJL DZ8NFVAidbb3qtjdNiviQbwvY8hRBg/5jzeRg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696983979; x=1697588779; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8mdeBYmV3Iz7hBYw8oNEhI6gNWC/shNZ9/fkqlI8Fj8=; b=DX5x67So7NHAKbfXEW8lj5LjFyCVU0VmLryjdA76vP7tcZ0VT72T2MAdpSoplKpPok R8Ymcg+HSe8Keo4oBrC8RLjdbBa7NvNiThW7spSU3erl21vSCxmOKYpyRfZlYH/vnHU7 fG1E6IBl3NzwETjvmku4Cu+LB1ZybMcx+Iv/bmIgnEDwEyIWEB7bCvSlwXu+NzOHeqYJ cejPxiaOqJ60/He+YaVvKTr2/l9IsIOjYZqxgOci/YieCJvznd3ZLGegCWMsQqPsEzrN vHR9kJijcezWFZJrgPvFORvhIQi4Xvfx5lWLmJynmlEoslnN8uKaY0QQt7nZPHW7JqsH LFtg== X-Gm-Message-State: AOJu0YwyLuOPqmFIOEOSsnVNWAcd853lTYIcJnaYpcgbnb257dVFnvSI AxDrhR56AupWvhdHCV7dPm6UnQ== X-Received: by 2002:a05:6a00:b52:b0:690:15c7:60d8 with SMTP id p18-20020a056a000b5200b0069015c760d8mr25141187pfo.22.1696983979003; Tue, 10 Oct 2023 17:26:19 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id a9-20020a63bd09000000b005891f3af36asm10776300pgf.87.2023.10.10.17.26.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 17:26:18 -0700 (PDT) Date: Tue, 10 Oct 2023 17:26:16 -0700 From: Kees Cook To: Hengqi Chen Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, luto@amacapital.net, wad@chromium.org, alexyonghe@tencent.com Subject: Re: [PATCH 4/4] selftests/seccomp: Test SECCOMP_LOAD_FILTER and SECCOMP_ATTACH_FILTER Message-ID: <202310101725.0BCB9CBA9@keescook> References: <20231009124046.74710-1-hengqi.chen@gmail.com> <20231009124046.74710-5-hengqi.chen@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231009124046.74710-5-hengqi.chen@gmail.com> X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Tue, 10 Oct 2023 17:28:48 -0700 (PDT) X-Spam-Level: ** On Mon, Oct 09, 2023 at 12:40:46PM +0000, Hengqi Chen wrote: > Add a testcase to exercise the newly added SECCOMP_LOAD_FILTER > and SECCOMP_ATTACH_FILTER operations. > > Signed-off-by: Hengqi Chen > --- > tools/testing/selftests/seccomp/seccomp_bpf.c | 20 +++++++++++++++++++ > 1 file changed, 20 insertions(+) > > diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c > index 38f651469968..8f7010482194 100644 > --- a/tools/testing/selftests/seccomp/seccomp_bpf.c > +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c > @@ -4735,6 +4735,26 @@ TEST(user_notification_wait_killable_fatal) > EXPECT_EQ(SIGTERM, WTERMSIG(status)); > } > > +TEST(seccomp_filter_load_and_attach) > +{ > + struct sock_filter filter[] = { > + BPF_STMT(BPF_RET|BPF_K, SECCOMP_RET_ALLOW), > + }; > + struct sock_fprog prog = { > + .len = (unsigned short)ARRAY_SIZE(filter), > + .filter = filter, > + }; > + int fd, ret; > + > + fd = seccomp(SECCOMP_LOAD_FILTER, 0, &prog); > + ASSERT_GT(fd, -1); > + > + ret = seccomp(SECCOMP_ATTACH_FILTER, 0, &fd); > + ASSERT_EQ(ret, 0); > + > + close(fd); > +} This is a good start -- please check all the error paths as well. Thanks for continuing to work on this! -- Kees Cook