Blame src/arch-s390.c

Packit 56e23f
/*
Packit 56e23f
 * Copyright 2015 IBM
Packit 56e23f
 * Author: Jan Willeke <willeke@linux.vnet.com.com>
Packit 56e23f
 */
Packit 56e23f
Packit 56e23f
#include <stdlib.h>
Packit 56e23f
#include <errno.h>
Packit 56e23f
#include <string.h>
Packit 56e23f
#include <linux/audit.h>
Packit 56e23f
Packit Service 10c312
#include "db.h"
Packit Service 10c312
#include "syscalls.h"
Packit 56e23f
#include "arch.h"
Packit 56e23f
#include "arch-s390.h"
Packit 56e23f
Packit 56e23f
/* s390 syscall numbers */
Packit 56e23f
#define __s390_NR_socketcall		102
Packit 56e23f
#define __s390_NR_ipc			117
Packit 56e23f
Packit Service 10c312
/**
Packit Service 10c312
 * Resolve a syscall name to a number
Packit Service 10c312
 * @param name the syscall name
Packit Service 10c312
 *
Packit Service 10c312
 * Resolve the given syscall name to the syscall number using the syscall table.
Packit Service 10c312
 * Returns the syscall number on success, including negative pseudo syscall
Packit Service 10c312
 * numbers; returns __NR_SCMP_ERROR on failure.
Packit Service 10c312
 *
Packit Service 10c312
 */
Packit Service 10c312
int s390_syscall_resolve_name_munge(const char *name)
Packit Service 10c312
{
Packit Service 10c312
	if (strcmp(name, "accept") == 0)
Packit Service 10c312
		return __PNR_accept;
Packit Service 10c312
	if (strcmp(name, "accept4") == 0)
Packit Service 10c312
		return __PNR_accept4;
Packit Service 10c312
	else if (strcmp(name, "bind") == 0)
Packit Service 10c312
		return __PNR_bind;
Packit Service 10c312
	else if (strcmp(name, "connect") == 0)
Packit Service 10c312
		return __PNR_connect;
Packit Service 10c312
	else if (strcmp(name, "getpeername") == 0)
Packit Service 10c312
		return __PNR_getpeername;
Packit Service 10c312
	else if (strcmp(name, "getsockname") == 0)
Packit Service 10c312
		return __PNR_getsockname;
Packit Service 10c312
	else if (strcmp(name, "getsockopt") == 0)
Packit Service 10c312
		return __PNR_getsockopt;
Packit Service 10c312
	else if (strcmp(name, "listen") == 0)
Packit Service 10c312
		return __PNR_listen;
Packit Service 10c312
	else if (strcmp(name, "msgctl") == 0)
Packit Service 10c312
		return __PNR_msgctl;
Packit Service 10c312
	else if (strcmp(name, "msgget") == 0)
Packit Service 10c312
		return __PNR_msgget;
Packit Service 10c312
	else if (strcmp(name, "msgrcv") == 0)
Packit Service 10c312
		return __PNR_msgrcv;
Packit Service 10c312
	else if (strcmp(name, "msgsnd") == 0)
Packit Service 10c312
		return __PNR_msgsnd;
Packit Service 10c312
	else if (strcmp(name, "recv") == 0)
Packit Service 10c312
		return __PNR_recv;
Packit Service 10c312
	else if (strcmp(name, "recvfrom") == 0)
Packit Service 10c312
		return __PNR_recvfrom;
Packit Service 10c312
	else if (strcmp(name, "recvmsg") == 0)
Packit Service 10c312
		return __PNR_recvmsg;
Packit Service 10c312
	else if (strcmp(name, "semctl") == 0)
Packit Service 10c312
		return __PNR_semctl;
Packit Service 10c312
	else if (strcmp(name, "semget") == 0)
Packit Service 10c312
		return __PNR_semget;
Packit Service 10c312
	else if (strcmp(name, "semtimedop") == 0)
Packit Service 10c312
		return __PNR_semtimedop;
Packit Service 10c312
	else if (strcmp(name, "recvmmsg") == 0)
Packit Service 10c312
		return __PNR_recvmmsg;
Packit Service 10c312
	else if (strcmp(name, "send") == 0)
Packit Service 10c312
		return __PNR_send;
Packit Service 10c312
	else if (strcmp(name, "sendmsg") == 0)
Packit Service 10c312
		return __PNR_sendmsg;
Packit Service 10c312
	else if (strcmp(name, "sendmmsg") == 0)
Packit Service 10c312
		return __PNR_sendmmsg;
Packit Service 10c312
	else if (strcmp(name, "sendto") == 0)
Packit Service 10c312
		return __PNR_sendto;
Packit Service 10c312
	else if (strcmp(name, "setsockopt") == 0)
Packit Service 10c312
		return __PNR_setsockopt;
Packit Service 10c312
	else if (strcmp(name, "shmat") == 0)
Packit Service 10c312
		return __PNR_shmat;
Packit Service 10c312
	else if (strcmp(name, "shmdt") == 0)
Packit Service 10c312
		return __PNR_shmdt;
Packit Service 10c312
	else if (strcmp(name, "shmget") == 0)
Packit Service 10c312
		return __PNR_shmget;
Packit Service 10c312
	else if (strcmp(name, "shmctl") == 0)
Packit Service 10c312
		return __PNR_shmctl;
Packit Service 10c312
	else if (strcmp(name, "shutdown") == 0)
Packit Service 10c312
		return __PNR_shutdown;
Packit Service 10c312
	else if (strcmp(name, "socket") == 0)
Packit Service 10c312
		return __PNR_socket;
Packit Service 10c312
	else if (strcmp(name, "socketpair") == 0)
Packit Service 10c312
		return __PNR_socketpair;
Packit Service 10c312
Packit Service 10c312
	return s390_syscall_resolve_name(name);
Packit Service 10c312
}
Packit Service 10c312
Packit Service 10c312
/**
Packit Service 10c312
 * Resolve a syscall number to a name
Packit Service 10c312
 * @param num the syscall number
Packit Service 10c312
 *
Packit Service 10c312
 * Resolve the given syscall number to the syscall name using the syscall table.
Packit Service 10c312
 * Returns a pointer to the syscall name string on success, including pseudo
Packit Service 10c312
 * syscall names; returns NULL on failure.
Packit Service 10c312
 *
Packit Service 10c312
 */
