Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1850432pxb; Wed, 20 Oct 2021 13:04:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx93xqW50pI7G//BWyKSOQq8dSrCTeSW6y+v9VGBlBK+DwQivCDFuQfvzSqPluyMaUXphQG X-Received: by 2002:a17:906:b803:: with SMTP id dv3mr1701876ejb.289.1634760253475; Wed, 20 Oct 2021 13:04:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634760253; cv=none; d=google.com; s=arc-20160816; b=BKc7Fksiq5d9lr8pQ54XDjOY0QRonpaTayKhVTHQr6o23n+hVWsJ4heXQUs59Eg3MI DBXiPToiRusMon8gD6cDABJbZeu4GjpsaQ6K0Xx5cD9Is+6gkbG49Y2O4Be4IKLkohcO duSpNy93iy1ynz2+LVe+k3/D0Fcy+u0Ny9Bt4S2s66rhXF3h6Ak1UXWc9fJ5JOVdfwwI oFd4Tg0xNO341pD5zvsQFqmMFdJrQOBc6JN75YqS+PIwf3Okb9l9sJ0JTnvg5tpkCRpu TdnyWgk6en9TBxtVd0wr2TtKFC7p0FM7G27qf5ivqQ5S59VRgjJ8Xtxlssbb+YpYWw4S stRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=oC4xL40TX4gXKdUr3q9ajhThG3X3Mfmq07w1fzRH4Aw=; b=BR0O94EA6IoEbACi2nNUhHhg+WJ7lXFEpTVQ/TvrncVvd6sBEef+0fwzKuplz9uPop 1mGsrQAYuS6TfWxnUv5z1tYIrA5HpqH2aLbSG5UNRbPM4DE6K5UfEM4MkMFcz10MIx3G HBtyqAIpnnqJe7BHCXV0agoKkvVbipAzcpc0ivxvshRwSNZSF8Ze0LM0y0o/kPBOhcsM 8ZaRQxrB9Le2qq+lozGwj1ZKmBP/J7FKrYExs0GG0b+L/NIOWdcHUtMroYFYEeTt2sal Sei7/DoEkqTeojVLADHuvz7XXvAQNUnoXDVf9kPYyzOKFY+8yY1HXsa95pxD6GrXJtqm Tc9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=OmdDlCIt; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n4si4176290edv.329.2021.10.20.13.03.26; Wed, 20 Oct 2021 13:04:13 -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=@chromium.org header.s=google header.b=OmdDlCIt; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231143AbhJTUC5 (ORCPT + 99 others); Wed, 20 Oct 2021 16:02:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231485AbhJTUC5 (ORCPT ); Wed, 20 Oct 2021 16:02:57 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6396DC06161C for ; Wed, 20 Oct 2021 13:00:42 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id e10so12006937plh.8 for ; Wed, 20 Oct 2021 13:00:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=oC4xL40TX4gXKdUr3q9ajhThG3X3Mfmq07w1fzRH4Aw=; b=OmdDlCItAcCb/kTnNchESefFDugeJRmqEOURb8x56zQo5I5kRPFFNpZ3AZHKV3RgdH odz+moYgtrmUkutIShXd8I7cTi4l7Vl4MiDSTLbkBlPJpUzM/jnX15Bvbae1BrUGSwnr BucewZViScIzDAeYr+Z6HUxqtNPww80bAlcw0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=oC4xL40TX4gXKdUr3q9ajhThG3X3Mfmq07w1fzRH4Aw=; b=fIeISpv70yFhXuwErzbyYGgwBFDqELdSRd5S5IyE0oNsdbGocJyE1YWcqP9FeIlL+i w/zG+CEZWPSQOF847DrHpnmGFmMdMHVg9LCq7W5QbxDPf7PEvRZd4nchM2npGCO06co8 HP55vWkNJaiOPZMLBfkOIvCaV2sGM2TUwSPsYbQkOtl5mYA0FzGPSPFllCg7YxEXaCJu HKkcbuL2rPKQ3LMkYLjADCk01om4MuVyPML8GY9pQHRxAAiGeeNfxVJxXVyWEH7a5+EV 1H0dD8NJEZbX8VNcbnQknCGGlTOnENu+BIhVOudSXp5OV2P2P3t6ynVUfKJBIryKiXf4 GN3A== X-Gm-Message-State: AOAM531mZ1aggt/nW2asmsCSsbI8p99s/JoNsinWnVmnjE30wTvF5+CJ r5eG2Y+RlFpYZ2glzumEQIbx8Q== X-Received: by 2002:a17:90a:ba94:: with SMTP id t20mr1252632pjr.138.1634760041858; Wed, 20 Oct 2021 13:00:41 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id c24sm3395267pgj.63.2021.10.20.13.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 13:00:41 -0700 (PDT) From: Kees Cook To: Miguel Ojeda Cc: Kees Cook , Arnd Bergmann , Nathan Chancellor , 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: [PATCH] compiler-gcc.h: Define __SANITIZE_ADDRESS__ under hwaddress sanitizer Date: Wed, 20 Oct 2021 13:00:39 -0700 Message-Id: <20211020200039.170424-1-keescook@chromium.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2522; h=from:subject; bh=+AiIfOEWeU4E8zLDOWbiVHd+8UI+lXGPUfqkac57NL8=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBhcHVme5xsJftDfqmCCSgSYRYO6v7mHerNYn5Qyc6C BdJDITyJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCYXB1ZgAKCRCJcvTf3G3AJn6rD/ 9CXjeQGLjf3oKlM6TefCvtpbxL4/ogO5zIGXingOCOmIkTeHY9aC1xQlWJlNU92OMNrNQJ9R6tU7mj hGSwd3u0IrZokg9OjaDGX1gYqrcxbtUlqp3yOgA6CR04920Ck1Ymg7gnv2p4DPSS5oMLZ6Fk5Z7aRp D0aKpCQlBUwvE8wp2/kQSdyJ5lKillOvaVBIK8Hud/yLPlHZi/LtNaC7DP6yT+OaCFBgE/o8T14fEC 7MfAhnUVNLkC5KCZtj3dA2zzUY1CvbzOHNyEdUorP8QcgiaWOR49E6gKrrxaPRheOIahz1qzOpfuyP GM3YbY4v6HIOQU72kDHavZfOo/bmiVXLwivVfKage1nJu6O1nSDiqkm9tfkLjDbzrdR7SR8cKYEdbj X2zBRXCQQq2yfaPIKVYIO8N5fPROW8WoQgdMqmfegeBjD/QQVSGVYPQMm1M30I1lV4K2N2H+gupzlm EhXmmU0Z7bBAKxTlPRJSIb7GtfLrjEC9NrOAKXiX09GOGJlmV6/I2Cm6KPo1WNNdU8tXHY8ClFvGzY rldZo6Bq35Ff3oXFAcWNeGDRDnGSRKkmFpj1Vv86OnQH7cnX9pmvnaAx+Qa/KuzYw0XvlFxTOMESdb OeV7Ic+Z33LM4bzofOue5WZCp3HcpGv7+Fy2SBnjzRMgzpsQGigkHLOl4QHQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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