From patchwork Wed Feb 8 18:42:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 54576 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3625542wrn; Wed, 8 Feb 2023 10:51:09 -0800 (PST) X-Google-Smtp-Source: AK7set+HaxHfBTtscOMoNC/FnYZ0ZfGLH3l+FsFNgf2FPvmXS3vdR+EGsBjFoVrXsVZkOoIdce3w X-Received: by 2002:a17:906:283:b0:878:4bda:2011 with SMTP id 3-20020a170906028300b008784bda2011mr7668659ejf.4.1675882269073; Wed, 08 Feb 2023 10:51:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675882269; cv=none; d=google.com; s=arc-20160816; b=JafjSan2JkISJ/L32CzGngFBfh7SMUbnGRHRj4D9lh6KgnsEcSOGUOC6m/9uEriKg0 aAGUInAttpt7RZDcq3GQq5wb7VWxZ27JoEDqaYjwWt5lPz76zBUgdhYioYNsuPKci7YP /v2cb3eyVEKcyLdrgowziTlXeYx26Rpir7S+x5k1DSyg3dqpTrMBWbJSIu4hD8BnkdoK W39ndq8AZjZqmr8ighjs0SDBmPY9IaAa7EmSlVscIwuE4WlERVOgYi9jYzR1SrQJhwdD 6nWVJIQuAvKV8eFen/l9F1oIx9sIR3D5Be896k8z1UYGKHbbVUK6Kbng20wejbPiIbdw kUAg== 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=muGKsBQpDMjO2rXBhVjlNe2+4h4S1u+JGQBqWajmnMY=; b=Y1sn7oMyRXLCuu0CLVhUVX/B04g+hT57V4u8afch9yahfeLwyuxqouJB1I8oMjbVNj Sf3UvV9LAZ9+AQ8GDLdptrTphjTPDhJDm1GuY9DysRhvyx/OVf1fHf3yjsF099ke/8V8 0PlmVEaj4DehhTJDUM/E8uabke/b/AOBJB1EuZcLnNW7kcChtBQReXuyxsGAss5n+TAY YZL3mlbizd2FXRn6D923GK9r9YhQKZYwkp1UMo2nTDovBBeEEJ3kYJppNoFwQlvj08Jn OW0zt0JlYnt21NMW+ARvVtwKYJtQWioLzkdTlHaCP7OgD+S5Wr2VSIiqwiBLO+0QlRus 4Xzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=HxBkYsCy; 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 15-20020a17090602cf00b0088b3b09e143si3643747ejk.593.2023.02.08.10.50.46; Wed, 08 Feb 2023 10:51:09 -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=HxBkYsCy; 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 S230335AbjBHSmo (ORCPT + 99 others); Wed, 8 Feb 2023 13:42:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229740AbjBHSmn (ORCPT ); Wed, 8 Feb 2023 13:42:43 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE12944B6 for ; Wed, 8 Feb 2023 10:42:41 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id k15-20020a5b0a0f000000b007eba3f8e3baso17974076ybq.4 for ; Wed, 08 Feb 2023 10:42:41 -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=muGKsBQpDMjO2rXBhVjlNe2+4h4S1u+JGQBqWajmnMY=; b=HxBkYsCyEckUoHuvqVZ5uRlBgYs41lGpzh9bJv5RycbHZDeZvkaOSzuAVFVt1ocvW2 GUtHG6k3mrzIxEGxYLtddoREAd1jMYdlSfDEJ+H9rP1xQ3pUllwwQPEUZH1vYPa5ulra 2/+qrCz0H5FEJKh2E1cpdMySNo/1cFVZG7fO8PhEVzQPZ3sEBVYBhs0rgDlHIWhU0+kO Yf9vVPbuo9u+AY1zPiE/WEBlftJL/MvXqqHw8ylsVXWkRAYZDDqRFx62tiV63uOOqLZe kMWoCoa+EkILLVIvTVknwJXc+UnFkKSqYWNUe0meeh0pNPjtvUMwge+IQDK+CpWpGHW4 OFDw== 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=muGKsBQpDMjO2rXBhVjlNe2+4h4S1u+JGQBqWajmnMY=; b=SBCWr+hKE61NcKuSYgHh9eUA0ZtRuULwLuoxA/YEWvs5YAHybqvML/pEjdrolByOY7 fHw13F42yDH09rJrWQYaihRWHWUwBeDOC/Au8HLrjix4XYSNHQcztJ0/KdNEh7+iYtYa iKTMrAI1lbjzxNbO2rxK7zjKCszHCBMAorVQVktdoTzSq91WFksXFLtuMcD1XhhVGoNv YT39ucFv77KzYlZqCpxlOxyNLb3L2GfZo2Hs6s1lyJwP/HCg3+MOyEPXUV4rKuF+YIA8 VSzy+Fcyt1sWzClXicJzGRTdReGb4MGrgQ2Kxz4Cwjl43G/rjSZlBQxu7Xc2RTNW2ZwQ DkDQ== X-Gm-Message-State: AO0yUKUVpRFiwqRLOpsHj8kAOqjhudGAVZRU2Ol2IylLU7bnH8EAUy8L S4yYOCXmpDwNIl48tDMe9v/BUk5oJw== X-Received: from elver.muc.corp.google.com ([2a00:79e0:9c:201:a0ba:1bc4:8b19:5b22]) (user=elver job=sendgmr) by 2002:a81:1312:0:b0:528:37bd:c122 with SMTP id 18-20020a811312000000b0052837bdc122mr10ywt.5.1675881760758; Wed, 08 Feb 2023 10:42:40 -0800 (PST) Date: Wed, 8 Feb 2023 19:42:03 +0100 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.1.519.gcb327c4b5f-goog Message-ID: <20230208184203.2260394-1-elver@google.com> Subject: [PATCH -tip] 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 , 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?1757289925766776554?= Clang 15 will provide an option to prefix calls to memcpy/memset/memmove with __asan_ in instrumented functions: https://reviews.llvm.org/D122724 GCC does not yet have similar support. 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 --- 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..78336b04c077 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) +endif + endif # CONFIG_KASAN_GENERIC ifdef CONFIG_KASAN_SW_TAGS