Packit Service 10c312
const char *s390_syscall_resolve_num_munge(int num)
Packit Service 10c312
{
Packit Service 10c312
	if (num == __PNR_accept)
Packit Service 10c312
		return "accept";
Packit Service 10c312
	else if (num == __PNR_accept4)
Packit Service 10c312
		return "accept4";
Packit Service 10c312
	else if (num == __PNR_bind)
Packit Service 10c312
		return "bind";
Packit Service 10c312
	else if (num == __PNR_connect)
Packit Service 10c312
		return "connect";
Packit Service 10c312
	else if (num == __PNR_getpeername)
Packit Service 10c312
		return "getpeername";
Packit Service 10c312
	else if (num == __PNR_getsockname)
Packit Service 10c312
		return "getsockname";
Packit Service 10c312
	else if (num == __PNR_getsockopt)
Packit Service 10c312
		return "getsockopt";
Packit Service 10c312
	else if (num == __PNR_listen)
Packit Service 10c312
		return "listen";
Packit Service 10c312
	else if (num == __PNR_msgctl)
Packit Service 10c312
		return "msgctl";
Packit Service 10c312
	else if (num == __PNR_msgget)
Packit Service 10c312
		return "msgget";
Packit Service 10c312
	else if (num == __PNR_msgrcv)
Packit Service 10c312
		return "msgrcv";
Packit Service 10c312
	else if (num == __PNR_msgsnd)
Packit Service 10c312
		return "msgsnd";
Packit Service 10c312
	else if (num == __PNR_recv)
Packit Service 10c312
		return "recv";
Packit Service 10c312
	else if (num == __PNR_recvfrom)
Packit Service 10c312
		return "recvfrom";
Packit Service 10c312
	else if (num == __PNR_recvmsg)
Packit Service 10c312
		return "recvmsg";
Packit Service 10c312
	else if (num == __PNR_recvmmsg)
Packit Service 10c312
		return "recvmmsg";
Packit Service 10c312
	else if (num == __PNR_semctl)
Packit Service 10c312
		return "semctl";
Packit Service 10c312
	else if (num == __PNR_semget)
Packit Service 10c312
		return "semget";
Packit Service 10c312
	else if (num == __PNR_semtimedop)
Packit Service 10c312
		return "semtimedop";
Packit Service 10c312
	else if (num == __PNR_send)
Packit Service 10c312
		return "send";
Packit Service 10c312
	else if (num == __PNR_sendmsg)
Packit Service 10c312
		return "sendmsg";
Packit Service 10c312
	else if (num == __PNR_sendmmsg)
Packit Service 10c312
		return "sendmmsg";
Packit Service 10c312
	else if (num == __PNR_sendto)
Packit Service 10c312
		return "sendto";
Packit Service 10c312
	else if (num == __PNR_setsockopt)
Packit Service 10c312
		return "setsockopt";
Packit Service 10c312
	else if (num == __PNR_shmat)
Packit Service 10c312
		return "shmat";
Packit Service 10c312
	else if (num == __PNR_shmdt)
Packit Service 10c312
		return "shmdt";
Packit Service 10c312
	else if (num == __PNR_shmget)
Packit Service 10c312
		return "shmget";
Packit Service 10c312
	else if (num == __PNR_shmctl)
Packit Service 10c312
		return "shmctl";
Packit Service 10c312
	else if (num == __PNR_shutdown)
Packit Service 10c312
		return "shutdown";
Packit Service 10c312
	else if (num == __PNR_socket)
Packit Service 10c312
		return "socket";
Packit Service 10c312
	else if (num == __PNR_socketpair)
Packit Service 10c312
		return "socketpair";
Packit Service 10c312
Packit Service 10c312
	return s390_syscall_resolve_num(num);
Packit Service 10c312
}
Packit 56e23f
Packit 56e23f
/**
Packit 56e23f
 * Convert a multiplexed pseudo syscall into a direct syscall
Packit 56e23f
 * @param syscall the multiplexed pseudo syscall number
Packit 56e23f
 *
Packit 56e23f
 * Return the related direct syscall number, __NR_SCMP_UNDEF is there is
Packit 56e23f
 * no related syscall, or __NR_SCMP_ERROR otherwise.
Packit 56e23f
 *
Packit 56e23f
 */
