|
Packit |
56e23f |
/**
|
|
Packit |
56e23f |
* Seccomp Library test program
|
|
Packit |
56e23f |
*
|
|
Packit |
56e23f |
* Copyright (c) 2019 Cisco Systems, Inc. <pmoore2@cisco.com>
|
|
Packit |
56e23f |
* Author: Paul Moore <paul@paul-moore.com>
|
|
Packit |
56e23f |
* Additions: Michael Weiser <michael.weiser@gmx.de>
|
|
Packit |
56e23f |
*/
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
/*
|
|
Packit |
56e23f |
* This library is free software; you can redistribute it and/or modify it
|
|
Packit |
56e23f |
* under the terms of version 2.1 of the GNU Lesser General Public License as
|
|
Packit |
56e23f |
* published by the Free Software Foundation.
|
|
Packit |
56e23f |
*
|
|
Packit |
56e23f |
* This library is distributed in the hope that it will be useful, but WITHOUT
|
|
Packit |
56e23f |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
Packit |
56e23f |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
Packit |
56e23f |
* for more details.
|
|
Packit |
56e23f |
*
|
|
Packit |
56e23f |
* You should have received a copy of the GNU Lesser General Public License
|
|
Packit |
56e23f |
* along with this library; if not, see <http://www.gnu.org/licenses>.
|
|
Packit |
56e23f |
*/
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
#include <errno.h>
|
|
Packit |
56e23f |
#include <unistd.h>
|
|
Packit |
56e23f |
#include <inttypes.h>
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
#include <seccomp.h>
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
#include "util.h"
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
int main(int argc, char *argv[])
|
|
Packit |
56e23f |
{
|
|
Packit |
56e23f |
int rc;
|
|
Packit |
56e23f |
struct util_options opts;
|
|
Packit |
56e23f |
scmp_filter_ctx ctx = NULL;
|
|
Packit |
56e23f |
struct args {
|
|
Packit |
56e23f |
uint32_t action;
|
|
Packit |
56e23f |
int syscall;
|
|
Packit |
56e23f |
struct scmp_arg_cmp cmp;
|
|
Packit |
56e23f |
} *a, f[] = {
|
|
Packit |
56e23f |
{SCMP_ACT_ALLOW, 2000, SCMP_A0(SCMP_CMP_EQ, -1)},
|
|
Packit |
56e23f |
{SCMP_ACT_ALLOW, 2064, SCMP_A0_64(SCMP_CMP_EQ, -1)},
|
|
Packit |
56e23f |
{SCMP_ACT_ALLOW, 2032, SCMP_A0_32(SCMP_CMP_EQ, -1)},
|
|
Packit |
56e23f |
{0},
|
|
Packit |
56e23f |
};
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
rc = util_getopt(argc, argv, &opts);
|
|
Packit |
56e23f |
if (rc < 0)
|
|
Packit |
56e23f |
goto out;
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
ctx = seccomp_init(SCMP_ACT_KILL);
|
|
Packit |
56e23f |
if (ctx == NULL)
|
|
Packit |
56e23f |
return ENOMEM;
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1000, 1,
|
|
Packit |
56e23f |
SCMP_A0(SCMP_CMP_EQ, -1));
|
|
Packit |
56e23f |
if (rc != 0)
|
|
Packit |
56e23f |
goto out;
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1064, 1,
|
|
Packit |
56e23f |
SCMP_A0_64(SCMP_CMP_EQ, -1));
|
|
Packit |
56e23f |
if (rc != 0)
|
|
Packit |
56e23f |
goto out;
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
rc = seccomp_rule_add_exact(ctx, SCMP_ACT_ALLOW, 1032, 1,
|
|
Packit |
56e23f |
SCMP_A0_32(SCMP_CMP_EQ, -1));
|
|
Packit |
56e23f |
if (rc != 0)
|
|
Packit |
56e23f |
goto out;
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
for (a = f; a->syscall != 0; a++) {
|
|
Packit |
56e23f |
rc = seccomp_rule_add_exact(ctx, a->action, a->syscall, 1,
|
|
Packit |
56e23f |
a->cmp);
|
|
Packit |
56e23f |
if (rc != 0)
|
|
Packit |
56e23f |
goto out;
|
|
Packit |
56e23f |
}
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
rc = util_filter_output(&opts, ctx);
|
|
Packit |
56e23f |
if (rc)
|
|
Packit |
56e23f |
goto out;
|
|
Packit |
56e23f |
|
|
Packit |
56e23f |
out:
|
|
Packit |
56e23f |
seccomp_release(ctx);
|
|
Packit |
56e23f |
return (rc < 0 ? -rc : rc);
|
|
Packit |
56e23f |
}
|