forked from seccomp/libseccomp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ops for checking whether arguments are in a specified range, optionally negated and/or with mask: SCMP_CMP_{MASKED_}{NOT_}IN_RANGE. Closes: seccomp#94 Signed-off-by: Topi Miettinen <toiwoton@gmail.com>
- Loading branch information
1 parent
9e61fd7
commit 363dfca
Showing
8 changed files
with
268 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* Seccomp Library test program | ||
* | ||
* Copyright (c) 2017 Red Hat <pmoore@redhat.com> | ||
* Author: Paul Moore <paul@paul-moore.com> | ||
*/ | ||
|
||
/* | ||
* This library is free software; you can redistribute it and/or modify it | ||
* under the terms of version 2.1 of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation. | ||
* | ||
* This library is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | ||
* for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this library; if not, see <http://www.gnu.org/licenses>. | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <unistd.h> | ||
|
||
#include <seccomp.h> | ||
|
||
#include "util.h" | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
int rc; | ||
struct util_options opts; | ||
scmp_filter_ctx ctx = NULL; | ||
|
||
rc = util_getopt(argc, argv, &opts); | ||
if (rc < 0) | ||
goto out; | ||
|
||
ctx = seccomp_init(SCMP_ACT_KILL); | ||
if (ctx == NULL) | ||
return ENOMEM; | ||
|
||
/* the syscall and argument numbers are all fake to make the test | ||
* simpler */ | ||
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1000, 3, | ||
SCMP_A0(SCMP_CMP_EQ, 0), | ||
SCMP_A1(SCMP_CMP_IN_RANGE, 0xf0, 0xff), | ||
SCMP_A2(SCMP_CMP_EQ, 2)); | ||
if (rc != 0) | ||
goto out; | ||
|
||
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1001, 3, | ||
SCMP_A0(SCMP_CMP_EQ, 0), | ||
SCMP_A1(SCMP_CMP_NOT_IN_RANGE, 0xf0, 0xff), | ||
SCMP_A2(SCMP_CMP_EQ, 2)); | ||
if (rc != 0) | ||
goto out; | ||
|
||
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1002, 3, | ||
SCMP_A0(SCMP_CMP_EQ, 0), | ||
SCMP_A1(SCMP_CMP_MASKED_IN_RANGE, 0xff00, 0xf000, 0xfe00), | ||
SCMP_A2(SCMP_CMP_EQ, 2)); | ||
if (rc != 0) | ||
goto out; | ||
|
||
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1003, 3, | ||
SCMP_A0(SCMP_CMP_EQ, 0), | ||
SCMP_A1(SCMP_CMP_MASKED_NOT_IN_RANGE, 0xff00, 0xf000, 0xfe00), | ||
SCMP_A2(SCMP_CMP_EQ, 2)); | ||
if (rc != 0) | ||
goto out; | ||
|
||
rc = util_filter_output(&opts, ctx); | ||
if (rc) | ||
goto out; | ||
|
||
out: | ||
seccomp_release(ctx); | ||
return (rc < 0 ? -rc : rc); | ||
} |
Oops, something went wrong.