Packit 56e23f
static int _s390_syscall_demux(int syscall)
Packit 56e23f
{
Packit 56e23f
	switch (syscall) {
Packit 56e23f
	case -101:
Packit 56e23f
		/* socket */
Packit 56e23f
		return 359;
Packit 56e23f
	case -102:
Packit 56e23f
		/* bind */
Packit 56e23f
		return 361;
Packit 56e23f
	case -103:
Packit 56e23f
		/* connect */
Packit 56e23f
		return 362;
Packit 56e23f
	case -104:
Packit 56e23f
		/* listen */
Packit 56e23f
		return 363;
Packit 56e23f
	case -105:
Packit 56e23f
		/* accept - not defined */
Packit 56e23f
		return __NR_SCMP_UNDEF;
Packit 56e23f
	case -106:
Packit 56e23f
		/* getsockname */
Packit 56e23f
		return 367;
Packit 56e23f
	case -107:
Packit 56e23f
		/* getpeername */
Packit 56e23f
		return 368;
Packit 56e23f
	case -108:
Packit 56e23f
		/* socketpair */
Packit 56e23f
		return 360;
Packit 56e23f
	case -109:
Packit 56e23f
		/* send - not defined */
Packit 56e23f
		return __NR_SCMP_UNDEF;
Packit 56e23f
	case -110:
Packit 56e23f
		/* recv - not defined */
Packit 56e23f
		return __NR_SCMP_UNDEF;
Packit 56e23f
	case -111:
Packit 56e23f
		/* sendto */
Packit 56e23f
		return 369;
Packit 56e23f
	case -112:
Packit 56e23f
		/* recvfrom */
Packit 56e23f
		return 371;
Packit 56e23f
	case -113:
Packit 56e23f
		/* shutdown */
Packit 56e23f
		return 373;
Packit 56e23f
	case -114:
Packit 56e23f
		/* setsockopt */
Packit 56e23f
		return 366;
Packit 56e23f
	case -115:
Packit 56e23f
		/* getsockopt */
Packit 56e23f
		return 365;
Packit 56e23f
	case -116:
Packit 56e23f
		/* sendmsg */
Packit 56e23f
		return 370;
Packit 56e23f
	case -117:
Packit 56e23f
		/* recvmsg */
Packit 56e23f
		return 372;
Packit 56e23f
	case -118:
Packit 56e23f
		/* accept4 */
Packit 56e23f
		return 364;
Packit 56e23f
	case -119:
Packit 56e23f
		/* recvmmsg */
Packit 56e23f
		return 337;
Packit 56e23f
	case -120:
Packit 56e23f
		/* sendmmsg */
Packit 56e23f
		return 345;
Packit 56e23f
	case -201:
Packit 56e23f
		/* semop - not defined */
Packit 56e23f
		return __NR_SCMP_UNDEF;
Packit 56e23f
	case -202:
Packit 56e23f
		/* semget */
Packit 56e23f
		return 393;
Packit 56e23f
	case -203:
Packit 56e23f
		/* semctl */
Packit 56e23f
		return 394;
Packit 56e23f
	case -204:
Packit Service 10c312
		/* semtimedop */
Packit Service 10c312
		return 392;
Packit 56e23f
	case -211:
Packit 56e23f
		/* msgsnd */
Packit 56e23f
		return 400;
Packit 56e23f
	case -212:
Packit 56e23f
		/* msgrcv */
Packit 56e23f
		return 401;
Packit 56e23f
	case -213:
Packit 56e23f
		/* msgget */
Packit 56e23f
		return 399;
Packit 56e23f
	case -214:
Packit 56e23f
		/* msgctl */
Packit 56e23f
		return 402;
Packit 56e23f
	case -221:
Packit 56e23f
		/* shmat */
Packit 56e23f
		return 397;
Packit 56e23f
	case -222:
Packit 56e23f
		/* shmdt */
Packit 56e23f
		return 398;
Packit 56e23f
	case -223:
Packit 56e23f
		/* shmget */
Packit 56e23f
		return 395;
Packit 56e23f
	case -224:
Packit 56e23f
		/* shmctl */
Packit 56e23f
		return 396;
Packit 56e23f
Packit 56e23f
	}
Packit 56e23f
Packit 56e23f
	return __NR_SCMP_ERROR;
Packit 56e23f
}
Packit 56e23f
Packit 56e23f
/**
Packit 56e23f
 * Convert a direct socket syscall into multiplexed pseudo socket syscall
Packit 56e23f
 * @param syscall the direct syscall
Packit 56e23f
 *
Packit 56e23f
 * Return the related multiplexed pseduo syscall number, __NR_SCMP_UNDEF is
Packit 56e23f
 * there is no related pseudo syscall, or __NR_SCMP_ERROR otherwise.
Packit 56e23f
 *
Packit 56e23f
 */
