Blame tests/28-sim-arch_x86.c

Packit 56e23f
/**
Packit 56e23f
 * Seccomp Library test program
Packit 56e23f
 *
Packit 56e23f
 * This test triggered a bug in libseccomp erroneously allowing the close()
Packit 56e23f
 * syscall on x32 instead of 'KILL'ing it, as it should do for unsupported
Packit 56e23f
 * architectures.
Packit 56e23f
 *
Packit 56e23f
 * Copyright (c) 2012 Red Hat <pmoore@redhat.com>
Packit 56e23f
 * Authors: Paul Moore <pmoore@redhat.com>
Packit 56e23f
 *          Mathias Krause <minipli@googlemail.com>
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
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
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_ALLOW);
Packit 56e23f
	if (ctx == NULL)
Packit 56e23f
		return ENOMEM;
Packit 56e23f
Packit 56e23f
	rc = seccomp_arch_remove(ctx, SCMP_ARCH_NATIVE);
Packit 56e23f
	if (rc != 0)
Packit 56e23f
		goto out;
Packit 56e23f
Packit 56e23f
	/* add x86-64 and x86 (in that order!) but explicitly leave out x32 */
Packit 56e23f
	rc = seccomp_arch_add(ctx, SCMP_ARCH_X86_64);
Packit 56e23f
	if (rc != 0)
Packit 56e23f
		goto out;
Packit 56e23f
	rc = seccomp_arch_add(ctx, SCMP_ARCH_X86);
Packit 56e23f
	if (rc != 0)
Packit 56e23f
		goto out;
Packit 56e23f
Packit 56e23f
	rc = seccomp_rule_add(ctx, SCMP_ACT_ERRNO(1), SCMP_SYS(close), 0);
Packit 56e23f
	if (rc != 0)
Packit 56e23f
		goto out;
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
}