Skip to content

Commit c12945d

Browse files
glaubitzpcmoore
authored andcommitted
arch: Add SuperH 32-bit support
Initial support for seccomp for SuperH in Linux was added in 2.6.27-rc2, support for SECCOMP_FILTER was added for Linux 5.9. This adds support for SuperH in libseccomp, both for little-endian and big-endian mode. Signed-off-by: John Paul Adrian Glaubitz <[email protected]> Acked-by: Tom Hromatka <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 83d7b02 commit c12945d

24 files changed

+183
-7
lines changed

CREDITS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Jan Willeke <[email protected]>
2929
3030
Jiannan Guo <[email protected]>
3131
Joe MacDonald <[email protected]>
32+
John Paul Adrian Glaubitz <[email protected]>
3233
Jonah Petri <[email protected]>
3334
Justin Cormack <[email protected]>
3435
Kees Cook <[email protected]>

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ The libseccomp library currently supports the architectures listed below:
5454
* 32-bit s390 (s390)
5555
* 64-bit s390x (s390x)
5656
* 64-bit RISC-V (riscv64)
57+
* 32-bit SuperH big endian (sheb)
58+
* 32-bit SuperH (sh)
5759

5860
## Documentation
5961

doc/man/man1/scmp_sys_resolver.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The architecture to use for resolving the system call. Valid
3636
.I ARCH
3737
values are "x86", "x86_64", "x32", "arm", "aarch64", "mips", "mipsel", "mips64",
3838
"mipsel64", "mips64n32", "mipsel64n32", "parisc", "parisc64", "ppc", "ppc64",
39-
"ppc64le", "s390" and "s390x".
39+
"ppc64le", "s390", "s390x", "sheb" and "sh".
4040
.TP
4141
.B \-t
4242
If necessary, translate the system call name to the proper system call number,

include/seccomp.h.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ struct scmp_arg_cmp {
216216
#endif /* AUDIT_ARCH_RISCV64 */
217217
#define SCMP_ARCH_RISCV64 AUDIT_ARCH_RISCV64
218218

219+
/**
220+
* The SuperH architecture tokens
221+
*/
222+
#define SCMP_ARCH_SHEB AUDIT_ARCH_SH
223+
#define SCMP_ARCH_SH AUDIT_ARCH_SHEL /* Little-endian SH is more common than big */
224+
219225
/**
220226
* Convert a syscall name into the associated syscall number
221227
* @param x the syscall name

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ SOURCES_ALL = \
4646
arch-riscv64.h arch-riscv64.c \
4747
arch-s390.h arch-s390.c \
4848
arch-s390x.h arch-s390x.c \
49+
arch-sh.h arch-sh.c \
4950
syscalls.h syscalls.c syscalls.perf.c
5051

5152
EXTRA_DIST = \

src/arch-sh.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* This library is free software; you can redistribute it and/or modify it
3+
* under the terms of version 2.1 of the GNU Lesser General Public License as
4+
* published by the Free Software Foundation.
5+
*
6+
* This library is distributed in the hope that it will be useful, but WITHOUT
7+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
9+
* for more details.
10+
*
11+
* You should have received a copy of the GNU Lesser General Public License
12+
* along with this library; if not, see <http://www.gnu.org/licenses>.
13+
*/
14+
15+
#include <stdlib.h>
16+
#include <errno.h>
17+
#include <linux/audit.h>
18+
19+
#include "arch.h"
20+
#include "arch-sh.h"
21+
22+
const struct arch_def arch_def_sheb = {
23+
.token = SCMP_ARCH_SHEB,
24+
.token_bpf = AUDIT_ARCH_SH,
25+
.size = ARCH_SIZE_32,
26+
.endian = ARCH_ENDIAN_BIG,
27+
.syscall_resolve_name = sh_syscall_resolve_name,
28+
.syscall_resolve_num = sh_syscall_resolve_num,
29+
.syscall_rewrite = NULL,
30+
.rule_add = NULL,
31+
};
32+
33+
const struct arch_def arch_def_sh = {
34+
.token = SCMP_ARCH_SH,
35+
.token_bpf = AUDIT_ARCH_SHEL,
36+
.size = ARCH_SIZE_32,
37+
.endian = ARCH_ENDIAN_LITTLE,
38+
.syscall_resolve_name = sh_syscall_resolve_name,
39+
.syscall_resolve_num = sh_syscall_resolve_num,
40+
.syscall_rewrite = NULL,
41+
.rule_add = NULL,
42+
};

src/arch-sh.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* This library is free software; you can redistribute it and/or modify it
3+
* under the terms of version 2.1 of the GNU Lesser General Public License as
4+
* published by the Free Software Foundation.
5+
*
6+
* This library is distributed in the hope that it will be useful, but WITHOUT
7+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
9+
* for more details.
10+
*
11+
* You should have received a copy of the GNU Lesser General Public License
12+
* along with this library; if not, see <http://www.gnu.org/licenses>.
13+
*/
14+
15+
#ifndef _ARCH_SH_H
16+
#define _ARCH_SH_H
17+
18+
#include "arch.h"
19+
20+
ARCH_DECL(sheb)
21+
ARCH_DECL(sh)
22+
23+
#endif

src/arch-syscall-check.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "arch-ppc64.h"
3939
#include "arch-s390.h"
4040
#include "arch-s390x.h"
41+
#include "arch-sh.h"
4142

4243
/**
4344
* compare the syscall values
@@ -77,6 +78,7 @@ int main(int argc, char *argv[])
7778
int i_ppc64 = 0;
7879
int i_s390 = 0;
7980
int i_s390x = 0;
81+
int i_sh = 0;
8082
char str_miss[256];
8183
const char *sys_name;
8284
const struct arch_syscall_def *sys;
@@ -115,6 +117,8 @@ int main(int argc, char *argv[])
115117
s390_syscall_iterate(i_s390));
116118
syscall_check(str_miss, sys_name, "s390x",
117119
s390x_syscall_iterate(i_s390x));
120+
syscall_check(str_miss, sys_name, "sh",
121+
sh_syscall_iterate(i_sh));
118122

119123
/* output the results */
120124
printf("%s: ", sys_name);
@@ -151,12 +155,14 @@ int main(int argc, char *argv[])
151155
i_s390 = -1;
152156
if (!s390x_syscall_iterate(++i_s390x)->name)
153157
i_s390x = -1;
158+
if (!sh_syscall_iterate(++i_sh)->name)
159+
i_sh = -1;
154160
} while (i_x86_64 >= 0 && i_x32 >= 0 &&
155161
i_arm >= 0 && i_aarch64 >= 0 &&
156162
i_mips >= 0 && i_mips64 >= 0 && i_mips64n32 >= 0 &&
157163
i_parisc >= 0 &&
158164
i_ppc >= 0 && i_ppc64 >= 0 &&
159-
i_s390 >= 0 && i_s390x >= 0);
165+
i_s390 >= 0 && i_s390x >= 0 && i_sh >= 0);
160166