Packit 56e23f
static int _s390_syscall_mux(int syscall)
Packit 56e23f
{
Packit 56e23f
	switch (syscall) {
Packit 56e23f
	case 337:
Packit 56e23f
		/* recvmmsg */
Packit 56e23f
		return -119;
Packit 56e23f
	case 345:
Packit 56e23f
		/* sendmmsg */
Packit 56e23f
		return -120;
Packit 56e23f
	case 359:
Packit 56e23f
		/* socket */
Packit 56e23f
		return -101;
Packit 56e23f
	case 360:
Packit 56e23f
		/* socketpair */
Packit 56e23f
		return -108;
Packit 56e23f
	case 361:
Packit 56e23f
		/* bind */
Packit 56e23f
		return -102;
Packit 56e23f
	case 362:
Packit 56e23f
		/* connect */
Packit 56e23f
		return -103;
Packit 56e23f
	case 363:
Packit 56e23f
		/* listen */
Packit 56e23f
		return -104;
Packit 56e23f
	case 364:
Packit 56e23f
		/* accept4 */
Packit 56e23f
		return -118;
Packit 56e23f
	case 365:
Packit 56e23f
		/* getsockopt */
Packit 56e23f
		return -115;
Packit 56e23f
	case 366:
Packit 56e23f
		/* setsockopt */
Packit 56e23f
		return -114;
Packit 56e23f
	case 367:
Packit 56e23f
		/* getsockname */
Packit 56e23f
		return -106;
Packit 56e23f
	case 368:
Packit 56e23f
		/* getpeername */
Packit 56e23f
		return -107;
Packit 56e23f
	case 369:
Packit 56e23f
		/* sendto */
Packit 56e23f
		return -111;
Packit 56e23f
	case 370:
Packit 56e23f
		/* sendmsg */
Packit 56e23f
		return -116;
Packit 56e23f
	case 371:
Packit 56e23f
		/* recvfrom */
Packit 56e23f
		return -112;
Packit 56e23f
	case 372:
Packit 56e23f
		/* recvmsg */
Packit 56e23f
		return -117;
Packit 56e23f
	case 373:
Packit 56e23f
		/* shutdown */
Packit 56e23f
		return -113;
Packit 56e23f
	case 393:
Packit 56e23f
		/* semget */
Packit 56e23f
		return -202;
Packit 56e23f
	case 394:
Packit 56e23f
		/* semctl */
Packit 56e23f
		return -203;
Packit 56e23f
	case 400:
Packit 56e23f
		/* msgsnd */
Packit 56e23f
		return -211;
Packit 56e23f
	case 401:
Packit 56e23f
		/* msgrcv */
Packit 56e23f
		return -212;
Packit 56e23f
	case 399:
Packit 56e23f
		/* msgget */
Packit 56e23f
		return -213;
Packit 56e23f
	case 402:
Packit 56e23f
		/* msgctl */
Packit 56e23f
		return -214;
Packit 56e23f
	case 397:
Packit 56e23f
		/* shmat */
Packit 56e23f
		return -221;
Packit 56e23f
	case 398:
Packit 56e23f
		/* shmdt */
Packit 56e23f
		return -222;
Packit 56e23f
	case 395:
Packit 56e23f
		/* shmget */
Packit 56e23f
		return -223;
Packit 56e23f
	case 396:
Packit 56e23f
		/* shmctl */
Packit 56e23f
		return -224;
Packit Service 10c312
	case 392:
Packit Service 10c312
		/* semtimedop */
Packit Service 10c312
		return -204;
Packit 56e23f
	}
Packit 56e23f
Packit 56e23f
	return __NR_SCMP_ERROR;
Packit 56e23f
}
Packit 56e23f
Packit 56e23f
/**
Packit 56e23f
 * Rewrite a syscall value to match the architecture
Packit 56e23f
 * @param syscall the syscall number
Packit 56e23f
 *
Packit 56e23f
 * Syscalls can vary across different architectures so this function rewrites
Packit 56e23f
 * the syscall into the correct value for the specified architecture.  Returns
Packit 56e23f
 * zero on success, negative values on failure.
Packit 56e23f
 *
Packit 56e23f
 */
