From patchwork Mon Oct 24 21:21:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 10383 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp696557wru; Mon, 24 Oct 2022 16:11:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6vYV8jnHsmzGhdQDzLGk2loTJMUWTo0/4ZvbRqRGvJxd9QK3sit2x+dTZGqGRzZ+b/iRqb X-Received: by 2002:a17:907:7252:b0:791:9fd8:222e with SMTP id ds18-20020a170907725200b007919fd8222emr29405327ejc.729.1666653105506; Mon, 24 Oct 2022 16:11:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666653105; cv=none; d=google.com; s=arc-20160816; b=d3MBBKxXoGm/ZsfH9lHjYIfGk1aTMVlQd9utzTzIV0xoH4bhs/d4+PuQvZtndc/ZoR HuziK2ccdK8BKRwmOOVC5nki7tTFh1CQgcXoT0SoG87aUMg/Qw7xKJVLibJFefvyDl7N 8oLDvFfFbr3vz4l7Cpr0ofILCfSymb104XujxaOnWoeTGGFBtVCgxa5up/uYMwJQgyxk WvcNPFpAXbiNLsT0Spl8Kn/hCY4Wd/LRGXEcQAsmrLn5sfBfNTPe/TZAD4V1BVKumeM/ oXZa8CRho+ImbAvJVveLNzWBWxYMhjeTjXycaDynmujarlXEDDgAANDevHFxxwZFyIO+ zZ+A== 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=G4yBv7Ojnp7UF/vJeQGCUBcD6F1oQa7UXx9ZrIQaMAU=; b=qyaY4FRRVq9bUcnsiBBh987XsoKkqgayqb8wqLBLamsW9ug6Kz4nU+3ayGs/zE1Qm/ 1nw5ilcpESPdBsgt/pBWRQFq5hyxlWve6kTfFhLSvrFPibAUzGhM/DxiU9k1xIvicC01 MzCDw0dtcHduUzPsUbI6H8KD2ENzS3wIydt9Wn/d8/nuPJ9ot+y2FoaQc2gEhOHMM1f7 aNjrBpz9qf9Ij0nE+ZNfqFnSSNDK1wB+95QoHrjOoINsUiWpgsF9jEMOTiNDBeQXp1Ey yytZirdVJMQ2g5n84ZzqBU2UedpOrVC52r1R5liI1XIiTLyhy3hH18XIlJeN/BZMjuSY mukw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=aSgkiacZ; 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 i17-20020a05640242d100b00461ed1fe6ffsi1490898edc.85.2022.10.24.16.11.19; Mon, 24 Oct 2022 16:11:45 -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=aSgkiacZ; 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 S231433AbiJXXAz (ORCPT + 99 others); Mon, 24 Oct 2022 19:00:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230516AbiJXXAU (ORCPT ); Mon, 24 Oct 2022 19:00:20 -0400 Received: from mail-lj1-x249.google.com (mail-lj1-x249.google.com [IPv6:2a00:1450:4864:20::249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A9262D7814 for ; Mon, 24 Oct 2022 14:22:36 -0700 (PDT) Received: by mail-lj1-x249.google.com with SMTP id e9-20020a2ea549000000b0026fd9ba87acso4523196ljn.1 for ; Mon, 24 Oct 2022 14:22:35 -0700 (PDT) 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=G4yBv7Ojnp7UF/vJeQGCUBcD6F1oQa7UXx9ZrIQaMAU=; b=aSgkiacZ+5LH66/OSoz3MSDqz3zMIfvjCb/vyfftyLM0xQDT8v/cV4qgWN9uIWbM2D 5OZHLV9CdDaSYabYM5oDhFl/9ZFZxBB7UVaE+TCMSdHJ4OzpgUiYTbbaREJDJ5M7BdKw 7Yp611r8+sMWV+GwAvNDb5hW2BH9LuS76Frg8V4l+RxJ4pp10FD3oo1s5NeIbhGUhz0w 0i1mgmg0nYSCbbb5eW6qpKn9lWSlUKvjLWMU81zY+MVDWxf5KApWMkH3yS1m1A1Ci/5R 956P5mfY7HvBAFj+8gGanEIbLdPqM2iOq+oUYtxU3AimbVdcembaQ3RioMtPFtX9O6iC 4i9Q== 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=G4yBv7Ojnp7UF/vJeQGCUBcD6F1oQa7UXx9ZrIQaMAU=; b=trZdlrhrSvzQHvlSJAcvPL8nIE708iKGjGX3qHy8aDxzTVrhD6mT59RDGOL7AGZge5 VBiU31z/YxZzLAm5o9qnqOmXxP6C2tZ617Kr3c7wbNNeozOxDtvVbtMP+S8EE7G9Uk8W BNBlgZ9MraU3fsIHOF441ObJTyJcECA1a1HGZtZG8z57PJaoTGZCcz/nZ70Ptadn9qHY UHJRBfF+urvV/bNfs0l1UOPNMoCNSwbUdsq1nxJx+swFBxYkb+HNbUFQzkfnK+AIrzZ/ HXLvzN9krxWnFjvED6b7gPfIu+f8eEGBAf+62C5FgJDG3Pfb2faBf3zixV+FrDBLcNCq rvlA== X-Gm-Message-State: ACrzQf3K8Ogkw0AH0zIbXCdFKNF7Ll7GOChrt5WeMd4z/1rBn9eu4C1O qXZK4I92pCitFN3j+vNZRojB/M5GCcc= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:8695:7c88:66ed:f9d1]) (user=glider job=sendgmr) by 2002:a05:6512:104c:b0:4a2:6b99:c8f3 with SMTP id c12-20020a056512104c00b004a26b99c8f3mr13590896lfb.519.1666646508884; Mon, 24 Oct 2022 14:21:48 -0700 (PDT) Date: Mon, 24 Oct 2022 23:21:40 +0200 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Message-ID: <20221024212144.2852069-1-glider@google.com> Subject: [PATCH 1/5] mm: kmsan: export kmsan_copy_page_meta() From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton 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?1747612446891174702?= X-GMAIL-MSGID: =?utf-8?q?1747612446891174702?= Certain modules call copy_user_highpage(), which calls kmsan_copy_page_meta() under KMSAN, so we need to export the latter. Cc: Andrew Morton Fixes: b073d7f8aee4 ("mm: kmsan: maintain KMSAN metadata for page operations") Link: https://github.com/google/kmsan/issues/89 Signed-off-by: Alexander Potapenko --- mm/kmsan/shadow.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/kmsan/shadow.c b/mm/kmsan/shadow.c index 21e3e196ec3cf..a787c04e9583c 100644 --- a/mm/kmsan/shadow.c +++ b/mm/kmsan/shadow.c @@ -167,6 +167,7 @@ void kmsan_copy_page_meta(struct page *dst, struct page *src) __memcpy(origin_ptr_for(dst), origin_ptr_for(src), PAGE_SIZE); kmsan_leave_runtime(); } +EXPORT_SYMBOL(kmsan_copy_page_meta); void kmsan_alloc_page(struct page *page, unsigned int order, gfp_t flags) { From patchwork Mon Oct 24 21:21:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 10384 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp696598wru; Mon, 24 Oct 2022 16:11:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4tGbZpIvFW68SapGF97tXB5kTmdrdwZTB6AmYQUhjXYxHo0rwVSQIcTdGvEYrkavVUqGyI X-Received: by 2002:a05:6402:3581:b0:461:a977:5f86 with SMTP id y1-20020a056402358100b00461a9775f86mr9245290edc.33.1666653109436; Mon, 24 Oct 2022 16:11:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666653109; cv=none; d=google.com; s=arc-20160816; b=b1tKy82BJXykqWHoCJVEmoNi3l+X7yNpkRDeW6SXpHhLUmmKCsjhdBBgFIPpXx9Iq5 CGV2WYa5M385sq4HTTR0IccfcfwTO8THwI2rzeBsQ2ZQrGQ6HO52Wlv5lhOhqjvbC47B NBbFarUmIpimTr2dl9qFaXXCbva47H+1wbnnkPdPNN0sLu2BvSMNabfqbhqeNZDYVEzW CQuB2DNoNtogo93Ictf6acsOY3NaaHsCv8IxcAsRfOpHFG5YwKUDwOsIVJrT6rdhh2wB nzmLGMtq6GE53AnYBji1wFBrn47xtQ0PkaisHjul10ox1OaDIfmoAT92kSddEYyS/KUd 9Vug== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=h1brEJBipb7gPKmBCB4iwvDw2G6SbkIMFGPFK60cCqY=; b=nBRPiY0nssm0Xq6imm/xlTXgcpGXGqFd2tvhSptFj1NLrLEx616G/QGPl/+Kz/u+Vx yun91fLLR0EIQcufnMc+ggSEjw4zQ9nRcTJOw6zu4hrVAOBxbjJddxA1CbA1WC6AFnMg cGsG7VJex5XtLuRosS839wAtRgBADfs7iHwdoj23TW88Tq7+Z/mNC+jX98Iz6Tx6+tB0 o04MM6ct77VJFoC5B6VN3DzCYGOAnt4aFrToMl54pc3fsbufXkhvWtQAY9KMyjUl1qJT V6nb5dIa8Z5SoNiVsK3nZPCKzbUVzEQt+mY2TQxpy50R5q8WeVQP0PZ500S8Pdpsi3BW Hg9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=QrB2Fv9L; 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 dm8-20020a170907948800b007316ac034a1si982413ejc.831.2022.10.24.16.11.25; Mon, 24 Oct 2022 16:11:49 -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=QrB2Fv9L; 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 S231131AbiJXXBA (ORCPT + 99 others); Mon, 24 Oct 2022 19:01:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230343AbiJXXA3 (ORCPT ); Mon, 24 Oct 2022 19:00:29 -0400 Received: from mail-lf1-x149.google.com (mail-lf1-x149.google.com [IPv6:2a00:1450:4864:20::149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10844816A0 for ; Mon, 24 Oct 2022 14:22:40 -0700 (PDT) Received: by mail-lf1-x149.google.com with SMTP id w2-20020ac24422000000b004a299d12364so3126639lfl.13 for ; Mon, 24 Oct 2022 14:22:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=h1brEJBipb7gPKmBCB4iwvDw2G6SbkIMFGPFK60cCqY=; b=QrB2Fv9LJDXRdkYo1W6sAUZYFUSBeG66/qzzdNhF4QszBRYGVKofytU+Xl1qy6Rz4I I8Yiy0O6Aibk99xbAG3sK5grh6C8aHbcfosiscsjIQNfEklGhC3c96zp/HDNoYLx9+KJ hPMWl1sJhW2LUnPXauuud99OpqjZJBiwQMEQL9D2FwX4DgKLGzq9iGY0t0D9opbdb5+D zWvcc8t93kpL3shnq/n4C9Q8SmbywVo6gn4tT2ZCdtPTJK9UyQd08jpWSQ/e2t74qO1G KyFnztlBqXN3ZwWi/fNbkJaHHAQkZtBZZXoMgXzgEHtGas2KrLoVoiZza/P/b5smYnEl soPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=h1brEJBipb7gPKmBCB4iwvDw2G6SbkIMFGPFK60cCqY=; b=Q8dnk/Dr3lcSA//1dHuzLN04YPUl54QRQUQCvogQBVjVYzzRd+YulIPIGN+Rb+voTB z5e/H5sieX8dU/jmRDU9o3YsThKaRVo0id8bZUzygkyrporLCIFGdFXZAqHD5E7xE/0c uT2AjZmef7WGqs5MW+4Lu5qwZGn17Itb+bkLPtRzUm4+R4XxytW6Hr4DHkhh0Q+bJ8SF 1meie1tttHM9Sn3ewwkfgwtFT3TwKCbHwJgAo7HSljeMMon8vEUlZ+Cz4EmLaBHoymmO 99C9P/cAHynreOS1ph9jS1xdduXIYegpSShaudNAxIgtDEiOpiBsWnUPFWTqsdfGwmqY 8Utg== X-Gm-Message-State: ACrzQf1QbN+OMVL/s6RQfXZwKEvCKE5Ru81FKisYWooE+BiQlI6VGn2D Q/N9CE4A3eK2813HajFwL20Z5ymPLQ8= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:8695:7c88:66ed:f9d1]) (user=glider job=sendgmr) by 2002:a05:6512:3c8b:b0:4a2:6e64:7049 with SMTP id h11-20020a0565123c8b00b004a26e647049mr13241229lfv.196.1666646517702; Mon, 24 Oct 2022 14:21:57 -0700 (PDT) Date: Mon, 24 Oct 2022 23:21:41 +0200 In-Reply-To: <20221024212144.2852069-1-glider@google.com> Mime-Version: 1.0 References: <20221024212144.2852069-1-glider@google.com> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Message-ID: <20221024212144.2852069-2-glider@google.com> Subject: [PATCH 2/5] x86/purgatory: disable KMSAN instrumentation From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Thomas Gleixner , Ingo Molnar , x86@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?1747612450832659045?= X-GMAIL-MSGID: =?utf-8?q?1747612450832659045?= The stand-alone purgatory.ro does not contain the KMSAN runtime, therefore it can't be built with KMSAN compiler instrumentation. Cc: Andrew Morton Cc: Thomas Gleixner Cc: Ingo Molnar Cc: x86@kernel.org Link: https://github.com/google/kmsan/issues/89 Signed-off-by: Alexander Potapenko --- arch/x86/purgatory/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/x86/purgatory/Makefile b/arch/x86/purgatory/Makefile index 58a200dc762d6..17f09dc263811 100644 --- a/arch/x86/purgatory/Makefile +++ b/arch/x86/purgatory/Makefile @@ -26,6 +26,7 @@ GCOV_PROFILE := n KASAN_SANITIZE := n UBSAN_SANITIZE := n KCSAN_SANITIZE := n +KMSAN_SANITIZE := n KCOV_INSTRUMENT := n # These are adjustments to the compiler flags used for objects that From patchwork Mon Oct 24 21:21:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 10390 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp697565wru; Mon, 24 Oct 2022 16:14:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM59wB/Hs5zHzVfWOAvobedIFdBd4bluSefDXnecJmTfNIT5CUf2gpKo6eTZscyCcUgj6zHs X-Received: by 2002:a17:903:24f:b0:178:bf4f:fc7c with SMTP id j15-20020a170903024f00b00178bf4ffc7cmr36286698plh.124.1666653249352; Mon, 24 Oct 2022 16:14:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666653249; cv=none; d=google.com; s=arc-20160816; b=tqLZJTExmY8x0OzOZ6eFpnWKwnHjpzs6UIcWiFI+zmwXmFUErPt22XVV28QCaJ/RX4 O+I9rCyK6QC3UJv2/M2WzoQw/J63NpEcPzrTucWWBNxfKKjdrrcPW8z8285s61rSJCHj GwZ9zaZb5gQu5tV9mMmekYKQpv2PJMbhx+f/UlLSEkRQVmXla7hda4Jvk3x/zgH//Rwf VmBVVqGg7kqi9B2XlSkinoXQ8p5DDULV4GDtFi5lQDGSX4TpKamrXmf/QkdWzAuyKbO9 678db8ZCdxreZXdXeqAaFPtejsLCRyUgJmhoKE8s5EfXIRzhyN62MMiwJ9ln8kusNrBx 53ng== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=XYIeNtcSMBuwQ4ZUNtMrq5SFnntAuabRdvmK/d2x8js=; b=Z9ByE+SyAooMxeLmgeGmeZ5LFe/ezlYdRjL6IpCMx0TlCbFIfhC+NwIsF8cBghOup/ nRc+GXPAlgcJ0uh+J/x+pVzGbJXigsmouK8ZC9wo8pRlPdQKiaHeNodJuxawNe+zb2wd 1t8E9w4SxyUu/uLv23lZJsa6j9SRc8dB2jVTjApzNbii8NVmbpacaWiXjAF572GBv+W2 21xOERyv0tvJf45aycS6wHqSOtTWYSpsuDEfhtx1rUZlumSgCwnTdzqesKZ7hWpo8m25 gPFpPNHo9SSUfyxkGm/+y6mObfk3nyUilOiI1FYFFHXJk+y8dylpln/tDpulBdqMFNT4 BWJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Z2RX/saD"; 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 s6-20020a17090302c600b0018685c33ec2si1071022plk.7.2022.10.24.16.13.56; Mon, 24 Oct 2022 16:14:09 -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="Z2RX/saD"; 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 S231446AbiJXXBe (ORCPT + 99 others); Mon, 24 Oct 2022 19:01:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230379AbiJXXAg (ORCPT ); Mon, 24 Oct 2022 19:00:36 -0400 Received: from mail-ed1-x54a.google.com (mail-ed1-x54a.google.com [IPv6:2a00:1450:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D8D82D7803 for ; Mon, 24 Oct 2022 14:22:54 -0700 (PDT) Received: by mail-ed1-x54a.google.com with SMTP id w17-20020a056402269100b00461e28a75ccso2806637edd.8 for ; Mon, 24 Oct 2022 14:22:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=XYIeNtcSMBuwQ4ZUNtMrq5SFnntAuabRdvmK/d2x8js=; b=Z2RX/saDef7hn683V4j0i5oZ/4CeWuvGJYbdKV5tISFit7ef+6l5PCAipzwyZ7BeiO EPirZ8Rv7RC5dlr2jbxe8J5rDP6eyCRFXSbvCOHFLTgHO38oNZ8NcKEZz7LRJV9whBzw SlOVNCjuhY1/3D3mJnUM8hAamOdsnb/MAYvqsbY87QLHYWOnDOLJk2St3m6OCZXsAM0P wiQfeGmmaTY/zb3roX1oY3y/wFJBytPp5+wk9GOpCrE1kCU6zWIY1Vzoyj/dZdyQokMi KtKVBt799EJxWAxrx6ZXHTTkUeoPkaZT3jX6k+JwokHO7Nf58TS2z0+z03halrOoEixy Q+lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XYIeNtcSMBuwQ4ZUNtMrq5SFnntAuabRdvmK/d2x8js=; b=nfnae4oYgfaC2tB92nZ0z1qq3CPjGY4fJdNUhRgPazCVEOACqAjs35lJrKb86VOcwM nlEeLdli0tF70KGP0RoIHzcshrTGcYZ1ku1gUXzaWjzfd02D6+JDYrCGs6S0KNi79k13 OZVkEQKjac8VK9XbgX68fgJUXiUQDr0aeXQ89dW1zOR25cim5yO0sJXwpItmFzokozjp v/+J6x+TFliuveVnpOA2DM3TG8NromDczo/FOy91MoIrN20aWy2yT23pezNl6SUDR1R5 25sAELJcpxXF/oYoANF6Nk/66AvJ/014qf1/obJSdAz9WaKCLW4eXvP6PuTqCO/+cTnf awAg== X-Gm-Message-State: ACrzQf1IMZgiN7VFSobCAUqowKWGGda1wT/qCsG/rV+hAu9InEpR9fnh P/XAgT6xMEmV48tgRldgdimYcSLQWS0= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:8695:7c88:66ed:f9d1]) (user=glider job=sendgmr) by 2002:a17:906:8451:b0:79d:af69:8a20 with SMTP id e17-20020a170906845100b0079daf698a20mr15002244ejy.406.1666646524113; Mon, 24 Oct 2022 14:22:04 -0700 (PDT) Date: Mon, 24 Oct 2022 23:21:42 +0200 In-Reply-To: <20221024212144.2852069-1-glider@google.com> Mime-Version: 1.0 References: <20221024212144.2852069-1-glider@google.com> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Message-ID: <20221024212144.2852069-3-glider@google.com> Subject: [PATCH 3/5] Kconfig.debug: disable CONFIG_FRAME_WARN for KMSAN by default From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Kees Cook , Masahiro Yamada , Nick Desaulniers , linux-kbuild@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=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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747612597773709442?= X-GMAIL-MSGID: =?utf-8?q?1747612597773709442?= KMSAN adds a lot of instrumentation to the code, which results in increased stack usage (up to 2048 bytes and more in some cases). It's hard to predict how big the stack frames can be, so we disable the warnings for KMSAN instead. Cc: Andrew Morton Cc: Kees Cook Cc: Masahiro Yamada Cc: Nick Desaulniers Cc: linux-kbuild@vger.kernel.org Link: https://github.com/google/kmsan/issues/89 Signed-off-by: Alexander Potapenko --- lib/Kconfig.debug | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 3fc7abffc7aa2..29280072dc0e4 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -400,8 +400,9 @@ config FRAME_WARN default 1536 if (!64BIT && XTENSA) default 1024 if !64BIT default 2048 if 64BIT + default 0 if KMSAN help - Tell gcc to warn at build time for stack frames larger than this. + Tell the compiler to warn at build time for stack frames larger than this. Setting this too low will cause a lot of warnings. Setting it to 0 disables the warning. From patchwork Mon Oct 24 21:21:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 10385 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp696899wru; Mon, 24 Oct 2022 16:12:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7AVJrL2uRoESD6RuREbhMc2Ii2iRse9kEeLita46JqdSN3ZJsBZgTkFMlIsxUJjgIolmh1 X-Received: by 2002:a17:90b:1c0c:b0:213:1455:131f with SMTP id oc12-20020a17090b1c0c00b002131455131fmr7668835pjb.129.1666653141481; Mon, 24 Oct 2022 16:12:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666653141; cv=none; d=google.com; s=arc-20160816; b=aIgHeIyebfiNI9DKcDQ2V2JqAWWaHqkcVAYw/yv4mV/lKOFn5Brw/WPCri1KVucf/4 JjbGv1wPoF1lqHTijRDqp1Tu2mwo9o5POE1kL8/MhSWnAmtvpJBXYnL40sKi9faGh5+u UyPGtXPTg9sofkEsnFVctzVn4K2OGQq6w4ouRWMVnGa0rbYkmixkrItOipLFdD1T8uoe pM5o/lFWLyrobBEpU8v0oayR5mGrITF//WT2vSVBXSdKSsL1aj1lXSW7N1N4zZeIjtNG FB6XE8SUnZMZZ3pbqt2ZssnQKu6tA4fNQL36wi1Yu8gceJz+FNcC0blDRvp4neNPz0uE jw9g== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=volBetDwZhQX9fC04zMVYOMbO1RkS1wEneNzDmowndU=; b=yILDUrbv/+hCyiCnGX7jeB8QxZbHOYuhJk0dqrlJp/6/VrneVit0UDMr84mKfxQeEI JtYEvsBut308mfsITkyhqBuqSAe75TenW/uvL5IegCe+gI4o/vFOD++pTHs/KfadImeE wFSfu59A/XtYXtyUOX4zY2+vjZdbrFkiSBtRuxIIY0B12Ss4YTJ8yLyIIWyZoP9lo8n/ ImT0bTBLJ45I9pu/uUN9MCEu+8+Bpb1WuAR/nCpDi1mhwjFndKS/vUq4f5Ar58A8BvFW wm41IItc4Y43gOAu0jsgwFWbD0lMObZq38/er4ArcVyZeqzFzrsUTi39fp0HQ6S5yLXD 4+LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=J4G17c7U; 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 z21-20020a63d015000000b0045d1aa2a586si852932pgf.197.2022.10.24.16.12.08; Mon, 24 Oct 2022 16:12:21 -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=J4G17c7U; 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 S231705AbiJXXBI (ORCPT + 99 others); Mon, 24 Oct 2022 19:01:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231348AbiJXXAd (ORCPT ); Mon, 24 Oct 2022 19:00:33 -0400 Received: from mail-ed1-x54a.google.com (mail-ed1-x54a.google.com [IPv6:2a00:1450:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D85CE2D73A0 for ; Mon, 24 Oct 2022 14:22:51 -0700 (PDT) Received: by mail-ed1-x54a.google.com with SMTP id x18-20020a05640226d200b00461e027f704so2852237edd.7 for ; Mon, 24 Oct 2022 14:22:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=volBetDwZhQX9fC04zMVYOMbO1RkS1wEneNzDmowndU=; b=J4G17c7UDbBB6vaIpcTMG+Yagy71XxidcSxJ/NpEIZ/jbOzoWk0kfwY4J5fIF7ruNg uGi67M7F6hDRJg9OeFqAKsiOneRo4mQZvIZQBucP08UFRGzIzuGOszxXz8ZopyHKDuIS IULIJgo8TuuvhCkpN2E1BwhlE/tvb0ROX1J8+selQyU1FbEVIVZjgsRAfyWC7ZcYSyo4 UjBJSA65gpAUSXRfDlsMoLWLxjJd5ueHDjT7imXUcZo67G6nmMBYnLAJ2fFWILv1HmXJ loSrTZVNG/l/jpFZB3PUMQp3G0hSpSh8ejfuFn4zQ+5FICyuMUvWK71XzUK5hasUFpYa eOGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=volBetDwZhQX9fC04zMVYOMbO1RkS1wEneNzDmowndU=; b=mCwrwtC+uvL0+YDkF50bH3MzIUzMLyyUqLRPnLnGgNfbMpjEh4TD05UtUR9L6POm6q gc+h8cxj8U0slxtEThVsDi19dhPAcUoHTsjpu3Se6Q9Pqcp6TyvN2PAP/dd6lTRxWkn3 DWMWsEOFfjQyCw2wO8clXfH6uL0v5lLJvbCxTffGipdyq1dl32zlQ1MoMm4C568K0q0u knkK+T6bHqgv7aHShgQ/qH8s2lqMoH94cI+T7i1QRMRUPbftp4oL6B0xHl29YBkttp0v Jusqw+Pw5aRm4ux68CKlMzcmE0G5WYIWZufVPbJqQncBS/X2pKSeLbLuZnJUyHVxnDr0 ytVQ== X-Gm-Message-State: ACrzQf3Go0iOnvIEyU5TMDQR9Ce7MkyYV17Ed2+HKsphGATQ/i0Igdu0 JTZdv8wJmhRInsqyI16xPOw4s4wkNE4= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:8695:7c88:66ed:f9d1]) (user=glider job=sendgmr) by 2002:a17:907:3f96:b0:7ab:34aa:9094 with SMTP id hr22-20020a1709073f9600b007ab34aa9094mr2182051ejc.85.1666646527998; Mon, 24 Oct 2022 14:22:07 -0700 (PDT) Date: Mon, 24 Oct 2022 23:21:43 +0200 In-Reply-To: <20221024212144.2852069-1-glider@google.com> Mime-Version: 1.0 References: <20221024212144.2852069-1-glider@google.com> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Message-ID: <20221024212144.2852069-4-glider@google.com> Subject: [PATCH 4/5] x86: asm: make sure __put_user_size() evaluates pointer once From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Borislav Petkov , Ingo Molnar , Thomas Gleixner , x86@kernel.org, youling257 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?1747612484153729425?= X-GMAIL-MSGID: =?utf-8?q?1747612484153729425?= User access macros must ensure their arguments are evaluated only once if they are used more than once in the macro body. Adding instrument_put_user() to __put_user_size() resulted in double evaluation of the `ptr` argument, which led to correctness issues when performing e.g. unsafe_put_user(..., p++, ...). To fix those issues, evaluate the `ptr` argument of __put_user_size() at the beginning of the macro. Cc: Andrew Morton Cc: Borislav Petkov Cc: Ingo Molnar Cc: Thomas Gleixner Cc: x86@kernel.org Reported-by: youling257 Signed-off-by: Alexander Potapenko Fixes: 888f84a6da4d ("x86: asm: instrument usercopy in get_user() and put_user()") --- arch/x86/include/asm/uaccess.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index 8bc614cfe21b9..1cc756eafa447 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -254,24 +254,25 @@ extern void __put_user_nocheck_8(void); #define __put_user_size(x, ptr, size, label) \ do { \ __typeof__(*(ptr)) __x = (x); /* eval x once */ \ - __chk_user_ptr(ptr); \ + __typeof__(ptr) __ptr = (ptr); /* eval ptr once */ \ + __chk_user_ptr(__ptr); \ switch (size) { \ case 1: \ - __put_user_goto(__x, ptr, "b", "iq", label); \ + __put_user_goto(__x, __ptr, "b", "iq", label); \ break; \ case 2: \ - __put_user_goto(__x, ptr, "w", "ir", label); \ + __put_user_goto(__x, __ptr, "w", "ir", label); \ break; \ case 4: \ - __put_user_goto(__x, ptr, "l", "ir", label); \ + __put_user_goto(__x, __ptr, "l", "ir", label); \ break; \ case 8: \ - __put_user_goto_u64(__x, ptr, label); \ + __put_user_goto_u64(__x, __ptr, label); \ break; \ default: \ __put_user_bad(); \ } \ - instrument_put_user(__x, ptr, size); \ + instrument_put_user(__x, __ptr, size); \ } while (0) #ifdef CONFIG_CC_HAS_ASM_GOTO_OUTPUT From patchwork Mon Oct 24 21:21:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 10387 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp697265wru; Mon, 24 Oct 2022 16:13:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Mm+BTQsENnlaXjBKKDn7dkqephSlsjOra2Nh6ocaCeh5X98SHIvv1hy89PgERfGBe+sRn X-Received: by 2002:a17:902:d4c4:b0:186:a951:b8f9 with SMTP id o4-20020a170902d4c400b00186a951b8f9mr7410411plg.130.1666653196012; Mon, 24 Oct 2022 16:13:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666653196; cv=none; d=google.com; s=arc-20160816; b=LPdDDisphbfUQuVLN5fVwMRRBdpXTA79P01Ky9rLJx1d9E5CIZa/hqBjt3wXTPZSUz FKF8e7sB/vDdEx8H38LWtuBbsGpZreu9OFPFPsIkWn5GMn7gzdFEjdcUuZuyvpKnzBKg 9aPFt6tUAGJVJLzj3S5i1ezL2Esjuc4b2T88cfJcTpN/YXzmB4x2soj96NpZAoImQ7bf iV1nD7LA78Abim9ReMvdRFd+bbtWEN/5cN6ijV4yMegwSVV2Raur+aLMfS+K3QmRb9Ye S7GSE9xXVA5+svX/1tRI6/VL+efpHW4XPnuWZzdq/AdtYE/BlxEC1eXG6sZPbRzFmQG9 Iimw== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=O4b5t5V5Gcz1RUui4LqlZYe/T5V0+jbf0EermbhLbCo=; b=tSQmqbvKmm8TLE4bAc6kSh2h/pD5Wnv2smj0xRUPZnwnOSrfJsIRvgn0YtMT2EqR9f v4bKI6RRrlt/8BxIms8gNLmHUguHGm7xy2njtiUEdfqNPM73QLRyi8XrCm0zF1hjMJth EfNxHOKKtf7gxUZfZxhCv/D97lQFn+sTif91QMv6jgWcZvGtDNkRz8j4nBCcQFnqovKU qnJSV5DU57zi4frPxxZcle/Z/tj1ohOE+EQClNH8APUEvpAXjIbagAI0EUlM6q5OUlyC ncz/i/N03pgcjoNSK7/mOuX4PuoBpIviePCmkZV++wlTn5FeyZA5z3CS11yJVMdZdssK iluQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=UB5us+L6; 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 o31-20020a635a1f000000b004561c1f132csi907723pgb.346.2022.10.24.16.13.02; Mon, 24 Oct 2022 16:13:15 -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=UB5us+L6; 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 S230016AbiJXXBj (ORCPT + 99 others); Mon, 24 Oct 2022 19:01:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229939AbiJXXAg (ORCPT ); Mon, 24 Oct 2022 19:00:36 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D97002D7D0C for ; Mon, 24 Oct 2022 14:22:52 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-367dc159c2fso101321987b3.19 for ; Mon, 24 Oct 2022 14:22:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=O4b5t5V5Gcz1RUui4LqlZYe/T5V0+jbf0EermbhLbCo=; b=UB5us+L65WuSV7LKHhI52HcB3sYCuWwNnK8ltyO4u0vIvjaAB05ZLOAGafpo8l5cGa wBMFCT4Kkvrs5x4wtnBYfMOzahxa569zXfrrKTeHgqfmIyNP4oI+XztTL1fPKIJ8gpn3 0qkGExeFsAY6JZvk24haFa3HrCY2p0BIZwn7gyOEapmadRNJv3JRV0JguVi3J5+d36gN eqa6FcGmhPmYjXJhbPUKqqlQx3k9kRlFuROjUY1SCl88+13znc8K5XUxIlRLoL6bXrBN VHDy4KdKJBliLnYUrxmcBAiyhgWHSM9VL/a952Bi8+gPciMk2TXd+F4AepHVcsqQrC8T /i9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=O4b5t5V5Gcz1RUui4LqlZYe/T5V0+jbf0EermbhLbCo=; b=NWTNvwuKzvM9Vscanu8rzKyD3sNsSZ8GslREPICw+d4bc6gl4XiXh/YZQqHER2QhGI 21XBt4ZCbStF0BgwS42gy0MD4LxijAe9Ynz3hxRaJVMbxgyBA+yTyUZQgJsyqltb/FN4 6uhXgM7GKrjRQo22MhECP6O4Nin9wp1Gqn6FY8u/hzjkepaC7WuY+XWw0lavWQLaAmCT HpR/rQefj2xYSap806ITQZKRNAniu2rlSAnfHOMnyo/APkJ63RLK/Y+5h9/4QTTRoU3j IvDXKkaDEOmkCUTLe+3LeenuAMTP7HH98S1N4X4PIdaVXHEBqg/dBE1BvA0BcyKbJ/L8 YotQ== X-Gm-Message-State: ACrzQf02uN4xYtGlIoYvb6ZZuqaLBuLvS18S8srU91ZLLWNAfkCJl71T mlV4UlM/sImSK8V9nLv1vJRBcFYM9LE= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:8695:7c88:66ed:f9d1]) (user=glider job=sendgmr) by 2002:a81:5a57:0:b0:353:6de6:3263 with SMTP id o84-20020a815a57000000b003536de63263mr30747701ywb.358.1666646530679; Mon, 24 Oct 2022 14:22:10 -0700 (PDT) Date: Mon, 24 Oct 2022 23:21:44 +0200 In-Reply-To: <20221024212144.2852069-1-glider@google.com> Mime-Version: 1.0 References: <20221024212144.2852069-1-glider@google.com> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Message-ID: <20221024212144.2852069-5-glider@google.com> Subject: [PATCH 5/5] x86: fortify: kmsan: fix KMSAN fortify builds From: Alexander Potapenko To: glider@google.com Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Nathan Chancellor , Nick Desaulniers , Kees Cook , Tamas K Lengyel 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?1747612541815973117?= X-GMAIL-MSGID: =?utf-8?q?1747612541815973117?= Ensure that KMSAN builds replace memset/memcpy/memmove calls with the respective __msan_XXX functions, and that none of the macros are redefined twice. This should allow building kernel with both CONFIG_KMSAN and CONFIG_FORTIFY_SOURCE. Cc: Andrew Morton Cc: Nathan Chancellor Cc: Nick Desaulniers Cc: Kees Cook Cc: linux-mm@kvack.org Reported-by: Tamas K Lengyel Link: https://github.com/google/kmsan/issues/89 Signed-off-by: Alexander Potapenko --- arch/x86/include/asm/string_64.h | 11 +++++++---- include/linux/fortify-string.h | 17 +++++++++++++++-- include/linux/kmsan_string.h | 21 +++++++++++++++++++++ mm/kmsan/instrumentation.c | 1 + 4 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 include/linux/kmsan_string.h diff --git a/arch/x86/include/asm/string_64.h b/arch/x86/include/asm/string_64.h index 3b87d889b6e16..888731ccf1f67 100644 --- a/arch/x86/include/asm/string_64.h +++ b/arch/x86/include/asm/string_64.h @@ -10,10 +10,13 @@ /* Even with __builtin_ the compiler may decide to use the out of line function. */ +#if defined(__SANITIZE_MEMORY__) && defined(__NO_FORTIFY) +#include +#endif + #define __HAVE_ARCH_MEMCPY 1 -#if defined(__SANITIZE_MEMORY__) +#if defined(__SANITIZE_MEMORY__) && defined(__NO_FORTIFY) #undef memcpy -void *__msan_memcpy(void *dst, const void *src, size_t size); #define memcpy __msan_memcpy #else extern void *memcpy(void *to, const void *from, size_t len); @@ -21,7 +24,7 @@ extern void *memcpy(void *to, const void *from, size_t len); extern void *__memcpy(void *to, const void *from, size_t len); #define __HAVE_ARCH_MEMSET -#if defined(__SANITIZE_MEMORY__) +#if defined(__SANITIZE_MEMORY__) && defined(__NO_FORTIFY) extern void *__msan_memset(void *s, int c, size_t n); #undef memset #define memset __msan_memset @@ -67,7 +70,7 @@ static inline void *memset64(uint64_t *s, uint64_t v, size_t n) } #define __HAVE_ARCH_MEMMOVE -#if defined(__SANITIZE_MEMORY__) +#if defined(__SANITIZE_MEMORY__) && defined(__NO_FORTIFY) #undef memmove void *__msan_memmove(void *dest, const void *src, size_t len); #define memmove __msan_memmove diff --git a/include/linux/fortify-string.h b/include/linux/fortify-string.h index 4029fe368a4f6..18a31b125f9d6 100644 --- a/include/linux/fortify-string.h +++ b/include/linux/fortify-string.h @@ -43,11 +43,24 @@ extern __kernel_size_t __underlying_strlen(const char *p) __RENAME(strlen); extern char *__underlying_strncat(char *p, const char *q, __kernel_size_t count) __RENAME(strncat); extern char *__underlying_strncpy(char *p, const char *q, __kernel_size_t size) __RENAME(strncpy); #else -#define __underlying_memchr __builtin_memchr -#define __underlying_memcmp __builtin_memcmp + +#if defined(__SANITIZE_MEMORY__) +/* + * For KMSAN builds all memcpy/memset/memmove calls should be replaced by the + * corresponding __msan_XXX functions. + */ +#include +#define __underlying_memcpy __msan_memcpy +#define __underlying_memmove __msan_memmove +#define __underlying_memset __msan_memset +#else #define __underlying_memcpy __builtin_memcpy #define __underlying_memmove __builtin_memmove #define __underlying_memset __builtin_memset +#endif + +#define __underlying_memchr __builtin_memchr +#define __underlying_memcmp __builtin_memcmp #define __underlying_strcat __builtin_strcat #define __underlying_strcpy __builtin_strcpy #define __underlying_strlen __builtin_strlen diff --git a/include/linux/kmsan_string.h b/include/linux/kmsan_string.h new file mode 100644 index 0000000000000..7287da6f52eff --- /dev/null +++ b/include/linux/kmsan_string.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * KMSAN string functions API used in other headers. + * + * Copyright (C) 2022 Google LLC + * Author: Alexander Potapenko + * + */ +#ifndef _LINUX_KMSAN_STRING_H +#define _LINUX_KMSAN_STRING_H + +/* + * KMSAN overrides the default memcpy/memset/memmove implementations in the + * kernel, which requires having __msan_XXX function prototypes in several other + * headers. Keep them in one place instead of open-coding. + */ +void *__msan_memcpy(void *dst, const void *src, size_t size); +void *__msan_memset(void *s, int c, size_t n); +void *__msan_memmove(void *dest, const void *src, size_t len); + +#endif /* _LINUX_KMSAN_STRING_H */ diff --git a/mm/kmsan/instrumentation.c b/mm/kmsan/instrumentation.c index 280d154132684..271f135f97a16 100644 --- a/mm/kmsan/instrumentation.c +++ b/mm/kmsan/instrumentation.c @@ -14,6 +14,7 @@ #include "kmsan.h" #include +#include #include #include