Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp344022pxk; Thu, 17 Sep 2020 04:48:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9/aiPUWJH5a97IFxDHdm8cg3+bAuYHI3TtNVbM4v9XTu168bReJZr+xlWn+j1UeKWqd/r X-Received: by 2002:a17:906:b813:: with SMTP id dv19mr29866719ejb.70.1600343311455; Thu, 17 Sep 2020 04:48:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600343311; cv=none; d=google.com; s=arc-20160816; b=cRZumP1tv9Avmw1/A6f+1dWdcYP8rKsDq+TJazorDJAgKwMztHCsgVtMOIA2aIk025 tuT1cc9g7dRHBP8Gh6DHOFIfqNzhKU19kLi3g0QkQY0XKM1MFJXn2mTrA1CIVALWNCtF d7lDOvylEYs+BgWt3R6w3Ee2xrvCIvhviJPGWQpdXmRYA/05bRO+MMXwfBWi30ZCxphO vUlT/XCi+3lwPScQ4q5E6+fklhP3dkVRnewo9X9T05Ybc7+got5D/27U/kqZYrawGpsj tlB+kdQgDx8p8QHjXeqCsZrb/Rh8eM+ULCwPiSTfl/F7dEWZ3wB17uft19WrE3yvQRTT f1JQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=EtH4/cbuQgykQYd+jjjiuY8limbLr894Hm1Wfr5TKQE=; b=gLHQJC54NMIU+h09DaKIy8Q//tvXapyB70JlBMhDBLwsjKAO9Fz0MPanwz2xPijrCA R4EzHdIKMR1S+BVYeOgNrZgk9Uynh1jrWZ91uvnCHrt7i4RSCkqbO4J6r/jnj+xrK5P1 X46lPv6VpCVdNLXc0e5KIqA0jeI20YW+6lCLWzbktfhsJgBtnd4SgdCZoSHvue9DrkB4 nOvGg0H/2YMurocWNDK75+PUIwJQXXs8MNyo2UAEmVkmnCrFrQTDSTkGNkaluIEX5m7L 4V+xZRvcYr2lqy7BZN6yo6/bzPT3WzZVbmF7WZYsvE0Lpm8ciiY5M/tj63i2L5ayTxbu g34Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=MZtwfo2W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id bc11si14475159edb.532.2020.09.17.04.48.07; Thu, 17 Sep 2020 04:48:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=MZtwfo2W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726845AbgIQLqp (ORCPT + 99 others); Thu, 17 Sep 2020 07:46:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726871AbgIQLgJ (ORCPT ); Thu, 17 Sep 2020 07:36:09 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6A9DC06174A for ; Thu, 17 Sep 2020 04:35:45 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id k15so1678634wrn.10 for ; Thu, 17 Sep 2020 04:35:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=EtH4/cbuQgykQYd+jjjiuY8limbLr894Hm1Wfr5TKQE=; b=MZtwfo2Wkr6xjMeQYiz0AzKCHXOeKN48g2ul8ghIqc3xiqk9zQf+HOBZ+UHRPpswvD 9SBgHRwMaFLJDl27uhHNtO8R/rVQPrHwHvld1k1cSpz8o0eAbb3ZsN9tjQpOpqlJKGlW GrwSOQnzS9k0pLp3WVTGsfCkX2nwuK4/KULnQidX0PveC+EMFDCZsR5EPDsAU4hnW/C4 FwjND5Y6WgjF+MR48bLLBhiZwio2a9ADpBpQiFIj+6TTVuegNGnGK+5dwnjCcZZiHSIO 9G8jASY5hC9NeCi7D/s0svoVNRSESbWKf5XK5jmgjExYi5hfODHSRbI3XH+jyy9nFahP i+zA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=EtH4/cbuQgykQYd+jjjiuY8limbLr894Hm1Wfr5TKQE=; b=Tt5XVNOTMvW+YunuYgEiU8pt8p/CUVKx/nDmVyXfu2aXBAFh2Amgh9/o7BKne+KvXM rSgdTKsPZ8DCLkFdd/Xje7vE/sWVjMGexgbeN1jqlvl3+ZoEeyikowpZqJvs14CCFI8W B25rrwbka1FrnqBLqdOzz72tBuMr9Vvf/5fYwSapa4gh0zTP8itOcfOdpCsKP2lz0E+k vfzC6tICZ4x4Y+paEugm/r4AFJ8FOH83Puq9NP3a3IWtvBqbm6qoDY6IeQpdsVDByFDM KFwti5VP+wpc7sgxXHPhjo/+KdYaLwliVpnDsIjOyx/z3Jiy4VLmAotReeZZO1amWH8X Fcng== X-Gm-Message-State: AOAM531WXZfyrAVel6NUOg3d7+2vy5w4mN5v982qoBUrme4I/n/bidnG Jn7LHUzD5dgRHLbcXwM6PIF3Ug== X-Received: by 2002:adf:df87:: with SMTP id z7mr32658549wrl.239.1600342544219; Thu, 17 Sep 2020 04:35:44 -0700 (PDT) Received: from google.com (49.222.77.34.bc.googleusercontent.com. [34.77.222.49]) by smtp.gmail.com with ESMTPSA id f14sm10591991wme.22.2020.09.17.04.35.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 04:35:42 -0700 (PDT) Date: Thu, 17 Sep 2020 11:35:40 +0000 From: George Popescu To: Marco Elver Cc: Kees Cook , maz@kernel.org, Catalin Marinas , Will Deacon , Masahiro Yamada , Michal Marek , Linux ARM , kvmarm@lists.cs.columbia.edu, LKML , Linux Kbuild mailing list , clang-built-linux , james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, Nathan Chancellor , Nick Desaulniers , David Brazdil , broonie@kernel.org, Fangrui Song , Andrew Scull , Andrew Morton , Dmitry Vyukov , Thomas Gleixner , Arnd Bergmann , kasan-dev , Andrey Konovalov , Alexander Potapenko Subject: Re: [PATCH 06/14] Fix CFLAGS for UBSAN_BOUNDS on Clang Message-ID: <20200917113540.GA1742660@google.com> References: <202009141509.CDDC8C8@keescook> <20200915102458.GA1650630@google.com> <20200915120105.GA2294884@google.com> <20200916074027.GA2946587@google.com> <20200916121401.GA3362356@google.com> <20200916134029.GA1146904@elver.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 17, 2020 at 08:37:07AM +0200, Marco Elver wrote: > On Wed, 16 Sep 2020 at 15:40, Marco Elver wrote: > > On Wed, Sep 16, 2020 at 12:14PM +0000, George Popescu wrote: > > > On Wed, Sep 16, 2020 at 10:32:40AM +0200, Marco Elver wrote: > > > > On Wed, 16 Sep 2020 at 09:40, George Popescu wrote: > > > > > On Tue, Sep 15, 2020 at 07:32:28PM +0200, Marco Elver wrote: > > > > > > On Tue, 15 Sep 2020 at 14:01, George Popescu wrote: > > > > > > > On Tue, Sep 15, 2020 at 01:18:11PM +0200, Marco Elver wrote: > > > > > > > > On Tue, 15 Sep 2020 at 12:25, George Popescu wrote: > > > > > > > > > On Mon, Sep 14, 2020 at 03:13:14PM -0700, Kees Cook wrote: > > > > > > > > > > On Mon, Sep 14, 2020 at 05:27:42PM +0000, George-Aurelian Popescu wrote: > > > > > > > > > > > From: George Popescu > > > > > > > > > > > > > > > > > > > > > > When the kernel is compiled with Clang, UBSAN_BOUNDS inserts a brk after > > > > > > > > > > > the handler call, preventing it from printing any information processed > > > > > > > > > > > inside the buffer. > > > > > > > > > > > For Clang -fsanitize=bounds expands to -fsanitize=array-bounds and > > > > > > > > > > > -fsanitize=local-bounds, and the latter adds a brk after the handler > > > > > > > > > > > call > > > > > > > > > > > > > > > > > > > This would mean losing the local-bounds coverage. I tried to test it without > > > > > > > > > local-bounds and with a locally defined array on the stack and it works fine > > > > > > > > > (the handler is called and the error reported). For me it feels like > > > > > > > > > --array-bounds and --local-bounds are triggered for the same type of > > > > > > > > > undefined_behaviours but they are handling them different. > > > > > > > > > > > > > > > > Does -fno-sanitize-trap=bounds help? > > [...] > > > > Your full config would be good, because it includes compiler version etc. > > > My full config is: > > > > Thanks. Yes, I can reproduce, and the longer I keep digging I start > > wondering why we have local-bounds at all. > > > > It appears that local-bounds finds a tiny subset of the issues that > > KASAN finds: > > > > http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20131021/091536.html > > http://llvm.org/viewvc/llvm-project?view=revision&revision=193205 > > > > fsanitize=undefined also does not include local-bounds: > > > > https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-checks > > > > And the reason is that we do want to enable KASAN and UBSAN together; > > but local-bounds is useless overhead if we already have KASAN. > > > > I'm inclined to say that what you propose is reasonable (but the commit > > message needs to be more detailed explaining the relationship with > > KASAN) -- but I have no idea if this is going to break somebody's > > usecase (e.g. find some OOB bugs, but without KASAN -- but then why not > > use KASAN?!) > > So, it seems that local-bounds can still catch some rare OOB accesses, > where KASAN fails to catch it because the access might skip over the > redzone. > > The other more interesting bit of history is that > -fsanitize=local-bounds used to be -fbounds-checking, and meant for > production use as a hardening feature: > http://lists.llvm.org/pipermail/llvm-dev/2012-May/049972.html > > And local-bounds just does not behave like any other sanitizer as a > result, it just traps. The fact that it's enabled via > -fsanitize=local-bounds (or just bounds) but hasn't much changed in > behaviour is a little unfortunate. > I suppose there are 3 options: > > 1. George implements trap handling somehow. Is this feasible? If not, > why not? Maybe that should also have been explained in the commit > message. > > 2. Only enable -fsanitize=local-bounds if UBSAN_TRAP was selected, at > least for as long as Clang traps for local-bounds. I think this makes > sense either way, because if we do not expect UBSAN to trap, it really > should not trap! > > 3. Change the compiler. As always, this will take a while to implement > and then to reach whoever should have that updated compiler. > > Preferences? Considering of what you said above, I find option 2 the most elegant. The first one doesn't sound doable for the moment, also the third. I will edit this patch considering your comments and resend it to the list. Thank you for your support. Thanks, George