Packit 56e23f
int s390_syscall_rewrite(int *syscall)
Packit 56e23f
{
Packit 56e23f
	int sys = *syscall;
Packit 56e23f
Packit 56e23f
	if (sys <= -100 && sys >= -120)
Packit 56e23f
		*syscall = __s390_NR_socketcall;
Packit 56e23f
	else if (sys <= -200 && sys >= -224)
Packit 56e23f
		*syscall = __s390_NR_ipc;
Packit 56e23f
	else if (sys < 0)
Packit 56e23f
		return -EDOM;
Packit 56e23f
Packit 56e23f
	return 0;
Packit 56e23f
}
Packit 56e23f
Packit 56e23f
/**
Packit 56e23f
 * add a new rule to the s390 seccomp filter
Packit 56e23f
 * @param db the seccomp filter db
Packit 56e23f
 * @param rule the filter rule
Packit 56e23f
 *
Packit 56e23f
 * This function adds a new syscall filter to the seccomp filter db, making any
Packit 56e23f
 * necessary adjustments for the s390 ABI.  Returns zero on success, negative
Packit 56e23f
 * values on failure.
Packit 56e23f
 *
Packit 56e23f
 * It is important to note that in the case of failure the db may be corrupted,
Packit 56e23f
 * the caller must use the transaction mechanism if the db integrity is
Packit 56e23f
 * important.
Packit 56e23f
 *
Packit 56e23f
 */
