@@ -94,3 +94,11 @@ config DEBUG_RODATA_TEST
depends on STRICT_KERNEL_RWX
---help---
This option enables a testcase for the setting rodata read-only.
+
+config DEBUG_PRMEM
+ bool "Verify each write rare operation."
+ depends on PRMEM
+ default n
+ help
+ After any write rare operation, compares the data written with the
+ value provided by the caller.
@@ -61,6 +61,9 @@ void *wr_memcpy(void *p, const void *q, __kernel_size_t size)
__wr_enable(&wr_state);
__wr_memcpy(wr_poking_addr, q, size);
__wr_disable(&wr_state);
+#ifdef CONFIG_DEBUG_PRMEM
+ VM_WARN_ONCE(memcmp(p, q, size), "Failed %s()", __func__);
+#endif
local_irq_enable();
return p;
}
@@ -92,6 +95,9 @@ void *wr_memset(void *p, int c, __kernel_size_t len)
__wr_enable(&wr_state);
__wr_memset(wr_poking_addr, c, len);
__wr_disable(&wr_state);
+#ifdef CONFIG_DEBUG_PRMEM
+ VM_WARN_ONCE(memtst(p, c, len), "Failed %s()", __func__);
+#endif
local_irq_enable();
return p;
}
After each write operation, confirm that it was successful, otherwise generate a warning. Signed-off-by: Igor Stoppa <igor.stoppa@huawei.com> CC: Andy Lutomirski <luto@amacapital.net> CC: Nadav Amit <nadav.amit@gmail.com> CC: Matthew Wilcox <willy@infradead.org> CC: Peter Zijlstra <peterz@infradead.org> CC: Kees Cook <keescook@chromium.org> CC: Dave Hansen <dave.hansen@linux.intel.com> CC: Mimi Zohar <zohar@linux.vnet.ibm.com> CC: Thiago Jung Bauermann <bauerman@linux.ibm.com> CC: Ahmed Soliman <ahmedsoliman@mena.vt.edu> CC: linux-integrity@vger.kernel.org CC: kernel-hardening@lists.openwall.com CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org --- mm/Kconfig.debug | 8 ++++++++ mm/prmem.c | 6 ++++++ 2 files changed, 14 insertions(+)