kfence: add function to mask address bits
s390 only reports the page address during a translation fault. To make the kfence unit tests pass, add a function that might be implemented by architectures to mask out address bits. Signed-off-by: Sven Schnelle <svens@linux.ibm.com> Reviewed-by: Marco Elver <elver@google.com> Link: https://lore.kernel.org/r/20210728190254.3921642-3-hca@linux.ibm.com Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
This commit is contained in:
parent
b3e1a00c8f
commit
f99e12b21b
@ -23,8 +23,15 @@
|
|||||||
#include <linux/tracepoint.h>
|
#include <linux/tracepoint.h>
|
||||||
#include <trace/events/printk.h>
|
#include <trace/events/printk.h>
|
||||||
|
|
||||||
|
#include <asm/kfence.h>
|
||||||
|
|
||||||
#include "kfence.h"
|
#include "kfence.h"
|
||||||
|
|
||||||
|
/* May be overridden by <asm/kfence.h>. */
|
||||||
|
#ifndef arch_kfence_test_address
|
||||||
|
#define arch_kfence_test_address(addr) (addr)
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Report as observed from console. */
|
/* Report as observed from console. */
|
||||||
static struct {
|
static struct {
|
||||||
spinlock_t lock;
|
spinlock_t lock;
|
||||||
@ -82,6 +89,7 @@ static const char *get_access_type(const struct expect_report *r)
|
|||||||
/* Check observed report matches information in @r. */
|
/* Check observed report matches information in @r. */
|
||||||
static bool report_matches(const struct expect_report *r)
|
static bool report_matches(const struct expect_report *r)
|
||||||
{
|
{
|
||||||
|
unsigned long addr = (unsigned long)r->addr;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
typeof(observed.lines) expect;
|
typeof(observed.lines) expect;
|
||||||
@ -131,22 +139,25 @@ static bool report_matches(const struct expect_report *r)
|
|||||||
switch (r->type) {
|
switch (r->type) {
|
||||||
case KFENCE_ERROR_OOB:
|
case KFENCE_ERROR_OOB:
|
||||||
cur += scnprintf(cur, end - cur, "Out-of-bounds %s at", get_access_type(r));
|
cur += scnprintf(cur, end - cur, "Out-of-bounds %s at", get_access_type(r));
|
||||||
|
addr = arch_kfence_test_address(addr);
|
||||||
break;
|
break;
|
||||||
case KFENCE_ERROR_UAF:
|
case KFENCE_ERROR_UAF:
|
||||||
cur += scnprintf(cur, end - cur, "Use-after-free %s at", get_access_type(r));
|
cur += scnprintf(cur, end - cur, "Use-after-free %s at", get_access_type(r));
|
||||||
|
addr = arch_kfence_test_address(addr);
|
||||||
break;
|
break;
|
||||||
case KFENCE_ERROR_CORRUPTION:
|
case KFENCE_ERROR_CORRUPTION:
|
||||||
cur += scnprintf(cur, end - cur, "Corrupted memory at");
|
cur += scnprintf(cur, end - cur, "Corrupted memory at");
|
||||||
break;
|
break;
|
||||||
case KFENCE_ERROR_INVALID:
|
case KFENCE_ERROR_INVALID:
|
||||||
cur += scnprintf(cur, end - cur, "Invalid %s at", get_access_type(r));
|
cur += scnprintf(cur, end - cur, "Invalid %s at", get_access_type(r));
|
||||||
|
addr = arch_kfence_test_address(addr);
|
||||||
break;
|
break;
|
||||||
case KFENCE_ERROR_INVALID_FREE:
|
case KFENCE_ERROR_INVALID_FREE:
|
||||||
cur += scnprintf(cur, end - cur, "Invalid free of");
|
cur += scnprintf(cur, end - cur, "Invalid free of");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
cur += scnprintf(cur, end - cur, " 0x%p", (void *)r->addr);
|
cur += scnprintf(cur, end - cur, " 0x%p", (void *)addr);
|
||||||
|
|
||||||
spin_lock_irqsave(&observed.lock, flags);
|
spin_lock_irqsave(&observed.lock, flags);
|
||||||
if (!report_available())
|
if (!report_available())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user