public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v2] mprotect: Add mprotect05 testcase
@ 2023-03-01 19:33 Liam R. Howlett
  2023-03-02 14:19 ` Petr Vorel
  0 siblings, 1 reply; 4+ messages in thread
From: Liam R. Howlett @ 2023-03-01 19:33 UTC (permalink / raw)
  To: ltp; +Cc: Liam R. Howlett

Add a test that uses mprotect to split and combine VMAs.  Created to
ensure the correctness of the VMA iterator after a bug report.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=217061
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
---
 .../kernel/syscalls/mprotect/mprotect05.c     | 69 +++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100644 testcases/kernel/syscalls/mprotect/mprotect05.c

diff --git a/testcases/kernel/syscalls/mprotect/mprotect05.c b/testcases/kernel/syscalls/mprotect/mprotect05.c
new file mode 100644
index 000000000..974e026ae
--- /dev/null
+++ b/testcases/kernel/syscalls/mprotect/mprotect05.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2023 Oracle and/or its affiliates. All Rights Reserved.
+ * Author: Liam R. Howlett <liam.howlett@oracle.com>
+ */
+
+/*\
+ * [Description]
+ *
+ *	Testcase to check the mprotect(2) system call split and merge
+ *
+ * Reference links:
+ *  - https://bugzilla.kernel.org/show_bug.cgi?id=217061
+ *
+ */
+
+#include <errno.h>
+#include <stdio.h>
+
+#include "tst_test.h"
+
+#define TEST_FILE "mprotect05-testfile"
+
+static int fd;
+static char *addr = MAP_FAILED;
+static unsigned long pagesize;
+static unsigned long fullsize;
+
+static void setup(void)
+{
+	pagesize = getpagesize();
+	fullsize = 5 * pagesize;
+}
+
+static void run(void)
+{
+	fd = SAFE_OPEN(TEST_FILE, O_RDWR | O_CREAT, 0777);
+	addr = SAFE_MMAP(0, fullsize, PROT_READ, MAP_SHARED, fd, 0);
+
+	if (mprotect(addr + pagesize, pagesize, PROT_EXEC))
+		tst_res(TFAIL | TERRNO, "mprotect failed to exec");
+
+	if (mprotect(addr + 3 * pagesize, pagesize, PROT_WRITE))
+		tst_res(TFAIL | TERRNO, "mprotect failed to write");
+
+	if (mprotect(addr + pagesize, pagesize * 4, PROT_READ))
+		tst_res(TFAIL | TERRNO, "mprotect failed to read");
+
+	SAFE_MUNMAP(addr, fullsize);
+	SAFE_CLOSE(fd);
+	addr = MAP_FAILED;
+	SAFE_UNLINK(TEST_FILE);
+	tst_res(TPASS, "test successfull");
+}
+
+static void cleanup(void)
+{
+	if (addr != MAP_FAILED) {
+		SAFE_MUNMAP(addr, fullsize);
+		SAFE_CLOSE(fd);
+	}
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir  = 1,
+};
-- 
2.39.2


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH v2] mprotect: Add mprotect05 testcase
  2023-03-01 19:33 [LTP] [PATCH v2] mprotect: Add mprotect05 testcase Liam R. Howlett
@ 2023-03-02 14:19 ` Petr Vorel
  2023-03-02 20:09   ` Cyril Hrubis
  0 siblings, 1 reply; 4+ messages in thread
From: Petr Vorel @ 2023-03-02 14:19 UTC (permalink / raw)
  To: Liam R. Howlett; +Cc: ltp

Hi Liam,

> Add a test that uses mprotect to split and combine VMAs.  Created to
> ensure the correctness of the VMA iterator after a bug report.

LGTM, thank you.

Reviewed-by: Petr Vorel <pvorel@suse.cz>

...
> +/*\
> + * [Description]
> + *
> + *	Testcase to check the mprotect(2) system call split and merge
> + *
> + * Reference links:
> + *  - https://bugzilla.kernel.org/show_bug.cgi?id=217061
This would be formatted as inline in our docs.
> + *
> + */
> +
> +#include <errno.h>
> +#include <stdio.h>
These aren't needed.

Waiting little longer for any feedback before merging with the diff below.

Kind regards,
Petr

+++ testcases/kernel/syscalls/mprotect/mprotect05.c
@@ -9,14 +9,10 @@
  *
  *	Testcase to check the mprotect(2) system call split and merge
  *
- * Reference links:
- *  - https://bugzilla.kernel.org/show_bug.cgi?id=217061
+ * https://bugzilla.kernel.org/show_bug.cgi?id=217061
  *
  */
 
-#include <errno.h>
-#include <stdio.h>
-
 #include "tst_test.h"
 
 #define TEST_FILE "mprotect05-testfile"

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH v2] mprotect: Add mprotect05 testcase
  2023-03-02 14:19 ` Petr Vorel
@ 2023-03-02 20:09   ` Cyril Hrubis
  2023-03-03  7:46     ` Petr Vorel
  0 siblings, 1 reply; 4+ messages in thread
From: Cyril Hrubis @ 2023-03-02 20:09 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp, Liam R. Howlett

Hi!
> > Add a test that uses mprotect to split and combine VMAs.  Created to
> > ensure the correctness of the VMA iterator after a bug report.
> 
> LGTM, thank you.
> 
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
> 
> ...
> > +/*\
> > + * [Description]
> > + *
> > + *	Testcase to check the mprotect(2) system call split and merge
> > + *
> > + * Reference links:
> > + *  - https://bugzilla.kernel.org/show_bug.cgi?id=217061
> This would be formatted as inline in our docs.
> > + *
> > + */
> > +
> > +#include <errno.h>
> > +#include <stdio.h>
> These aren't needed.
> 
> Waiting little longer for any feedback before merging with the diff below.

Can we also add a git tag to the test? It looks like fix is in mainline
in:

commit 2fcd07b7ccd5fd10b2120d298363e4e6c53ccf9c
Author: Liam R. Howlett <Liam.Howlett@oracle.com>
Date:   Fri Feb 24 16:20:55 2023 -0500

    mm/mprotect: Fix successful vma_merge() of next in do_mprotect_pkey()


-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH v2] mprotect: Add mprotect05 testcase
  2023-03-02 20:09   ` Cyril Hrubis
@ 2023-03-03  7:46     ` Petr Vorel
  0 siblings, 0 replies; 4+ messages in thread
From: Petr Vorel @ 2023-03-03  7:46 UTC (permalink / raw)
  To: Cyril Hrubis; +Cc: ltp, Liam R. Howlett

Hi Cyril, Liam,

> Can we also add a git tag to the test? It looks like fix is in mainline
> in:

> commit 2fcd07b7ccd5fd10b2120d298363e4e6c53ccf9c
> Author: Liam R. Howlett <Liam.Howlett@oracle.com>
> Date:   Fri Feb 24 16:20:55 2023 -0500

>     mm/mprotect: Fix successful vma_merge() of next in do_mprotect_pkey()

Good catch, thanks!
Merged with git tag + added .gitignore and runtest/syscalls entry.

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-03-03  6:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-01 19:33 [LTP] [PATCH v2] mprotect: Add mprotect05 testcase Liam R. Howlett
2023-03-02 14:19 ` Petr Vorel
2023-03-02 20:09   ` Cyril Hrubis
2023-03-03  7:46     ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox