public inbox for kvmarm@lists.cs.columbia.edu
 help / color / mirror / Atom feed
From: Andrey Ryabinin <aryabinin@virtuozzo.com>
To: Andrey Konovalov <andreyknvl@google.com>
Cc: Julien Thierry <julien.thierry@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Christopher Li <sparse@chrisli.org>,
	Tyler Baicar <tbaicar@codeaurora.org>,
	Will Deacon <will.deacon@arm.com>,
	Paul Lawrence <paullawrence@google.com>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	Yury Norov <ynorov@caviumnetworks.com>,
	Alexander Potapenko <glider@google.com>,
	Christoph Lameter <cl@linux.com>,
	Michael Weiser <michael.weiser@gmx.de>,
	Ingo Molnar <mingo@kernel.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Jonathan Corbet <corbet@lwn.net>,
	linux-doc@vger.kernel.org, Mark Brand <markbrand@google.com>,
	kasan-dev <kasan-dev@googlegroups.com>,
	kvmarm@lists.cs.columbia.edu, linux-sparse@vger.kernel.org,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	Linux ARM <linux-arm-kernel@lists.infradead.org>,
	David Rientjes <rientjes@google.com>,
	Ramana Radhakrishnan <Ramana.Radhakrishna>
Subject: Re: [RFC PATCH v2 13/15] khwasan: add hooks implementation
Date: Thu, 12 Apr 2018 20:20:47 +0300	[thread overview]
Message-ID: <a29d22c7-bcae-ec8d-1810-95eef013e699@virtuozzo.com> (raw)
In-Reply-To: <CAAeHK+wzwXnJh1bbhUN6bm788q52BA2EfC+Q3dMS=peP7Px4Rg@mail.gmail.com>



On 04/12/2018 07:45 PM, Andrey Konovalov wrote:
> On Tue, Apr 10, 2018 at 6:31 PM, Andrey Ryabinin
> <aryabinin@virtuozzo.com> wrote:
>>
>>
>> On 04/10/2018 07:07 PM, Andrey Konovalov wrote:
>>> On Fri, Apr 6, 2018 at 2:27 PM, Andrey Ryabinin <aryabinin@virtuozzo.com> wrote:
>>>> On 04/06/2018 03:14 PM, Andrey Konovalov wrote:
>>>>> On Thu, Apr 5, 2018 at 3:02 PM, Andrey Ryabinin <aryabinin@virtuozzo.com> wrote:
>>>>>> Nevertheless, this doesn't mean that we should ignore *all* accesses to !slab memory.
>>>>>
>>>>> So you mean we need to find a way to ignore accesses via pointers
>>>>> returned by page_address(), but still check accesses through all other
>>>>> pointers tagged with 0xFF? I don't see an obvious way to do this. I'm
>>>>> open to suggestions though.
>>>>>
>>>>
>>>> I'm saying that we need to ignore accesses to slab objects if pointer
>>>> to slab object obtained via page_address() + offset_in_page() trick, but don't ignore
>>>> anything else.
>>>>
>>>> So, save tag somewhere in page struct and poison shadow with that tag. Make page_address() to
>>>> return tagged address for all !PageSlab() pages. For PageSlab() pages page_address() should return
>>>> 0xff tagged address, so we could ignore such accesses.
>>>
>>> Which pages do you mean by !PageSlab()?
>>
>> Literally the "PageSlab(page) == false" pages.
>>
>>> The ones that are allocated and freed by pagealloc, but mot managed by the slab allocator?
>>
>> Yes.
>>
>>> Perhaps we should then add tagging to the pagealloc hook instead?
>>>
>>
>> Of course the tagging would be in kasan_alloc_pages(), where else that could be? And instead of what?
> 
> I think I misunderstood your suggestion twice already :)
> 
> To make it clear, you're suggesting:
> 
> 1. Tag memory with a random tag in kasan_alloc_pages() and returned a
> tagged pointer from pagealloc.
 
Tag memory with a random tag in kasan_alloc_pages() and store that tag in page struct (that part is also in kasan_alloc_pages()).
page_address(page) will retrieve that tag from struct page to return tagged address.

I've no idea what do you mean by "returning a tagged pointer from pagealloc".
Once again, the page allocator (__alloc_pages_nodemask()) returns pointer to *struct page*,
not the address in the linear mapping where is that page mapped (or not mapped at all if this is highmem).
One have to call page_address()/kmap() to use that page.


> 2. Restore the tag for the pointers returned from page_address for
> !PageSlab() pages.
> 

Right.

> 3. Set the tag to 0xff for the pointers returned from page_address for
> PageSlab() pages.
> 

Right.

