Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1538801yba; Thu, 25 Apr 2019 01:15:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwtUHmfXJsCIlKfydBFQtruOTVWElcGAJH3vYIXQuX5p9RHr/k0HtyRSLAA58n0b4ZsGkV+ X-Received: by 2002:a17:902:e407:: with SMTP id ci7mr37533548plb.219.1556180144109; Thu, 25 Apr 2019 01:15:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556180144; cv=none; d=google.com; s=arc-20160816; b=a3OZoAvnJhBrTrU2mNmW6NKm9j3fCZLzrHvtB7uYi61exbRTFagFHLfZRqR/59KMOY ZotbeVmn7uofu33jWc3/MXzUQoG3hJ9nT6DyhRKv/Jp/eBBruWDCR0XEbjiGAEYZ0Vqr jxdNWOg1qtw4LfganbGgzKKkZihUBOuK7hO1u486L/MfN7Xww0LxxdCIxBNgXh+OgauF I/F908Akz0EU1UtAsWkGcQS2tRVJmfgIT6b8Lnuw8krNvSNvAHD/DWO5uzFewtWB2PRj /zQm04WHumA8kQQ5ArU0HGv62Kb6za39fy6344lzOSpgqOKyOSCz6cLrzEhbv/sZEeT2 0PdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=YXxYpHpTdjGr5w9yOLPfaE3Ua1h1w5UPyfVMheIgEBY=; b=0USnaOcOi16ssmC2/BSRzHwB5aW70Z4lEHTD8mJsix43Y770W8ONmO1MMOuXxDS5GT 2gmCQjdqD5ZPI2HenXQi7GqyZ92kCjolSOsWkW2xW7M+iB7pejvz22YThYGgJRBLyINH +/6CcIYcjyDannxEMCkTV7F21y/qE3oev5gLH+g5Ol6DtxL2W9Vg5og8nLgccng966Pk Je/XWTg1X6d8dwd+KbACwmpTIBkiIUE5uPyiKqLbK0Qk21n/ArmNvMmlX91XXok94U61 8OYdS/oPAhwVvt9O6f2ZERlkHqYVZLghU/swEPFIJG3jRDM4rOhnuxEK0B3wW3W/gsB3 gSEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g30si5692692pgl.9.2019.04.25.01.15.28; Thu, 25 Apr 2019 01:15:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729137AbfDYFaM (ORCPT + 99 others); Thu, 25 Apr 2019 01:30:12 -0400 Received: from namei.org ([65.99.196.166]:35708 "EHLO namei.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725900AbfDYFaM (ORCPT ); Thu, 25 Apr 2019 01:30:12 -0400 Received: from localhost (localhost [127.0.0.1]) by namei.org (8.14.4/8.14.4) with ESMTP id x3P5U7pC024926; Thu, 25 Apr 2019 05:30:07 GMT Date: Thu, 25 Apr 2019 15:30:07 +1000 (AEST) From: James Morris To: Kees Cook cc: Tycho Andersen , stable@vger.kernel.org, Andy Lutomirski , Will Drewry , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] selftests/seccomp: Prepare for exclusive seccomp flags In-Reply-To: <20190424163756.40001-2-keescook@chromium.org> Message-ID: References: <20190424163756.40001-1-keescook@chromium.org> <20190424163756.40001-2-keescook@chromium.org> User-Agent: Alpine 2.21 (LRH 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 24 Apr 2019, Kees Cook wrote: > Some seccomp flags will become exclusive, so the selftest needs to > be adjusted to mask those out and test them individually for the "all > flags" tests. > > Cc: stable@vger.kernel.org # v5.0+ > Signed-off-by: Kees Cook Acked-by: James Morris > --- > tools/testing/selftests/seccomp/seccomp_bpf.c | 34 ++++++++++++++----- > 1 file changed, 25 insertions(+), 9 deletions(-) > > diff --git a/tools/testing/selftests/seccomp/seccomp_bpf.c b/tools/testing/selftests/seccomp/seccomp_bpf.c > index f69d2ee29742..5019cdae5d0b 100644 > --- a/tools/testing/selftests/seccomp/seccomp_bpf.c > +++ b/tools/testing/selftests/seccomp/seccomp_bpf.c > @@ -2166,11 +2166,14 @@ TEST(detect_seccomp_filter_flags) > SECCOMP_FILTER_FLAG_LOG, > SECCOMP_FILTER_FLAG_SPEC_ALLOW, > SECCOMP_FILTER_FLAG_NEW_LISTENER }; > - unsigned int flag, all_flags; > + unsigned int exclusive[] = { > + SECCOMP_FILTER_FLAG_TSYNC, > + SECCOMP_FILTER_FLAG_NEW_LISTENER }; > + unsigned int flag, all_flags, exclusive_mask; > int i; > long ret; > > - /* Test detection of known-good filter flags */ > + /* Test detection of individual known-good filter flags */ > for (i = 0, all_flags = 0; i < ARRAY_SIZE(flags); i++) { > int bits = 0; > > @@ -2197,16 +2200,29 @@ TEST(detect_seccomp_filter_flags) > all_flags |= flag; > } > > - /* Test detection of all known-good filter flags */ > - ret = seccomp(SECCOMP_SET_MODE_FILTER, all_flags, NULL); > - EXPECT_EQ(-1, ret); > - EXPECT_EQ(EFAULT, errno) { > - TH_LOG("Failed to detect that all known-good filter flags (0x%X) are supported!", > - all_flags); > + /* > + * Test detection of all known-good filter flags combined. But > + * for the exclusive flags we need to mask them out and try them > + * individually for the "all flags" testing. > + */ > + exclusive_mask = 0; > + for (i = 0; i < ARRAY_SIZE(exclusive); i++) > + exclusive_mask |= exclusive[i]; > + for (i = 0; i < ARRAY_SIZE(exclusive); i++) { > + flag = all_flags & ~exclusive_mask; > + flag |= exclusive[i]; > + > + ret = seccomp(SECCOMP_SET_MODE_FILTER, flag, NULL); > + EXPECT_EQ(-1, ret); > + EXPECT_EQ(EFAULT, errno) { > + TH_LOG("Failed to detect that all known-good filter flags (0x%X) are supported!", > + flag); > + } > } > > - /* Test detection of an unknown filter flag */ > + /* Test detection of an unknown filter flags, without exclusives. */ > flag = -1; > + flag &= ~exclusive_mask; > ret = seccomp(SECCOMP_SET_MODE_FILTER, flag, NULL); > EXPECT_EQ(-1, ret); > EXPECT_EQ(EINVAL, errno) { > -- James Morris