Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1933485pxb; Wed, 20 Oct 2021 15:00:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7TL1DUy/jDTB1/MktkpEXa6eP/1VLZoW79Z9Py0hjEP4fDEkpobT3lqZUepS6sZR++/eK X-Received: by 2002:a17:902:be17:b0:13f:3fa3:1f16 with SMTP id r23-20020a170902be1700b0013f3fa31f16mr1535175pls.83.1634767248521; Wed, 20 Oct 2021 15:00:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634767248; cv=none; d=google.com; s=arc-20160816; b=uaWSO1hutfHOKIFskbLZ/ZFEmcNfh5N5qQaLl4/nAGq/My0Lac0xiyNSVm+w99BBEs U02vGm+QGEaTd/qXkrYhlJDQ/bNqh8/+A9Cro4NJeQhGsjap0CC7t/7Lm85h0fMuaEnw o87dhY1jnyL8TChHvuyYxo8oWHElGxUgXS1wbqBq3EfM7pJbwsfs483swYGkBylyF0J7 uGImnzKLbVEoPQOmqEZX51IZZ52bS6IswEmblItkxtr6N9g5sWibyQAI/x8EJPS/a5en /hftL2AySEkoiOFY3HmQ7oekHMt7Tm0JZdthKq5Q7JCZl28Dnke6wAhcca06E3pwrPRL RUiQ== 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=ViTBTUNx1zM0yXUKEFauwaOTmCn4LlpijDtdPdFA6Xc=; b=wEBUXcFzjThuOOblocH7PT1EZVfebaSdmCL2j/yzQGU2o7/hqaXDUDwu5113gqvaHT hHjQhkla66r58KAUzggQTH9VFaVN1PMxZk2I3RKQqIElj3dMZu+rxoycKgjvbIUF4e1v fNJqMfRaEAbWowfjv9PKtTFoFKmQWzG5rLuMAYnR/HfyP6woM3flW0vTY/9IcsuFNcvP fvRIgk2vgc925nAekWzzCq/I21zNLYHnUK9Aa/Fk3XmMYKschSA7o6aKZXnrNvWf92nl IjYPE14vso1PV9+rHPw6KIEMimpjj+76UK+2dKil1FD41IgB0Ior6s7nAIHjC4ftoWBz f2ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mYND7Su8; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t190si1846669pgd.313.2021.10.20.15.00.34; Wed, 20 Oct 2021 15:00:48 -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=@kernel.org header.s=k20201202 header.b=mYND7Su8; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230325AbhJTWBs (ORCPT + 99 others); Wed, 20 Oct 2021 18:01:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:60310 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229695AbhJTWBr (ORCPT ); Wed, 20 Oct 2021 18:01:47 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F030E611CB; Wed, 20 Oct 2021 21:59:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634767172; bh=p/FrOCkd3lRrm2AfwEqVbzWLSKdO/oVRmjDk7ncCiIo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=mYND7Su80MFf6on5xybMBeQ3xq3iEPl3QFGuUPqq886JJm9kANRaq5nIg7JyfWyhj IujPCDxkdoDXx9DQcX5UAPJAcLl0ufZJW/j6XvlYEdY5nXqTxepLwwq0XXNsMXkTLx lnWr7zmXqnhNYPne9hBhBO+qSEkm9iHcv7mMm7RMaRsgcElkyLW3MdiAwxos0Oyxk1 DB86QqE6CDENE7xjacxOWji28VLhavIhqiiAZqVQVhCiJai3HwS+EZqiXJ9Yju5iYr nPzzLq7pSSXxWOKC3DSheXU3bukzE6mJXQleTLgM6Fq62SzHDS5a0iW7Ol5pOSWtCW Xqz3gVZeNkFcA== Date: Wed, 20 Oct 2021 14:59:26 -0700 From: Nathan Chancellor To: Kees Cook Cc: Miguel Ojeda , Arnd Bergmann , Nick Desaulniers , Andrew Morton , Marco Elver , Will Deacon , Arvind Sankar , Masahiro Yamada , llvm@lists.linux.dev, Ard Biesheuvel , Luc Van Oostenryck , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] compiler-gcc.h: Define __SANITIZE_ADDRESS__ under hwaddress sanitizer Message-ID: References: <20211020200039.170424-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211020200039.170424-1-keescook@chromium.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 20, 2021 at 01:00:39PM -0700, Kees Cook wrote: > When Clang is using the hwaddress sanitizer, it sets __SANITIZE_ADDRESS__ > explicitly: > > #if __has_feature(address_sanitizer) || __has_feature(hwaddress_sanitizer) > /* Emulate GCC's __SANITIZE_ADDRESS__ flag */ > #define __SANITIZE_ADDRESS__ > #endif > > Once hwaddress sanitizer was added to GCC, however, a separate define > was created, __SANITIZE_HWADDRESS__. The kernel is expecting to find > __SANITIZE_ADDRESS__ in either case, though, and the existing string > macros break on supported architectures: > > #if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ > !defined(__SANITIZE_ADDRESS__) > > where as other architectures (like arm32) have no idea about hwaddress > sanitizer and just check for __SANITIZE_ADDRESS__: > > #if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) > > This would lead to compiler foritfy self-test warnings when building > with CONFIG_KASAN_SW_TAGS=y: > > warning: unsafe memmove() usage lacked '__read_overflow2' symbol in lib/test_fortify/read_overflow2-memmove.c > warning: unsafe memcpy() usage lacked '__write_overflow' symbol in lib/test_fortify/write_overflow-memcpy.c > ... > > Sort this out by also defining __SANITIZE_ADDRESS__ in GCC under the > hwaddress sanitizer. > > Suggested-by: Arnd Bergmann > Cc: Nathan Chancellor > Cc: Nick Desaulniers > Cc: Miguel Ojeda > Cc: Andrew Morton > Cc: Marco Elver > Cc: Will Deacon > Cc: Arvind Sankar > Cc: Masahiro Yamada > Cc: llvm@lists.linux.dev > Signed-off-by: Kees Cook Reviewed-by: Nathan Chancellor > --- > I'm intending to take this via my overflow series, since that is what introduces > the compile-test regression tests (which found this legitimate bug). :) > > -Kees > --- > include/linux/compiler-gcc.h | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h > index 6f24eb8c5dda..ccbbd31b3aae 100644 > --- a/include/linux/compiler-gcc.h > +++ b/include/linux/compiler-gcc.h > @@ -121,6 +121,14 @@ > #define __no_sanitize_coverage > #endif > > +/* > + * Treat __SANITIZE_HWADDRESS__ the same as __SANITIZE_ADDRESS__ in the kernel, > + * matching the defines used by Clang. > + */ > +#ifdef __SANITIZE_HWADDRESS__ > +#define __SANITIZE_ADDRESS__ > +#endif > + > /* > * Turn individual warnings and errors on and off locally, depending > * on version. > -- > 2.30.2 >