diff mbox series

[mm] kfence: zero guard page after out-of-bounds access

Message ID 20210312121653.348518-1-elver@google.com (mailing list archive)
State New, archived
Headers show
Series [mm] kfence: zero guard page after out-of-bounds access | expand

Commit Message

Marco Elver March 12, 2021, 12:16 p.m. UTC
After an out-of-bounds accesses, zero the guard page before
re-protecting in kfence_guarded_free(). On one hand this helps make the
failure mode of subsequent out-of-bounds accesses more deterministic,
but could also prevent certain information leaks.

Signed-off-by: Marco Elver <elver@google.com>
---
 mm/kfence/core.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Alexander Potapenko March 12, 2021, 1:11 p.m. UTC | #1
On Fri, Mar 12, 2021 at 1:16 PM Marco Elver <elver@google.com> wrote:
>
> After an out-of-bounds accesses, zero the guard page before
> re-protecting in kfence_guarded_free(). On one hand this helps make the
> failure mode of subsequent out-of-bounds accesses more deterministic,
> but could also prevent certain information leaks.
>
> Signed-off-by: Marco Elver <elver@google.com>
Acked-by: Alexander Potapenko <glider@google.com>

> ---
>  mm/kfence/core.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/mm/kfence/core.c b/mm/kfence/core.c
> index 3b8ec938470a..f7106f28443d 100644
> --- a/mm/kfence/core.c
> +++ b/mm/kfence/core.c
> @@ -371,6 +371,7 @@ static void kfence_guarded_free(void *addr, struct kfence_metadata *meta, bool z
>
>         /* Restore page protection if there was an OOB access. */
>         if (meta->unprotected_page) {
> +               memzero_explicit((void *)ALIGN_DOWN(meta->unprotected_page, PAGE_SIZE), PAGE_SIZE);
>                 kfence_protect(meta->unprotected_page);
>                 meta->unprotected_page = 0;
>         }
> --
> 2.31.0.rc2.261.g7f71774620-goog
>
diff mbox series

Patch

diff --git a/mm/kfence/core.c b/mm/kfence/core.c
index 3b8ec938470a..f7106f28443d 100644
--- a/mm/kfence/core.c
+++ b/mm/kfence/core.c
@@ -371,6 +371,7 @@  static void kfence_guarded_free(void *addr, struct kfence_metadata *meta, bool z
 
 	/* Restore page protection if there was an OOB access. */
 	if (meta->unprotected_page) {
+		memzero_explicit((void *)ALIGN_DOWN(meta->unprotected_page, PAGE_SIZE), PAGE_SIZE);
 		kfence_protect(meta->unprotected_page);
 		meta->unprotected_page = 0;
 	}