Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Correctly align the size+redzone for KASAN, on amd6...
details: https://anonhg.NetBSD.org/src/rev/70c3e3801946
branches: trunk
changeset: 993427:70c3e3801946
user: maxv <maxv%NetBSD.org@localhost>
date: Mon Sep 10 13:11:05 2018 +0000
description:
Correctly align the size+redzone for KASAN, on amd64 it happens to be
always 8byte-aligned but on other architectures it may not be.
diffstat:
sys/kern/subr_pool.c | 25 +++++++++++++++++++------
1 files changed, 19 insertions(+), 6 deletions(-)
diffs (76 lines):
diff -r 7fe08b3bd187 -r 70c3e3801946 sys/kern/subr_pool.c
--- a/sys/kern/subr_pool.c Mon Sep 10 11:05:12 2018 +0000
+++ b/sys/kern/subr_pool.c Mon Sep 10 13:11:05 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_pool.c,v 1.226 2018/08/25 05:56:24 maxv Exp $ */
+/* $NetBSD: subr_pool.c,v 1.227 2018/09/10 13:11:05 maxv Exp $ */
/*-
* Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008, 2010, 2014, 2015
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.226 2018/08/25 05:56:24 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.227 2018/09/10 13:11:05 maxv Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@@ -2749,8 +2749,17 @@
static void
pool_redzone_init(struct pool *pp, size_t requested_size)
{
+ size_t redzsz;
size_t nsz;
+#ifdef KASAN
+ redzsz = requested_size;
+ kasan_add_redzone(&redzsz);
+ redzsz -= requested_size;
+#else
+ redzsz = POOL_REDZONE_SIZE;
+#endif
+
if (pp->pr_roflags & PR_NOTOUCH) {
pp->pr_reqsize = 0;
pp->pr_redzone = false;
@@ -2761,7 +2770,7 @@
* We may have extended the requested size earlier; check if
* there's naturally space in the padding for a red zone.
*/
- if (pp->pr_size - requested_size >= POOL_REDZONE_SIZE) {
+ if (pp->pr_size - requested_size >= redzsz) {
pp->pr_reqsize = requested_size;
pp->pr_redzone = true;
return;
@@ -2771,7 +2780,7 @@
* No space in the natural padding; check if we can extend a
* bit the size of the pool.
*/
- nsz = roundup(pp->pr_size + POOL_REDZONE_SIZE, pp->pr_align);
+ nsz = roundup(pp->pr_size + redzsz, pp->pr_align);
if (nsz <= pp->pr_alloc->pa_pagesz) {
/* Ok, we can */
pp->pr_size = nsz;
@@ -2791,7 +2800,9 @@
if (!pp->pr_redzone)
return;
#ifdef KASAN
- kasan_alloc(p, pp->pr_reqsize, pp->pr_reqsize + POOL_REDZONE_SIZE);
+ size_t size_with_redzone = pp->pr_reqsize;
+ kasan_add_redzone(&size_with_redzone);
+ kasan_alloc(p, pp->pr_reqsize, size_with_redzone);
#else
uint8_t *cp, pat;
const uint8_t *ep;
@@ -2820,7 +2831,9 @@
if (!pp->pr_redzone)
return;
#ifdef KASAN
- kasan_free(p, pp->pr_reqsize + POOL_REDZONE_SIZE);
+ size_t size_with_redzone = pp->pr_reqsize;
+ kasan_add_redzone(&size_with_redzone);
+ kasan_free(p, size_with_redzone);
#else
uint8_t *cp, pat, expected;
const uint8_t *ep;
Home |
Main Index |
Thread Index |
Old Index