Packit 56e23f
int s390_rule_add(struct db_filter *db, struct db_api_rule_list *rule)
Packit 56e23f
{
Packit 56e23f
	int rc = 0;
Packit 56e23f
	unsigned int iter;
Packit 56e23f
	int sys = rule->syscall;
Packit 56e23f
	int sys_a, sys_b;
Packit 56e23f
	struct db_api_rule_list *rule_a, *rule_b, *rule_dup = NULL;
Packit 56e23f
Packit 56e23f
	if ((sys <= -100 && sys >= -120) || (sys >= 359 && sys <= 373)) {
Packit 56e23f
		/* (-100 to -120) : multiplexed socket syscalls
Packit 56e23f
		   (359 to 373)   : direct socket syscalls, Linux 4.3+ */
Packit 56e23f
Packit 56e23f
		/* strict check for the multiplexed socket syscalls */
Packit 56e23f
		for (iter = 0; iter < ARG_COUNT_MAX; iter++) {
Packit 56e23f
			if ((rule->args[iter].valid != 0) && (rule->strict)) {
Packit 56e23f
				rc = -EINVAL;
Packit 56e23f
				goto add_return;
Packit 56e23f
			}
Packit 56e23f
		}
Packit 56e23f
Packit 56e23f
		/* determine both the muxed and direct syscall numbers */
Packit 56e23f
		if (sys > 0) {
Packit 56e23f
			sys_a = _s390_syscall_mux(sys);
Packit 56e23f
			if (sys_a == __NR_SCMP_ERROR) {
Packit 56e23f
				rc = __NR_SCMP_ERROR;
Packit 56e23f
				goto add_return;
Packit 56e23f
			}
Packit 56e23f
			sys_b = sys;
Packit 56e23f
		} else {
Packit 56e23f
			sys_a = sys;
Packit 56e23f
			sys_b = _s390_syscall_demux(sys);
Packit 56e23f
			if (sys_b == __NR_SCMP_ERROR) {
Packit 56e23f
				rc = __NR_SCMP_ERROR;
Packit 56e23f
				goto add_return;
Packit 56e23f
			}
Packit 56e23f
		}
Packit 56e23f
Packit 56e23f
		/* use rule_a for the multiplexed syscall and use rule_b for
Packit 56e23f
		 * the direct wired syscall */
Packit 56e23f
Packit 56e23f
		if (sys_a == __NR_SCMP_UNDEF) {
Packit 56e23f
			rule_a = NULL;
Packit 56e23f
			rule_b = rule;
Packit 56e23f
		} else if (sys_b == __NR_SCMP_UNDEF) {
Packit 56e23f
			rule_a = rule;
Packit 56e23f
			rule_b = NULL;
Packit 56e23f
		} else {
Packit 56e23f
			/* need two rules, dup the first and link together */
Packit 56e23f
			rule_a = rule;
Packit 56e23f
			rule_dup = db_rule_dup(rule_a);
Packit 56e23f
			rule_b = rule_dup;
Packit 56e23f
			if (rule_b == NULL) {
Packit 56e23f
				rc = -ENOMEM;
Packit 56e23f
				goto add_return;
Packit 56e23f
			}
Packit 56e23f
			rule_b->prev = rule_a;
Packit 56e23f
			rule_b->next = NULL;
Packit 56e23f
			rule_a->next = rule_b;
Packit 56e23f
		}
Packit 56e23f
Packit 56e23f
		/* multiplexed socket syscalls */
Packit 56e23f
		if (rule_a != NULL) {
Packit 56e23f
			rule_a->syscall = __s390_NR_socketcall;
Packit 56e23f
			rule_a->args[0].arg = 0;
Packit 56e23f
			rule_a->args[0].op = SCMP_CMP_EQ;
Packit 56e23f
			rule_a->args[0].mask = DATUM_MAX;
Packit 56e23f
			rule_a->args[0].datum = (-sys_a) % 100;
Packit 56e23f
			rule_a->args[0].valid = 1;
Packit 56e23f
		}
Packit 56e23f
Packit 56e23f
		/* direct wired socket syscalls */
Packit 56e23f
		if (rule_b != NULL)
Packit 56e23f
			rule_b->syscall = sys_b;
Packit 56e23f
Packit 56e23f
		/* we should be protected by a transaction checkpoint */
Packit 56e23f
		if (rule_a != NULL) {
Packit 56e23f
			rc = db_rule_add(db, rule_a);
Packit 56e23f
			if (rc < 0)
Packit 56e23f
				goto add_return;
Packit 56e23f
		}
Packit 56e23f
		if (rule_b != NULL) {
Packit 56e23f
			rc = db_rule_add(db, rule_b);
Packit 56e23f
			if (rc < 0)
Packit 56e23f
				goto add_return;
Packit 56e23f
		}
Packit 56e23f
	} else if ((sys <= -200 && sys >= -224) || (sys >= 393 && sys <= 402)) {
Packit 56e23f
		/* (-200 to -224) : multiplexed ipc syscalls
Packit 56e23f
		   (393 to 402) : direct ipc syscalls */
Packit 56e23f
Packit 56e23f
		/* strict check for the multiplexed socket syscalls */
Packit 56e23f
		for (iter = 0; iter < ARG_COUNT_MAX; iter++) {
Packit 56e23f
			if ((rule->args[iter].valid != 0) && (rule->strict)) {
Packit 56e23f
				rc = -EINVAL;
Packit 56e23f
				goto add_return;
Packit 56e23f
			}
Packit 56e23f
		}
Packit 56e23f
Packit 56e23f
		/* determine both the muxed and direct syscall numbers */
Packit 56e23f
		if (sys > 0) {
Packit 56e23f
			sys_a = _s390_syscall_mux(sys);
Packit 56e23f
			if (sys_a == __NR_SCMP_ERROR) {
Packit 56e23f
				rc = __NR_SCMP_ERROR;
Packit 56e23f
				goto add_return;
Packit 56e23f
			}
Packit 56e23f
			sys_b = sys;
Packit 56e23f
		} else {
Packit 56e23f
			sys_a = sys;
Packit 56e23f
			sys_b = _s390_syscall_demux(sys);
Packit 56e23f
			if (sys_b == __NR_SCMP_ERROR) {
Packit 56e23f
				rc = __NR_SCMP_ERROR;
Packit 56e23f
				goto add_return;
Packit 56e23f
			}
Packit 56e23f
		}
Packit 56e23f
Packit 56e23f
		/* use rule_a for the multiplexed syscall and use rule_b for
Packit 56e23f
		 * the direct wired syscall */
Packit 56e23f
Packit 56e23f
		if (sys_a == __NR_SCMP_UNDEF) {
Packit 56e23f
			rule_a = NULL;
Packit 56e23f
			rule_b = rule;
Packit 56e23f
		} else if (sys_b == __NR_SCMP_UNDEF) {
Packit 56e23f
			rule_a = rule;
Packit 56e23f
			rule_b = NULL;
Packit 56e23f
		} else {
Packit 56e23f
			/* need two rules, dup the first and link together */
Packit 56e23f
			rule_a = rule;
Packit 56e23f
			rule_dup = db_rule_dup(rule_a);
Packit 56e23f
			rule_b = rule_dup;
Packit 56e23f
			if (rule_b == NULL)
Packit 56e23f
				goto add_return;
Packit 56e23f
			rule_b->prev = rule_a;
Packit 56e23f
			rule_b->next = NULL;
Packit 56e23f
			rule_a->next = rule_b;
Packit 56e23f
		}
Packit 56e23f
Packit 56e23f
		/* multiplexed socket syscalls */
Packit 56e23f
		if (rule_a != NULL) {
Packit 56e23f
			rule_a->syscall = __s390_NR_ipc;
Packit 56e23f
			rule_a->args[0].arg = 0;
Packit 56e23f
			rule_a->args[0].op = SCMP_CMP_EQ;
Packit 56e23f
			rule_a->args[0].mask = DATUM_MAX;
Packit 56e23f
			rule_a->args[0].datum = (-sys_a) % 200;
Packit 56e23f
			rule_a->args[0].valid = 1;
Packit 56e23f
		}
Packit 56e23f
Packit 56e23f
		/* direct wired socket syscalls */
Packit 56e23f
		if (rule_b != NULL)
Packit 56e23f
			rule_b->syscall = sys_b;
Packit 56e23f
Packit 56e23f
		/* we should be protected by a transaction checkpoint */
Packit 56e23f
		if (rule_a != NULL) {
Packit 56e23f
			rc = db_rule_add(db, rule_a);
Packit 56e23f
			if (rc < 0)
Packit 56e23f
				goto add_return;
Packit 56e23f
		}
Packit 56e23f
		if (rule_b != NULL) {
Packit 56e23f
			rc = db_rule_add(db, rule_b);
Packit 56e23f
			if (rc < 0)
Packit 56e23f
				goto add_return;
Packit 56e23f
		}
Packit 56e23f
	} else if (sys >= 0) {
Packit 56e23f
		/* normal syscall processing */
Packit 56e23f
		rc = db_rule_add(db, rule);
Packit 56e23f
		if (rc < 0)
Packit 56e23f
			goto add_return;
Packit 56e23f
	} else if (rule->strict) {
Packit 56e23f
		rc = -EDOM;
Packit 56e23f
		goto add_return;
Packit 56e23f
	}
Packit 56e23f
Packit 56e23f
add_return:
Packit 56e23f
	if (rule_dup != NULL)
Packit 56e23f
		free(rule_dup);
Packit 56e23f
	return rc;
Packit 56e23f
}
Packit Service 10c312
Packit Service 10c312
const struct arch_def arch_def_s390 = {
Packit Service 10c312
	.token = SCMP_ARCH_S390,
Packit Service 10c312
	.token_bpf = AUDIT_ARCH_S390,
Packit Service 10c312
	.size = ARCH_SIZE_32,
Packit Service 10c312
	.endian = ARCH_ENDIAN_BIG,
Packit Service 10c312
	.syscall_resolve_name = s390_syscall_resolve_name_munge,
Packit Service 10c312
	.syscall_resolve_num = s390_syscall_resolve_num_munge,
Packit Service 10c312
	.syscall_rewrite = s390_syscall_rewrite,
Packit Service 10c312
	.rule_add = s390_rule_add,
Packit Service 10c312
};