From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D14AC433FE for ; Wed, 19 Oct 2022 17:29:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C37D86B0072; Wed, 19 Oct 2022 13:29:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BE78C6B0073; Wed, 19 Oct 2022 13:29:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AAF0B6B0074; Wed, 19 Oct 2022 13:29:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 982E56B0072 for ; Wed, 19 Oct 2022 13:29:46 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4AB8BAB1D0 for ; Wed, 19 Oct 2022 17:29:46 +0000 (UTC) X-FDA: 80038386372.02.7919687 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by imf29.hostedemail.com (Postfix) with ESMTP id A9F2C120044 for ; Wed, 19 Oct 2022 17:29:45 +0000 (UTC) Received: by mail-pl1-f177.google.com with SMTP id l4so17905912plb.8 for ; Wed, 19 Oct 2022 10:29:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=GKQx/U9Oi8K1uuimUXOQCwOAtdhTQa9BCE+heeFHVSk=; b=llqmXm0CMlRdNxGJQhZzu79UZsKVDaHayVNH4B/+FR4a9XyRxvDx+sElvKdhad4pNv mdLaT0+TyxGeqlA5slg0RvPDNxFyAi+/JB2MjN8PttYL66+BXuR2g8J0hhUwFniWn/aF BHuDOF4poTYwjD4PiI/xZLXK5T6ND5/qAuzDI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=GKQx/U9Oi8K1uuimUXOQCwOAtdhTQa9BCE+heeFHVSk=; b=BsH4pk17C6BTh9/6ii2cPho8FswpgN4bJuvqPo0q+Z/svB3z/9sky/c6Wy1jYQW3yC xjLoEfRWE/JLgfC8CzQouAQh9beBJviQVd4A0pcJopZxc4+rILeniov4av/BKMeTL/dZ N7n4M9F3mBzoXf/QJ/zFM8xUsePIv7Of3dFoRF1cEAZhO9lNBUvn/UyRDAmRQr6Z56HB pAGY0AL6XUSiMnqNmZAISWVv68sjVoBvnVET42Y+NCc1lchwAaeO7DkK1u92Pso1S+K2 7GzhRbXZM4+H/M6yFNG5IiGgg8XDFT03c6eiYb335LCkLrh5+zY+fg2P6avO7DcBGiog CblQ== X-Gm-Message-State: ACrzQf3avUDUNTvIBTxVWjPHA6klUAJBg6DfsHbXx3v25pKBGJhva3Ap HL7m02Pcpfn+E8n+5EfOKf7LDQ== X-Google-Smtp-Source: AMsMyM75Ysi1bNtlIMQFZXd7UXOoVE+FnIFfAU6AD/yNPktRVFZZYOFMxR3rHB2s2wdxINdFWWXNZw== X-Received: by 2002:a17:903:2312:b0:185:43a2:3d0e with SMTP id d18-20020a170903231200b0018543a23d0emr9702582plh.118.1666200584506; Wed, 19 Oct 2022 10:29:44 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id y8-20020a17090a16c800b00205d85cfb30sm234077pje.20.2022.10.19.10.29.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 10:29:43 -0700 (PDT) Date: Wed, 19 Oct 2022 10:29:42 -0700 From: Kees Cook To: Alexander Potapenko Cc: Nathan Chancellor , Andrew Morton , linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, kasan-dev@googlegroups.com, linux-mm@kvack.org Subject: Re: -Wmacro-redefined in include/linux/fortify-string.h Message-ID: <202210190930.26BF0CE2@keescook> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666200585; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GKQx/U9Oi8K1uuimUXOQCwOAtdhTQa9BCE+heeFHVSk=; b=B3R2QJwXMAfVGCbx6v8ODEdlUOBZjctcia2il402IejFmCeteReryCMQ0TgC1ZP5cWEJAj oWPwsqnSdDsiSpkZF4MvNngIQnobyRvsFTe6P18CxpEWWGndQ/r0gio3xCSY4tdrhaN52f JZ9W5FpPTm7q6/8dd5gzcM2PsCD+tIg= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=llqmXm0C; spf=pass (imf29.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.177 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666200585; a=rsa-sha256; cv=none; b=EwwRgB6+pRo0Tdyk5uESzPtDoIvlU2neMld6Wf6hrX3QtXGclgcPs67gMLv5EhqrZiE8ua INTFeEzTgaD1sNthvJOuZr/XbXS5W/qqgy3KvIAmUyDzshi3XtkHyRSD4nfQorEhvyklNZ NrLC8JC/CrYAnvfJbfgFoPI2JB8gp/Q= Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=llqmXm0C; spf=pass (imf29.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.177 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A9F2C120044 X-Stat-Signature: 8ewqty3zbceg74k85tbgo3bebwpum7au X-Rspam-User: X-HE-Tag: 1666200585-343929 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Oct 19, 2022 at 08:37:19AM -0700, Nathan Chancellor wrote: > I am seeing the following set of warnings when building an x86_64 > configuration that has CONFIG_FORTIFY_SOURCE=y and CONFIG_KMSAN=y: > > 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 here > #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 redefined [-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 here > #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-string.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_size_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_size_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(memscan); > __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 in 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 in 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 in lib/test_fortify/write_overflow_field-memset.c > > Should CONFIG_KMSAN depend on CONFIG_FORTIFY_SOURCE=n 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_SOURCE > select STACKDEPOT > select STACKDEPOT_ALWAYS_INIT > help > > or is there a different obvious fix that I am missing? Hm, why can't KMSAN use the same thing KASAN does, and compose correctly with FORTIFY? (i.e. redefine the "__underlaying_mem*" macros?) -- Kees Cook