Skip to content

Commit 2592591

Browse files
xuyang0410metan-ucw
authored andcommitted
syscalls/mlock03: Convert into new api
This case is a regression test on old RHEL5.6. You can see the following url: https://bugzilla.redhat.com/show_bug.cgi?id=643426 Still keep this case is meaningful because we can test whether kernel has bug on stack guard page reporting through /proc/self/maps in the future. Also remove tst_require_root. Test mlock/munlock instead of mlock by default. Signed-off-by: Yang Xu <[email protected]> Reviewed-by: Cyril Hrubis <[email protected]>
1 parent 810c631 commit 2592591

File tree

1 file changed

+47
-84
lines changed

1 file changed

+47
-84
lines changed
Lines changed: 47 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
// SPDX-License-Identifier: GPL-2.0
12
/*
3+
* Copyright (C) 2010 Red Hat, Inc.
4+
*/
5+
6+
/*\
7+
* [Description]
8+
*
9+
* This case is a regression test on old RHEL5.
10+
*
211
* Stack size mapping is decreased through mlock/munlock call.
12+
* See the following url:
13+
* https://bugzilla.redhat.com/show_bug.cgi?id=643426
314
*
415
* This is to test kernel if it has a problem with shortening [stack]
516
* mapping through several loops of mlock/munlock of /proc/self/maps.
@@ -11,109 +22,61 @@
1122
* munlock 44KiB bfefa000-bff05000 rw-p 00000000 00:00 0 [stack]
1223
*
1324
* with more iterations - could drop to 0KiB.
14-
*
15-
* Copyright (C) 2010 Red Hat, Inc.
16-
* This program is free software; you can redistribute it and/or
17-
* modify it under the terms of version 2 of the GNU General Public
18-
* License as published by the Free Software Foundation.
19-
*
20-
* This program is distributed in the hope that it would be useful,
21-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
22-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23-
*
24-
* Further, this software is distributed without any warranty that it
25-
* is free of the rightful claim of any third person regarding
26-
* infringement or the like. Any license provided herein, whether
27-
* implied or otherwise, applies only to this software file. Patent
28-
* licenses, if any, provided herein do not apply to combinations of
29-
* this program with other software, or any other product whatsoever.
30-
*
31-
* You should have received a copy of the GNU General Public License
32-
* along with this program; if not, write the Free Software
33-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
34-
* 02110-1301, USA.
3525
*/
26+
3627
#include <sys/mman.h>
3728
#include <stdio.h>
3829
#include <string.h>
39-
#include "test.h"
30+
#include <pwd.h>
31+
#include "tst_test.h"
32+
#include "tst_safe_stdio.h"
4033

4134
#define KB 1024
4235

43-
char *TCID = "mlock03";
44-
int TST_TOTAL = 1;
45-
46-
static void setup(void);
47-
static void cleanup(void);
48-
49-
int main(int argc, char *argv[])
36+
static void verify_mlock(void)
5037
{
51-
int lc;
5238
long from, to;
5339
long first = -1, last = -1;
5440
char b[KB];
5541
FILE *fp;
5642

57-
tst_parse_opts(argc, argv, NULL, NULL);
58-
59-
setup();
43+
fp = SAFE_FOPEN("/proc/self/maps", "r");
44+
while (!feof(fp)) {
45+
if (!fgets(b, KB - 1, fp))
46+
break;
47+
b[strlen(b) - 1] = '\0';
48+
if (sscanf(b, "%lx-%lx", &from, &to) != 2) {
49+
tst_brk(TBROK, "parse %s start and end address failed",
50+
b);
51+
continue;
52+
}
6053

61-
for (lc = 0; TEST_LOOPING(lc); lc++) {
62-
fp = fopen("/proc/self/maps", "r");
63-
if (fp == NULL)
64-
tst_brkm(TBROK | TERRNO, cleanup, "fopen");
65-
while (!feof(fp)) {
66-
if (!fgets(b, KB - 1, fp))
67-
break;
68-
b[strlen(b) - 1] = '\0';
69-
sscanf(b, "%lx-%lx", &from, &to);
54+
/* Record the initial stack size. */
55+
if (strstr(b, "[stack]") != NULL)
56+
first = (to - from) / KB;
7057

71-
/* Record the initial stack size. */
72-
if (lc == 0 && strstr(b, "[stack]") != NULL)
73-
first = (to - from) / KB;
58+
tst_res(TINFO, "mlock [%lx,%lx]", from, to);
59+
if (mlock((const void *)from, to - from) == -1)
60+
tst_res(TINFO | TERRNO, "mlock failed");
7461

75-
switch (lc & 1) {
76-
case 0:
77-
if (mlock((const void *)from, to - from) == -1)
78-
tst_resm(TINFO | TERRNO,
79-
"mlock failed");
80-
break;
81-
case 1:
82-
if (munlock((void *)from, to - from) == -1)
83-
tst_resm(TINFO | TERRNO,
84-
"munlock failed");
85-
break;
86-
default:
87-
break;
88-
}
89-
tst_resm(TINFO, "%s from %lx to %0lx",
90-
(lc & 1) ? "munlock" : "mlock", from, to);
62+
tst_res(TINFO, "munlock [%lx,%lx]", from, to);
63+
if (munlock((void *)from, to - from) == -1)
64+
tst_res(TINFO | TERRNO, "munlock failed");
9165

92-
/* Record the final stack size. */
93-
if (strstr(b, "[stack]") != NULL)
94-
last = (to - from) / KB;
95-
}
96-
fclose(fp);
66+
/* Record the final stack size. */
67+
if (strstr(b, "[stack]") != NULL)
68+
last = (to - from) / KB;
9769
}
98-
tst_resm(TINFO, "starting stack size is %ld", first);
99-
tst_resm(TINFO, "final stack size is %ld", last);
70+
SAFE_FCLOSE(fp);
71+
72+
tst_res(TINFO, "starting stack size is %ld", first);
73+
tst_res(TINFO, "final stack size is %ld", last);
10074
if (last < first)
101-
tst_resm(TFAIL, "stack size is decreased.");
75+
tst_res(TFAIL, "stack size is decreased.");
10276
else
103-
tst_resm(TPASS, "stack size is not decreased.");
104-
105-
cleanup();
106-
tst_exit();
77+
tst_res(TPASS, "stack size is not decreased.");
10778
}
10879

109-
void setup(void)
110-
{
111-
tst_require_root();
112-
113-
tst_sig(FORK, DEF_HANDLER, cleanup);
114-
TEST_PAUSE;
115-
}
116-
117-
void cleanup(void)
118-
{
119-
}
80+
static struct tst_test test = {
81+
.test_all = verify_mlock,
82+
};

0 commit comments

Comments
 (0)