Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1427090rwi; Wed, 19 Oct 2022 10:24:29 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5SLJsrPWa4wOPZYx+52Wf1njtRLJ7Dn0kvjB/KAQMTWBcDIFvjRHe1fsTiCMAxbEXPD1Mk X-Received: by 2002:a17:902:ead1:b0:181:991f:2d25 with SMTP id p17-20020a170902ead100b00181991f2d25mr9643810pld.107.1666200268997; Wed, 19 Oct 2022 10:24:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666200268; cv=none; d=google.com; s=arc-20160816; b=LnqGgo3qbG4iP/BCRHqPol7Oe83kcubgrMQ6LJUd8WIvO5idydSGvyhoqsqVIjWtVj 5OuOsX25TtGXHB0xeLzbna9UadeoJifUrxJrPvHHm7KE/zRJtMFy/vYKJB23cWWV2F75 LQC730Gk/N3VYGieRCE8hmxLzISNxBwsmA7c8L5U2fcsH1vbn1xWHLHCciCP9/PJiye+ 8hqxtHa8RlUyOnUZ9H7FOmKD7HBX2NLgcd5jfvUcbpQ/hkFHkHfGznXkiYmI0bH2/8V+ kQNTuUEZ0EtQFo8bZJDUUduWIdGDljjXwoJY/Rxfezkz0DTZ/GJ7fs9GUsi4QK8Pj9MR Uc8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=z9ZfzDpEuznz7JDO0MpUy4J66NH5NE0QVJuq6p+mpt0=; b=BK8WswgVALdorNNUwB8LN4J55zBd/A23LGkQHvn+y7aJXB8H/6tkUFI5YLhbjKwDHI NQjTq0yIWfG0hn8m+6ddEhR8hS4g8XRr5OyMRdYxyGRR/WVWvG4sW9KGZEeeXTj3wbfn vH2pe/Pgus8aek+haNtfKpvLrVXFXvhIXmqctX73cBPCaKI6tiirI5pUc73zkpnROQZP R113rgUdqZ0hv0wIsj+RvUcqMfW6p6SS9oSrT1qgVM9E7Ri8xrExmAje1GW4f14yrE9G kL1xjs6brTFMTXHb8aq6usd9K+vCalpaC6vX5NRVKl7Tzb+JYyXopWgaQgvRCZLYk2nL dVug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=epFsZjbP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w8-20020a170902e88800b00178170100fasi22371620plg.337.2022.10.19.10.24.15; Wed, 19 Oct 2022 10:24:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=epFsZjbP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229869AbiJSQtI (ORCPT + 99 others); Wed, 19 Oct 2022 12:49:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230367AbiJSQtF (ORCPT ); Wed, 19 Oct 2022 12:49:05 -0400 Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E89001C73C1 for ; Wed, 19 Oct 2022 09:49:04 -0700 (PDT) Received: by mail-yb1-xb33.google.com with SMTP id j130so1273732ybj.9 for ; Wed, 19 Oct 2022 09:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=z9ZfzDpEuznz7JDO0MpUy4J66NH5NE0QVJuq6p+mpt0=; b=epFsZjbPDXKs/uJnbEHMuvJD+hZrSt9FzMgYqd/mH8LtXPiGaV8psQumxCoXK9sgfO L10JN3dev2bKHCRDrs3OjqjHjqP+DmJmalTXZ/su3aO/i+eyVaXECZfyIQagOIxt5D9b 5SMvlmwAs0H2C1TBNV5QcfBY6uZ2M0NEkjIiSlRkS27+uMxADwcXQZixVJer/7fwovPQ ZfrzPQWM4yMQgVuEHHVrJyL9JPYOZXe11yu6u3AsOtQ30CyqlON+fSkmFmmN/wcOhnVO uujO7oXtYYA6V+oMiT56WCpR+V6Ust2lrtV8qJlCpv3uTmIoH2wx3iECkgQDsZokbFQC ZDqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z9ZfzDpEuznz7JDO0MpUy4J66NH5NE0QVJuq6p+mpt0=; b=zIdKTI8IBqYaHftcCwkBnqgcc1JVw/MDXzNIIztGW56v1NgeTdlqSR8EZR6ZW2mUOv zl+wVAH1ZIaBGQDYWmJX156+BLJ1L6QvbtrEtMWc6MCiJEuVh77AZKcugqxVYKI6/6k3 A5L0cY4oJNHEOPljvyYxC/pyLK4+wjXpl7rwKsennFeWXWsciNXOvMAfrc6nO5TPTevp 6QT5EzV6X1tIP+HJr5vcuNekq8SrAvoJxpb2GguDowE1MCre6zHtRADU64mEpLEKoffP wdwb07ZYULeuSwvo+/J54UaDmtkXU2DdQ1n28g861RjMph8Y4hoAoD6khT3BuWYrli3u iJqw== X-Gm-Message-State: ACrzQf38GzTwGrMHCwk10Uo7WJum5uc/ttNPeA2GKt0qZLGl6NYJ4AUf qmPUIAjVcoSe17qnvkZ7VO6JuHLFToEwt3SkA8nh9A== X-Received: by 2002:a25:9d0a:0:b0:6bc:2641:19d4 with SMTP id i10-20020a259d0a000000b006bc264119d4mr7252756ybp.388.1666198143952; Wed, 19 Oct 2022 09:49:03 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Alexander Potapenko Date: Wed, 19 Oct 2022 09:48:27 -0700 Message-ID: Subject: Re: -Wmacro-redefined in include/linux/fortify-string.h To: Nathan Chancellor Cc: Kees Cook , Andrew Morton , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, kasan-dev@googlegroups.com, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 19, 2022 at 8:37 AM Nathan Chancellor wrote= : > > Hi all, > > I am seeing the following set of warnings when building an x86_64 > configuration that has CONFIG_FORTIFY_SOURCE=3Dy and CONFIG_KMSAN=3Dy: I was also looking into this issue recently, because people start running into it: https://github.com/google/kmsan/issues/89 I have a solution that redefines __underlying_memXXX to __msan_memXXX under __SANITIZE_MEMORY__ in fortify-string.h and skips `#define memXXX __msan_memXXX` in string_64.h, making KMSAN kinda work with FORTIFY_SOURCE. Dunno if that's necessary though: KMSAN is a debugging tool anyway, and supporting it in fortify-string.h sounds excessive. So I'm fine with disabling FORTIFY_STRING under KMSAN, unless someone objec= ts. > In file included from scripts/mod/devicetable-offsets.c:3: > In file included from ./include/linux/mod_devicetable.h:13: > In file included from ./include/linux/uuid.h:12: > In file included from ./include/linux/string.h:253: > ./include/linux/fortify-string.h:496:9: error: 'memcpy' macro redefined= [-Werror,-Wmacro-redefined] > #define memcpy(p, q, s) __fortify_memcpy_chk(p, q, s, = \ > ^ > ./arch/x86/include/asm/string_64.h:17:9: note: previous definition is h= ere > #define memcpy __msan_memcpy > ^ > In file included from scripts/mod/devicetable-offsets.c:3: > In file included from ./include/linux/mod_devicetable.h:13: > In file included from ./include/linux/uuid.h:12: > In file included from ./include/linux/string.h:253: > ./include/linux/fortify-string.h:500:9: error: 'memmove' macro redefine= d [-Werror,-Wmacro-redefined] > #define memmove(p, q, s) __fortify_memcpy_chk(p, q, s, = \ > ^ > ./arch/x86/include/asm/string_64.h:73:9: note: previous definition is h= ere > #define memmove __msan_memmove > ^ > 2 errors generated. > > I can see that commit ff901d80fff6 ("x86: kmsan: use __msan_ string > functions where possible.") appears to include a fix up for this warning > with memset() but not memcpy() or memmove(). If I apply a similar fix up > like so: > > diff --git a/include/linux/fortify-string.h b/include/linux/fortify-strin= g.h > index 4029fe368a4f..718ee17b31e3 100644 > --- a/include/linux/fortify-string.h > +++ b/include/linux/fortify-string.h > @@ -493,6 +493,7 @@ __FORTIFY_INLINE bool fortify_memcpy_chk(__kernel_siz= e_t size, > * __struct_size() vs __member_size() must be captured here to avoid > * evaluating argument side-effects further into the macro layers. > */ > +#ifndef CONFIG_KMSAN > #define memcpy(p, q, s) __fortify_memcpy_chk(p, q, s, \ > __struct_size(p), __struct_size(q), \ > __member_size(p), __member_size(q), \ > @@ -501,6 +502,7 @@ __FORTIFY_INLINE bool fortify_memcpy_chk(__kernel_siz= e_t size, > __struct_size(p), __struct_size(q), \ > __member_size(p), __member_size(q), \ > memmove) > +#endif > > extern void *__real_memscan(void *, int, __kernel_size_t) __RENAME(memsc= an); > __FORTIFY_INLINE void *memscan(void * const POS0 p, int c, __kernel_size= _t size) > > Then the instances of -Wmacro-redefined disappear but the fortify tests > no longer pass for somewhat obvious reasons: > > warning: unsafe memcpy() usage lacked '__read_overflow2' symbol in lib/= test_fortify/read_overflow2-memcpy.c > warning: unsafe memmove() usage lacked '__read_overflow2' symbol in lib= /test_fortify/read_overflow2-memmove.c > warning: unsafe memcpy() usage lacked '__read_overflow2_field' symbol i= n lib/test_fortify/read_overflow2_field-memcpy.c > warning: unsafe memmove() usage lacked '__read_overflow2_field' symbol = in lib/test_fortify/read_overflow2_field-memmove.c > warning: unsafe memcpy() usage lacked '__write_overflow' symbol in lib/= test_fortify/write_overflow-memcpy.c > warning: unsafe memmove() usage lacked '__write_overflow' symbol in lib= /test_fortify/write_overflow-memmove.c > warning: unsafe memset() usage lacked '__write_overflow' symbol in lib/= test_fortify/write_overflow-memset.c > warning: unsafe memcpy() usage lacked '__write_overflow_field' symbol i= n lib/test_fortify/write_overflow_field-memcpy.c > warning: unsafe memmove() usage lacked '__write_overflow_field' symbol = in lib/test_fortify/write_overflow_field-memmove.c > warning: unsafe memset() usage lacked '__write_overflow_field' symbol i= n lib/test_fortify/write_overflow_field-memset.c > > Should CONFIG_KMSAN depend on CONFIG_FORTIFY_SOURCE=3Dn like so? It seems > like the two features are incompatible if I am reading ff901d80fff6 > correctly. > > diff --git a/lib/Kconfig.kmsan b/lib/Kconfig.kmsan > index b2489dd6503f..6a681621e3c5 100644 > --- a/lib/Kconfig.kmsan > +++ b/lib/Kconfig.kmsan > @@ -11,7 +11,7 @@ config HAVE_KMSAN_COMPILER > config KMSAN > bool "KMSAN: detector of uninitialized values use" > depends on HAVE_ARCH_KMSAN && HAVE_KMSAN_COMPILER > - depends on SLUB && DEBUG_KERNEL && !KASAN && !KCSAN > + depends on SLUB && DEBUG_KERNEL && !KASAN && !KCSAN && !FORTIFY_S= OURCE > select STACKDEPOT > select STACKDEPOT_ALWAYS_INIT > help > > or is there a different obvious fix that I am missing? > > Cheers, > Nathan -- Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Stra=C3=9Fe, 33 80636 M=C3=BCnchen Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Liana Sebastian Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg