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: 13018170 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 245D7C67871 for ; Mon, 24 Oct 2022 21:21:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90BC6940008; Mon, 24 Oct 2022 17:21:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BB63940007; Mon, 24 Oct 2022 17:21:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7AA5D940008; Mon, 24 Oct 2022 17:21:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6FD7B940007 for ; Mon, 24 Oct 2022 17:21:51 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 47E58805D5 for ; Mon, 24 Oct 2022 21:21:51 +0000 (UTC) X-FDA: 80057115222.06.C533FD2 Received: from mail-lj1-f201.google.com (mail-lj1-f201.google.com [209.85.208.201]) by imf09.hostedemail.com (Postfix) with ESMTP id D31B514000E for ; Mon, 24 Oct 2022 21:21:50 +0000 (UTC) Received: by mail-lj1-f201.google.com with SMTP id bj23-20020a2eaa97000000b00276a677c474so3824034ljb.0 for ; Mon, 24 Oct 2022 14:21:50 -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=5PH+FCbzf9wgvEDjsJ4MFLvGJf2jwDaasoH420pXipQMgvtoPiVFV9GVJvevUdTe1F dOMwgdJV+SwQOvlki6suCJX+/5fnDYp3KPVhAGZMUBzufoxNgTCKt0vBfbxwixhhdy3M EofDJ7uBVxKV0o9r6INresamV7D4zM1WW84tEbXHMsrYMinGQvMRGelsC9yp5zs7abDV evuJFM3oYSy6K1xVR9QOPrgubd85Tq+Ua4YdsjEbBjpZ0e5tQ7i0/afnIRriGmF9SbCL /EGBwBtOA0ZZkU4vJdYuzGyc/f755ME5T2ZbQs0RJuWn9hH+60FjNftD3KHnahuJYhmo ALLg== X-Gm-Message-State: ACrzQf3LIgzzSwCAarNFntBM+I6DmA4/UIx6ns63+6nf4O8mz7vC5ILh o5uPnL631inTXgLQWxJRJ+nBnX/VrjM= X-Google-Smtp-Source: AMsMyM48tMgyNJTcQaeP49oPDEv9IHgkDLnPXKM/jKBNnXEO6qCwgCXK+Fopa0pPG4zOuEJQI1VErzmH0jI= 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666646511; a=rsa-sha256; cv=none; b=vgWfqQvB12Wy36RQHbTUS7ooa0nVdoaLTpTqnBhNyYYJ3puJsvpL2cndouxyIg7BZKVBWs AKR5OFFYyjuPfY2Ve1zs/RNeKu6VZimS7vrx5clSaNG/ZZn8tRt8Bw6fZ54r4kjfGhekAV 1Dr+z6XgubW/JRJUt92fhptmaduemlA= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=aSgkiacZ; spf=pass (imf09.hostedemail.com: domain of 37AFXYwYKCG0RWTOPcRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--glider.bounces.google.com designates 209.85.208.201 as permitted sender) smtp.mailfrom=37AFXYwYKCG0RWTOPcRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666646511; 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: references:dkim-signature; bh=G4yBv7Ojnp7UF/vJeQGCUBcD6F1oQa7UXx9ZrIQaMAU=; b=qYayku81FxHT0mB3XUKivCoh/oAUzrHTDv1JgxilDFfy+3KNF25GYGrsyLxENfVNqlo1q9 2HNdVdiayikTuGlFQfo8TfCN1kAPXuKJaqEse17HqoANCsAUx4dfRy2l7U6OYBKQw91PmR FeRRKsAcjUY+7fNIT8zg9KvZj6hceEo= X-Rspamd-Queue-Id: D31B514000E X-Rspam-User: Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=aSgkiacZ; spf=pass (imf09.hostedemail.com: domain of 37AFXYwYKCG0RWTOPcRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--glider.bounces.google.com designates 209.85.208.201 as permitted sender) smtp.mailfrom=37AFXYwYKCG0RWTOPcRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam04 X-Stat-Signature: rw3qtd6cnow7bz4gr5mzgj3nz7t7deiw X-HE-Tag: 1666646510-260885 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: 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: 13018171 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 BEF1DC67871 for ; Mon, 24 Oct 2022 21:22:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 58957940009; Mon, 24 Oct 2022 17:22:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 538B1940007; Mon, 24 Oct 2022 17:22:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42890940009; Mon, 24 Oct 2022 17:22:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 380DD940007 for ; Mon, 24 Oct 2022 17:22:01 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 021CA1606C7 for ; Mon, 24 Oct 2022 21:22:00 +0000 (UTC) X-FDA: 80057115642.15.AFE0D08 Received: from mail-lj1-f202.google.com (mail-lj1-f202.google.com [209.85.208.202]) by imf09.hostedemail.com (Postfix) with ESMTP id 15B19140015 for ; Mon, 24 Oct 2022 21:21:58 +0000 (UTC) Received: by mail-lj1-f202.google.com with SMTP id x7-20020a2ea7c7000000b002770aeb6d15so1635186ljp.13 for ; Mon, 24 Oct 2022 14:21:58 -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=yHw5fpMRipUSD4Jb72/0Nh9ke9rx4EXXuq3wdCRhuFPtZcI2UgiNd98fxuQ2xpYKDJ fOwWeJ44Geo/AYHvki02HjSaV4Lo+leM+wRxacLD0i+9pWW49uxmIVT4q/lUwcTwNOkJ b1OmLMaf7CMdRH8HxhPl6NFktLOKlwn53oe9IgnkgBLQ318Lz/+CaqFlVtzC9RjVfOO5 xIBjFBal6Mnmd4E7L5VLqRzAQ88tXcB+g2q4u/gSL+F6TG+hvG0me9qslXvNnhQ3Y8IO 9Kj/Ua0egCLXaL+qlLCGZYA/OpkF4v8WgRVz1hTbWavSlOXCbS7UNYWDmAxtuAooqz/8 x6GQ== X-Gm-Message-State: ACrzQf2s/1fw3VgAbj6cAJ+wfFTDBR+7oXA0cmldyuPQcD/ZIRJ3BaYS 4Jnlnpl/QDYA/Lq3Z1l/RMkGwcKJHkE= X-Google-Smtp-Source: AMsMyM71innvLamIkBMpwiwhUw/yYthw7zM8NGpJq9LhH+G7pZpYkhGY54RKQfT1VYVKSQ9sih3hlGce8Og= 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666646519; a=rsa-sha256; cv=none; b=nq0sAWCBkwTFYz1AAiPChm/rzbp9jKRio3CN0Csb8ONXpsHvZFyX5Xe5llQw7S2r0oWENu 6IYdM5bx3EWIM9F/+DmrAvu4w4kqFP1O/yGZOfedD59xEGzu3ixo4p/S14jqXEcOVWX/je pjI0IDv5WX5Ni7HhE+S95Uq2slvZBL4= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=QrB2Fv9L; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 39QFXYwYKCHYafcXYlaiiafY.Wigfchor-ggepUWe.ila@flex--glider.bounces.google.com designates 209.85.208.202 as permitted sender) smtp.mailfrom=39QFXYwYKCHYafcXYlaiiafY.Wigfchor-ggepUWe.ila@flex--glider.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666646519; 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=h1brEJBipb7gPKmBCB4iwvDw2G6SbkIMFGPFK60cCqY=; b=2t3uAvPK7V2ditXe5Yu17wRnM7p+/hniY3Y1Nb4ZEg5gSlcIxWSvAaG3OeMuatrZSmoV7m Pa09wtBo/O8p0lxd6sUCAb+NRkQUp9XlOyr9ZLR3mEYVIw9g7eBJ6VoGoeqooWiZwbAb8e m8EjmPk4Tz3zzX1e/dmsD72l81Ztwq0= X-Rspam-User: Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=QrB2Fv9L; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 39QFXYwYKCHYafcXYlaiiafY.Wigfchor-ggepUWe.ila@flex--glider.bounces.google.com designates 209.85.208.202 as permitted sender) smtp.mailfrom=39QFXYwYKCHYafcXYlaiiafY.Wigfchor-ggepUWe.ila@flex--glider.bounces.google.com X-Rspamd-Server: rspam11 X-Stat-Signature: 3oecaxcqt5boh3qjcy8ud9qhzetygnqm X-Rspamd-Queue-Id: 15B19140015 X-HE-Tag: 1666646518-289886 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: 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: 13018172 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 01498C67871 for ; Mon, 24 Oct 2022 21:22:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8216894000A; Mon, 24 Oct 2022 17:22:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D1CB940007; Mon, 24 Oct 2022 17:22:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6994694000A; Mon, 24 Oct 2022 17:22:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 5BDA0940007 for ; Mon, 24 Oct 2022 17:22:06 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 259761C5D4E for ; Mon, 24 Oct 2022 21:22:06 +0000 (UTC) X-FDA: 80057115852.17.20967E5 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) by imf15.hostedemail.com (Postfix) with ESMTP id AD47EA0002 for ; Mon, 24 Oct 2022 21:22:05 +0000 (UTC) Received: by mail-ed1-f73.google.com with SMTP id c9-20020a05640227c900b0045d4a88c750so10469758ede.12 for ; Mon, 24 Oct 2022 14:22:05 -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=NYfSpn8vNUdA2m0rtBYZDj36ntcYpP50i025wrSyqnsnevt/wKYW7B+2F55eXiphSZ t4gAVIlhZAd9gozjVuSnKYdvmvbIsxuYEpP6Rnf/4g4L7AVoJ5sVz7OKrHh3YQe6ZM+W YgwGs4fHuOQVpWzyKraN2tsz2ZhziW3McU1zEpg3z/JZsK8O3pjVdDDjcIq35rbgNUtp 4pT1c6C0hjAdf2W/hdNDOinGQX8EskliNe2oiMzSpZ+5eCohLxoNfLs2rLl50WKu3MOr +zQvbTqhewL4NpEGYXVQRYbnYOWjqqqjUsxZKKUIEmeOcoqhoJbzTBFg4IY/nxQfx4nm aE1A== X-Gm-Message-State: ACrzQf10b56Np+GokvgyTaAvVKO9YELl37O5g/SMriGijg5cp7+6GMta eReVj2hCrn5bZR0R+ohg4zVwyKB0dWg= X-Google-Smtp-Source: AMsMyM4v3Qlkg/xauVd+MHmORNpeKek6l2QBmxJ3e+SVVwmlcYAuzT3vjefHuTAy1CPMCwZF2Oldi5XsCCI= 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666646525; a=rsa-sha256; cv=none; b=6Xw9amKjHhoNbuvaeI2fhyFBZYNLbtZJjI8fLk/8ystB5rVj8NON3yGbNrf4n7oAdTtvmm BAUKA6Fcpmi7hRpxFWWraXQ3oz+VsFdy/AR5801d1AvhItI8gdCppUcBlwvZX3Qi6+ZxBV VLk62yqxYjOD4z6ZmB7uIydIcaIbHbI= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="Z2RX/saD"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3_AFXYwYKCH0hmjefshpphmf.dpnmjovy-nnlwbdl.psh@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3_AFXYwYKCH0hmjefshpphmf.dpnmjovy-nnlwbdl.psh@flex--glider.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666646525; 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=XYIeNtcSMBuwQ4ZUNtMrq5SFnntAuabRdvmK/d2x8js=; b=1avKAUQeUAUPQ9jGHKaEbTCbybvJqgT2rAIuXkTCabL0DUpAwWWieBWiIcmBsmMbk86INS ydNGmk2yPDMeDI+hyfhBImuxUNtGSiRPxUrBImwAuXkf7u5YPXW+F80TzqCMIiIkDqj4WF HpJEez7QihtuQ16it63EY/Z0iVPV28A= X-Rspamd-Queue-Id: AD47EA0002 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="Z2RX/saD"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3_AFXYwYKCH0hmjefshpphmf.dpnmjovy-nnlwbdl.psh@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3_AFXYwYKCH0hmjefshpphmf.dpnmjovy-nnlwbdl.psh@flex--glider.bounces.google.com X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: 7dm3res1apr7rpj5ot6pxp9by4jgtfrw X-HE-Tag: 1666646525-893839 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: 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: 13018173 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 0C84FC67871 for ; Mon, 24 Oct 2022 21:22:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C1D1940007; Mon, 24 Oct 2022 17:22:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6727494000B; Mon, 24 Oct 2022 17:22:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56AF0940007; Mon, 24 Oct 2022 17:22:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4891E940007 for ; Mon, 24 Oct 2022 17:22:09 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0EE08A0D29 for ; Mon, 24 Oct 2022 21:22:09 +0000 (UTC) X-FDA: 80057115978.21.2AC10E6 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) by imf15.hostedemail.com (Postfix) with ESMTP id 98031A000A for ; Mon, 24 Oct 2022 21:22:08 +0000 (UTC) Received: by mail-ed1-f73.google.com with SMTP id c9-20020a05640227c900b0045d4a88c750so10469831ede.12 for ; Mon, 24 Oct 2022 14:22:08 -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=DwkIiCO1A1m/cXs7zbxoLv7o04SUjhRhUgDGqGlekEWGKfK2pwL9CyVdtaQAjh8YMD gqGpcOQXp49e06MIPGedYuW6ekeAE28h8O7NOFOi49g+lNXj3pREZKO4sGGYnCyVHMmm DghHGgaN/3vsHpqpCFyxBSvfM8sE89wAzhN5NMLXOFuEbJFinI20AuptoChJQJIbnN9h M/2EIiOhDdkyISfPTjeRDWG1Q2R4wdcR69bY/P/oedCSnibStcaZXaa9MxpdqEkSNZwf XXQjeW5Q9aCoQ4DeaRInx4WE0Rul3/tvBLK0kwutm7VuiEZ46Dnh0hyf/iMCEOkBwM7P St+w== X-Gm-Message-State: ACrzQf371j2bI7g2xgj7Djd8dbz3XWduKBsd++cuNWaJ47MaSFTFm0uQ sXq3vYum0j2vdDU/MRdQlpoLRypt9Ug= X-Google-Smtp-Source: AMsMyM6Tq20dngPWWsHMTzhzn39uWvW18mFyDgT+su4EaQ1IkASlw4U74YHbIUx7kj1tUnUMLAaBPw2aqg0= 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666646528; a=rsa-sha256; cv=none; b=8of3Wi1DIXTTQSMMFb9JtU1Pv7pLzdozBPjvvAL4xd9bLbbj3ux3njKnKKVRdwXZDhhkEC jy5BD9OIC/bL0ozusAkV4vM78ThX0ZhkYFSv+4Rc0fGaapqgLVuuG2L3ZPIrNigok7AxTz KqD99PZorkbk3oaGW6vNNagHREo/Dek= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=J4G17c7U; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3_wFXYwYKCIAkpmhivksskpi.gsqpmry1-qqozego.svk@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3_wFXYwYKCIAkpmhivksskpi.gsqpmry1-qqozego.svk@flex--glider.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666646528; 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=volBetDwZhQX9fC04zMVYOMbO1RkS1wEneNzDmowndU=; b=URnlSkpqGV9S184S/dnYAaw9JSivvOaANVQsQi8yh+zFfULDEZ4OG5B6st2v2rhXGO31iB 2gaKb6oECzsK+fAPrc4MMR/GSRxeIKy1piWy+0qb7Cz7+m/oVVJWhuDpe42lFb8hGhYuXT fd30uxIYvb1HsSyblp7hY08lCykrspw= X-Rspamd-Queue-Id: 98031A000A Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=J4G17c7U; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3_wFXYwYKCIAkpmhivksskpi.gsqpmry1-qqozego.svk@flex--glider.bounces.google.com designates 209.85.208.73 as permitted sender) smtp.mailfrom=3_wFXYwYKCIAkpmhivksskpi.gsqpmry1-qqozego.svk@flex--glider.bounces.google.com X-Rspamd-Server: rspam12 X-Rspam-User: X-Stat-Signature: h97s4rgq68667rstximsybwhnswe7q45 X-HE-Tag: 1666646528-251909 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: 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: 13018174 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 99637C38A2D for ; Mon, 24 Oct 2022 21:22:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3664C94000B; Mon, 24 Oct 2022 17:22:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3165B940008; Mon, 24 Oct 2022 17:22:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1DE6094000B; Mon, 24 Oct 2022 17:22:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0FE0E940008 for ; Mon, 24 Oct 2022 17:22:12 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D788EA01F7 for ; Mon, 24 Oct 2022 21:22:11 +0000 (UTC) X-FDA: 80057116062.01.267D89B Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf13.hostedemail.com (Postfix) with ESMTP id 63F8E20011 for ; Mon, 24 Oct 2022 21:22:11 +0000 (UTC) Received: by mail-yb1-f201.google.com with SMTP id 204-20020a2510d5000000b006be7970889cso10334323ybq.21 for ; Mon, 24 Oct 2022 14:22:11 -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=AnkjWr1gHRFej+eCeZhFY+aZ+yY96Km+smSicHK2+wxk/rh91CHNENAaAxc8IAPSYG 3jvXZYqmYrb26OB+xtwHVTqdbo047C7/d7ZTIbLWioJb+yCwGedrCWKUffKgES9FXV4C PAhcFMciPAcgrE8XbF8UaKdzhhBECImKUjaXOfaA1fwmDoixauooyJ3FeORnvEpEools 5lz9sc6is799oov5khuTutQi48xeGj9jRPOZ+RrTxiZw7LC/8aExUBrPqIgxpskWZ6OS 9P6hpkhEy7ic1/mPi6WwzLqIJyhIOd/GPC5FWn0ew9eBlCWN0rsSMr4Vn+4ES9r88kz/ KPBQ== X-Gm-Message-State: ACrzQf21app0P0QYMF06BXeMQcyU6GlzUFHUhr0zQ0x1EWXtgKSMRm7R FE3NZymWAR6IGrTyTId5vyajX07G6QA= X-Google-Smtp-Source: AMsMyM5VBxRcm1qmP+PFj9h/2lKWDWBZikjFrcTw4qx0rnWZ6p3EtaAFU2NKQO0mL3nnRdjEwSH7GuhQvh0= 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666646531; a=rsa-sha256; cv=none; b=OyVDVEyJeFeFIlP8W6nOLT0IVDL9PHEWA/DGEX88YLB05hal8LegqkeaWwXZmJMpxTNub/ ZzeYDwqoaSYUcK/cQKH0asK8cMEEL6kYZO0VJvrNDnvxWB5V2mXqeo1e3u9a9lAdzWYRmI /73wvCJpyLQ9W3DuDEoRxenREshTcUI= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=UB5us+L6; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of 3AgJXYwYKCIMnspklynvvnsl.jvtspu14-ttr2hjr.vyn@flex--glider.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3AgJXYwYKCIMnspklynvvnsl.jvtspu14-ttr2hjr.vyn@flex--glider.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666646531; 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=O4b5t5V5Gcz1RUui4LqlZYe/T5V0+jbf0EermbhLbCo=; b=6HHOPqGBP1emd8dV9uN40YK4cWX2cdf/3aohy07HIEWwjTwHjGN3YOCpCJur9fquz+xbJI PW7OXO3jYJITb80wr4BHNBU10l2Lxnu/qKwjcnPvkymciSBkaGCQWVj+RDr51rz6qsWWju ixNmTKDZvOL6xPC3FEfEXCrYtOYrRrA= X-Stat-Signature: nam1rqpqgb6btp97rhyu9j9k5oxw8rso X-Rspam-User: X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 63F8E20011 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=UB5us+L6; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf13.hostedemail.com: domain of 3AgJXYwYKCIMnspklynvvnsl.jvtspu14-ttr2hjr.vyn@flex--glider.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3AgJXYwYKCIMnspklynvvnsl.jvtspu14-ttr2hjr.vyn@flex--glider.bounces.google.com X-HE-Tag: 1666646531-634997 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: 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