Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp405610imm; Thu, 13 Sep 2018 01:37:46 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ4wP4UZZvUZA2CanXOe2hLMj/t3BlP8AMeBeeGmkUsfxfaNd+fL/2QjRNa/1s2wY33588O X-Received: by 2002:a65:5284:: with SMTP id y4-v6mr4930423pgp.283.1536827866936; Thu, 13 Sep 2018 01:37:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536827866; cv=none; d=google.com; s=arc-20160816; b=gVsM7zad3n1mtZVmqEOHuat1Q/pdbI9c/cUG8WacuRuPlzY/yWs7aF245hKKkfOZvq z5GWVjmMkLsOxrChtUeD0FgB53GqJLm0ZvPdDs1UPAk+uNPhWFlrwxLvvgfgSv8edimf rkEVx8+8f7l8O488/ffhgvc0SjRR3ZdoyFF+8XzjN0kiTAMXiUuzM6p+U9TwHehFn26q bI5ed21WzqN+qHJVVr270shrPTVOyjTP42u9/sOGdb1fxV3I0jI2gZhkGr7hCZloi80W F1zOHXGY2TV3Hfq7N805GmZL1dRIUxSz0ReXT9L+FqNydv59xtiGZ1oBlzSGetym2hk5 HJ3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=6Bb2A5n9HnIKxxiAYVSOIkWwld1KVWNHVDF2g+uXCCM=; b=EseWm1qACoHfHdshlaghmFgcB3W/D1FNw5AkG3h9mUPvlK07L44HY6uSa+vTgMuKsY 3TqRC2p2yIVJiJBvFjimYaXezIgi1IYsJcPmQTXhRM37iHY8UOOp3OnBfB1oSeKONYEF UbY7IdX/fpzOcjJUn+08WJGjrrTicxr84KNcZkL3AiJ36BDPdjMm5ZwgsvXRsTHqhWYn VY8cBaObVdqNXgcv/hY3R0THUD6z2enE6/YAEFlJUu9bdcNxGQcBC4Z8Wy6IPRRDrmf9 KK5mYSf7g4cQNWUUIxtEvLjNdAYGvmTXeiBtb7kaMaAsoPi8gLaTobmAuTExFVzIw3hL kyBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pDUeEFhd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q67-v6si3378190pga.63.2018.09.13.01.37.30; Thu, 13 Sep 2018 01:37:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pDUeEFhd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727781AbeIMNpt (ORCPT + 99 others); Thu, 13 Sep 2018 09:45:49 -0400 Received: from mail-it0-f65.google.com ([209.85.214.65]:34457 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726932AbeIMNps (ORCPT ); Thu, 13 Sep 2018 09:45:48 -0400 Received: by mail-it0-f65.google.com with SMTP id x79-v6so1168210ita.1 for ; Thu, 13 Sep 2018 01:37:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=6Bb2A5n9HnIKxxiAYVSOIkWwld1KVWNHVDF2g+uXCCM=; b=pDUeEFhdU3zyhg1x/HiI0W40JAo8WB6SaePlNyo8Q0n0V/q7tljZewVt2zTb4bq/xI MeT4IY7fqyJhiSJ/gr44MUgCFAkCz/PWQuaE5JHdKHNfNZ0Y8wTo5s7okWcbHhdz6dVq Niu7d2qmciT/wAlXFO3kbI9Q8JDMcWEL90exZVIruYcyGk/x6GuQOG6L4y7ZD0L7fgB9 IrhCzO38rx8QlFqc6Vz35yF7UO5w7bx3EKO69D99ARAyuEbRlmrFQMlJ6ekhVmQYywJM 6wlYnlASoI34Qk5Ptf+olmJ4ka7wfm/zD4tQ2iPbFzDPq/lav+saA1jtaPkswb1CbIKr 2T2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=6Bb2A5n9HnIKxxiAYVSOIkWwld1KVWNHVDF2g+uXCCM=; b=RrJ9C4KglYHj+JaOCE7/h+ic5p2+P1GiP+gPQJ6AaHK/tV0oZIwf+C6lt0Ogls/cbe U6hXFDsbvEUiCVr5oN6jCtUGhz4JdSltPs9Fh3hx4HUTeKpOJAwMkqkRjDPbXgoqS/Un jAh+uuf58Soe2VdAF2hEuXP4x3BCcKo6iFRQOy4QpFNS0Rm2VU7ACGVDKZuVj1iszmOW fwarXgA3cdTEuk1F2DX8/2Z14xFPZEnX86Kg5W5hrM44h9968uBMAh+bmuEL9Ojkwz8M 0SJsnQxROfe7xEw2f5JjVmqoeCBDajDGPSa44vRSop+l6tblRNC27mjc+NdOBwT3bdgZ ijKw== X-Gm-Message-State: APzg51DRASuOkMcw8oFZFfoMc+kHfU3qv2/UnUPXQj5UbHQq4rf33ePi g/RHf781NNGR8BX4mmTh4DU0F4UAoBB47SWjMS8+1A== X-Received: by 2002:a02:4009:: with SMTP id n9-v6mr5701091jaa.19.1536827840777; Thu, 13 Sep 2018 01:37:20 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a02:5942:0:0:0:0:0 with HTTP; Thu, 13 Sep 2018 01:37:00 -0700 (PDT) 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 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.