Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2241749rdb; Mon, 9 Oct 2023 19:03:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG/475A7E/7TbnayheX3deBaAbSVq8BA6sE8kKU63ItW8YetYzaVRkm07FTcNZMcExCg6WX X-Received: by 2002:a05:6e02:2143:b0:351:4b68:ec3b with SMTP id d3-20020a056e02214300b003514b68ec3bmr23199592ilv.10.1696903383043; Mon, 09 Oct 2023 19:03:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696903383; cv=none; d=google.com; s=arc-20160816; b=aZ2ci2TGKiB4/bXX19BQ7IM/skUb6jYeQdPR3kxNLEWZYuqvEdaXXp5GZkiJ5wld4I xulpHZ4F9+lB+e6sLP74WhPhUJXZWyhbutt4TVkdviZ+o1y5teBkaP8hJjuW8Leh7tOe DGWgg69i725Bk36YDGuGBoJ4+PHQDdy/rZRqTAGhxZbNF4qrZI0rEISU6N2Er52pRJmR Hgom5xOQuuRMkrYmECx15E//7vqymLr9o+jLx9CnUb14fF+11LIZHjXtbWPrffB3as3E Cv+WgbiANI73fJ1cqyzfXq4Wq0IaAZwEL7tBMOtLWF/etZIEewysg1ilS1wGRxf5mRHU O80Q== 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=WtdXd8zzfUQBn/Ye5tSm8UdJuve0zGYoqRvrat58Hz4=; fh=UUVBB6hdZtgkdevQaSWXrPPcR6FiQNJo3IQxWCli3s0=; b=MJMtpbU7jIEkIvoZoaHQAaymJW2hOnKOD4T8IqAaR97EPrR4kjR+XlNt2olS7AMqTZ 7NDNvGekweMqpaL34wAT77aSvbaUcFgdvyGpfHERcC40EUWEbKHO887mI5kNZo59ENCn fAQBJEhfWnd86IjoMg0c+L3FJI0uaE2Osq5lI6IeftnfMwyHV1w7E8+RQZFGy+8jO7we oRgI14+e7wYduQkOwFNfED9T/0Rzfn6HhOsCVozoaJ47wfvKLACEN33pBJL827a3l7Xx qRh52dUHBoAYPMCLxSzjjF9gmM6VtogDDO8K/1KUpihCSQ5F8s0d89lOYs1tuDPDXyEk VaJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=YfDFt3MU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id i69-20020a636d48000000b00584af407e80si10923048pgc.293.2023.10.09.19.03.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 19:03:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=YfDFt3MU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id ED71E81EA5F1; Mon, 9 Oct 2023 19:03:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1441832AbjJJCCu (ORCPT + 99 others); Mon, 9 Oct 2023 22:02:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379396AbjJJCCp (ORCPT ); Mon, 9 Oct 2023 22:02:45 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA13FD7; Mon, 9 Oct 2023 19:02:41 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-692b2bdfce9so4605182b3a.3; Mon, 09 Oct 2023 19:02:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696903361; x=1697508161; darn=vger.kernel.org; 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=WtdXd8zzfUQBn/Ye5tSm8UdJuve0zGYoqRvrat58Hz4=; b=YfDFt3MUbqGgM/HZkE2Z0BZgFPz4kxIntfVYoquRfJYLracZLwXn07A04W9v4+ckGR mzUZQmMdivzFvfdFTRvMaWVf5rLsoXu6UAmhhUzJpBI3xm2Tr0q4jKvggb6E7tXVWV1G HRLcABEPJUld8TujAJNhhkVYbxc3XziO21zCwwNV0ZOHwe8WW5wIK3bp8SKt7k9nmRji ZF+gzl3KBkjyXGSVmsudoQi2Nvje5Nydc0MOYvVpZgbZPdcKxXGKLyyPp7yMTrZt9WTF a7XGLEkv/lbL9+iJ4+1MLbsqT/RubTpOUEsOezmxrlMkRFwNZGOg9ewAS4q/nWfskEX0 tLtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696903361; x=1697508161; 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=WtdXd8zzfUQBn/Ye5tSm8UdJuve0zGYoqRvrat58Hz4=; b=PUtOR1Bm7vaIcsblnY6/bXIgcT6jg16MKZhazdHLjXYsP5/52cHNpPCVLd9dzrFxN4 Qk+CfF0LwJj447g0efMEUxKeHzSPXdFNSvoWMU6peFpjAoSxxREoczYu3/fiIgxlKCmc zuUHuTRcQbplQ42QkB6fwaeHwDtvtVZyF0S2imfS4gdQBV9PSpwypTPPiRACHHmp4xnY Rt/5PE/jfZoHlr/WlEUSqgHLKpKzGTzOh3A3tSm1KoEwmQNwe/on+zNDCU/6iG0UYJw3 QM6AcG1OfXwUWxlCFxdn3kFyLnaL98Sxr+mBaSnjpl2vL82A1DDSAZZz39J97Ej0W6ZV FCrQ== X-Gm-Message-State: AOJu0YwyM5chVCeZ/NhucUr6UhLTvcQrJvAr18hNwpo32L0sIzjj0GjA yAJxT5kDV3eEDJo5EEVekxbqXlSruMcgyg== X-Received: by 2002:a05:6a00:2405:b0:68f:cd71:45d5 with SMTP id z5-20020a056a00240500b0068fcd7145d5mr19253361pfh.3.1696903361038; Mon, 09 Oct 2023 19:02:41 -0700 (PDT) Received: from ubuntu.. ([43.132.98.112]) by smtp.googlemail.com with ESMTPSA id t28-20020aa7939c000000b0068a46cd4120sm7044809pfe.199.2023.10.09.19.02.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 19:02:40 -0700 (PDT) From: Hengqi Chen To: linux-kernel@vger.kernel.org, bpf@vger.kernel.org Cc: keescook@chromium.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, luto@amacapital.net, wad@chromium.org, alexyonghe@tencent.com, hengqi.chen@gmail.com Subject: [PATCH 4/4] selftests/seccomp: Test SECCOMP_LOAD_FILTER and SECCOMP_ATTACH_FILTER Date: Mon, 9 Oct 2023 12:40:46 +0000 Message-Id: <20231009124046.74710-5-hengqi.chen@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231009124046.74710-1-hengqi.chen@gmail.com> References: <20231009124046.74710-1-hengqi.chen@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=3.8 required=5.0 tests=DATE_IN_PAST_12_24,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 morse.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 (morse.vger.email [0.0.0.0]); Mon, 09 Oct 2023 19:03:01 -0700 (PDT) X-Spam-Level: *** 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); +} + /* * TODO: * - expand NNP testing -- 2.34.1