From patchwork Mon Feb 13 20:13:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 56535 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2553093wrn; Mon, 13 Feb 2023 12:17:50 -0800 (PST) X-Google-Smtp-Source: AK7set/f99WYgsDeuhfhggoWHyv06cnrD5hV8eosNYSFTlPkTu6xGldUcPmD2rFTDf4GH5qOnOsr X-Received: by 2002:a17:906:3784:b0:88d:3c85:4ccf with SMTP id n4-20020a170906378400b0088d3c854ccfmr177499ejc.25.1676319469926; Mon, 13 Feb 2023 12:17:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676319469; cv=none; d=google.com; s=arc-20160816; b=JT7p3J4pU7m4i11xe3q/nbjHTXCEkdPlMFhCUNK6Tbr/P2FFiS58r+i9aNtFP7qGfd gMLuWcms6QgTSI1yB9Ie0HqdF9US0dyNzCHmgvVwjBlfv5dyHcooEQuDHsHmSbYt4w9S E6NKT/p92jmQ8V2sGta2s1dP+DTJabkPyfiVVV9BqBPuwgatvB3IPxuhhN5rg8vGZtWC vXLqIAfEdZD8LJzMx6Rl8eqtAAoB4C7sTaL8/JT1iXox/HnXMV+5+x7SsYSp8fciYx0n awcD2C38kb3PMyrELd0r18xxGZlBpVYgOS4TkGCrgLB58s87iyP6dg4HWvgXLLikKNSh ZtdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=VhrJl5YJ7d2XgMTj7m/kCtzHq/X4U46pZjqetmx6EIU=; b=Rgnv2JeoOpW980sD6jSAHb+IDCoCfCitQ/ClTN3un4PiNq9Ie2PvTx+Z/E1LO22cg5 pY0LGS8p7jW4jvT6v4trY83fMK+1cAnJzyjhy4MZ0BSxAyifw2aqr1sxOHAqIEveF90a xgJWACsx9ccj3regz6xfJ2mxLL3D7vKO3x+GLDY1XFOOlacAbdVgmh5KuQyetNNcjeD/ eoiij1w/rx6CuC+/LQH4wHTqZjmczGyPt/9asSWZUBjROxX0qf8sBK4e0BeZwc3kQIfG h+xZ3xWJfSNZoVzEmu47bRtjVGBB2Na2CeQPga50ct6mqsHigO/TiYJDhpF3Jj45rl7Q 9OAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=E84LspmK; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 3-20020a170906008300b0088a91abb147si17852189ejc.658.2023.02.13.12.17.26; Mon, 13 Feb 2023 12:17:49 -0800 (PST) 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=E84LspmK; 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 S230428AbjBMUNx (ORCPT + 99 others); Mon, 13 Feb 2023 15:13:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230361AbjBMUNw (ORCPT ); Mon, 13 Feb 2023 15:13:52 -0500 Received: from mail-ej1-x64a.google.com (mail-ej1-x64a.google.com [IPv6:2a00:1450:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B7C61E2B0 for ; Mon, 13 Feb 2023 12:13:51 -0800 (PST) Received: by mail-ej1-x64a.google.com with SMTP id z2-20020a1709060be200b0088b579825f9so8212541ejg.18 for ; Mon, 13 Feb 2023 12:13:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=VhrJl5YJ7d2XgMTj7m/kCtzHq/X4U46pZjqetmx6EIU=; b=E84LspmK1D8CXYJ1386IiSX+2k5JvewADoqzxlVfJfiuzplqS+qe96ezEhckq47eoC I7MJxBjlzNIhSX7Luw4uTSli+Chwbl/PPWFlMOWohdwzIjriQ7EN6xOiPO0fJ0/VuUvg 8cgjJ+VL2sso67wojRMlMstNwr4HP2B8/KtBlYx9+ulA3D5b7xkHHflOa5+nsJEEjLxV xTZVcIVI/F2oQ9HDud3W+SFSQoSiA3TSAXdF0W8PZvJyp/y88r50fsxg4TWdiUKdeIXN uL82iRVvCTHNjqxwZ+4Y6O2F0xn403iW7uF/DnPkemHbXKiDYFAcQoAPHJzBi1NhRl9/ ZkCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=VhrJl5YJ7d2XgMTj7m/kCtzHq/X4U46pZjqetmx6EIU=; b=BdWPsB4fN8YGKF5/jpLI/9EpalWp9hPE3+1Y1EAJE7VpmyZ5hgpuL7DOmGHMxMf5mY pnGLVffuD/7aDHIa9hDhtWtVFKGzxpQzpegJuo4Y5oyT/M49pf7i//f8J5sJUuJrF2+G D9FC/UTSHg9SpMiuvUMVBiVLceZAyOeU/M+zjW2kuw1Ppy5qEw2O8XUnWhTDbly42uv9 xEOVtlyIvL+6JbAEnp7DeZnM6y7KLyyGyukGV2G2rtYcRVRuEm2UUsevbRqS+QjCmGR1 FLJeRGQoamB6dLccZvJGesXc6sJ41Zw7J8s7stjMvgnbwGXHavAiw7fTaC1zK9mkUnOx 3ErA== X-Gm-Message-State: AO0yUKWeY0POv2BUrJiiMPgPXhgcSdgg+0DuBL4FOsSafVp+0tl4GMNa /hWa+NjSPy8KBlAVKgrghbzjjicc3Q== X-Received: from elver.muc.corp.google.com ([2a00:79e0:9c:201:6cba:3834:3b50:a0b2]) (user=elver job=sendgmr) by 2002:a50:ab5b:0:b0:4ab:c702:656 with SMTP id t27-20020a50ab5b000000b004abc7020656mr4694edc.1.1676319229479; Mon, 13 Feb 2023 12:13:49 -0800 (PST) Date: Mon, 13 Feb 2023 21:13:35 +0100 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Message-ID: <20230213201334.1494626-1-elver@google.com> Subject: [PATCH -tip v3] kasan: Emit different calls for instrumentable memintrinsics From: Marco Elver To: elver@google.com, Peter Zijlstra Cc: Masahiro Yamada , Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , linux-kbuild@vger.kernel.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, Ingo Molnar , Tony Lindgren , Ulf Hansson , Jakub Jelinek , linux-toolchains@vger.kernel.org X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757289925766776554?= X-GMAIL-MSGID: =?utf-8?q?1757748364184753792?= Clang 15 will provide an option to prefix calls to memcpy/memset/memmove with __asan_ in instrumented functions: https://reviews.llvm.org/D122724 GCC will add support in future: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108777 Use it to regain KASAN instrumentation of memcpy/memset/memmove on architectures that require noinstr to be really free from instrumented mem*() functions (all GENERIC_ENTRY architectures). Fixes: 69d4c0d32186 ("entry, kasan, x86: Disallow overriding mem*() functions") Signed-off-by: Marco Elver Acked-by: Peter Zijlstra (Intel) --- v3: * Resend with actual fix. v2: * Use asan-kernel-mem-intrinsic-prefix=1, so that once GCC supports the param, it also works there (it needs the =1). The Fixes tag is just there to show the dependency, and that people shouldn't apply this patch without 69d4c0d32186. --- scripts/Makefile.kasan | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/Makefile.kasan b/scripts/Makefile.kasan index b9e94c5e7097..3b35a88af60d 100644 --- a/scripts/Makefile.kasan +++ b/scripts/Makefile.kasan @@ -38,6 +38,13 @@ endif CFLAGS_KASAN += $(call cc-param,asan-stack=$(stack_enable)) +ifdef CONFIG_GENERIC_ENTRY +# Instrument memcpy/memset/memmove calls by using instrumented __asan_mem*() +# instead. With compilers that don't support this option, compiler-inserted +# memintrinsics won't be checked by KASAN. +CFLAGS_KASAN += $(call cc-param,asan-kernel-mem-intrinsic-prefix=1) +endif + endif # CONFIG_KASAN_GENERIC ifdef CONFIG_KASAN_SW_TAGS