Skip to contentSkip to conversation

syscalls/fork: add new case fork14

PATCH Superseded Madper Xie 2 participants 2 messages Jan 27, 2014 – Jan 28, 2014

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Madper Xie

author
#0 lore raw

PATCH v2 1/1 syscalls/fork: add new case fork14

This testcase is a reproducer for https://lkml.org/lkml/2012/4/24/328.
Modified from Siddhesh Poyarekar's testcase posted on above link. Since vma length in dup_mmap is calculated and stored in a unsigned int, which is insufficient and hence overflows for very large maps (beyond 16TB). Once overflow occurred, the fork after mmaped memory > 16TB will succeed incorrectly.

This case will run following loop:
+ mmap one (more) GB memory
+ fork and check return value.
When mmaped more than 16 * 1024 GB, it will check if fork still fail. Expected result: Fork failed even if mmaped memory > 16 * 1024 GB

The issue has been fixed by:
commit 7edc8b0ac16cbaed7cb4ea4c6b95ce98d2997e84
Author: Siddhesh Poyarekar <[email protected]>
mm/fork: fix overflow in vma length when copying mmap on clone

---
 runtest/syscalls                        |   1 +
 testcases/kernel/syscalls/fork/fork14.c | 118 ++++++++++++++++++++++++++++++++
 2 files changed, 119 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fork/fork14.c
runtest/syscalls +1 -0
index afa7976..4cf90e8 100644
@@ -277,6 +277,7 @@ fork09 fork09
 fork10 fork10
 fork11 fork11
 fork13 fork13 -i 1000000
+fork14 fork14
 
 fpathconf01 fpathconf01
 
testcases/kernel/syscalls/fork/fork14.c new file +118 -0

118 lines not on this page · raw message

Signature · 13 lines
1.8.5.3


------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
#1 lore raw

Hi!

Quoted 35 lines
testcases/kernel/syscalls/fork/fork14.c new file +35 -0
+int main(int ac, char **av)
+{
+	int lc, ret;
+	char *msg;
+
+	msg = parse_opts(ac, av, NULL, NULL);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+/*
+ * Tested on ppc64/x86_64/i386/s390x. And only 64bit has this issue.
+ * Since a 32bit program can't mmap so many memory.
+ */
+#if __WORDSIZE == 32
+	tst_brkm(TCONF, NULL, "This test is only for 64bit.");
+#endif
+	setup();
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		tst_count = 0;
+
+		ret = fork_test();
+		if (ret == 0)
+			tst_resm(TPASS, "fork failed as expected.");
+	}
+	cleanup();
+	tst_exit();
+}
+
+static void setup(void)
+{
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+	TEST_PAUSE;
+}
+
+static void cleanup(void)
+{

testcases/kernel/syscalls/fork/fork14.c line 96

Quoted 10 lines
testcases/kernel/syscalls/fork/fork14.c new file +10 -0
+	TEST_CLEANUP;
+}
+
+static int fork_test(void)
+{
+	int i, ret = 0;
+	void *addr;
+
+	for (i = 0; i < EXTENT; i++) {
+		addr = mmap(NULL, (size_t) 1 * GB, PROT_READ | PROT_WRITE,

^
Why do you multiply the size by 1 casted to (size_t) that does not make much sense.

testcases/kernel/syscalls/fork/fork14.c line 99

Quoted 3 lines
testcases/kernel/syscalls/fork/fork14.c new file +3 -0
+			MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+		if (addr == MAP_FAILED)
+			tst_brkm(TBROK|TERRNO, cleanup, "mmap");

I wonder if this should be really TBROK. This could easily fail with ENOMEM if you turn off memory overcommit and you machine does not have enough RAM.

Quoted 19 lines
testcases/kernel/syscalls/fork/fork14.c new file +19 -0
+		switch (fork()) {
+		case -1:
+			break;
+		case 0:
+			exit(0);
+		default:
+			if (waitpid(-1, NULL, 0) == -1)
+				tst_brkm(TBROK|TERRNO,
+					cleanup, "waitpid");
+
+			if (i >= LARGE) {
+				tst_brkm(TFAIL, NULL,
+					"Fork succeeds incorrectly");
+				ret++;
+			}
+		}
+	}
+	return ret;
+}
Signature · 13 lines
Cyril Hrubis
[email protected]

------------------------------------------------------------------------------
WatchGuard Dimension instantly turns raw network data into actionable 
security intelligence. It gives you real-time visual feedback on key
security issues and trends.  Skip the complicated setup - simply import
a virtual appliance and go from zero to informed in seconds.
http://pubads.g.doubleclick.net/gampad/clk?id=123612991&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list