linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: kasan: Index page hierarchy as an array
@ 2020-11-06  8:51 Linus Walleij
  2020-11-06  9:25 ` Mike Rapoport
  0 siblings, 1 reply; 2+ messages in thread
From: Linus Walleij @ 2020-11-06  8:51 UTC (permalink / raw)
  To: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov, kasan-dev
  Cc: kernel test robot, Arnd Bergmann, Linus Walleij, Mike Rapoport,
	Ard Biesheuvel, linux-arm-kernel

When freeing page directories, KASan was consistently
indexing through the page hierarchy like this:

  static void kasan_free_pud(pud_t *pud_start, p4d_t *p4d) {
    pud_t *pud;
    int i;

    for (i = 0; i < PTRS_PER_PUD; i++) {
      pud = pud_start + i;
      if (!pud_none(*pud))
        if (!pud_none(pud_start[i]))
          return;
    }
  }

That is: implicitly add i sizeof(put_t) idices to
the variable pud.

On ARM32 arch/arm/include/asm/pgtable-2level.h has folded
the PMDs into the PUDs and thus has this definition of
pud_none():

  #define pud_none(pud)           (0)

This will make the above construction emit this harmless
build warning on ARM32:

  mm/kasan/init.c: In function 'kasan_free_pud':
  >> mm/kasan/init.c:318:9: warning: variable 'pud' set but not used [-Wunused-but-set-variable]
     318 |  pud_t *pud;
         |         ^~~

Using an explicit array removes this problem and also makes
the build warning go away. Arguably the code also gets
easier to read.

So I fixed all the kasan_free_p??() to use explicit
array inidices instead.

Fixes: 421015713b30 ("ARM: 9017/2: Enable KASan for ARM")
Reported-by: kernel test robot <lkp@intel.com>
Suggested-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 mm/kasan/init.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/mm/kasan/init.c b/mm/kasan/init.c
index fe6be0be1f76..3c74c30996ef 100644
--- a/mm/kasan/init.c
+++ b/mm/kasan/init.c
@@ -285,12 +285,10 @@ int __ref kasan_populate_early_shadow(const void *shadow_start,
 
 static void kasan_free_pte(pte_t *pte_start, pmd_t *pmd)
 {
-	pte_t *pte;
 	int i;
 
 	for (i = 0; i < PTRS_PER_PTE; i++) {
-		pte = pte_start + i;
-		if (!pte_none(*pte))
+		if (!pte_none(pte_start[i]))
 			return;
 	}
 
@@ -300,12 +298,10 @@ static void kasan_free_pte(pte_t *pte_start, pmd_t *pmd)
 
 static void kasan_free_pmd(pmd_t *pmd_start, pud_t *pud)
 {
-	pmd_t *pmd;
 	int i;
 
 	for (i = 0; i < PTRS_PER_PMD; i++) {
-		pmd = pmd_start + i;
-		if (!pmd_none(*pmd))
+		if (!pmd_none(pmd_start[i]))
 			return;
 	}
 
@@ -315,12 +311,10 @@ static void kasan_free_pmd(pmd_t *pmd_start, pud_t *pud)
 
 static void kasan_free_pud(pud_t *pud_start, p4d_t *p4d)
 {
-	pud_t *pud;
 	int i;
 
 	for (i = 0; i < PTRS_PER_PUD; i++) {
-		pud = pud_start + i;
-		if (!pud_none(*pud))
+		if (!pud_none(pud_start[i]))
 			return;
 	}
 
@@ -330,12 +324,10 @@ static void kasan_free_pud(pud_t *pud_start, p4d_t *p4d)
 
 static void kasan_free_p4d(p4d_t *p4d_start, pgd_t *pgd)
 {
-	p4d_t *p4d;
 	int i;
 
 	for (i = 0; i < PTRS_PER_P4D; i++) {
-		p4d = p4d_start + i;
-		if (!p4d_none(*p4d))
+		if (!p4d_none(p4d_start[i]))
 			return;
 	}
 
-- 
2.26.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-06  9:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-06  8:51 [PATCH] mm: kasan: Index page hierarchy as an array Linus Walleij
2020-11-06  9:25 ` Mike Rapoport

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).