1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (C) 2021 SUSE LLC <[email protected]>
4*49cdfc7eSAndroid Build Coastguard Worker */
5*49cdfc7eSAndroid Build Coastguard Worker
6*49cdfc7eSAndroid Build Coastguard Worker /*\
7*49cdfc7eSAndroid Build Coastguard Worker * [Description]
8*49cdfc7eSAndroid Build Coastguard Worker *
9*49cdfc7eSAndroid Build Coastguard Worker * Reproducer of CVE-2018-10124; INT_MIN negation.
10*49cdfc7eSAndroid Build Coastguard Worker *
11*49cdfc7eSAndroid Build Coastguard Worker * On most two's complement CPUs negation of INT_MIN will result in
12*49cdfc7eSAndroid Build Coastguard Worker * INT_MIN because ~((unsigned)INT_MIN) + 1 overflows to INT_MIN
13*49cdfc7eSAndroid Build Coastguard Worker * (unless trapped). On one's complement ~((unsigned)INT_MIN) = INT_MAX.
14*49cdfc7eSAndroid Build Coastguard Worker *
15*49cdfc7eSAndroid Build Coastguard Worker * Without UBSAN kill will always return ESRCH. Regardless of if the
16*49cdfc7eSAndroid Build Coastguard Worker * bug is present as INT_MIN/INT_MAX are invalid PIDs. It checks the
17*49cdfc7eSAndroid Build Coastguard Worker * PID before the signal number so we can not cause EINVAL. A trivial
18*49cdfc7eSAndroid Build Coastguard Worker * test of kill is performed elsewhere. So we don't run the test
19*49cdfc7eSAndroid Build Coastguard Worker * without UBSAN to avoid giving the impression we have actually
20*49cdfc7eSAndroid Build Coastguard Worker * tested for the bug.
21*49cdfc7eSAndroid Build Coastguard Worker */
22*49cdfc7eSAndroid Build Coastguard Worker
23*49cdfc7eSAndroid Build Coastguard Worker #include <limits.h>
24*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
25*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
26*49cdfc7eSAndroid Build Coastguard Worker
run(void)27*49cdfc7eSAndroid Build Coastguard Worker static void run(void)
28*49cdfc7eSAndroid Build Coastguard Worker {
29*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_FAIL2(kill(INT_MIN, 0), ESRCH,
30*49cdfc7eSAndroid Build Coastguard Worker "kill(INT_MIN, ...) fails with ESRCH");
31*49cdfc7eSAndroid Build Coastguard Worker }
32*49cdfc7eSAndroid Build Coastguard Worker
33*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
34*49cdfc7eSAndroid Build Coastguard Worker .test_all = run,
35*49cdfc7eSAndroid Build Coastguard Worker .taint_check = TST_TAINT_W | TST_TAINT_D,
36*49cdfc7eSAndroid Build Coastguard Worker .needs_kconfigs = (const char *[]) {
37*49cdfc7eSAndroid Build Coastguard Worker "CONFIG_UBSAN_SIGNED_OVERFLOW",
38*49cdfc7eSAndroid Build Coastguard Worker NULL
39*49cdfc7eSAndroid Build Coastguard Worker },
40*49cdfc7eSAndroid Build Coastguard Worker .tags = (const struct tst_tag[]) {
41*49cdfc7eSAndroid Build Coastguard Worker {"linux-git", "4ea77014af0d"},
42*49cdfc7eSAndroid Build Coastguard Worker {"CVE", "CVE-2018-10124"},
43*49cdfc7eSAndroid Build Coastguard Worker {}
44*49cdfc7eSAndroid Build Coastguard Worker }
45*49cdfc7eSAndroid Build Coastguard Worker };
46