From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-it0-f70.google.com (mail-it0-f70.google.com [209.85.214.70]) by kanga.kvack.org (Postfix) with ESMTP id 098578E0001 for ; Thu, 13 Sep 2018 04:37:23 -0400 (EDT) Received: by mail-it0-f70.google.com with SMTP id q5-v6so7545056ith.1 for ; Thu, 13 Sep 2018 01:37:23 -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 68-v6sor1996509jaf.94.2018.09.13.01.37.21 for (Google Transport Security); Thu, 13 Sep 2018 01:37:21 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Dmitry Vyukov Date: Thu, 13 Sep 2018 10:37:00 +0200 Message-ID: Subject: Re: [PATCH v6 15/18] khwasan, arm64: add brk handler for inline instrumentation Content-Type: text/plain; charset="UTF-8" Sender: owner-linux-mm@kvack.org List-ID: To: Jann Horn Cc: Andrey Konovalov , Andrey Ryabinin , Alexander Potapenko , Catalin Marinas , Will Deacon , Christoph Lameter , Andrew Morton , Mark Rutland , Nick Desaulniers , Marc Zyngier , Dave Martin , 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, kernel list , Linux ARM , linux-sparse@vger.kernel.org, Linux-MM , "open list:KERNEL BUILD + fi..." , Kostya Serebryany , Evgenii Stepanov , Lee Smith , Ramana Radhakrishnan , Jacob Bramley , Ruben Ayrapetyan , Mark Brand , Chintan Pandya , Vishwath Mohan On Wed, Sep 12, 2018 at 7:39 PM, Jann Horn wrote: > On Wed, Sep 12, 2018 at 7:16 PM Dmitry Vyukov wrote: >> On Wed, Aug 29, 2018 at 1:35 PM, Andrey Konovalov wrote: > [...] >> > +static int khwasan_handler(struct pt_regs *regs, unsigned int esr) >> > +{ >> > + bool recover = esr & KHWASAN_ESR_RECOVER; >> > + bool write = esr & KHWASAN_ESR_WRITE; >> > + size_t size = KHWASAN_ESR_SIZE(esr); >> > + u64 addr = regs->regs[0]; >> > + u64 pc = regs->pc; >> > + >> > + if (user_mode(regs)) >> > + return DBG_HOOK_ERROR; >> > + >> > + kasan_report(addr, size, write, pc); >> > + >> > + /* >> > + * The instrumentation allows to control whether we can proceed after >> > + * a crash was detected. This is done by passing the -recover flag to >> > + * the compiler. Disabling recovery allows to generate more compact >> > + * code. >> > + * >> > + * Unfortunately disabling recovery doesn't work for the kernel right >> > + * now. KHWASAN reporting is disabled in some contexts (for example when >> > + * the allocator accesses slab object metadata; same is true for KASAN; >> > + * this is controlled by current->kasan_depth). All these accesses are >> > + * detected by the tool, even though the reports for them are not >> > + * printed. >> > + * >> > + * This is something that might be fixed at some point in the future. >> > + */ >> > + if (!recover) >> > + die("Oops - KHWASAN", regs, 0); >> >> Why die and not panic? Die seems to be much less used function, and it >> calls panic anyway, and we call panic in kasan_report if panic_on_warn >> is set. > > die() is vaguely equivalent to BUG(); die() and BUG() normally only > terminate the current process, which may or may not leave the system > somewhat usable, while panic() always brings down the whole system. > AFAIK panic() shouldn't be used unless you're in some very low-level > code where you know that trying to just kill the current process can't > work and the entire system is broken beyond repair. > > If KASAN traps on some random memory access, there's a good chance > that just killing the current process will allow at least parts of the > system to continue. I'm not sure whether BUG() or die() is more > appropriate here, but I think it definitely should not be a panic(). Nick, do you know if die() will be enough to catch problems on Android phones? panic_on_warn would turn this into panic, but I guess one does not want panic_on_warn on a canary phone.