linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Haibo Li <haibo.li@mediatek.com>
To: <haibo.li@mediatek.com>
Cc: <akpm@linux-foundation.org>, <andreyknvl@gmail.com>,
	<angelogioacchino.delregno@collabora.com>, <dvyukov@google.com>,
	<glider@google.com>, <jannh@google.com>,
	<kasan-dev@googlegroups.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>,
	<linux-mediatek@lists.infradead.org>, <linux-mm@kvack.org>,
	<mark.rutland@arm.com>, <matthias.bgg@gmail.com>,
	<ryabinin.a.a@gmail.com>, <vincenzo.frascino@arm.com>,
	<xiaoming.yu@mediatek.com>
Subject: Re: [PATCH] kasan:fix access invalid shadow address when input is illegal
Date: Fri, 15 Sep 2023 17:40:04 +0800	[thread overview]
Message-ID: <20230915094004.113104-1-haibo.li@mediatek.com> (raw)
In-Reply-To: <20230915024559.32806-1-haibo.li@mediatek.com>

> > On Thu, Sep 14, 2023 at 10:41 PM Jann Horn <jannh@google.com> wrote:
> > >
> > > > Accessing unmapped memory with KASAN always led to a crash when
> > > > checking shadow memory. This was reported/discussed before. To improve
> > > > crash reporting for this case, Jann added kasan_non_canonical_hook and
> > > > Mark integrated it into arm64. But AFAIU, for some reason, it stopped
> > > > working.
> > > >
> > > > Instead of this patch, we need to figure out why
> > > > kasan_non_canonical_hook stopped working and fix it.
> > > >
> > > > This approach taken by this patch won't work for shadow checks added
> > > > by compiler instrumentation. It only covers explicitly checked
> > > > accesses, such as via memcpy, etc.
> > >
> > > FWIW, AFAICS kasan_non_canonical_hook() currently only does anything
> > > under CONFIG_KASAN_INLINE;
> > 
> > Ah, right. I was thinking about the inline mode, but the patch refers
> > to the issue with the outline mode.
> > 
> > However, I just checked kasan_non_canonical_hook for SW_TAGS with the
> > inline mode: it does not work when accessing 0x42ffffb80aaaaaaa, the
> > addr < KASAN_SHADOW_OFFSET check fails. It appears there's something
> > unusual about how instrumentation calculates the shadow address. I
> > didn't investigate further yet.
Sorry to miss this message.
I checked inline mode just now.kasan_non_canonical_hook can print 
something like below:
Unable to handle kernel paging request at virtual address ffffffb80aaaaaaa
KASAN: maybe wild-memory-access in range [0xffffff80aaaaaaa0-0xffffff80aaaaaaaf]
...
[ffffffb80aaaaaaa] pgd=000000005d3d6003, p4d=000000005d3d6003, pud=000000005d3d6003,
pmd=0000000000000000
...
pc : __hwasan_check_x20_67043363+0x4/0x34
lr : do_ib_ob+0x108/0x114
...
Call trace:
 __hwasan_check_x20_67043363+0x4/0x34
 die_selftest+0x68/0x80
 param_attr_store+0xec/0x164
 module_attr_store+0x34/0x4c
 sysfs_kf_write+0x78/0x8c
 kernfs_fop_write_iter+0x154/0x214
 vfs_write+0x36c/0x4c4
 ksys_write+0x98/0x110
 __arm64_sys_write+0x3c/0x48
 invoke_syscall+0x58/0x154
 el0_svc_common+0xe8/0x120
 do_el0_svc_compat+0x2c/0x38
 el0_svc_compat+0x34/0x84
 el0t_32_sync_handler+0x78/0xb4
 el0t_32_sync+0x194/0x198

When addr < KASAN_SHADOW_OFFSET meets,the original addr_has_metadata should return false
and trigger kasan_report in kasan_check_range.
> > 
> > > I think the idea when I added that was that
> > > it assumes that when KASAN checks an access in out-of-line
> > > instrumentation or a slowpath, it will do the required checks to avoid
> > > this kind of fault?
> > 
> > Ah, no, KASAN doesn't do it.
> > 
> > However, I suppose we could add what the original patch proposes for
> > the outline mode. For the inline mode, it seems to be pointless, as
> > most access checks happen though the compiler inserted code anyway.
> > 
> > I also wonder how much slowdown this patch will introduce.
> > 
> > Haibo, could you check how much slower the kernel becomes with your
> > patch? If possible, with all GENERIC/SW_TAGS and INLINE/OUTLINE
> > combinations.
> > 
> > If the slowdown is large, we can just make kasan_non_canonical_hook
> > work for both modes (and fix it for SW_TAGS).
> 
> Thanks.
> The patch checks each shadow address,so it introduces extra overhead.
> Now kasan_non_canonical_hook only works for CONFIG_KASAN_INLINE.
> And CONFIG_KASAN_OUTLINE is set in my case.
> Is it possible to make kasan_non_canonical_hook works for both 
> INLINE and OUTLINE by simply remove the "#ifdef CONFIG_KASAN_INLINE"?
> Since kasan_non_canonical_hook is only used after kernel fault,it 
> is better if there is no limit.


  reply	other threads:[~2023-09-15  9:40 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-14  8:08 Haibo Li
2023-09-14 17:46 ` Andrey Konovalov
2023-09-14 18:29 ` Andrew Morton
2023-09-14 20:34   ` Andrey Konovalov
2023-09-14 20:40     ` Jann Horn
2023-09-15  1:51       ` Andrey Konovalov
2023-09-15  2:45         ` Haibo Li
2023-09-15  9:40           ` Haibo Li [this message]
2023-09-15 16:53             ` Andrey Konovalov
2023-09-15 16:50           ` Andrey Konovalov
2023-09-15 17:04             ` Jann Horn
2023-09-18  8:12               ` Haibo Li
2023-09-18  7:25             ` Haibo Li

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=20230915094004.113104-1-haibo.li@mediatek.com \
    --to=haibo.li@mediatek.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=jannh@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=mark.rutland@arm.com \
    --cc=matthias.bgg@gmail.com \
    --cc=ryabinin.a.a@gmail.com \
    --cc=vincenzo.frascino@arm.com \
    --cc=xiaoming.yu@mediatek.com \
    /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