• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
4  * Author: Xie Ziyao <xieziyao@huawei.com>
5  */
6 
7 /*\
8  * [Description]
9  *
10  * Verify that, epoll_pwait() and epoll_pwait2() return -1 and set errno to
11  * EFAULT with a sigmask points outside user's accessible address space.
12  */
13 
14 #include <sys/epoll.h>
15 
16 #include "tst_test.h"
17 #include "epoll_pwait_var.h"
18 
19 static int efd, sfd[2];
20 static struct epoll_event e;
21 static void *bad_addr;
22 
run(void)23 static void run(void)
24 {
25 	TST_EXP_FAIL(do_epoll_pwait(efd, &e, 1, -1, bad_addr),
26 		     EFAULT, "with an invalid sigmask pointer");
27 }
28 
setup(void)29 static void setup(void)
30 {
31 	epoll_pwait_info();
32 
33 	SAFE_SOCKETPAIR(AF_UNIX, SOCK_STREAM, 0, sfd);
34 
35 	efd = epoll_create(1);
36 	if (efd == -1)
37 		tst_brk(TBROK | TERRNO, "epoll_create()");
38 
39 	e.events = EPOLLIN;
40 	if (epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], &e))
41 		tst_brk(TBROK | TERRNO, "epoll_clt(..., EPOLL_CTL_ADD, ...)");
42 	SAFE_WRITE(SAFE_WRITE_ALL, sfd[1], "w", 1);
43 
44 	bad_addr = tst_get_bad_addr(NULL);
45 }
46 
cleanup(void)47 static void cleanup(void)
48 {
49 	if (efd > 0)
50 		SAFE_CLOSE(efd);
51 
52 	if (sfd[0] > 0)
53 		SAFE_CLOSE(sfd[0]);
54 
55 	if (sfd[1] > 0)
56 		SAFE_CLOSE(sfd[1]);
57 }
58 
59 static struct tst_test test = {
60 	.test_all = run,
61 	.setup = setup,
62 	.cleanup = cleanup,
63 	.test_variants = TEST_VARIANTS,
64 };
65