• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
4  * Copyright (c) 2020 Yang Xu <xuyang2018.jy@cn.fujitsu.com>
5  * Author: Sowmya Adiga <sowmya.adiga@wipro.com>
6  *
7  * This is a error test for the socketcall(2) system call.
8  */
9 
10 #include <unistd.h>
11 #include <errno.h>
12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #include <linux/net.h>
15 #include <sys/un.h>
16 #include <netinet/in.h>
17 
18 #include "tst_test.h"
19 #include "lapi/syscalls.h"
20 
21 static unsigned long args_valid[3] = {PF_INET, SOCK_STREAM, 0};
22 
23 struct test_case_t {
24 	int call;
25 	unsigned long *args;
26 	int exp_err;
27 	char *desc;
28 } TC[] = {
29 	{0, args_valid, EINVAL, "invalid call(<1)"},
30 	{21, args_valid, EINVAL, "invalid call(>20)"},
31 	{SYS_SOCKET, NULL, EFAULT, "invalid args address"},
32 };
33 
verify_socketcall(unsigned int i)34 static void verify_socketcall(unsigned int i)
35 {
36 	tst_res(TINFO, "%s", TC[i].desc);
37 
38 	TEST(tst_syscall(__NR_socketcall, TC[i].call, TC[i].args));
39 	if (TST_RET != -1) {
40 		tst_res(TFAIL, "socketcall() succeeded unexpectedly");
41 		return;
42 	}
43 	if (TST_ERR == TC[i].exp_err)
44 		tst_res(TPASS | TTERRNO, "socketcall() failed as expected ");
45 	else
46 		tst_res(TFAIL | TTERRNO, "socketcall fail expected %s got", tst_strerrno(TC[i].exp_err));
47 }
48 
setup(void)49 static void setup(void)
50 {
51 	unsigned int i;
52 
53 	for (i = 0; i < ARRAY_SIZE(TC); i++) {
54 		if (!TC[i].args)
55 			TC[i].args = tst_get_bad_addr(NULL);
56 	}
57 }
58 
59 static struct tst_test test = {
60 	.setup = setup,
61 	.test = verify_socketcall,
62 	.tcnt = ARRAY_SIZE(TC),
63 };
64 
65