From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io0-f200.google.com (mail-io0-f200.google.com [209.85.223.200]) by kanga.kvack.org (Postfix) with ESMTP id EB3C56B0008 for ; Wed, 18 Jul 2018 13:16:28 -0400 (EDT) Received: by mail-io0-f200.google.com with SMTP id v2-v6so3814600ioh.17 for ; Wed, 18 Jul 2018 10:16:28 -0700 (PDT) Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id k71-v6sor1499713jad.95.2018.07.18.10.16.27 for (Google Transport Security); Wed, 18 Jul 2018 10:16:27 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <20180703173608.GF27243@arm.com> References: <20180628105057.GA26019@e103592.cambridge.arm.com> <20180629110709.GA17859@arm.com> <20180703173608.GF27243@arm.com> From: Andrey Konovalov Date: Wed, 18 Jul 2018 19:16:25 +0200 Message-ID: Subject: Re: [PATCH v4 00/17] khwasan: kernel hardware assisted address sanitizer Content-Type: text/plain; charset="UTF-8" Sender: owner-linux-mm@kvack.org List-ID: To: Andrew Morton , Will Deacon , Catalin Marinas Cc: Dave Martin , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Christoph Lameter , Mark Rutland , Nick Desaulniers , Marc Zyngier , Ard Biesheuvel , "Eric W . Biederman" , Ingo Molnar , Paul Lawrence , Geert Uytterhoeven , Arnd Bergmann , "Kirill A . Shutemov" , Greg Kroah-Hartman , Kate Stewart , Mike Rapoport , kasan-dev , linux-doc@vger.kernel.org, LKML , Linux ARM , linux-sparse@vger.kernel.org, Linux Memory Management List , Linux Kbuild mailing list , Chintan Pandya , Jacob Bramley , Jann Horn , Ruben Ayrapetyan , Lee Smith , Kostya Serebryany , Mark Brand , Ramana Radhakrishnan , Evgeniy Stepanov On Mon, Jul 2, 2018 at 10:30 PM, Andrew Morton wrote: > OK, anecdotal experience works for me. But this is all stuff that > should have been in the changelog from day zero, please. It describes > the reason for the patchset's existence! I will add all those points to the cover letter in v5. On Tue, Jul 3, 2018 at 7:36 PM, Will Deacon wrote: > Hmm, but elsewhere in this thread, Evgenii is motivating the need for this > patch set precisely because the lower overhead means it's suitable for > "near-production" use. So I don't think writing this off as a debugging > feature is the right approach, and we instead need to put effort into > analysing the impact of address tags on the kernel as a whole. Playing > whack-a-mole with subtle tag issues sounds like the worst possible outcome > for the long-term. I don't see a way to find cases where pointer tags would matter statically, so I've implemented the dynamic approach that I mentioned above. I've instrumented all pointer comparisons/subtractions in an LLVM compiler pass and used a kernel module that would print a bug report whenever two pointers with different tags are being compared/subtracted (ignoring comparisons with NULL pointers and with pointers obtained by casting an error code to a pointer type). Then I tried booting the kernel in QEMU and on an Odroid C2 board and I ran syzkaller overnight. This yielded the following results. ====== The two places that look interesting are: is_vmalloc_addr in include/linux/mm.h (already mentioned by Catalin) is_kernel_rodata in mm/util.c Here we compare a pointer with some fixed untagged values to make sure that the pointer lies in a particular part of the kernel address space. Since KWHASAN doesn't add tags to pointers that belong to rodata or vmalloc regions, this should work as is. To make sure I've added debug checks to those two functions that check that the result doesn't change whether we operate on pointers with or without untagging. ====== A few other cases that don't look that interesting: Comparing pointers to achieve unique sorting order of pointee objects (e.g. sorting locks addresses before performing a double lock): tty_ldisc_lock_pair_timeout in drivers/tty/tty_ldisc.c pipe_double_lock in fs/pipe.c unix_state_double_lock in net/unix/af_unix.c lock_two_nondirectories in fs/inode.c mutex_lock_double in kernel/events/core.c ep_cmp_ffd in fs/eventpoll.c fsnotify_compare_groups fs/notify/mark.c Nothing needs to be done here, since the tags embedded into pointers don't change, so the sorting order would still be unique. Check that a pointer belongs to some particular allocation: is_sibling_entry lib/radix-tree.c object_is_on_stack in include/linux/sched/task_stack.h Nothing needs to be here either, since two pointers can only belong to the same allocation if they have the same tag. ====== Will, Catalin, WDYT?