Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2826930pxk; Tue, 15 Sep 2020 03:28:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyegLvIkP1yhGfZSAFZ8VdUJBXJ1IGy68pO9U8xgcW0uIxFrtY6niYF09UZS3537wFBuaQW X-Received: by 2002:a17:906:af6a:: with SMTP id os10mr18872679ejb.34.1600165688898; Tue, 15 Sep 2020 03:28:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600165688; cv=none; d=google.com; s=arc-20160816; b=P8kkAQLheUxcQCGg+KNWwd+jVYQk9bUC17bsPFzpkHb2mO0jnuZTskplCgCWwRo1tO kM9k4rF2uEozfd7JI+YzNZZaAIGWjzimUYhMhdZxbEJWYRprfPYk1hnuTqGIgCMcY0HE 2wLpV1P7Mb2j5XWK4UJ+RW1kxHFVvDZk5AjuQ/HXka2eNwZfmd3LCO2Wk9rLZy+7xZOu 2DXJx2DULfP1T4lNmdyyVNt89qlTvqLyrywNrZnXIGEqyYEHQBexvHeEfXo1MWyfqyzF JOIQEmbzaZbxpQPzOf/rpMz98Fn2pOVw0mdqG0m/n/eeEolMSFKTopEkwxsSGSKDWaYs 4Uag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=nCObEKoOnmpHrzYJFBm9pkBKEq9SNCMkpHaxOskN+KQ=; b=hPIdlFfrUfHmrq4X1vI6FW/CngZMTEEdLa9h0AhM8DS/eHqN4KV4S35zZfo+hBMJFm eH2x1eqboPcYJnrGvXgEB6XBfm+yF1c8JWxWm8mZNZ7uRsISvZfriSl79KkRIk4QJlPp m4YIibRrN/qqWfHrwZlPYODDe1iF/1Ehp5HVq+0FlODfKV0AGMQUiJyp+coQ8TxNP5JR SLN+BXBtYEa3US2S6D3gfjReei7sPHnLB+ejTGX20ygIeGTUx7Tb3oGkYLh9GDESiw3P AjArGc0qPQzXo0nzZrULHi48folXLDXV5w/h2UrmJrhBlfrI8+HjIU7JKqqFllsqx/tR fgJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=vbBJy4kw; 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 q24si7639212edi.78.2020.09.15.03.27.46; Tue, 15 Sep 2020 03:28:08 -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=vbBJy4kw; 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 S1726131AbgIOKZK (ORCPT + 99 others); Tue, 15 Sep 2020 06:25:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726102AbgIOKZD (ORCPT ); Tue, 15 Sep 2020 06:25:03 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 839D3C06174A for ; Tue, 15 Sep 2020 03:25:02 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id d4so2798666wmd.5 for ; Tue, 15 Sep 2020 03:25:02 -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=nCObEKoOnmpHrzYJFBm9pkBKEq9SNCMkpHaxOskN+KQ=; b=vbBJy4kwOuP8fps7ENGxPva5zUYL7ASA78U0Ik7uGtyQwbCdxLIDc5R+Lkce3LiyG9 tLhWib3rO23PtT7aBoJi1Wh5s5YnYthzHConFQ9L9lfT5mJzO+PvYFbCpNkD3Y3Y5pV7 ccjX2TexQXkFDZFRXCF4Vu7sGsVYCi2n6CfR+ga+FrmT/CM19VfdHrlV+uoAyQb7Wnux Ua6jN3ov5SDmM4C4t32H7+HFTozTlN8q3kPzjcNZy74cI/nUj7maUu2W1Xv0iRcsns8V 7sMEIca6qA/KcCQnNsC8rCvlnSY3mxClh6VbPDZTXsnqTmoM6xWaK0XxddnzL4J3SJO6 b+3A== 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=nCObEKoOnmpHrzYJFBm9pkBKEq9SNCMkpHaxOskN+KQ=; b=PeeopoQAlekOqLOE0E5lm7VHUkm9NYexnrhBgQdt00tFf0UEOoPxfxHOjZwjpEIkZT xqLl/0tGl0Zva1PTgjwHz7v8sWwIVgS4PlF607PfKIyKwJHB4380wmO1QrFeTh398b7C L8pD3y1zMZsqvveIaty/uaUhkOLrXmRAQ9QxXM9Tn5gM0HgXfuV/78oUk8/LgJ7L6nSf tdwvb4HiDAtsmIqUKz22bywZjWZxTu87iy23XcdVi52xTJu0stxpLP3vNc0f/c0yQXl7 r0GJQWan4FmCPDMotyG/p5EcHvhT8r9MY2/iJldOOoLMNxFtGGDyQprTMZpjjEWTDVSM yE6g== X-Gm-Message-State: AOAM530GSmw1QKW0E2ght80ZDPXlrUk71yBLvlEYQr6GQZrsXVXNEzEs Mrgcl9BK4RvSsUqaZzc8HxFu7w== X-Received: by 2002:a1c:2e08:: with SMTP id u8mr4155025wmu.156.1600165500941; Tue, 15 Sep 2020 03:25:00 -0700 (PDT) Received: from google.com (49.222.77.34.bc.googleusercontent.com. [34.77.222.49]) by smtp.gmail.com with ESMTPSA id w15sm27651716wro.46.2020.09.15.03.25.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2020 03:25:00 -0700 (PDT) Date: Tue, 15 Sep 2020 10:24:58 +0000 From: George Popescu To: Kees Cook Cc: maz@kernel.org, catalin.marinas@arm.com, will@kernel.org, masahiroy@kernel.org, michal.lkml@markovi.net, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, clang-built-linux@googlegroups.com, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, natechancellor@gmail.com, ndesaulniers@google.com, dbrazdil@google.com, broonie@kernel.org, maskray@google.com, ascull@google.com, akpm@linux-foundation.org, dvyukov@google.com, elver@google.com, tglx@linutronix.de, arnd@arndb.de Subject: Re: [PATCH 06/14] Fix CFLAGS for UBSAN_BOUNDS on Clang Message-ID: <20200915102458.GA1650630@google.com> References: <20200914172750.852684-1-georgepope@google.com> <20200914172750.852684-7-georgepope@google.com> <202009141509.CDDC8C8@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202009141509.CDDC8C8@keescook> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > That sounds like a compiler bug? Actually in clang 12 documentation is written that -fsanitize=bounds expands to that. GCC doesn't have those two options, only the -fsanitize=bounds which looks similar to -fsanitize=array-bounds from clang. So I don't see it as a compiler bug, just a misuse of flags. > > Signed-off-by: George Popescu > > --- > > scripts/Makefile.ubsan | 9 ++++++++- > > 1 file changed, 8 insertions(+), 1 deletion(-) > > > > diff --git a/scripts/Makefile.ubsan b/scripts/Makefile.ubsan > > index 27348029b2b8..3d15ac346c97 100644 > > --- a/scripts/Makefile.ubsan > > +++ b/scripts/Makefile.ubsan > > @@ -4,7 +4,14 @@ ifdef CONFIG_UBSAN_ALIGNMENT > > endif > > > > ifdef CONFIG_UBSAN_BOUNDS > > - CFLAGS_UBSAN += $(call cc-option, -fsanitize=bounds) > > + # For Clang -fsanitize=bounds translates to -fsanitize=array-bounds and > > + # -fsanitize=local-bounds; the latter adds a brk right after the > > + # handler is called. > > + ifdef CONFIG_CC_IS_CLANG > > + CFLAGS_UBSAN += $(call cc-option, -fsanitize=array-bounds) > > This would mean losing the local-bounds coverage? Isn't that for locally > defined arrays on the stack? 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. > > + else > > + CFLAGS_UBSAN += $(call cc-option, -fsanitize=bounds) > > + endif > > endif > > > > ifdef CONFIG_UBSAN_MISC > > -- > > 2.28.0.618.gf4bc123cb7-goog > > > > -- Thanks, George