mm-commits.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: akpm@linux-foundation.org, dvyukov@google.com, elver@google.com,
	glider@google.com, Kuan-Ying.Lee@mediatek.com,
	linux-mm@kvack.org, mm-commits@vger.kernel.org,
	stable@vger.kernel.org, torvalds@linux-foundation.org
Subject: [patch 09/10] kfence: fix is_kfence_address() for addresses below KFENCE_POOL_SIZE
Date: Thu, 19 Aug 2021 19:04:30 -0700	[thread overview]
Message-ID: <20210820020430.mQDxQa8Jr%akpm@linux-foundation.org> (raw)
In-Reply-To: <20210819190327.14fc4e97102e1af7929e30af@linux-foundation.org>

From: Marco Elver <elver@google.com>
Subject: kfence: fix is_kfence_address() for addresses below KFENCE_POOL_SIZE

Originally the addr != NULL check was meant to take care of the case where
__kfence_pool == NULL (KFENCE is disabled).  However, this does not work
for addresses where addr > 0 && addr < KFENCE_POOL_SIZE.

This can be the case on NULL-deref where addr > 0 && addr < PAGE_SIZE or
any other faulting access with addr < KFENCE_POOL_SIZE.  While the kernel
would likely crash, the stack traces and report might be confusing due to
double faults upon KFENCE's attempt to unprotect such an address.

Fix it by just checking that __kfence_pool != NULL instead.

Link: https://lkml.kernel.org/r/20210818130300.2482437-1-elver@google.com
Fixes: 0ce20dd84089 ("mm: add Kernel Electric-Fence infrastructure")
Signed-off-by: Marco Elver <elver@google.com>
Reported-by: Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
Acked-by: Alexander Potapenko <glider@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: <stable@vger.kernel.org>    [5.12+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 include/linux/kfence.h |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

--- a/include/linux/kfence.h~kfence-fix-is_kfence_address-for-addresses-below-kfence_pool_size
+++ a/include/linux/kfence.h
@@ -51,10 +51,11 @@ extern atomic_t kfence_allocation_gate;
 static __always_inline bool is_kfence_address(const void *addr)
 {
 	/*
-	 * The non-NULL check is required in case the __kfence_pool pointer was
-	 * never initialized; keep it in the slow-path after the range-check.
+	 * The __kfence_pool != NULL check is required to deal with the case
+	 * where __kfence_pool == NULL && addr < KFENCE_POOL_SIZE. Keep it in
+	 * the slow-path after the range-check!
 	 */
-	return unlikely((unsigned long)((char *)addr - __kfence_pool) < KFENCE_POOL_SIZE && addr);
+	return unlikely((unsigned long)((char *)addr - __kfence_pool) < KFENCE_POOL_SIZE && __kfence_pool);
 }
 
 /**
_

  parent reply	other threads:[~2021-08-20  2:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-20  2:03 incoming Andrew Morton
2021-08-20  2:04 ` [patch 01/10] Revert "mm/shmem: fix shmem_swapin() race with swapoff" Andrew Morton
2021-08-20  2:04 ` [patch 02/10] Revert "mm: swap: check if swap backing device is congested or not" Andrew Morton
2021-08-20  2:04 ` [patch 03/10] mm/page_alloc: don't corrupt pcppage_migratetype Andrew Morton
2021-08-20  2:04 ` [patch 04/10] mmflags.h: add missing __GFP_ZEROTAGS and __GFP_SKIP_KASAN_POISON names Andrew Morton
2021-08-20  2:04 ` [patch 05/10] MAINTAINERS: update ClangBuiltLinux IRC chat Andrew Morton
2021-08-20  2:04 ` [patch 06/10] mm: memcontrol: fix occasional OOMs due to proportional memory.low reclaim Andrew Morton
2021-08-20  2:04 ` [patch 07/10] mm/hwpoison: retry with shake_page() for unhandlable pages Andrew Morton
2021-08-20  2:04 ` [patch 08/10] mm: vmscan: fix missing psi annotation for node_reclaim() Andrew Morton
2021-08-20  2:04 ` Andrew Morton [this message]
2021-08-20  2:04 ` [patch 10/10] hugetlb: don't pass page cache pages to restore_reserve_on_error Andrew Morton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210820020430.mQDxQa8Jr%akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=Kuan-Ying.Lee@mediatek.com \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=glider@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mm-commits@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).