• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *  Copyright (c) Linux Test Project, 2020
4  *  Copyright (c) Wipro Technologies Ltd, 2002
5  */
6 
7 /*
8  * This is a basic test for iopl(2) system call.
9  *
10  * Test the system call for possible privelege levels.
11  * As the privelge level for a normal process is 0, start by
12  * setting/changing the level to 0.
13  *
14  * Author: Subhab Biswas <subhabrata.biswas@wipro.com>
15  */
16 
17 #include <errno.h>
18 #include <unistd.h>
19 
20 #include "tst_test.h"
21 
22 #if defined __i386__ || defined(__x86_64__)
23 #include <sys/io.h>
24 
verify_iopl(void)25 static void verify_iopl(void)
26 {
27 	int total_level = 4;
28 	int level;
29 
30 	for (level = 0; level < total_level; ++level) {
31 
32 		TEST(iopl(level));
33 
34 		if (TST_RET == -1) {
35 			tst_res(TFAIL | TTERRNO, "iopl() failed for level %d, "
36 					"errno=%d : %s", level,
37 					TST_ERR, tst_strerrno(TST_ERR));
38 		} else {
39 			tst_res(TPASS, "iopl() passed for level %d, "
40 					"returned %ld", level, TST_RET);
41 		}
42 	}
43 }
44 
cleanup(void)45 static void cleanup(void)
46 {
47 	/*
48 	 * back to I/O privilege for normal process.
49 	 */
50 	if (iopl(0) == -1)
51 		tst_res(TWARN, "iopl() cleanup failed");
52 }
53 
54 static struct tst_test test = {
55 	.test_all = verify_iopl,
56 	.needs_root = 1,
57 	/* iopl() is restricted under kernel lockdown. */
58 	.skip_in_lockdown = 1,
59 	.cleanup = cleanup,
60 };
61 
62 #else
63 TST_TEST_TCONF("LSB v1.3 does not specify iopl() for this architecture. (only for i386 or x86_64)");
64 #endif /* __i386_, __x86_64__*/
65