Skip to content

Commit

Permalink
Merge branch 'kcsan.2020.11.06a' into HEAD
Browse files Browse the repository at this point in the history
kcsan.2020.11.06a:  Kernel concurrency sanitizer (KCSAN) updates.
  • Loading branch information
Paul E. McKenney committed Nov 20, 2020
2 parents 7fc91fc + 1d094ce commit c4638ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
20 changes: 11 additions & 9 deletions kernel/kcsan/encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,20 @@
*/
#define WATCHPOINT_ADDR_BITS (BITS_PER_LONG-1 - WATCHPOINT_SIZE_BITS)

/*
* Masks to set/retrieve the encoded data.
*/
#define WATCHPOINT_WRITE_MASK BIT(BITS_PER_LONG-1)
#define WATCHPOINT_SIZE_MASK \
GENMASK(BITS_PER_LONG-2, BITS_PER_LONG-2 - WATCHPOINT_SIZE_BITS)
#define WATCHPOINT_ADDR_MASK \
GENMASK(BITS_PER_LONG-3 - WATCHPOINT_SIZE_BITS, 0)
/* Bitmasks for the encoded watchpoint access information. */
#define WATCHPOINT_WRITE_MASK BIT(BITS_PER_LONG-1)
#define WATCHPOINT_SIZE_MASK GENMASK(BITS_PER_LONG-2, WATCHPOINT_ADDR_BITS)
#define WATCHPOINT_ADDR_MASK GENMASK(WATCHPOINT_ADDR_BITS-1, 0)
static_assert(WATCHPOINT_ADDR_MASK == (1UL << WATCHPOINT_ADDR_BITS) - 1);
static_assert((WATCHPOINT_WRITE_MASK ^ WATCHPOINT_SIZE_MASK ^ WATCHPOINT_ADDR_MASK) == ~0UL);

static inline bool check_encodable(unsigned long addr, size_t size)
{
return size <= MAX_ENCODABLE_SIZE;
/*
* While we can encode addrs<PAGE_SIZE, avoid crashing with a NULL
* pointer deref inside KCSAN.
*/
return addr >= PAGE_SIZE && size <= MAX_ENCODABLE_SIZE;
}

static inline long
Expand Down
3 changes: 3 additions & 0 deletions kernel/kcsan/selftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ static bool test_encode_decode(void)
unsigned long addr;

prandom_bytes(&addr, sizeof(addr));
if (addr < PAGE_SIZE)
addr = PAGE_SIZE;

if (WARN_ON(!check_encodable(addr, size)))
return false;

Expand Down

0 comments on commit c4638ff

Please sign in to comment.