From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl0-f72.google.com (mail-pl0-f72.google.com [209.85.160.72]) by kanga.kvack.org (Postfix) with ESMTP id 528D46B0006 for ; Thu, 5 Apr 2018 09:01:46 -0400 (EDT) Received: by mail-pl0-f72.google.com with SMTP id t8-v6so16823193ply.22 for ; Thu, 05 Apr 2018 06:01:46 -0700 (PDT) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on0127.outbound.protection.outlook.com. [104.47.1.127]) by mx.google.com with ESMTPS id y7si5922725pfl.313.2018.04.05.06.01.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Apr 2018 06:01:38 -0700 (PDT) Subject: Re: [RFC PATCH v2 13/15] khwasan: add hooks implementation References: <805d1e85-2d3c-2327-6e6c-f14a56dc0b67@virtuozzo.com> <0c4397da-e231-0044-986f-b8468314be76@virtuozzo.com> From: Andrey Ryabinin Message-ID: <0857f052-a27a-501e-8923-c6f31510e4fe@virtuozzo.com> Date: Thu, 5 Apr 2018 16:02:20 +0300 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Andrey Konovalov Cc: Alexander Potapenko , Dmitry Vyukov , Jonathan Corbet , Catalin Marinas , Will Deacon , Marc Zyngier , Christopher Li , Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Masahiro Yamada , Michal Marek , Mark Rutland , Ard Biesheuvel , Yury Norov , Nick Desaulniers , Suzuki K Poulose , Kristina Martsenko , Punit Agrawal , Dave Martin , Michael Weiser , James Morse , Julien Thierry , Steve Capper , Tyler Baicar , "Eric W . Biederman" , Thomas Gleixner , Ingo Molnar , Paul Lawrence , Greg Kroah-Hartman , David Woodhouse , Sandipan Das , Kees Cook , Herbert Xu , Geert Uytterhoeven , Josh Poimboeuf , Arnd Bergmann , kasan-dev , linux-doc@vger.kernel.org, LKML , Linux ARM , kvmarm@lists.cs.columbia.edu, linux-sparse@vger.kernel.org, Linux Memory Management List , Linux Kbuild mailing list , Kostya Serebryany , Evgeniy Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Kees Cook , Jann Horn , Mark Brand On 04/04/2018 08:00 PM, Andrey Konovalov wrote: > On Wed, Apr 4, 2018 at 2:39 PM, Andrey Ryabinin wrote: >>>> >>>> You can save tag somewhere in page struct and make page_address() return tagged address. >>>> >>>> I'm not sure it might be even possible to squeeze the tag into page->flags on some configurations, >>>> see include/linux/page-flags-layout.h >>> >>> One page can contain multiple objects with different tags, so we would >>> need to save the tag for each of them. >> >> What do you mean? Slab page? The per-page tag is needed only for !PageSlab pages. >> For slab pages we have kmalloc/kmem_cache_alloc() which already return properly tagged address. >> >> But the page allocator returns a pointer to struct page. One has to call page_address(page) >> to use that page. Returning 'ignore-me'-tagged address from page_address() makes the whole >> class of bugs invisible to KHWASAN. This is a serious downside comparing to classic KASAN which can >> detect missuses of page allocator API. > > Yes, slab page. Here's an example: > > 1. do_get_write_access() allocates frozen_buffer with jbd2_alloc, > which calls kmem_cache_alloc, and then saves the result to > jh->b_frozen_data. > > 2. jbd2_journal_write_metadata_buffer() takes the value of > jh_in->b_frozen_data and calls virt_to_page() (and offset_in_page()) > on it. > > 3. jbd2_journal_write_metadata_buffer() then calls kmap_atomic(), > which calls page_address(), on the resulting page address. > > The tag gets erased. The page belongs to slab and can contain multiple > objects with different tags. > I see. Ideally that kind of problem should be fixed by reworking/redesigning such code, however jbd2_journal_write_metadata_buffer() is far from the only place which does that trick. Fixing all of them would be a huge task probably, so ignoring such accesses seems to be the only choice we have. Nevertheless, this doesn't mean that we should ignore *all* accesses to !slab memory.