@@ -60,7 +60,14 @@ void *__wr_op(unsigned long dst, unsigned long src, __kernel_size_t len,
copy_to_user((void __user *)wr_poking_addr, (void *)src, len);
else if (op == WR_MEMSET)
memset_user((void __user *)wr_poking_addr, (u8)src, len);
-
+#ifdef CONFIG_DEBUG_PRMEM
+ if (op == WR_MEMCPY)
+ VM_WARN_ONCE(memcmp((void *)dst, (void *)src, len),
+ "Failed wr_memcpy()");
+ else if (op == WR_MEMSET)
+ VM_WARN_ONCE(memtst((void *)dst, (u8)src, len),
+ "Failed wr_memset()");
+#endif
unuse_temporary_mm(prev);
local_irq_enable();
return (void *)dst;
@@ -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.
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: linux-integrity@vger.kernel.org CC: kernel-hardening@lists.openwall.com CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org --- arch/x86/mm/prmem.c | 9 ++++++++- mm/Kconfig.debug | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-)