Add tst_get_hugepage_size() to LTP library
PATCH v2 1/2 Add tst_get_hugepage_size() to LTP library
---
No changes since v1.
include/tst_hugepage.h | 5 +++++ lib/tst_hugepage.c | 9 +++++++++ 2 files changed, 14 insertions(+)
include/tst_hugepage.h +5 -0
@@ -12,6 +12,11 @@extern char *nr_opt;/* -s num Set the number of the been allocated hugepages */ extern char *Hopt;/* -H /.. Location of hugetlbfs, i.e. -H /var/hugetlbfs */ +/* +* Get the default hugepage size. Returns 0 if hugepages are not supported. +*/ +size_t tst_get_hugepage_size (void ); +/* * Try the best to request a specified number of huge pages from system, * it will store the reserved hpage number in tst_hugepages.
lib/tst_hugepage.c +9 -0
@@ -12,6 +12,15 @@ unsigned long tst_hugepages;char *nr_opt;char *Hopt; +size_t tst_get_hugepage_size (void ) +{ +if (access (PATH_HUGEPAGES ,F_OK )) { +return 0 ; + } + +return SAFE_READ_MEMINFO ("Hugepagesize:" ) *1024 ; +} +unsigned long tst_request_hugepages (unsigned long hpages) {unsigned long val, max_hpages;
Signature · 1 line
2.26.2
PATCH v2 2/2 Add test for CVE 2017-1000405
Fixes #316
---
Changes since v1:
- include lapi/mmap.h
- TCONF if madvise(MADV_HUGEPAGE) fails with EINVAL
runtest/cve | 1 + runtest/mm | 1 + testcases/kernel/mem/.gitignore | 1 + testcases/kernel/mem/thp/Makefile | 1 + testcases/kernel/mem/thp/thp04.c | 160 ++++++++++++++++++++++++++++++ 5 files changed, 164 insertions(+) create mode 100644 testcases/kernel/mem/thp/thp04.c
runtest/cve +1 -0
@@ -43,6 +43,7 @@ cve-2017-18075 pcrypt_aead01 cve-2017-1000111 setsockopt07 cve-2017-1000112 setsockopt05 cve-2017-1000380 snd_timer01 +cve-2017-1000405 thp04 cve-2018-5803 sctp_big_chunk cve-2018-7566 snd_seq01 cve-2018-8897 ptrace09
runtest/mm +1 -0
@@ -86,6 +86,7 @@ swapping01 swapping01 -i 5 thp01 thp01 -I 120 thp02 thp02 thp03 thp03 +thp04 thp04 vma01 vma01 vma02 vma02
testcases/kernel/mem/.gitignore +1 -0
@@ -65,6 +65,7 @@ /thp/thp01 /thp/thp02 /thp/thp03 +/thp/thp04 /tunable/max_map_count /tunable/min_free_kbytes /tunable/overcommit_memory
testcases/kernel/mem/thp/Makefile +1 -0
@@ -18,6 +18,7 @@ # top_srcdir ?= ../../../.. +thp04: LDLIBS += -lrt include $(top_srcdir)/include/mk/testcases.mk include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk
testcases/kernel/mem/thp/thp04.c new file +160 -0
160 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v2 2/2 Add test for CVE 2017-1000405
Martin Doucha <[email protected]> wrote:
...
testcases/kernel/mem/thp/thp04.c line 39
Quoted 11 lines
testcases/kernel/mem/thp/thp04.c new file +6
-0+static void *alloc_zero_page (void *baseaddr) +{ +int i; +void *ret; + +/* Find aligned chunk of address space. MAP_HUGETLB doesn't work. */
testcases/kernel/mem/thp/thp04.c new file +3
-0+for (i =0 ; i <16 ; i++, baseaddr += thp_size) { + ret =mmap (baseaddr, thp_size,PROT_READ , +MAP_PRIVATE |MAP_ANONYMOUS ,-1 ,0 );
I'm wondering why here request the READ ONLY memory, shouldn't we write something into the write_thp loopingly then?
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20200702/373aa7d0/attachment.htm>
PATCH v2 2/2 Add test for CVE 2017-1000405
Quoted 16 lines · Li Wang
Martin Doucha <[email protected] <mailto:[email protected]>> wrote:
... +static void *alloc_zero_page(void *baseaddr) +{ +? ? ? ?int i; +? ? ? ?void *ret; + +? ? ? ?/* Find aligned chunk of address space. MAP_HUGETLB doesn't work. */ +? ? ? ?for (i = 0; i < 16; i++, baseaddr += thp_size) { +? ? ? ? ? ? ? ?ret = mmap(baseaddr, thp_size, PROT_READ, +? ? ? ? ? ? ? ? ? ? ? ?MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
Quoted 2 lines
I'm wondering why here request the READ ONLY memory, shouldn't we write something into the
write_thploopingly then?
We do write into it. Except we do it through /proc/self/mem file descriptor. I didn't try with PROT_WRITE but presume that mapping the memory as read-only is important for confusing the kernel into thinking that the address space doesn't need to be copied on write.
Nevertheless, I've tested the reproducer on a vulnerable kernel and it works reliably.
Signature · 7 lines
Martin Doucha [email protected] QA Engineer for Software Maintenance SUSE LINUX, s.r.o. CORSO IIa Krizikova 148/34 186 00 Prague 8 Czech Republic
PATCH v2 2/2 Add test for CVE 2017-1000405
Quoted 20 lines · Martin Doucha
Quoted 16 lines · Li Wang
Martin Doucha <[email protected] <mailto:[email protected]>> wrote:
...
+static void *alloc_zero_page(void *baseaddr)
+{
+ int i;
+ void *ret;
+
+ /* Find aligned chunk of address space.MAP_HUGETLBdoesn't
work. */
+ for (i = 0; i < 16; i++, baseaddr +=thp_size) {
+ ret = mmap(baseaddr,thp_size,PROT_READ,
+MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);Quoted 2 lines
I'm wondering why here request the READ ONLY memory, shouldn't we write something into the
write_thploopingly then?
Quoted 8 lines
We do write into it. Except we do it through
/proc/self/memfile descriptor. I didn't try withPROT_WRITEbut presume that mapping the memory as read-only is important for confusing the kernel into thinking that the address space doesn't need to be copied on write.Nevertheless, I've tested the reproducer on a vulnerable kernel and it works reliably.
Thanks for the explanation, I helped merge the patchset v3.
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20200703/a1f14e85/attachment-0001.htm>
PATCH v2 1/2 Add tst_get_hugepage_size() to LTP library
In reply to Martin DouchaQuoted 2 lines · Martin Doucha
Signed-off-by Martin Doucha <[email protected]>
Quoted 32 lines
---
No changes since v1.
include/tst_hugepage.h | 5 +++++ lib/tst_hugepage.c | 9 +++++++++ 2 files changed, 14 insertions(+)include/tst_hugepage.h +0
-0@@ -12,6 +12,11 @@extern char *nr_opt;/* -s num Set the number of the been allocated hugepages */
extern char *Hopt; /* -H /.. Location of hugetlbfs, i.e. -H/var/hugetlbfs*/+/*
+ * Get the default hugepage size. Returns 0 if hugepages are not supported.
+ */include/tst_hugepage.h +2
-0+size_t tst_get_hugepage_size (void ); +/* * Try the best to request a specified number of huge pages from system, * it will store the reserved hpage number in tst_hugepages. lib/tst_hugepage.c +0
-0
lib/tst_hugepage.c unsigned long tst_hugepages; · line 18
Quoted 7 lines
lib/tst_hugepage.c +3
-0@@ -12,6 +12,15 @@ unsigned long tst_hugepages;char *nr_opt;char *Hopt; +size_t tst_get_hugepage_size (void ) +{ +if (access (PATH_HUGEPAGES ,F_OK )) {
The braces here is redundant. Someone who merging the patch can help clean this.
Quoted 17 lines
lib/tst_hugepage.c +6
-0+return 0 ; + } + +return SAFE_READ_MEMINFO ("Hugepagesize:" ) *1024 ; +} +unsigned long tst_request_hugepages (unsigned long hpages) {unsigned long val, max_hpages;--
2.26.2--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Regards, Li Wang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.linux.it/pipermail/ltp/attachments/20200702/c2b85b7a/attachment.htm>