> Is this correct?
> 
> In 2 instead of storing the tag in page_struct, we can just recover it
> from the shadow memory that corresponds to that page. What do you
> think about this?

Sounds ok. Don't see any problem with that.

  reply	other threads:[~2018-04-12 17:11 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-23 18:05 [RFC PATCH v2 00/15] khwasan: kernel hardware assisted address sanitizer Andrey Konovalov
2018-03-23 18:05 ` [RFC PATCH v2 01/15] khwasan, mm: change kasan hooks signatures Andrey Konovalov
2018-03-23 18:05 ` [RFC PATCH v2 02/15] khwasan: move common kasan and khwasan code to common.c Andrey Konovalov
2018-03-23 18:05 ` [RFC PATCH v2 03/15] khwasan: add CONFIG_KASAN_CLASSIC and CONFIG_KASAN_TAGS Andrey Konovalov
2018-03-24  8:43   ` Ingo Molnar
2018-03-27 16:23     ` Andrey Konovalov
2018-03-27 20:02       ` Ingo Molnar
2018-03-23 18:05 ` [RFC PATCH v2 04/15] khwasan, arm64: adjust shadow size for CONFIG_KASAN_TAGS Andrey Konovalov
2018-03-23 18:05 ` [RFC PATCH v2 05/15] khwasan: initialize shadow to 0xff Andrey Konovalov
2018-03-30 16:07   ` Andrey Ryabinin
2018-04-03 14:43     ` Andrey Konovalov
2018-03-23 18:05 ` [RFC PATCH v2 06/15] khwasan, arm64: untag virt address in __kimg_to_phys Andrey Konovalov
2018-03-23 18:05 ` [RFC PATCH v2 07/15] khwasan, arm64: fix up fault handling logic Andrey Konovalov
2018-03-23 18:05 ` [RFC PATCH v2 08/15] khwasan: add tag related helper functions Andrey Konovalov
2018-03-30 16:13   ` Andrey Ryabinin
2018-04-03 14:45     ` Andrey Konovalov
2018-03-23 18:05 ` [RFC PATCH v2 09/15] khwasan, kvm: untag pointers in kern_hyp_va Andrey Konovalov
2018-03-23 18:05 ` [RFC PATCH v2 10/15] khwasan, arm64: enable top byte ignore for the kernel Andrey Konovalov
2018-03-23 18:05 ` [RFC PATCH v2 11/15] khwasan, mm: perform untagged pointers comparison in krealloc Andrey Konovalov
2018-03-24  8:29   ` Ingo Molnar
2018-03-27 12:20     ` Andrey Konovalov
2018-03-27 20:01       ` Ingo Molnar
2018-03-23 18:05 ` [RFC PATCH v2 12/15] khwasan: add bug reporting routines Andrey Konovalov
2018-03-23 18:05 ` [RFC PATCH v2 13/15] khwasan: add hooks implementation Andrey Konovalov
2018-03-30 17:47   ` Andrey Ryabinin
2018-04-03 14:59     ` Andrey Konovalov
2018-04-04 12:39       ` Andrey Ryabinin
2018-04-04 17:00         ` Andrey Konovalov
2018-04-05 13:02           ` Andrey Ryabinin
2018-04-06 12:14             ` Andrey Konovalov
2018-04-06 12:27               ` Andrey Ryabinin
2018-04-10 16:07                 ` Andrey Konovalov
     [not found]                   ` <bfc3da50-66df-c6ed-ad6a-a285efe617ec@virtuozzo.com>
2018-04-12 16:45                     ` Andrey Konovalov
2018-04-12 17:20                       ` Andrey Ryabinin [this message]
2018-04-12 17:37                         ` Andrey Konovalov
2018-03-23 18:05 ` [RFC PATCH v2 14/15] khwasan, arm64: add brk handler for inline instrumentation Andrey Konovalov
2018-03-23 18:05 ` [RFC PATCH v2 15/15] khwasan: update kasan documentation Andrey Konovalov

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=a29d22c7-bcae-ec8d-1810-95eef013e699@virtuozzo.com \
    --to=aryabinin@virtuozzo.com \
    --cc=andreyknvl@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=cl@linux.com \
    --cc=corbet@lwn.net \
    --cc=geert@linux-m68k.org \
    --cc=glider@google.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=julien.thierry@arm.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=markbrand@google.com \
    --cc=michael.weiser@gmx.de \
    --cc=mingo@kernel.org \
    --cc=paullawrence@google.com \
    --cc=rientjes@google.com \
    --cc=sparse@chrisli.org \
    --cc=tbaicar@codeaurora.org \
    --cc=will.deacon@arm.com \
    --cc=yamada.masahiro@socionext.com \
    --cc=ynorov@caviumnetworks.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