161167
/* check for any leftovers */
162168
sys = x86_syscall_iterate(i_x86 + 1);
@@ -212,6 +218,10 @@ int main(int argc, char *argv[])
212218
printf("ERROR, s390x has additional syscalls\n");
213219
return 1;
214220
}
221+
if (i_sh >= 0) {
222+
printf("ERROR, sh has additional syscalls\n");
223+
return 1;
224+
}
215225

216226
/* if we made it here, all is good */
217227
return 0;

src/arch-syscall-dump.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "arch-riscv64.h"
4646
#include "arch-s390.h"
4747
#include "arch-s390x.h"
48+
#include "arch-sh.h"
4849

4950
/**
5051
* Print the usage information to stderr and exit
@@ -140,6 +141,10 @@ int main(int argc, char *argv[])
140141
case SCMP_ARCH_S390X:
141142
sys = s390x_syscall_iterate(iter);
142143
break;
144+
case SCMP_ARCH_SH:
145+
case SCMP_ARCH_SHEB:
146+
sys = sh_syscall_iterate(iter);
147+
break;
143148
default:
144149
/* invalid arch */
145150
exit_usage(argv[0]);

src/arch-syscall-validate

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,31 @@ function dump_lib_s390x() {
567567
dump_lib_arch s390x | mangle_lib_syscall s390x
568568
}
569569

570+
#
571+
# Dump the sh system syscall table
572+
#
573+
# Arguments:
574+
# 1 path to the kernel source
575+
#
576+
# Dump the architecture's syscall table to stdout.
577+
#
578+
function dump_sys_sh() {
579+
cat $1/arch/sh/kernel/syscalls/syscall.tbl | \
580+
grep -v "^#" | \
581+
sed -n "/[0-9]\+[ \t]\+\(common\)/p" | \
582+
awk '{ print $3","$1 }' | \
583+
sort
584+
}
585+
586+
#
587+
# Dump the sh library syscall table
588+
#
589+
# Dump the library's syscall table to stdout.
590+
#
591+
function dump_lib_sh() {
592+
dump_lib_arch sh | mangle_lib_syscall sh
593+
}
594+
570595
#
571596
# Dump the system syscall table
572597
#
@@ -623,6 +648,9 @@ function dump_sys() {
623648
s390x)
624649
dump_sys_s390x "$2"
625650
;;
651+
sh)
652+
dump_sys_sh "$2"
653+
;;
626654
*)
627655
echo ""
628656
return 1
@@ -687,6 +715,9 @@ function dump_lib() {
687715
s390x)
688716
dump_lib_s390x
689717
;;
718+
sh)
719+
dump_lib_sh
720+
;;
690721
*)
691722
echo ""
692723
return 1
@@ -722,6 +753,7 @@ function gen_csv() {
722753
abi_list+=" ppc ppc64"
723754
abi_list+=" riscv64"
724755
abi_list+=" s390 s390x"
756+
abi_list+=" sh"
725757

726758
# get the full syscall list
727759
for abi in $abi_list; do
@@ -809,7 +841,8 @@ if [[ $opt_arches == "" ]]; then
809841
mips mips64 mips64n32 \
810842
parisc parisc64 \
811843
ppc ppc64 \
812-
s390 s390x"
844+
s390 s390x \
845+
sh"
813846
fi
814847

815848
# sanity checks

0 commit comments

Comments
 (0)