From patchwork Wed Nov 4 23:18:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883253 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EE17C00A89 for ; Thu, 5 Nov 2020 05:05:32 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7466E2151B for ; Thu, 5 Nov 2020 05:05:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="n1/DyqJp"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="jEMAS1fm"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="vfRlFfDi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7466E2151B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=twTdjda4cieOAO3mWxprSuxyEV6HGOVOhz34VPxSIwU=; b=n1/DyqJpC3HD/cf3JqkLzv1So W/PbeR/n/ynzPC5o/Jb9R8Zue5cPdG1p3leUSfrrQtYoG8KRb4pEaFmwQ0yOhHUiQl4Fjw7I3Y/35 aPLRsm90X4qVm6jmZ6a+K2DFd+Laj/xnPc7J2LotJcJ6uFrSKqV7rnnK5AzVhGElJXgidvACbhs4v dUtwLztKQjbJmuD5kN1p2Z0BgrF+8sM3mrBO66yFv+vQzVg1GJ6rMmX4T/8N09LuGPNfS2drvOo96 zNjkhQVHdT65/Mai3pqAHR4BDwDChBWb1EkXObTelQBiOpWqs7DxrA8rX77BqyDCF9dlcMGzreofc AybzZSfqQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXQx-00046R-Fs; Thu, 05 Nov 2020 05:03:39 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5N-000145-Tf for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=EAVCYXK+qwXTj64iW4lXgFSidDhKD1r7M09orz7ePT4=; b=jEMAS1fmwW4z6AjhliDxBKmsDV lFmC+O1EpIgqt+afVd2YAsq9pns4tOwu48tWfKLu/bOq+VukuhrrOFy7hGzZoHgvMLZ3D7B4sWRxi 3mqhJhyiy5DP90ObhyNqGI08cC2irbUA/eMEdTmhw6NErNvLkbVFm9zGsKtzqwY8G8siDLrrgGHon R8w18y7qbfviaX5LirqRuBCBgmLDe0ccm2+84fGhnx2f43O2HumpiiHbwx8SH+Us+vOuSMRfxMKRu K286G4Wwxh8wTTE3I4UZ24hvUhzP/KOKnULo6FA6aqyNb4fj0XYipzUiBGZr2scIYxc729i1hNaA5 Q+W28EZA==; Received: from mail-qv1-xf4a.google.com ([2607:f8b0:4864:20::f4a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS4d-0003sZ-10 for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:18 +0000 Received: by mail-qv1-xf4a.google.com with SMTP id z9so13819204qvo.20 for ; Wed, 04 Nov 2020 15:20:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=EAVCYXK+qwXTj64iW4lXgFSidDhKD1r7M09orz7ePT4=; b=vfRlFfDihd/uPXYkjaLumolTNaGVq/OgPmxJrlxg9zSZB143sC2lJrSxJ/DrPtClFq p5pAKXCc+xO+JhpNQxAFtDWThSHF+F6tbEahLhDmchbt6KwzmfftXluNO23Hbwa/wUgf 7/GmE2N0KXWgHKob5O9Dq53sNqUaPOd/IYKDs3c3twsh0gmODiDnM4ijXbFBgl9v1rGm mkCv/HNO3IXFdD1CQgdMUR73S2IAVOiQGRCkKaD1UPjwlRgPJAYiuLa6p4tTyedq9U8Q st0La4aBrcY7GeFviyh8Xxf0qymhaxkXhRYv6dG34fRTWNGAvH8/WNWNhc6cF1blrr2n mT+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=EAVCYXK+qwXTj64iW4lXgFSidDhKD1r7M09orz7ePT4=; b=lcziFt7hkMYOPKz3qBhXN36a/x7Ub5YviCIzktRuFkTFgNebzqpKecXMamZU/wXFd9 orUVDfarJ84pXHMImw0z+sIu96BsEgYC7Ad7Whs6jcYoZrBeOjriUg26OPKtNh1u3/kb HbEpwdn7n7fMJj7m5ytjHEv38Rj8j6CAHvQU6pjmjyevO+v8qR6RB0ttk5+M1KmLyik3 8BRbYznwWUrwJbGOivFz0UT7TZ5fze6CnKQbtkUc2dT9NmHwhj019IcFBUx3axp1jhwr cIoPcBe/h9s8ZzFe0z0On/DuCYBWvx89pqWokYIxPcVnfNgeFEdwwGeGVgM4csr4xPzK SheQ== X-Gm-Message-State: AOAM533olU3ub7EgGlT+whKTHc6WA4t2T9m5pGTiyY4zmJexesx/BFlc 7SssuMCxsSsU8n5Uk2HKOjtVFpwuVftEbSfL X-Google-Smtp-Source: ABdhPJzNxrRe8w5RsxYjBRo0TPYmJG1CAxf2Ec+0gXPqgO7LOkWmdI05RCtX8PsMLSGHCuSAG1eoE7l7U+xKLWMv X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:40c6:: with SMTP id x6mr284828qvp.20.1604531947585; Wed, 04 Nov 2020 15:19:07 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:16 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 01/43] kasan: drop unnecessary GPL text from comment headers From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232015_596065_E902B7C3 X-CRM114-Status: GOOD ( 13.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Don't mention "GNU General Public License version 2" text explicitly, as it's already covered by the SPDX-License-Identifier. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: If0a2690042a2aa0fca70cea601ae9aabe72fa233 --- mm/kasan/common.c | 5 ----- mm/kasan/generic.c | 5 ----- mm/kasan/generic_report.c | 5 ----- mm/kasan/init.c | 5 ----- mm/kasan/quarantine.c | 10 ---------- mm/kasan/report.c | 5 ----- mm/kasan/tags.c | 5 ----- mm/kasan/tags_report.c | 5 ----- 8 files changed, 45 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 950fd372a07e..33d863f55db1 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -7,11 +7,6 @@ * * Some code borrowed from https://github.com/xairy/kasan-prototype by * Andrey Konovalov - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * */ #include diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 248264b9cb76..37ccfadd3263 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -7,11 +7,6 @@ * * Some code borrowed from https://github.com/xairy/kasan-prototype by * Andrey Konovalov - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt diff --git a/mm/kasan/generic_report.c b/mm/kasan/generic_report.c index a38c7a9e192a..6bb3f66992df 100644 --- a/mm/kasan/generic_report.c +++ b/mm/kasan/generic_report.c @@ -7,11 +7,6 @@ * * Some code borrowed from https://github.com/xairy/kasan-prototype by * Andrey Konovalov - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * */ #include diff --git a/mm/kasan/init.c b/mm/kasan/init.c index fe6be0be1f76..9ce8cc5b8621 100644 --- a/mm/kasan/init.c +++ b/mm/kasan/init.c @@ -4,11 +4,6 @@ * * Copyright (c) 2015 Samsung Electronics Co., Ltd. * Author: Andrey Ryabinin - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * */ #include diff --git a/mm/kasan/quarantine.c b/mm/kasan/quarantine.c index 4c5375810449..580ff5610fc1 100644 --- a/mm/kasan/quarantine.c +++ b/mm/kasan/quarantine.c @@ -6,16 +6,6 @@ * Copyright (C) 2016 Google, Inc. * * Based on code by Dmitry Chernenkov. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * version 2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * */ #include diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 00a53f1355ae..d500923abc8b 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -7,11 +7,6 @@ * * Some code borrowed from https://github.com/xairy/kasan-prototype by * Andrey Konovalov - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * */ #include diff --git a/mm/kasan/tags.c b/mm/kasan/tags.c index e02a36a51f42..5c8b08a25715 100644 --- a/mm/kasan/tags.c +++ b/mm/kasan/tags.c @@ -4,11 +4,6 @@ * * Copyright (c) 2018 Google, Inc. * Author: Andrey Konovalov - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * */ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt diff --git a/mm/kasan/tags_report.c b/mm/kasan/tags_report.c index bee43717d6f0..5f183501b871 100644 --- a/mm/kasan/tags_report.c +++ b/mm/kasan/tags_report.c @@ -7,11 +7,6 @@ * * Some code borrowed from https://github.com/xairy/kasan-prototype by * Andrey Konovalov - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * */ #include From patchwork Wed Nov 4 23:18:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883287 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45AACC00A89 for ; Thu, 5 Nov 2020 05:19:47 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 98BE52087D for ; Thu, 5 Nov 2020 05:19:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="eN6UcBBd"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="iPpPVNEV"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="bHVBEntx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 98BE52087D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LWiy7CDwKXhakYTUghwEsS0E2h8OqVeOg6hHcxe5qWQ=; b=eN6UcBBdVWC2UchwwM6oRwXqq bsryuAXxrajGKCJEY42k2dyVuPl6GLgkaDMo5siFF8esNqSBRyNA7nk388qa6py5of+bJAGGlb6yp 2rNatA4f5s7KpB3IImb+xK5Uv1iETw+vAUyk5KhXP25DB0G8qkR8CYkFgzRlCSxC7UKUGaHYMh1oC Dz7zveFKZUxh54loT9TS1A4S277Y3RHnUsccMwejK2btWtPeLcePHTNuAz4vT64sBVaL3F5EYBgJc X87zdL/dv3cpJQVe25Vo8jdz2Z4hF4x6mbnWYcYUa+wU8+3yuwpYUaTpf1o+qhL+uskB6EJz/ZV9t dhzn8XLTQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXfn-0002On-9h; Thu, 05 Nov 2020 05:18:59 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5O-00016k-DQ for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=LIY2nrONxUEpI3abKUGgXLbsvOzrU8dATPLwmTEHaeU=; b=iPpPVNEVnYSTzPFEhSdVPOrA1E pvPQlUXI0QtyUxBI1ZftUI4Lnw4aHg2TYfyXlmRvV4GGFQ4BY1VuHq6kGl5uue/EUQ2amR3LvqGzT MuGSQreDbmznlZ3+8wWUAWe6GXreDPon4iJRWu+AkX/4+rWYJoejE147ls9oKygPgsCel/+M70Dui ktzG5KkRnINJphb3tgv8wc++6hnNHmpMIJKChwcXcS+NeIseE3/bu54BWEoei7g+58HozyOZ2RuBm TCX/Sb64GYvo8DtPQcIBd6tJVp68DwhqXIdjWOmTpVEckpjVjyK0zfcn66hhSi1PG1sHbYWAIlKK+ TKBbWw5w==; Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS4c-0003sY-TN for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:17 +0000 Received: by mail-wm1-x34a.google.com with SMTP id l16so10922wmh.1 for ; Wed, 04 Nov 2020 15:20:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=LIY2nrONxUEpI3abKUGgXLbsvOzrU8dATPLwmTEHaeU=; b=bHVBEntxz8CISEU0UMN8g7zfiBYpgf9c3dPv6MGEzxLVFboSh9vX2gqioqWBXXsrKP N/z4fsTpVdinl1om2cC5j2OqJwtVuA1IwvmbAWZCF+nzFoZSZziKk4GDpcISqdFenC7m rpxqL8/6eID74piQHXlL2mI7svrDnPRnGWjaJ8yLj2TYEpxrEuEDIuPk2SEYJUd5e1/E NshGMDmoGdoc0ZoCeU958YNH8F8FVgzCipVqYsjgxe4rW0byTujl4L3kkg1lzkpeTJaF o81go1Z4TGVOEkQWgauTM+6m9WM+Aeirf6pRMTzBN/bn/BAuo4GS7mJMrxJRlrWpnvif PF+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=LIY2nrONxUEpI3abKUGgXLbsvOzrU8dATPLwmTEHaeU=; b=o8BMzhlFo151SwfizQRFyXcNEh8WKFPwzHqFeBT8p4nMZIOpWZsKOjajy/dqQh+Bct Ggmnp3ZfypYdocmUTjH7XMQHnfE0v1Jq3CJav1IeiO0yewZ+cgS3QcYbY9Xpl08Y3DFX 1/bxxgNTIKJuOfuNozxQUmVe/S2jDhXSz/UxGKmBcFK2Q5hffITLTwVQ4qFZtGhV6eac 2npWU78WVF1wUuTon0DFIm7wPqPSjYFUR/3rXvVWuehzeuWBl7xzm8yVoYG/179U5nZn 37o8QwnwVjASKXs7uSwrgWcy5vNHo6BZKt2rQLplgLguLmKPMkUA/1aeguZ9wt/ttIYj gm1A== X-Gm-Message-State: AOAM532c6jdJaiZCkD74tNLQIigiDIBFVqgKShOzzXoS+nD6jrM1I4vV 8Qn8KCum/C3ryzorEr9ozxv+BAL7Bg3Ht7K9 X-Google-Smtp-Source: ABdhPJz8PA1RC6TbYkCijZyVacH+F5qN5v5VA7bYMHwRsUMGn/QRHb6T2stA1tcRlIPO7sX4wK7ZATIKTk0Xn1vX X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:309:: with SMTP id 9mr83135wmd.80.1604531950904; Wed, 04 Nov 2020 15:19:10 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:17 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 02/43] kasan: KASAN_VMALLOC depends on KASAN_GENERIC From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232015_331780_7ED1C912 X-CRM114-Status: GOOD ( 12.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently only generic KASAN mode supports vmalloc, reflect that in the config. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: I1889e5b3bed28cc5d607802fb6ae43ba461c0dc1 --- lib/Kconfig.kasan | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan index 542a9c18398e..8f0742a0f23e 100644 --- a/lib/Kconfig.kasan +++ b/lib/Kconfig.kasan @@ -155,7 +155,7 @@ config KASAN_SW_TAGS_IDENTIFY config KASAN_VMALLOC bool "Back mappings in vmalloc space with real shadow memory" - depends on HAVE_ARCH_KASAN_VMALLOC + depends on KASAN_GENERIC && HAVE_ARCH_KASAN_VMALLOC help By default, the shadow region for vmalloc space is the read-only zero page. This means that KASAN cannot detect errors involving From patchwork Wed Nov 4 23:18:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883235 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AAD2C00A89 for ; Thu, 5 Nov 2020 04:55:58 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8029A2083B for ; Thu, 5 Nov 2020 04:55:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="CN4rFFUK"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="TmQEivFI"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Nde54gFH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8029A2083B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=9eXcPrwAqwcTPPz9G9QniVO4SBfOyb51w4eiBjh+GbY=; b=CN4rFFUKffUuL0LB32zs63ofj txKJaE5FRC3MVxV2qxbdlLw5TsT7H6lXjP6KEsYRXN+04rCzcBQXmhO6i/d3t0cxI2MhPx1oamYYJ d7i+lv0MPbJ/apvDjxPHxnztrzI5LyGUsltYAH4BZBHzR8IfswCK0z0/emWPaY5OSPDWJAZe/V2vi a0fPLnwGTnQMl4xkIi8dVZoh8b3uxxnU+HUcYwv2hCinLWJRmE/GwfQ2V4UGuPepBnohTPf0WWIkM ZVhHREzAp7uNfjXt1PF8JjzjiW8HGF1NywH8XiFeVBTyWTFJYa6PMwmiDJ7CZgjl0bl0OLn5GgusS +2SUFvgyg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXI3-0001PP-Lh; Thu, 05 Nov 2020 04:54:27 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5M-000145-W6 for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=RYRi/FAOTZ78lCIR1B7o4Jmj2D/EUC7lc1NuI1GE5uU=; b=TmQEivFIuHD4rMfWwTRfGnfoKV N3gt+h6D0lTstPl9iSVNWR2HGtrHgPSaTQwE/lirdCLLjJWrEUA3BBf2aIWpYzlIHzyk2YYIDhk06 taDoVKS+h9YVu7MjXXjZ/a+C3txYbmZk258VLmIeVEQRoJVJGsdw4e8YzfPWT7K1wPIcVGkz+U6Mq 6uKIvoNjzYuYKBaNaJ8wHE4/R5RnAYxZ9JfAMZrXdKcBW2Co6E4RE1oKUNe3WOuTUgh5cCrlg03dD lg40lbBA1LA417am9Ix1s2Bd1kIacK84J17lOgwg1O7S9ve54wl1kiQiDhB5UZYxrk1yRqKTs+44B QWW1a9Iw==; Received: from mail-ej1-x649.google.com ([2a00:1450:4864:20::649]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS4f-0003tV-Gk for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:20 +0000 Received: by mail-ej1-x649.google.com with SMTP id 2so77498ejv.4 for ; Wed, 04 Nov 2020 15:20:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=RYRi/FAOTZ78lCIR1B7o4Jmj2D/EUC7lc1NuI1GE5uU=; b=Nde54gFHWGOEqAyyuWq2rQzVJXRx/KDeTCAuAH/MdTHSRmk54Ggx/wnYNjjxYyGICS QZ1hTnIISQEY75MaSlxAnZPzPwfIQVxzeoiosPkms4fPNH9q+CTb1rQH6glIJzqDJZI1 JrbdKodfU4o+lHUgzHmMlGYpbHunS4DZUaZwQYLCMQsqVupABBc1W2AuOcNlvLIkP0AL 98JpGhChCAMAtiuGlhd8DdLEgPTCa85WnuRA4naQLqoFN5pSnmEm7bxlGrIW3L76vp1x Zg0HSD3pAj0Kvo/H0XS9uJaabK620FuUwAt+30SYKd2MmLJ2ocM4gQ+2QRngVduomxAP Xgxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=RYRi/FAOTZ78lCIR1B7o4Jmj2D/EUC7lc1NuI1GE5uU=; b=ScIE5NHS4PFZ6thM8PW04DtbuPuRfoT3FyiyvIVUY4R+0/RjGpAwE/V/YXnGzPUoH0 2XMlqb6WmNVqF6BB+t0LNDT1/NZtVSmUGY+/yVTQXXBukXZwHZ6EnRrUWXgXzq0behMS 1LM4QxGJ7idUnXRRg5Svu+I6o0KrKqoT9mzvAC9RHdnJE4upQNitscdgpeA9BpX8SLgS qbbaZr83LA0eIDPndJonzP3cR6H3PhvmChVSY5KCaiOixA6VWtjghT+Qv1e3NbqkSUu6 lR7UkqCR+sDZabaAD+jfKrn1lC0BzlbrCMgSf8F47ChAtxtmVwtl7CoHn+c7DO3+3jdS hxyw== X-Gm-Message-State: AOAM5331cm01UXaq2j3CeMe798GTkgh6fHLAXDKk1M07jmzk1t/l8tfv et15/95Hwim/nkdf5ONQ7DbkYf+/m7sucY0/ X-Google-Smtp-Source: ABdhPJzTbWEvaInDgCzi2OXp9Zq7P4vPYNbIjbyt1XtVnSDN5wV+5yh08HFfB0bdtVYiy9srehxVAVjiUxnZsQHu X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a50:fe98:: with SMTP id d24mr157767edt.223.1604531953601; Wed, 04 Nov 2020 15:19:13 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:18 +0100 In-Reply-To: Message-Id: <7762ae3696d59e0e38ed69d0a98930aea883be82.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 03/43] kasan: group vmalloc code From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232017_866806_D88C18D9 X-CRM114-Status: GOOD ( 18.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Group all vmalloc-related function declarations in include/linux/kasan.h, and their implementations in mm/kasan/common.c. No functional changes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: Ie20b6c689203cd6de4fd7f2c465ec081c00c5f15 --- include/linux/kasan.h | 41 +++++++++++++---------- mm/kasan/common.c | 78 ++++++++++++++++++++++--------------------- 2 files changed, 63 insertions(+), 56 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 30d343b4a40a..59538e795df4 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -75,19 +75,6 @@ struct kasan_cache { int free_meta_offset; }; -/* - * These functions provide a special case to support backing module - * allocations with real shadow memory. With KASAN vmalloc, the special - * case is unnecessary, as the work is handled in the generic case. - */ -#ifndef CONFIG_KASAN_VMALLOC -int kasan_module_alloc(void *addr, size_t size); -void kasan_free_shadow(const struct vm_struct *vm); -#else -static inline int kasan_module_alloc(void *addr, size_t size) { return 0; } -static inline void kasan_free_shadow(const struct vm_struct *vm) {} -#endif - int kasan_add_zero_shadow(void *start, unsigned long size); void kasan_remove_zero_shadow(void *start, unsigned long size); @@ -156,9 +143,6 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, return false; } -static inline int kasan_module_alloc(void *addr, size_t size) { return 0; } -static inline void kasan_free_shadow(const struct vm_struct *vm) {} - static inline int kasan_add_zero_shadow(void *start, unsigned long size) { return 0; @@ -211,13 +195,16 @@ static inline void *kasan_reset_tag(const void *addr) #endif /* CONFIG_KASAN_SW_TAGS */ #ifdef CONFIG_KASAN_VMALLOC + int kasan_populate_vmalloc(unsigned long addr, unsigned long size); void kasan_poison_vmalloc(const void *start, unsigned long size); void kasan_unpoison_vmalloc(const void *start, unsigned long size); void kasan_release_vmalloc(unsigned long start, unsigned long end, unsigned long free_region_start, unsigned long free_region_end); -#else + +#else /* CONFIG_KASAN_VMALLOC */ + static inline int kasan_populate_vmalloc(unsigned long start, unsigned long size) { @@ -232,7 +219,25 @@ static inline void kasan_release_vmalloc(unsigned long start, unsigned long end, unsigned long free_region_start, unsigned long free_region_end) {} -#endif + +#endif /* CONFIG_KASAN_VMALLOC */ + +#if defined(CONFIG_KASAN) && !defined(CONFIG_KASAN_VMALLOC) + +/* + * These functions provide a special case to support backing module + * allocations with real shadow memory. With KASAN vmalloc, the special + * case is unnecessary, as the work is handled in the generic case. + */ +int kasan_module_alloc(void *addr, size_t size); +void kasan_free_shadow(const struct vm_struct *vm); + +#else /* CONFIG_KASAN && !CONFIG_KASAN_VMALLOC */ + +static inline int kasan_module_alloc(void *addr, size_t size) { return 0; } +static inline void kasan_free_shadow(const struct vm_struct *vm) {} + +#endif /* CONFIG_KASAN && !CONFIG_KASAN_VMALLOC */ #ifdef CONFIG_KASAN_INLINE void kasan_non_canonical_hook(unsigned long addr); diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 33d863f55db1..89e5ef9417a7 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -536,44 +536,6 @@ void kasan_kfree_large(void *ptr, unsigned long ip) /* The object will be poisoned by page_alloc. */ } -#ifndef CONFIG_KASAN_VMALLOC -int kasan_module_alloc(void *addr, size_t size) -{ - void *ret; - size_t scaled_size; - size_t shadow_size; - unsigned long shadow_start; - - shadow_start = (unsigned long)kasan_mem_to_shadow(addr); - scaled_size = (size + KASAN_SHADOW_MASK) >> KASAN_SHADOW_SCALE_SHIFT; - shadow_size = round_up(scaled_size, PAGE_SIZE); - - if (WARN_ON(!PAGE_ALIGNED(shadow_start))) - return -EINVAL; - - ret = __vmalloc_node_range(shadow_size, 1, shadow_start, - shadow_start + shadow_size, - GFP_KERNEL, - PAGE_KERNEL, VM_NO_GUARD, NUMA_NO_NODE, - __builtin_return_address(0)); - - if (ret) { - __memset(ret, KASAN_SHADOW_INIT, shadow_size); - find_vm_area(addr)->flags |= VM_KASAN; - kmemleak_ignore(ret); - return 0; - } - - return -ENOMEM; -} - -void kasan_free_shadow(const struct vm_struct *vm) -{ - if (vm->flags & VM_KASAN) - vfree(kasan_mem_to_shadow(vm->addr)); -} -#endif - #ifdef CONFIG_MEMORY_HOTPLUG static bool shadow_mapped(unsigned long addr) { @@ -685,6 +647,7 @@ core_initcall(kasan_memhotplug_init); #endif #ifdef CONFIG_KASAN_VMALLOC + static int kasan_populate_vmalloc_pte(pte_t *ptep, unsigned long addr, void *unused) { @@ -923,4 +886,43 @@ void kasan_release_vmalloc(unsigned long start, unsigned long end, (unsigned long)shadow_end); } } + +#else /* CONFIG_KASAN_VMALLOC */ + +int kasan_module_alloc(void *addr, size_t size) +{ + void *ret; + size_t scaled_size; + size_t shadow_size; + unsigned long shadow_start; + + shadow_start = (unsigned long)kasan_mem_to_shadow(addr); + scaled_size = (size + KASAN_SHADOW_MASK) >> KASAN_SHADOW_SCALE_SHIFT; + shadow_size = round_up(scaled_size, PAGE_SIZE); + + if (WARN_ON(!PAGE_ALIGNED(shadow_start))) + return -EINVAL; + + ret = __vmalloc_node_range(shadow_size, 1, shadow_start, + shadow_start + shadow_size, + GFP_KERNEL, + PAGE_KERNEL, VM_NO_GUARD, NUMA_NO_NODE, + __builtin_return_address(0)); + + if (ret) { + __memset(ret, KASAN_SHADOW_INIT, shadow_size); + find_vm_area(addr)->flags |= VM_KASAN; + kmemleak_ignore(ret); + return 0; + } + + return -ENOMEM; +} + +void kasan_free_shadow(const struct vm_struct *vm) +{ + if (vm->flags & VM_KASAN) + vfree(kasan_mem_to_shadow(vm->addr)); +} + #endif From patchwork Wed Nov 4 23:18:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883251 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28D29C4742C for ; Thu, 5 Nov 2020 05:05:08 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 98AB32151B for ; Thu, 5 Nov 2020 05:05:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="2r5kSKcU"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="TI5gBTuE"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="XQOwaLsj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 98AB32151B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qIwaA7R2gRfr9BWJO3TSENxUbIxPK8RBFBlpT9ZGMQ0=; b=2r5kSKcUwX5+oxuqHgbJraOey L/+wZ1gKJ9flQO9SEs37RYRQ25JAXk/mcPWrDojK0Hwyvb0NUM69YjGBaSYZkY558g8OZLH3rzXME N/SrF7dkH9Jq9i5h/VmiMljSlQ7MBf9AJeVzdcrwKjdWkx67siGTICvLqw8AlN5hBakjTgcsVT+3V kCRC9TvEapS/npsljGC4UmYlSRYL6b06i2QakVT/pTuJQPuMATs+yv+E7E1z4eGZ9VC+uWkCj96vE Jz3bmEtbaDvf7sLwwwo2rGhDCBJpsuTifS8Hr+bNrR+5lE8jH5GJHFX92W2oVbJaTnH4HXtnHjmgn TBLOOBL2w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXQj-0003yU-ID; Thu, 05 Nov 2020 05:03:25 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5N-00016k-IE for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Z3coWAI2tcKTBrlblI3/IYJAWnH07Z1QBuIRVdtXJnY=; b=TI5gBTuEpMeVEV+DrA+ZN7GP+k 4ymtrmSK1t3p3oXkh1rJm10fIGrG4Qsdn5KSvXeFHWcC4EobengSMCLRwrB3Cm6GR4eQRJsL/AyOD f+WmXc+E9UoYyibDAlv1g4xLVDacUoE8zE763PJolw4qDwpYgDuljw02WA9fR7Uv5oHTfEY05ELNA 8bKbjcnSAoOZDBElkWnVogMQAMyF+L+A07pRfopCRK1iXMNaxUb5QLYy/LFe0KRxhikv036s9wanb vkTJ55bRSdQvaC0MXmhzPfcuz2rYzBMzGxA3UA6xWfEzP6gen4/OY+/VG8ToUuT8scKSvsA1d83b4 LrSBCJIQ==; Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS4f-0003tU-8u for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:19 +0000 Received: by mail-wm1-x34a.google.com with SMTP id t21so6765wmt.8 for ; Wed, 04 Nov 2020 15:20:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=Z3coWAI2tcKTBrlblI3/IYJAWnH07Z1QBuIRVdtXJnY=; b=XQOwaLsjIcVG6su3AN+CYUdsA5WUuBobYe8xvDWSId42JpjafUyuC5mkuGD9M7cJEO IRBpNjzWtQCQhoCS+AwXFlU/pJfHm4LUhojUCMSB5U7R+GQbyxixrZ3kmDIUuyHLxmiw D9JlmNxbc3wdURiVDE9fVjAUeid0zK0zFixaEt2UXw7Z2kx6Tc1s2UsqJfbLEYFJsNVX +FT5O6bxqlJZRiXsdHIY57GSre77QLnVThkrJu0ASjZCNtLRSexnsbU2gvQItwdvP3B8 xPC3JjiYAn62Q8QZ8HIQB1chVyCv4Q6GeZmmhIutTOV6zEgaFUeNhwKcV0fFQmGB7sFh 5iDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Z3coWAI2tcKTBrlblI3/IYJAWnH07Z1QBuIRVdtXJnY=; b=hOLtHXgraRGmlT1DB4Qp3pByyQwfC55YBJkr1TyqfRxZCcL693xFr376A/egL2WMv5 6TxOOa/orjvXQkJvoy3HnOLNKO2URWu6n+h8KY1xtaanec92Yoed8fWg8nZdzGgLfrgg wceVOt3/d4TAsghu+5SToeRqewue8wS8QIALB4wGgNVo6vS0WqwunNoGGYmfCmqSMO/7 yj7ufLPzalHR8wphGASfd+ivGbNPBwWq1px3RW+wV4Qit0xyhO8ZIWdx0mC+D4RcK4gP fGtXt9W2QL4lt2FpBN+BrXpKEOtBAg//Y2mXBrj71bo6Ck8VhOy7sCRF9EkBlkl8ewwj XCWQ== X-Gm-Message-State: AOAM533Ke7Q3c9+IUsY9kYq7Ysjy5uRfq5OOFNErUgUU7qHw47n6VP5c bR3PFWItxryZtZy+2wHuJ2J1INBiuli+2IpO X-Google-Smtp-Source: ABdhPJwNrhTgbZprL0G3S2ieCLesniBqAGqR/k9jY6mA8OpBniFVTsIN+owzPS7pLTwiZuVt4MXWlGO+IR55i+eQ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:a752:: with SMTP id q79mr97594wme.24.1604531956154; Wed, 04 Nov 2020 15:19:16 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:19 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 04/43] s390/kasan: include asm/page.h from asm/kasan.h From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232017_591455_106877F2 X-CRM114-Status: UNSURE ( 9.32 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Vasily Gorbik , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org asm/kasan.h relies on pgd_t and _REGION1_SHIFT definitions and therefore requires asm/pgtable.h include. Include asm/pgtable.h from asm/kasan.h. Signed-off-by: Andrey Konovalov Acked-by: Vasily Gorbik --- Change-Id: I369a8f9beb442b9d05733892232345c3f4120e0a --- arch/s390/include/asm/kasan.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/s390/include/asm/kasan.h b/arch/s390/include/asm/kasan.h index e9bf486de136..4753ad0c3cba 100644 --- a/arch/s390/include/asm/kasan.h +++ b/arch/s390/include/asm/kasan.h @@ -2,6 +2,8 @@ #ifndef __ASM_KASAN_H #define __ASM_KASAN_H +#include + #ifdef CONFIG_KASAN #define KASAN_SHADOW_SCALE_SHIFT 3 From patchwork Wed Nov 4 23:18:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883233 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 880D4C00A89 for ; Thu, 5 Nov 2020 04:55:51 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 04D6C2083B for ; Thu, 5 Nov 2020 04:55:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="S7Mu8/UZ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="CLw0LP3H"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="dgN/w1am" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 04D6C2083B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=MMVGao1u3fYlm+mzvjZQ+o67sqCJQv0+CnGTaOb4+ww=; b=S7Mu8/UZDDnHvbXykUHxjWJzy O6KqCLwfny/0Xz+G1h4GZ/t/qVY+UUFecQ0X04LbQr569YtRWcM10N+c6P/rr8hWTnbknsJUXRt2b Hvfs0xxi3Xf3pnN0P0YG27HDoNFkFTXE8C4f02mN0Bu5Qq6Ie2PlHX2aV3h4i9zo+L1th/vkQgd6W TQAnkSHgvQ6Ffp8BUUDrO58IvMN9hXI7ZmJSAREuVeva9UeYWxDV7F3DfUnhY4IyEQS3WrbI/jFBJ rvLn+6ek0tUdLKSqEBOFy1vmx9/JSUtLPCGcARiNnSh30oTp1OYg2OK4IuHhsjuamTESbio96bV8K YcAfUrcSw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXI1-0001Om-MK; Thu, 05 Nov 2020 04:54:25 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5M-00016k-KK for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=nboRM2CFBpQGYkXl6uRGVt4iydoGbxyL4XKrxiXLpKY=; b=CLw0LP3HXk5RGjISqnXidXtJ3A fMY4qHW0eMNgDyOEQh22iYLqZU/k/xc6yCsX5RYH2tWvxpwToA8o5nDRFUewDnaQeePjk7si3cSPv dW5cLWwTI2YEv/l8tXfbxSuhzUjlijUZ7kxV4WQarTmbuqnXheFgRXvUD0OvMIAYWVEG9Ie8Q0Crp JR/x56hQjqCD8MOa0IdAzFTdI1VEJdLIuuflN8KynVSPCd98lQ2RCXYMlWYW0Ot5d9zBOgzR+XWv3 hF87ArLkTslenASb7Vew3uMWkiSmJjZtsLrXGr6sbYbQOCdvcyX1xxqB+AtnsWJcI2ADp7C0zXr7p JBJrPG9w==; Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS4i-0003uM-M8 for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:23 +0000 Received: by mail-wr1-x44a.google.com with SMTP id h8so44306wrt.9 for ; Wed, 04 Nov 2020 15:20:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=nboRM2CFBpQGYkXl6uRGVt4iydoGbxyL4XKrxiXLpKY=; b=dgN/w1amHzWAucOFICHabUoYKns9E0EW4S17djL5Mq75cVwBGdDZqGYn8Qeq7nvUMW M97Jt+7e9lvcxl2kI9TAb+GXKY0QiGMIdyQ80daOWo5mtsE7SwttKp2xBsEJ2yjJSSCQ ayJDF8IL3/w0AgWFJMHoxvvtX/6pIISNeXHtetBbvP07VtsxAq5Dv50zks2RcMAKViLG CkyCLE5yfn5OdhtwmcfKGxnNruhoxrd+swkNI0152pnDJP/YtMLok9KSOn6eqZ38+VjO +BSkyPd2W9vydTe8BECVlFQ+za6j6eQ8FXktVLuLm2s382u0spMvJohHeUQmMlt4pBxG MK8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=nboRM2CFBpQGYkXl6uRGVt4iydoGbxyL4XKrxiXLpKY=; b=kNdoVuPQ7uKQsR4ot9neZ2NvZQxZTMr/0s1Obgsvx98R66rbwyZGDu4SoRiKmCgWMi SBP1kLzlPcYwZDNvMSKdx1sYIqpArsOmUTE2Jo3xQ4ueiU++kjM9/FdvxlEBhFa+oBV5 GFzmqKeP3AovxIuFN0WEc6JYcbHgIB2OKIJIdDCBRGfjxJFk5n3gY5/SPL2Qi2/0uEut sLIapkPp/4JtETuVcMofwEykUOojpLLdza3aLDdrSepZCpKAHy6iD7YSQsxFQ87gNBPg mL1Zm1hBaJDMa/E63sEjRjtOCUIBKdjhohkpEBxSTtj/d0e/SvJX7nFJ0WwLJERoqL+U bW3A== X-Gm-Message-State: AOAM531XwZmh5kg9CofKrIzDK4IHcUFRHrAWt4kOxuEOGSuOGBWMS+/Q O7HcLFGms/fe3HwYPZpikZhj3qb3YC5OqB9t X-Google-Smtp-Source: ABdhPJyqM0dDi4GfWkh1I27aN5R/lBK00hzYxseangjAFcdYFNu3XKGF2HJ+8fAAEsbL6D3qdB2J3NKnTJRwJA6F X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:4957:: with SMTP id w84mr86567wma.84.1604531958343; Wed, 04 Nov 2020 15:19:18 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:20 +0100 In-Reply-To: Message-Id: <36545c406b0aea73f636fa25e85de6a86a349775.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 05/43] kasan: shadow declarations only for software modes From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232020_869987_76143C06 X-CRM114-Status: GOOD ( 12.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Group shadow-related KASAN function declarations and only define them for the two existing software modes. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: I864be75a88b91b443c55e9c2042865e15703e164 --- include/linux/kasan.h | 45 ++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 59538e795df4..45345dd5cfd6 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -10,9 +10,20 @@ struct vm_struct; struct task_struct; #ifdef CONFIG_KASAN +#include +#endif + +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) #include -#include + +/* Software KASAN implementations use shadow memory. */ + +#ifdef CONFIG_KASAN_SW_TAGS +#define KASAN_SHADOW_INIT 0xFF +#else +#define KASAN_SHADOW_INIT 0 +#endif /* kasan_data struct is used in KUnit tests for KASAN expected failures */ struct kunit_kasan_expectation { @@ -35,6 +46,23 @@ static inline void *kasan_mem_to_shadow(const void *addr) + KASAN_SHADOW_OFFSET; } +int kasan_add_zero_shadow(void *start, unsigned long size); +void kasan_remove_zero_shadow(void *start, unsigned long size); + +#else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ + +static inline int kasan_add_zero_shadow(void *start, unsigned long size) +{ + return 0; +} +static inline void kasan_remove_zero_shadow(void *start, + unsigned long size) +{} + +#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ + +#ifdef CONFIG_KASAN + /* Enable reporting bugs after kasan_disable_current() */ extern void kasan_enable_current(void); @@ -75,9 +103,6 @@ struct kasan_cache { int free_meta_offset; }; -int kasan_add_zero_shadow(void *start, unsigned long size); -void kasan_remove_zero_shadow(void *start, unsigned long size); - size_t __ksize(const void *); static inline void kasan_unpoison_slab(const void *ptr) { @@ -143,14 +168,6 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, return false; } -static inline int kasan_add_zero_shadow(void *start, unsigned long size) -{ - return 0; -} -static inline void kasan_remove_zero_shadow(void *start, - unsigned long size) -{} - static inline void kasan_unpoison_slab(const void *ptr) { } static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } @@ -158,8 +175,6 @@ static inline size_t kasan_metadata_size(struct kmem_cache *cache) { return 0; } #ifdef CONFIG_KASAN_GENERIC -#define KASAN_SHADOW_INIT 0 - void kasan_cache_shrink(struct kmem_cache *cache); void kasan_cache_shutdown(struct kmem_cache *cache); void kasan_record_aux_stack(void *ptr); @@ -174,8 +189,6 @@ static inline void kasan_record_aux_stack(void *ptr) {} #ifdef CONFIG_KASAN_SW_TAGS -#define KASAN_SHADOW_INIT 0xFF - void kasan_init_tags(void); void *kasan_reset_tag(const void *addr); From patchwork Wed Nov 4 23:18:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883219 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1A54C00A89 for ; Thu, 5 Nov 2020 04:51:40 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 51A5A20735 for ; Thu, 5 Nov 2020 04:51:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Hh6QFeZr"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="aSucdghj"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="C284X/O6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 51A5A20735 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=2STYZCBrqwFBciz8q0fxfLvKV55OQe+QFfBrDN0mlDg=; b=Hh6QFeZrLfw+ETMgb8uxwt9Wq YgYwYWK0khGQy1ObfRms569fitqXUX7e4x/T/STgyFLtuDOlZx6lbNJZEW6IHUDnppk04rzHyvMuZ k0PZWmp2e+XPHADD6HlSq1UBqW78sXk7Zyh5nVt6uR5EMIxYZCpt0Gc8NbXj7Jk5xtfNYIpSnbo/M 25EtyvmVAGETRKTZmOpLBVWZAbdAJU/ptJisFRAgRo3w5b5cO/x5U32fDpe/quzFiMc7Bdx0tMqAJ wHozPK1H6y4B9wPDUFWuGAytwAdt6vo6H/v/9lFpr3a3HRbWk4wt05hJrKJylg7MpWKuzfXUORIVT 3Aq72pHrg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXEP-0000VW-Bm; Thu, 05 Nov 2020 04:50:41 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5L-000145-0i for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=IUUW0kfppB1Efh4tHJPvwp7oL4IQLWE1cA6kijbJlXk=; b=aSucdghjdZEYixynBE02szb31k xQEbJZFoT8gdzF/Apzs7OCjmiyP5lhEh6Iz4EEPSRlIxAh+IyFeMyTJ+sRs53KVIIQ0zX/JCHPURU nlnIUe+ZCogzMrwjrfipp46LGH74NKOpjFFg4MTc2dbllyNPcoZICMOkEZjj8VzyPZUBWyNhjw8In mckXMqIvdwNSLd3sZcD2a/NBeeImvkxMDllARA6UDpf46e20A11BCsupsNySdPKgAiDj8S+t9oI3E VjDIPOFVl9JuE1a9Yvp0yfEl6IR4w4ZPrVPjRk3fyeR7472Dx3haQTj4V77a/LbDAfxq/yH2gqhQT c5zT11Vg==; Received: from mail-ej1-x649.google.com ([2a00:1450:4864:20::649]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS4o-0003wW-V0 for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:32 +0000 Received: by mail-ej1-x649.google.com with SMTP id e9so53453ejb.16 for ; Wed, 04 Nov 2020 15:20:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=IUUW0kfppB1Efh4tHJPvwp7oL4IQLWE1cA6kijbJlXk=; b=C284X/O6tMJ0rheKEn6t5s4Pvwtgk8bIk+CTX5QxoYu1cSaHiGvHHBeDkPFdh4n0oB w1wpvN/3n10FG0NviHZhHBWM+YA41imkmlxRPmE54F7PasjAfvp1ZJBFPit5YFzsDky+ iEdHbt0Q+VEArx6WMTr9YFIfS9QY07NDpZJK4bAJNX/8I+UMYbboV6FN7tipIV7oGaxb YDLfzPiiBU8x2hQofzpbskqN5JxrRNRhRKyo5NXhQfHdtYaCjmz9KfErB/9M3ZQzklVn lIm9PP4gZ2fXf8kr1v/AYN5rH868gCSmmQ145Rq4LiVyWmeu6ZMobFrL/P/H98l33ijJ L/lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=IUUW0kfppB1Efh4tHJPvwp7oL4IQLWE1cA6kijbJlXk=; b=NE1IJWxopOBEfMjLe2MjA35oeSSSLok/iBIaEvhvIiuhyJQB/JcUr4DrZll1eqBgba o6itKAJobQbnLGTVujoQkewMRFAbzjKbEb02tVjg31o1G6fe/m1Y/ZsN8FrBqU9i1QUI KjFvABbZwb4WcL6AWp0nJWM0KkicON2BdksubOZigiF0VyAnDZmotWMQo3QWjzBYK+46 rWitNmlhn6U/NFAtcNzr15AyuoQGq1UzE9eCOBy7UBlcLzJ5TaFoePPoyZCc2w2ssscI 7rVoMAybNGdH16/3V5Q+pyGgWXMlozsDvjLzGfbBjDs93nYF235ZGO4/DapQdcjL/5re G1SQ== X-Gm-Message-State: AOAM531ZMaOzUyZxgN9rT6eBZeqzyLL88k7r83DV3iUndozAEvyz2717 JpszYNP9S5TUKyGBHLy/TL8LWX72IvsLsw8P X-Google-Smtp-Source: ABdhPJyL1hlprpbx3o8bMzjTDvjNYbkJUV40hy1W+VmXdyySnPbpZe3U7Wrz9xo/pc7xJ8UcXuranyhQ3qg9jCog X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6402:1844:: with SMTP id v4mr180332edy.346.1604531963010; Wed, 04 Nov 2020 15:19:23 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:22 +0100 In-Reply-To: Message-Id: <279a9eafac9ba2090bb02bbdcaf9d9a2deb9214d.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 07/43] kasan: rename KASAN_SHADOW_* to KASAN_GRANULE_* From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232027_324436_508FB64B X-CRM114-Status: GOOD ( 26.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. The new mode won't be using shadow memory, but will still use the concept of memory granules. Each memory granule maps to a single metadata entry: 8 bytes per one shadow byte for generic mode, 16 bytes per one shadow byte for software tag-based mode, and 16 bytes per one allocation tag for hardware tag-based mode. Rename KASAN_SHADOW_SCALE_SIZE to KASAN_GRANULE_SIZE, and KASAN_SHADOW_MASK to KASAN_GRANULE_MASK. Also use MASK when used as a mask, otherwise use SIZE. No functional changes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: Iac733e2248aa9d29f6fc425d8946ba07cca73ecf --- Documentation/dev-tools/kasan.rst | 2 +- lib/test_kasan.c | 2 +- lib/test_kasan_module.c | 2 +- mm/kasan/common.c | 39 ++++++++++++++++--------------- mm/kasan/generic.c | 14 +++++------ mm/kasan/generic_report.c | 8 +++---- mm/kasan/init.c | 8 +++---- mm/kasan/kasan.h | 4 ++-- mm/kasan/report.c | 10 ++++---- mm/kasan/tags_report.c | 2 +- 10 files changed, 46 insertions(+), 45 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index 2b68addaadcd..edca4be5e405 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -264,7 +264,7 @@ Most mappings in vmalloc space are small, requiring less than a full page of shadow space. Allocating a full shadow page per mapping would therefore be wasteful. Furthermore, to ensure that different mappings use different shadow pages, mappings would have to be aligned to -``KASAN_SHADOW_SCALE_SIZE * PAGE_SIZE``. +``KASAN_GRANULE_SIZE * PAGE_SIZE``. Instead, we share backing space across multiple mappings. We allocate a backing page when a mapping in vmalloc space uses a particular page diff --git a/lib/test_kasan.c b/lib/test_kasan.c index 662f862702fc..2947274cc2d3 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c @@ -25,7 +25,7 @@ #include "../mm/kasan/kasan.h" -#define OOB_TAG_OFF (IS_ENABLED(CONFIG_KASAN_GENERIC) ? 0 : KASAN_SHADOW_SCALE_SIZE) +#define OOB_TAG_OFF (IS_ENABLED(CONFIG_KASAN_GENERIC) ? 0 : KASAN_GRANULE_SIZE) /* * We assign some test results to these globals to make sure the tests diff --git a/lib/test_kasan_module.c b/lib/test_kasan_module.c index 2d68db6ae67b..fcb991c3aaf8 100644 --- a/lib/test_kasan_module.c +++ b/lib/test_kasan_module.c @@ -15,7 +15,7 @@ #include "../mm/kasan/kasan.h" -#define OOB_TAG_OFF (IS_ENABLED(CONFIG_KASAN_GENERIC) ? 0 : KASAN_SHADOW_SCALE_SIZE) +#define OOB_TAG_OFF (IS_ENABLED(CONFIG_KASAN_GENERIC) ? 0 : KASAN_GRANULE_SIZE) static noinline void __init copy_user_test(void) { diff --git a/mm/kasan/common.c b/mm/kasan/common.c index a4b73fa0dd7e..f65c9f792f8f 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -106,7 +106,7 @@ void *memcpy(void *dest, const void *src, size_t len) /* * Poisons the shadow memory for 'size' bytes starting from 'addr'. - * Memory addresses should be aligned to KASAN_SHADOW_SCALE_SIZE. + * Memory addresses should be aligned to KASAN_GRANULE_SIZE. */ void kasan_poison_memory(const void *address, size_t size, u8 value) { @@ -138,13 +138,13 @@ void kasan_unpoison_memory(const void *address, size_t size) kasan_poison_memory(address, size, tag); - if (size & KASAN_SHADOW_MASK) { + if (size & KASAN_GRANULE_MASK) { u8 *shadow = (u8 *)kasan_mem_to_shadow(address + size); if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) *shadow = tag; else - *shadow = size & KASAN_SHADOW_MASK; + *shadow = size & KASAN_GRANULE_MASK; } } @@ -296,7 +296,7 @@ void kasan_unpoison_object_data(struct kmem_cache *cache, void *object) void kasan_poison_object_data(struct kmem_cache *cache, void *object) { kasan_poison_memory(object, - round_up(cache->object_size, KASAN_SHADOW_SCALE_SIZE), + round_up(cache->object_size, KASAN_GRANULE_SIZE), KASAN_KMALLOC_REDZONE); } @@ -368,7 +368,7 @@ static inline bool shadow_invalid(u8 tag, s8 shadow_byte) { if (IS_ENABLED(CONFIG_KASAN_GENERIC)) return shadow_byte < 0 || - shadow_byte >= KASAN_SHADOW_SCALE_SIZE; + shadow_byte >= KASAN_GRANULE_SIZE; /* else CONFIG_KASAN_SW_TAGS: */ if ((u8)shadow_byte == KASAN_TAG_INVALID) @@ -407,7 +407,7 @@ static bool __kasan_slab_free(struct kmem_cache *cache, void *object, return true; } - rounded_up_size = round_up(cache->object_size, KASAN_SHADOW_SCALE_SIZE); + rounded_up_size = round_up(cache->object_size, KASAN_GRANULE_SIZE); kasan_poison_memory(object, rounded_up_size, KASAN_KMALLOC_FREE); if ((IS_ENABLED(CONFIG_KASAN_GENERIC) && !quarantine) || @@ -440,9 +440,9 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, return NULL; redzone_start = round_up((unsigned long)(object + size), - KASAN_SHADOW_SCALE_SIZE); + KASAN_GRANULE_SIZE); redzone_end = round_up((unsigned long)object + cache->object_size, - KASAN_SHADOW_SCALE_SIZE); + KASAN_GRANULE_SIZE); if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) tag = assign_tag(cache, object, false, keep_tag); @@ -486,7 +486,7 @@ void * __must_check kasan_kmalloc_large(const void *ptr, size_t size, page = virt_to_page(ptr); redzone_start = round_up((unsigned long)(ptr + size), - KASAN_SHADOW_SCALE_SIZE); + KASAN_GRANULE_SIZE); redzone_end = (unsigned long)ptr + page_size(page); kasan_unpoison_memory(ptr, size); @@ -584,8 +584,8 @@ static int __meminit kasan_mem_notifier(struct notifier_block *nb, shadow_size = nr_shadow_pages << PAGE_SHIFT; shadow_end = shadow_start + shadow_size; - if (WARN_ON(mem_data->nr_pages % KASAN_SHADOW_SCALE_SIZE) || - WARN_ON(start_kaddr % (KASAN_SHADOW_SCALE_SIZE << PAGE_SHIFT))) + if (WARN_ON(mem_data->nr_pages % KASAN_GRANULE_SIZE) || + WARN_ON(start_kaddr % (KASAN_GRANULE_SIZE << PAGE_SHIFT))) return NOTIFY_BAD; switch (action) { @@ -743,7 +743,7 @@ void kasan_poison_vmalloc(const void *start, unsigned long size) if (!is_vmalloc_or_module_addr(start)) return; - size = round_up(size, KASAN_SHADOW_SCALE_SIZE); + size = round_up(size, KASAN_GRANULE_SIZE); kasan_poison_memory(start, size, KASAN_VMALLOC_INVALID); } @@ -856,22 +856,22 @@ void kasan_release_vmalloc(unsigned long start, unsigned long end, unsigned long region_start, region_end; unsigned long size; - region_start = ALIGN(start, PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE); - region_end = ALIGN_DOWN(end, PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE); + region_start = ALIGN(start, PAGE_SIZE * KASAN_GRANULE_SIZE); + region_end = ALIGN_DOWN(end, PAGE_SIZE * KASAN_GRANULE_SIZE); free_region_start = ALIGN(free_region_start, - PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE); + PAGE_SIZE * KASAN_GRANULE_SIZE); if (start != region_start && free_region_start < region_start) - region_start -= PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE; + region_start -= PAGE_SIZE * KASAN_GRANULE_SIZE; free_region_end = ALIGN_DOWN(free_region_end, - PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE); + PAGE_SIZE * KASAN_GRANULE_SIZE); if (end != region_end && free_region_end > region_end) - region_end += PAGE_SIZE * KASAN_SHADOW_SCALE_SIZE; + region_end += PAGE_SIZE * KASAN_GRANULE_SIZE; shadow_start = kasan_mem_to_shadow((void *)region_start); shadow_end = kasan_mem_to_shadow((void *)region_end); @@ -897,7 +897,8 @@ int kasan_module_alloc(void *addr, size_t size) unsigned long shadow_start; shadow_start = (unsigned long)kasan_mem_to_shadow(addr); - scaled_size = (size + KASAN_SHADOW_MASK) >> KASAN_SHADOW_SCALE_SHIFT; + scaled_size = (size + KASAN_GRANULE_SIZE - 1) >> + KASAN_SHADOW_SCALE_SHIFT; shadow_size = round_up(scaled_size, PAGE_SIZE); if (WARN_ON(!PAGE_ALIGNED(shadow_start))) diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 7006157c674b..ec4417156943 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -46,7 +46,7 @@ static __always_inline bool memory_is_poisoned_1(unsigned long addr) s8 shadow_value = *(s8 *)kasan_mem_to_shadow((void *)addr); if (unlikely(shadow_value)) { - s8 last_accessible_byte = addr & KASAN_SHADOW_MASK; + s8 last_accessible_byte = addr & KASAN_GRANULE_MASK; return unlikely(last_accessible_byte >= shadow_value); } @@ -62,7 +62,7 @@ static __always_inline bool memory_is_poisoned_2_4_8(unsigned long addr, * Access crosses 8(shadow size)-byte boundary. Such access maps * into 2 shadow bytes, so we need to check them both. */ - if (unlikely(((addr + size - 1) & KASAN_SHADOW_MASK) < size - 1)) + if (unlikely(((addr + size - 1) & KASAN_GRANULE_MASK) < size - 1)) return *shadow_addr || memory_is_poisoned_1(addr + size - 1); return memory_is_poisoned_1(addr + size - 1); @@ -73,7 +73,7 @@ static __always_inline bool memory_is_poisoned_16(unsigned long addr) u16 *shadow_addr = (u16 *)kasan_mem_to_shadow((void *)addr); /* Unaligned 16-bytes access maps into 3 shadow bytes. */ - if (unlikely(!IS_ALIGNED(addr, KASAN_SHADOW_SCALE_SIZE))) + if (unlikely(!IS_ALIGNED(addr, KASAN_GRANULE_SIZE))) return *shadow_addr || memory_is_poisoned_1(addr + 15); return *shadow_addr; @@ -134,7 +134,7 @@ static __always_inline bool memory_is_poisoned_n(unsigned long addr, s8 *last_shadow = (s8 *)kasan_mem_to_shadow((void *)last_byte); if (unlikely(ret != (unsigned long)last_shadow || - ((long)(last_byte & KASAN_SHADOW_MASK) >= *last_shadow))) + ((long)(last_byte & KASAN_GRANULE_MASK) >= *last_shadow))) return true; } return false; @@ -200,7 +200,7 @@ void kasan_cache_shutdown(struct kmem_cache *cache) static void register_global(struct kasan_global *global) { - size_t aligned_size = round_up(global->size, KASAN_SHADOW_SCALE_SIZE); + size_t aligned_size = round_up(global->size, KASAN_GRANULE_SIZE); kasan_unpoison_memory(global->beg, global->size); @@ -274,10 +274,10 @@ EXPORT_SYMBOL(__asan_handle_no_return); /* Emitted by compiler to poison alloca()ed objects. */ void __asan_alloca_poison(unsigned long addr, size_t size) { - size_t rounded_up_size = round_up(size, KASAN_SHADOW_SCALE_SIZE); + size_t rounded_up_size = round_up(size, KASAN_GRANULE_SIZE); size_t padding_size = round_up(size, KASAN_ALLOCA_REDZONE_SIZE) - rounded_up_size; - size_t rounded_down_size = round_down(size, KASAN_SHADOW_SCALE_SIZE); + size_t rounded_down_size = round_down(size, KASAN_GRANULE_SIZE); const void *left_redzone = (const void *)(addr - KASAN_ALLOCA_REDZONE_SIZE); diff --git a/mm/kasan/generic_report.c b/mm/kasan/generic_report.c index 6bb3f66992df..7d5b9e5c7cfe 100644 --- a/mm/kasan/generic_report.c +++ b/mm/kasan/generic_report.c @@ -34,7 +34,7 @@ void *find_first_bad_addr(void *addr, size_t size) void *p = addr; while (p < addr + size && !(*(u8 *)kasan_mem_to_shadow(p))) - p += KASAN_SHADOW_SCALE_SIZE; + p += KASAN_GRANULE_SIZE; return p; } @@ -46,14 +46,14 @@ static const char *get_shadow_bug_type(struct kasan_access_info *info) shadow_addr = (u8 *)kasan_mem_to_shadow(info->first_bad_addr); /* - * If shadow byte value is in [0, KASAN_SHADOW_SCALE_SIZE) we can look + * If shadow byte value is in [0, KASAN_GRANULE_SIZE) we can look * at the next shadow byte to determine the type of the bad access. */ - if (*shadow_addr > 0 && *shadow_addr <= KASAN_SHADOW_SCALE_SIZE - 1) + if (*shadow_addr > 0 && *shadow_addr <= KASAN_GRANULE_SIZE - 1) shadow_addr++; switch (*shadow_addr) { - case 0 ... KASAN_SHADOW_SCALE_SIZE - 1: + case 0 ... KASAN_GRANULE_SIZE - 1: /* * In theory it's still possible to see these shadow values * due to a data race in the kernel code. diff --git a/mm/kasan/init.c b/mm/kasan/init.c index 9ce8cc5b8621..dfddd6c39fe6 100644 --- a/mm/kasan/init.c +++ b/mm/kasan/init.c @@ -442,8 +442,8 @@ void kasan_remove_zero_shadow(void *start, unsigned long size) end = addr + (size >> KASAN_SHADOW_SCALE_SHIFT); if (WARN_ON((unsigned long)start % - (KASAN_SHADOW_SCALE_SIZE * PAGE_SIZE)) || - WARN_ON(size % (KASAN_SHADOW_SCALE_SIZE * PAGE_SIZE))) + (KASAN_GRANULE_SIZE * PAGE_SIZE)) || + WARN_ON(size % (KASAN_GRANULE_SIZE * PAGE_SIZE))) return; for (; addr < end; addr = next) { @@ -477,8 +477,8 @@ int kasan_add_zero_shadow(void *start, unsigned long size) shadow_end = shadow_start + (size >> KASAN_SHADOW_SCALE_SHIFT); if (WARN_ON((unsigned long)start % - (KASAN_SHADOW_SCALE_SIZE * PAGE_SIZE)) || - WARN_ON(size % (KASAN_SHADOW_SCALE_SIZE * PAGE_SIZE))) + (KASAN_GRANULE_SIZE * PAGE_SIZE)) || + WARN_ON(size % (KASAN_GRANULE_SIZE * PAGE_SIZE))) return -EINVAL; ret = kasan_populate_early_shadow(shadow_start, shadow_end); diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 03450d3b31f7..c31e2c739301 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -5,8 +5,8 @@ #include #include -#define KASAN_SHADOW_SCALE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT) -#define KASAN_SHADOW_MASK (KASAN_SHADOW_SCALE_SIZE - 1) +#define KASAN_GRANULE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT) +#define KASAN_GRANULE_MASK (KASAN_GRANULE_SIZE - 1) #define KASAN_TAG_KERNEL 0xFF /* native kernel pointers tag */ #define KASAN_TAG_INVALID 0xFE /* inaccessible memory tag */ diff --git a/mm/kasan/report.c b/mm/kasan/report.c index d500923abc8b..7b8dcb799a78 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -314,24 +314,24 @@ static bool __must_check get_address_stack_frame_info(const void *addr, return false; aligned_addr = round_down((unsigned long)addr, sizeof(long)); - mem_ptr = round_down(aligned_addr, KASAN_SHADOW_SCALE_SIZE); + mem_ptr = round_down(aligned_addr, KASAN_GRANULE_SIZE); shadow_ptr = kasan_mem_to_shadow((void *)aligned_addr); shadow_bottom = kasan_mem_to_shadow(end_of_stack(current)); while (shadow_ptr >= shadow_bottom && *shadow_ptr != KASAN_STACK_LEFT) { shadow_ptr--; - mem_ptr -= KASAN_SHADOW_SCALE_SIZE; + mem_ptr -= KASAN_GRANULE_SIZE; } while (shadow_ptr >= shadow_bottom && *shadow_ptr == KASAN_STACK_LEFT) { shadow_ptr--; - mem_ptr -= KASAN_SHADOW_SCALE_SIZE; + mem_ptr -= KASAN_GRANULE_SIZE; } if (shadow_ptr < shadow_bottom) return false; - frame = (const unsigned long *)(mem_ptr + KASAN_SHADOW_SCALE_SIZE); + frame = (const unsigned long *)(mem_ptr + KASAN_GRANULE_SIZE); if (frame[0] != KASAN_CURRENT_STACK_FRAME_MAGIC) { pr_err("KASAN internal error: frame info validation failed; invalid marker: %lu\n", frame[0]); @@ -599,6 +599,6 @@ void kasan_non_canonical_hook(unsigned long addr) else bug_type = "maybe wild-memory-access"; pr_alert("KASAN: %s in range [0x%016lx-0x%016lx]\n", bug_type, - orig_addr, orig_addr + KASAN_SHADOW_MASK); + orig_addr, orig_addr + KASAN_GRANULE_SIZE - 1); } #endif diff --git a/mm/kasan/tags_report.c b/mm/kasan/tags_report.c index 5f183501b871..c87d5a343b4e 100644 --- a/mm/kasan/tags_report.c +++ b/mm/kasan/tags_report.c @@ -76,7 +76,7 @@ void *find_first_bad_addr(void *addr, size_t size) void *end = p + size; while (p < end && tag == *(u8 *)kasan_mem_to_shadow(p)) - p += KASAN_SHADOW_SCALE_SIZE; + p += KASAN_GRANULE_SIZE; return p; } From patchwork Wed Nov 4 23:18:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883071 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CA88C00A89 for ; Thu, 5 Nov 2020 03:52:19 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B6F152072C for ; Thu, 5 Nov 2020 03:52:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="iK1YvwXJ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="e5wu1RZW"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="oVOf4hGd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B6F152072C Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=9H8xbJQDmzG59diX4SrykW4U3ZYMPZV1d6dNterxYZ4=; b=iK1YvwXJOj9JGTpWYmm3v/34/ T1WtQw/B++Z2d36kb4FlqT3GCwKnZHuO3ZnSST5OYQZFh14K+tnnYJFJU7jbD2mE13SrFu9QGcd6Q sw5/byYlNWlKXUSMeDOag78/Ptx2/2rw2hBiY3Ke9ktPD3ejZE6B2pE2aAImU0lDVGSidF3aN+SsG bfc2zznFZOE5/K6DiUH8Tr6PblU3fQhshBB1KONHZnxKblmvoMChwD3ZxlKD9Kx3xL03LvSwiOkH7 xn+xd5UymfYFhpYYiuWqv47pAGucaOpQhFsedTUtJta4H1f+ZLrXYGpA4EW/mkANS75d/fdP/EPBF miB4xdvRA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWIH-0007Sk-8o; Thu, 05 Nov 2020 03:50:37 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5L-00016k-P1 for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Sy6BvWdNS0zjXQiflbFd/HmI5xZS6ylM1lYk0zN7bgc=; b=e5wu1RZW8PqdzZyNbn2UE9NmJT J656LKvXQBEyQla0ji26vUyCVPt6eSw+L7WJ7CjzSgMDFMR816XrBBYfRlJXImDldAM22vb2zund2 MHemHmEYV8Ze0ra9OgZKRgy//G0XDdiEcBvsE8ZvBPDm3cpiAgALAvEftGklVLMfuyq0CkUf+kXnv 7lEzhsJsmlRTo0dFAbbxuavbp/iJG+/lK+2Wa363h5UalQOITDsy75sFl4ewvkEfYMpEwiXNZRKtY 84/GliQ4WJrwfjFTloVxvrGPQn79UIFD6eOI1Gw5OZKIQRM8sTjkz2n5HEFA1Dkw2TvAd5bB9YvcH ozTRuL5A==; Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS4o-0003wV-RP for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:30 +0000 Received: by mail-wr1-x449.google.com with SMTP id h8so44418wrt.9 for ; Wed, 04 Nov 2020 15:20:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=Sy6BvWdNS0zjXQiflbFd/HmI5xZS6ylM1lYk0zN7bgc=; b=oVOf4hGd0AFUpYHuVm2bbign6nHRWolcZwyLGwFgY79eiGA40WA026JsLxFYnaMRE7 7Qem6yGDs0EHmGnM6hkyMzEZRilHhE4uuoTGoNFI8kk/PWDT3yde4UScHLCdSurvd0q0 PTjbFlCgFa1xinn/DonMGmZg9d7ox7TjjC2ckWrFCXprqFFkcqatr0L0ezoe6qUJqbZh /cbDHfQ3hOdkE4KA4ND1K9oqEpcDGgiUND1+0+5V3MK1p7sVvMmsZSzZh8e1MjDx+Ela Kt9TS7lx5nG+ua/Ca7UbdTEz6mPxPjgpJW9u9r9i4Y7KO5KjqhmfHOlpJVlVTuKZV5Ld s8eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Sy6BvWdNS0zjXQiflbFd/HmI5xZS6ylM1lYk0zN7bgc=; b=SBUm/3l3pMblARVYomroPxmyBYRA7v8c/kemX/och6hTQPonZfBgTw6lwzi8zNK/Ty yneXROPB7DvVdZfals7AZIcKxI//ScBoSTzzCAOjq4vJHSLNJeLde3yyFJM5nLvlbSl0 17C0CbZCFWJhVfDsfkPMLj1dRrdrW3MS/u8u9QI6s6r48Rns4M7iSxiEk5OfiLS/U55+ oCWApQJb70S/nuFUWLZyvcV6xfP2ZKUCHBukpCZYvgvYTd9gdmAId2i+xp43q2kq8FAZ ti0NUmty0z0UE1coj8CVBmH+vaDl3VwLErTtWvMECNOuCvEEZEf5Ysk1Vo6bMT+VEmfa 0BDw== X-Gm-Message-State: AOAM532lptD/HOjhwuZgCifzNcc5+YhfdiMIsLQTPOHrqe37IBLdMPtv aNNq3cUgSPB2VBR/2y0XKaMREYal1FpllbGP X-Google-Smtp-Source: ABdhPJzZ9KOcFwhWSCq7ThJthNaAtBBIIUJFB1KG0jE/KHPv0qGyNAKK4rhNYpc/h459aUe6dxs9fGZqdihpkt/y X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:309:: with SMTP id 9mr83914wmd.80.1604531965449; Wed, 04 Nov 2020 15:19:25 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:23 +0100 In-Reply-To: Message-Id: <88fb34d65d1ff22472a9a2ba6758203ce1bcfca9.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 08/43] kasan: only build init.c for software modes From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232027_204927_A9DCA762 X-CRM114-Status: GOOD ( 12.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. The new mode won't be using shadow memory, so only build init.c that contains shadow initialization code for software modes. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: I8d68c47345afc1dbedadde738f34a874dcae5080 --- mm/kasan/Makefile | 6 +++--- mm/kasan/init.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/kasan/Makefile b/mm/kasan/Makefile index 370d970e5ab5..7cf685bb51bd 100644 --- a/mm/kasan/Makefile +++ b/mm/kasan/Makefile @@ -29,6 +29,6 @@ CFLAGS_report.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_tags.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_tags_report.o := $(CC_FLAGS_KASAN_RUNTIME) -obj-$(CONFIG_KASAN) := common.o init.o report.o -obj-$(CONFIG_KASAN_GENERIC) += generic.o generic_report.o quarantine.o -obj-$(CONFIG_KASAN_SW_TAGS) += tags.o tags_report.o +obj-$(CONFIG_KASAN) := common.o report.o +obj-$(CONFIG_KASAN_GENERIC) += init.o generic.o generic_report.o quarantine.o +obj-$(CONFIG_KASAN_SW_TAGS) += init.o tags.o tags_report.o diff --git a/mm/kasan/init.c b/mm/kasan/init.c index dfddd6c39fe6..1a71eaa8c5f9 100644 --- a/mm/kasan/init.c +++ b/mm/kasan/init.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * This file contains some kasan initialization code. + * This file contains KASAN shadow initialization code. * * Copyright (c) 2015 Samsung Electronics Co., Ltd. * Author: Andrey Ryabinin From patchwork Wed Nov 4 23:18:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43586C00A89 for ; Thu, 5 Nov 2020 04:31:07 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 99E7D20825 for ; Thu, 5 Nov 2020 04:31:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GWWVOYfc"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="f+VRLUJv"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="dH+BMPhe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 99E7D20825 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=NmRwz4IGLqGIRdtY9P6g7x8wGBZMDT9xOnM5NrDOwS8=; b=GWWVOYfch8xFChOiwTiOZO7oW 8rExgQl5etaup1TsP8WaqX0P5MhQz6x+MT53sk7S2gYiqv026PYBNMBnkAvzoelrwKniD1yRSO3dr WFpyiWiBSrfJhdjHxY/NGyOrAcuovBh5jq4cycJESFQNeryRw9u7TN5JYtNqijfH/8u22md8isLeZ bXVMsJNYunBNTN+p1wJPu+IBH91SXPEltM55x4hMdIgNbwWJsBMCUuXHpOaisVW8iEq63owktKOin 1selEJZ6ZgwIxryVXtkOk6X9e5ZHVrGN5gDfaBSQJL+7unemBTdHpUtCU0PFLmguxRqjAXVXnjZT/ CQpTU/XyA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWtO-0000py-U9; Thu, 05 Nov 2020 04:28:59 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5K-000145-03 for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=JKR/Vyk0dE+gaWDMHhX5WcTwZcpnuIINGg9SojGy6kk=; b=f+VRLUJv9r6xcuYr7FiJ4J+bZf lbfmwntHUCNGOxr/L1YBql+fC7/HSInzkNFyEfzbjZ3giNl3zFpVZgVCGP4rVDCxoj/o+de94v9jN cKZdHWUjgv8ZuwiWF1qXhSJD+SOyIy+k3myREveaW2k0aZBVNaSm0Z4zN9mlui1K6rFqQDoYmDkor MmTSVnx3SVAFwfNY9oUdjp8CtgbTQlfpolu0H6S+RJM2iOimA1e+Vggo6JpGdIia7pvY+9BpEU+Ia sC1d/N6XYKv3MN33ZpxMaiq52tuHL3hy9mFDW1FryFrU4iDazBQ5XZTrDx4350EPctcOrVV5dD+xI xBRC6fGQ==; Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS4v-0003y5-Kh for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:38 +0000 Received: by mail-qk1-x74a.google.com with SMTP id v134so14522114qka.19 for ; Wed, 04 Nov 2020 15:20:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=JKR/Vyk0dE+gaWDMHhX5WcTwZcpnuIINGg9SojGy6kk=; b=dH+BMPheb5iHWzj2FG/mLTvtRd4dMzSK5wZ/llHM0D4+cmv39ARaIc6U94/TPxumYN DjsVZEwD9dEwwfD+J9xXy8NvQ0cLS5ikAb/vy6DhHRpYzonAo8tfClXoBcWPEUMRHz2+ XtvoVgLoAVZS19jXkJfq3rdNdmD0QUHt2A6GzYqLDex+c7MMedzTpQWE9xJRSg/3mBqw 8FDMuq8ZAUzvzOedbf/0EGaPECAzpitYzuSajExvxlSMrgbyiGoJ57zwAhK1BgjmXVut H8SlQ5478zJQn0xPzkYSbGWFpab7Xn048cR0HJTJmkmh8OHf2BTnpPI6KpWBmbYX7DWl ma1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=JKR/Vyk0dE+gaWDMHhX5WcTwZcpnuIINGg9SojGy6kk=; b=af8y8hZr2nYXRu+AxfOKMmwtgnHYrENiXh+Ctk5QPrKTJ/a7qouJaKd++j32ByTw/g MCY2RN90jTR2lByW/KqHrWBfP1hU0CAS+tW8FYzT9hGBVRUG2+Bf8nFiem5Su9VNrDYU Dnm5JXwYrNSTMIH6oox/zoANc2mmM6Dn4pjamkJg/DTjba5Vya8rfSS0elcx0tVTwDyy dbR1a8gsS9du78Pl4iljppB7237CVjp28Z5OxSFDrSPILnhnekJtAeG5QyjSjplGl11V IkgzgQThx1WPYUh6oeIkStQui3OunYNBURYR0A67w3X0LJXhcisaWgJfFuWjP2owmQ9v qHkA== X-Gm-Message-State: AOAM533R4dUdjzqaiq9nG9YyC8YN8KvTPveu7nmzP21W/3YfBhiwtjkf Uh3u3tWfdbXVgVH98x7sUS/7WfvtAOyMPP3R X-Google-Smtp-Source: ABdhPJylbI9vEHKBXsD13eTeq3mOQJGSekLkmtMQlMEIGR9ZnFLwX8LkYMB02wJ4pHNdAn2f0yAFNZKr89Rz9XqD X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6214:192d:: with SMTP id es13mr229250qvb.27.1604531967876; Wed, 04 Nov 2020 15:19:27 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:24 +0100 In-Reply-To: Message-Id: <35bd971b9e5b2575ad3ed7c93eeb6035df5dd775.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 09/43] kasan: split out shadow.c from common.c From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232033_928149_480A499C X-CRM114-Status: GOOD ( 28.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. The new mode won't be using shadow memory. Move all shadow-related code to shadow.c, which is only enabled for software KASAN modes that use shadow memory. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: Ic1c32ce72d4649848e9e6a1f2c8dd269c77673f2 --- mm/kasan/Makefile | 6 +- mm/kasan/common.c | 486 +------------------------------------------- mm/kasan/shadow.c | 505 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 510 insertions(+), 487 deletions(-) create mode 100644 mm/kasan/shadow.c diff --git a/mm/kasan/Makefile b/mm/kasan/Makefile index 7cf685bb51bd..7cc1031e1ef8 100644 --- a/mm/kasan/Makefile +++ b/mm/kasan/Makefile @@ -10,6 +10,7 @@ CFLAGS_REMOVE_generic_report.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_init.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_quarantine.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_shadow.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_tags.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_tags_report.o = $(CC_FLAGS_FTRACE) @@ -26,9 +27,10 @@ CFLAGS_generic_report.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_init.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_quarantine.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_report.o := $(CC_FLAGS_KASAN_RUNTIME) +CFLAGS_shadow.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_tags.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_tags_report.o := $(CC_FLAGS_KASAN_RUNTIME) obj-$(CONFIG_KASAN) := common.o report.o -obj-$(CONFIG_KASAN_GENERIC) += init.o generic.o generic_report.o quarantine.o -obj-$(CONFIG_KASAN_SW_TAGS) += init.o tags.o tags_report.o +obj-$(CONFIG_KASAN_GENERIC) += init.o generic.o generic_report.o shadow.o quarantine.o +obj-$(CONFIG_KASAN_SW_TAGS) += init.o shadow.o tags.o tags_report.o diff --git a/mm/kasan/common.c b/mm/kasan/common.c index f65c9f792f8f..123abfb760d4 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * This file contains common generic and tag-based KASAN code. + * This file contains common KASAN code. * * Copyright (c) 2014 Samsung Electronics Co., Ltd. * Author: Andrey Ryabinin @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -26,12 +25,8 @@ #include #include #include -#include #include -#include -#include - #include "kasan.h" #include "../slab.h" @@ -61,93 +56,6 @@ void kasan_disable_current(void) current->kasan_depth--; } -bool __kasan_check_read(const volatile void *p, unsigned int size) -{ - return check_memory_region((unsigned long)p, size, false, _RET_IP_); -} -EXPORT_SYMBOL(__kasan_check_read); - -bool __kasan_check_write(const volatile void *p, unsigned int size) -{ - return check_memory_region((unsigned long)p, size, true, _RET_IP_); -} -EXPORT_SYMBOL(__kasan_check_write); - -#undef memset -void *memset(void *addr, int c, size_t len) -{ - if (!check_memory_region((unsigned long)addr, len, true, _RET_IP_)) - return NULL; - - return __memset(addr, c, len); -} - -#ifdef __HAVE_ARCH_MEMMOVE -#undef memmove -void *memmove(void *dest, const void *src, size_t len) -{ - if (!check_memory_region((unsigned long)src, len, false, _RET_IP_) || - !check_memory_region((unsigned long)dest, len, true, _RET_IP_)) - return NULL; - - return __memmove(dest, src, len); -} -#endif - -#undef memcpy -void *memcpy(void *dest, const void *src, size_t len) -{ - if (!check_memory_region((unsigned long)src, len, false, _RET_IP_) || - !check_memory_region((unsigned long)dest, len, true, _RET_IP_)) - return NULL; - - return __memcpy(dest, src, len); -} - -/* - * Poisons the shadow memory for 'size' bytes starting from 'addr'. - * Memory addresses should be aligned to KASAN_GRANULE_SIZE. - */ -void kasan_poison_memory(const void *address, size_t size, u8 value) -{ - void *shadow_start, *shadow_end; - - /* - * Perform shadow offset calculation based on untagged address, as - * some of the callers (e.g. kasan_poison_object_data) pass tagged - * addresses to this function. - */ - address = reset_tag(address); - - shadow_start = kasan_mem_to_shadow(address); - shadow_end = kasan_mem_to_shadow(address + size); - - __memset(shadow_start, value, shadow_end - shadow_start); -} - -void kasan_unpoison_memory(const void *address, size_t size) -{ - u8 tag = get_tag(address); - - /* - * Perform shadow offset calculation based on untagged address, as - * some of the callers (e.g. kasan_unpoison_object_data) pass tagged - * addresses to this function. - */ - address = reset_tag(address); - - kasan_poison_memory(address, size, tag); - - if (size & KASAN_GRANULE_MASK) { - u8 *shadow = (u8 *)kasan_mem_to_shadow(address + size); - - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) - *shadow = tag; - else - *shadow = size & KASAN_GRANULE_MASK; - } -} - static void __kasan_unpoison_stack(struct task_struct *task, const void *sp) { void *base = task_stack_page(task); @@ -535,395 +443,3 @@ void kasan_kfree_large(void *ptr, unsigned long ip) kasan_report_invalid_free(ptr, ip); /* The object will be poisoned by page_alloc. */ } - -#ifdef CONFIG_MEMORY_HOTPLUG -static bool shadow_mapped(unsigned long addr) -{ - pgd_t *pgd = pgd_offset_k(addr); - p4d_t *p4d; - pud_t *pud; - pmd_t *pmd; - pte_t *pte; - - if (pgd_none(*pgd)) - return false; - p4d = p4d_offset(pgd, addr); - if (p4d_none(*p4d)) - return false; - pud = pud_offset(p4d, addr); - if (pud_none(*pud)) - return false; - - /* - * We can't use pud_large() or pud_huge(), the first one is - * arch-specific, the last one depends on HUGETLB_PAGE. So let's abuse - * pud_bad(), if pud is bad then it's bad because it's huge. - */ - if (pud_bad(*pud)) - return true; - pmd = pmd_offset(pud, addr); - if (pmd_none(*pmd)) - return false; - - if (pmd_bad(*pmd)) - return true; - pte = pte_offset_kernel(pmd, addr); - return !pte_none(*pte); -} - -static int __meminit kasan_mem_notifier(struct notifier_block *nb, - unsigned long action, void *data) -{ - struct memory_notify *mem_data = data; - unsigned long nr_shadow_pages, start_kaddr, shadow_start; - unsigned long shadow_end, shadow_size; - - nr_shadow_pages = mem_data->nr_pages >> KASAN_SHADOW_SCALE_SHIFT; - start_kaddr = (unsigned long)pfn_to_kaddr(mem_data->start_pfn); - shadow_start = (unsigned long)kasan_mem_to_shadow((void *)start_kaddr); - shadow_size = nr_shadow_pages << PAGE_SHIFT; - shadow_end = shadow_start + shadow_size; - - if (WARN_ON(mem_data->nr_pages % KASAN_GRANULE_SIZE) || - WARN_ON(start_kaddr % (KASAN_GRANULE_SIZE << PAGE_SHIFT))) - return NOTIFY_BAD; - - switch (action) { - case MEM_GOING_ONLINE: { - void *ret; - - /* - * If shadow is mapped already than it must have been mapped - * during the boot. This could happen if we onlining previously - * offlined memory. - */ - if (shadow_mapped(shadow_start)) - return NOTIFY_OK; - - ret = __vmalloc_node_range(shadow_size, PAGE_SIZE, shadow_start, - shadow_end, GFP_KERNEL, - PAGE_KERNEL, VM_NO_GUARD, - pfn_to_nid(mem_data->start_pfn), - __builtin_return_address(0)); - if (!ret) - return NOTIFY_BAD; - - kmemleak_ignore(ret); - return NOTIFY_OK; - } - case MEM_CANCEL_ONLINE: - case MEM_OFFLINE: { - struct vm_struct *vm; - - /* - * shadow_start was either mapped during boot by kasan_init() - * or during memory online by __vmalloc_node_range(). - * In the latter case we can use vfree() to free shadow. - * Non-NULL result of the find_vm_area() will tell us if - * that was the second case. - * - * Currently it's not possible to free shadow mapped - * during boot by kasan_init(). It's because the code - * to do that hasn't been written yet. So we'll just - * leak the memory. - */ - vm = find_vm_area((void *)shadow_start); - if (vm) - vfree((void *)shadow_start); - } - } - - return NOTIFY_OK; -} - -static int __init kasan_memhotplug_init(void) -{ - hotplug_memory_notifier(kasan_mem_notifier, 0); - - return 0; -} - -core_initcall(kasan_memhotplug_init); -#endif - -#ifdef CONFIG_KASAN_VMALLOC - -static int kasan_populate_vmalloc_pte(pte_t *ptep, unsigned long addr, - void *unused) -{ - unsigned long page; - pte_t pte; - - if (likely(!pte_none(*ptep))) - return 0; - - page = __get_free_page(GFP_KERNEL); - if (!page) - return -ENOMEM; - - memset((void *)page, KASAN_VMALLOC_INVALID, PAGE_SIZE); - pte = pfn_pte(PFN_DOWN(__pa(page)), PAGE_KERNEL); - - spin_lock(&init_mm.page_table_lock); - if (likely(pte_none(*ptep))) { - set_pte_at(&init_mm, addr, ptep, pte); - page = 0; - } - spin_unlock(&init_mm.page_table_lock); - if (page) - free_page(page); - return 0; -} - -int kasan_populate_vmalloc(unsigned long addr, unsigned long size) -{ - unsigned long shadow_start, shadow_end; - int ret; - - if (!is_vmalloc_or_module_addr((void *)addr)) - return 0; - - shadow_start = (unsigned long)kasan_mem_to_shadow((void *)addr); - shadow_start = ALIGN_DOWN(shadow_start, PAGE_SIZE); - shadow_end = (unsigned long)kasan_mem_to_shadow((void *)addr + size); - shadow_end = ALIGN(shadow_end, PAGE_SIZE); - - ret = apply_to_page_range(&init_mm, shadow_start, - shadow_end - shadow_start, - kasan_populate_vmalloc_pte, NULL); - if (ret) - return ret; - - flush_cache_vmap(shadow_start, shadow_end); - - /* - * We need to be careful about inter-cpu effects here. Consider: - * - * CPU#0 CPU#1 - * WRITE_ONCE(p, vmalloc(100)); while (x = READ_ONCE(p)) ; - * p[99] = 1; - * - * With compiler instrumentation, that ends up looking like this: - * - * CPU#0 CPU#1 - * // vmalloc() allocates memory - * // let a = area->addr - * // we reach kasan_populate_vmalloc - * // and call kasan_unpoison_memory: - * STORE shadow(a), unpoison_val - * ... - * STORE shadow(a+99), unpoison_val x = LOAD p - * // rest of vmalloc process - * STORE p, a LOAD shadow(x+99) - * - * If there is no barrier between the end of unpoisioning the shadow - * and the store of the result to p, the stores could be committed - * in a different order by CPU#0, and CPU#1 could erroneously observe - * poison in the shadow. - * - * We need some sort of barrier between the stores. - * - * In the vmalloc() case, this is provided by a smp_wmb() in - * clear_vm_uninitialized_flag(). In the per-cpu allocator and in - * get_vm_area() and friends, the caller gets shadow allocated but - * doesn't have any pages mapped into the virtual address space that - * has been reserved. Mapping those pages in will involve taking and - * releasing a page-table lock, which will provide the barrier. - */ - - return 0; -} - -/* - * Poison the shadow for a vmalloc region. Called as part of the - * freeing process at the time the region is freed. - */ -void kasan_poison_vmalloc(const void *start, unsigned long size) -{ - if (!is_vmalloc_or_module_addr(start)) - return; - - size = round_up(size, KASAN_GRANULE_SIZE); - kasan_poison_memory(start, size, KASAN_VMALLOC_INVALID); -} - -void kasan_unpoison_vmalloc(const void *start, unsigned long size) -{ - if (!is_vmalloc_or_module_addr(start)) - return; - - kasan_unpoison_memory(start, size); -} - -static int kasan_depopulate_vmalloc_pte(pte_t *ptep, unsigned long addr, - void *unused) -{ - unsigned long page; - - page = (unsigned long)__va(pte_pfn(*ptep) << PAGE_SHIFT); - - spin_lock(&init_mm.page_table_lock); - - if (likely(!pte_none(*ptep))) { - pte_clear(&init_mm, addr, ptep); - free_page(page); - } - spin_unlock(&init_mm.page_table_lock); - - return 0; -} - -/* - * Release the backing for the vmalloc region [start, end), which - * lies within the free region [free_region_start, free_region_end). - * - * This can be run lazily, long after the region was freed. It runs - * under vmap_area_lock, so it's not safe to interact with the vmalloc/vmap - * infrastructure. - * - * How does this work? - * ------------------- - * - * We have a region that is page aligned, labelled as A. - * That might not map onto the shadow in a way that is page-aligned: - * - * start end - * v v - * |????????|????????|AAAAAAAA|AA....AA|AAAAAAAA|????????| < vmalloc - * -------- -------- -------- -------- -------- - * | | | | | - * | | | /-------/ | - * \-------\|/------/ |/---------------/ - * ||| || - * |??AAAAAA|AAAAAAAA|AA??????| < shadow - * (1) (2) (3) - * - * First we align the start upwards and the end downwards, so that the - * shadow of the region aligns with shadow page boundaries. In the - * example, this gives us the shadow page (2). This is the shadow entirely - * covered by this allocation. - * - * Then we have the tricky bits. We want to know if we can free the - * partially covered shadow pages - (1) and (3) in the example. For this, - * we are given the start and end of the free region that contains this - * allocation. Extending our previous example, we could have: - * - * free_region_start free_region_end - * | start end | - * v v v v - * |FFFFFFFF|FFFFFFFF|AAAAAAAA|AA....AA|AAAAAAAA|FFFFFFFF| < vmalloc - * -------- -------- -------- -------- -------- - * | | | | | - * | | | /-------/ | - * \-------\|/------/ |/---------------/ - * ||| || - * |FFAAAAAA|AAAAAAAA|AAF?????| < shadow - * (1) (2) (3) - * - * Once again, we align the start of the free region up, and the end of - * the free region down so that the shadow is page aligned. So we can free - * page (1) - we know no allocation currently uses anything in that page, - * because all of it is in the vmalloc free region. But we cannot free - * page (3), because we can't be sure that the rest of it is unused. - * - * We only consider pages that contain part of the original region for - * freeing: we don't try to free other pages from the free region or we'd - * end up trying to free huge chunks of virtual address space. - * - * Concurrency - * ----------- - * - * How do we know that we're not freeing a page that is simultaneously - * being used for a fresh allocation in kasan_populate_vmalloc(_pte)? - * - * We _can_ have kasan_release_vmalloc and kasan_populate_vmalloc running - * at the same time. While we run under free_vmap_area_lock, the population - * code does not. - * - * free_vmap_area_lock instead operates to ensure that the larger range - * [free_region_start, free_region_end) is safe: because __alloc_vmap_area and - * the per-cpu region-finding algorithm both run under free_vmap_area_lock, - * no space identified as free will become used while we are running. This - * means that so long as we are careful with alignment and only free shadow - * pages entirely covered by the free region, we will not run in to any - * trouble - any simultaneous allocations will be for disjoint regions. - */ -void kasan_release_vmalloc(unsigned long start, unsigned long end, - unsigned long free_region_start, - unsigned long free_region_end) -{ - void *shadow_start, *shadow_end; - unsigned long region_start, region_end; - unsigned long size; - - region_start = ALIGN(start, PAGE_SIZE * KASAN_GRANULE_SIZE); - region_end = ALIGN_DOWN(end, PAGE_SIZE * KASAN_GRANULE_SIZE); - - free_region_start = ALIGN(free_region_start, - PAGE_SIZE * KASAN_GRANULE_SIZE); - - if (start != region_start && - free_region_start < region_start) - region_start -= PAGE_SIZE * KASAN_GRANULE_SIZE; - - free_region_end = ALIGN_DOWN(free_region_end, - PAGE_SIZE * KASAN_GRANULE_SIZE); - - if (end != region_end && - free_region_end > region_end) - region_end += PAGE_SIZE * KASAN_GRANULE_SIZE; - - shadow_start = kasan_mem_to_shadow((void *)region_start); - shadow_end = kasan_mem_to_shadow((void *)region_end); - - if (shadow_end > shadow_start) { - size = shadow_end - shadow_start; - apply_to_existing_page_range(&init_mm, - (unsigned long)shadow_start, - size, kasan_depopulate_vmalloc_pte, - NULL); - flush_tlb_kernel_range((unsigned long)shadow_start, - (unsigned long)shadow_end); - } -} - -#else /* CONFIG_KASAN_VMALLOC */ - -int kasan_module_alloc(void *addr, size_t size) -{ - void *ret; - size_t scaled_size; - size_t shadow_size; - unsigned long shadow_start; - - shadow_start = (unsigned long)kasan_mem_to_shadow(addr); - scaled_size = (size + KASAN_GRANULE_SIZE - 1) >> - KASAN_SHADOW_SCALE_SHIFT; - shadow_size = round_up(scaled_size, PAGE_SIZE); - - if (WARN_ON(!PAGE_ALIGNED(shadow_start))) - return -EINVAL; - - ret = __vmalloc_node_range(shadow_size, 1, shadow_start, - shadow_start + shadow_size, - GFP_KERNEL, - PAGE_KERNEL, VM_NO_GUARD, NUMA_NO_NODE, - __builtin_return_address(0)); - - if (ret) { - __memset(ret, KASAN_SHADOW_INIT, shadow_size); - find_vm_area(addr)->flags |= VM_KASAN; - kmemleak_ignore(ret); - return 0; - } - - return -ENOMEM; -} - -void kasan_free_shadow(const struct vm_struct *vm) -{ - if (vm->flags & VM_KASAN) - vfree(kasan_mem_to_shadow(vm->addr)); -} - -#endif diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c new file mode 100644 index 000000000000..ca0cc4c31454 --- /dev/null +++ b/mm/kasan/shadow.c @@ -0,0 +1,505 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This file contains KASAN runtime code that manages shadow memory for + * generic and software tag-based KASAN modes. + * + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * Author: Andrey Ryabinin + * + * Some code borrowed from https://github.com/xairy/kasan-prototype by + * Andrey Konovalov + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "kasan.h" + +bool __kasan_check_read(const volatile void *p, unsigned int size) +{ + return check_memory_region((unsigned long)p, size, false, _RET_IP_); +} +EXPORT_SYMBOL(__kasan_check_read); + +bool __kasan_check_write(const volatile void *p, unsigned int size) +{ + return check_memory_region((unsigned long)p, size, true, _RET_IP_); +} +EXPORT_SYMBOL(__kasan_check_write); + +#undef memset +void *memset(void *addr, int c, size_t len) +{ + if (!check_memory_region((unsigned long)addr, len, true, _RET_IP_)) + return NULL; + + return __memset(addr, c, len); +} + +#ifdef __HAVE_ARCH_MEMMOVE +#undef memmove +void *memmove(void *dest, const void *src, size_t len) +{ + if (!check_memory_region((unsigned long)src, len, false, _RET_IP_) || + !check_memory_region((unsigned long)dest, len, true, _RET_IP_)) + return NULL; + + return __memmove(dest, src, len); +} +#endif + +#undef memcpy +void *memcpy(void *dest, const void *src, size_t len) +{ + if (!check_memory_region((unsigned long)src, len, false, _RET_IP_) || + !check_memory_region((unsigned long)dest, len, true, _RET_IP_)) + return NULL; + + return __memcpy(dest, src, len); +} + +/* + * Poisons the shadow memory for 'size' bytes starting from 'addr'. + * Memory addresses should be aligned to KASAN_GRANULE_SIZE. + */ +void kasan_poison_memory(const void *address, size_t size, u8 value) +{ + void *shadow_start, *shadow_end; + + /* + * Perform shadow offset calculation based on untagged address, as + * some of the callers (e.g. kasan_poison_object_data) pass tagged + * addresses to this function. + */ + address = reset_tag(address); + + shadow_start = kasan_mem_to_shadow(address); + shadow_end = kasan_mem_to_shadow(address + size); + + __memset(shadow_start, value, shadow_end - shadow_start); +} + +void kasan_unpoison_memory(const void *address, size_t size) +{ + u8 tag = get_tag(address); + + /* + * Perform shadow offset calculation based on untagged address, as + * some of the callers (e.g. kasan_unpoison_object_data) pass tagged + * addresses to this function. + */ + address = reset_tag(address); + + kasan_poison_memory(address, size, tag); + + if (size & KASAN_GRANULE_MASK) { + u8 *shadow = (u8 *)kasan_mem_to_shadow(address + size); + + if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) + *shadow = tag; + else + *shadow = size & KASAN_GRANULE_MASK; + } +} + +#ifdef CONFIG_MEMORY_HOTPLUG +static bool shadow_mapped(unsigned long addr) +{ + pgd_t *pgd = pgd_offset_k(addr); + p4d_t *p4d; + pud_t *pud; + pmd_t *pmd; + pte_t *pte; + + if (pgd_none(*pgd)) + return false; + p4d = p4d_offset(pgd, addr); + if (p4d_none(*p4d)) + return false; + pud = pud_offset(p4d, addr); + if (pud_none(*pud)) + return false; + + /* + * We can't use pud_large() or pud_huge(), the first one is + * arch-specific, the last one depends on HUGETLB_PAGE. So let's abuse + * pud_bad(), if pud is bad then it's bad because it's huge. + */ + if (pud_bad(*pud)) + return true; + pmd = pmd_offset(pud, addr); + if (pmd_none(*pmd)) + return false; + + if (pmd_bad(*pmd)) + return true; + pte = pte_offset_kernel(pmd, addr); + return !pte_none(*pte); +} + +static int __meminit kasan_mem_notifier(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct memory_notify *mem_data = data; + unsigned long nr_shadow_pages, start_kaddr, shadow_start; + unsigned long shadow_end, shadow_size; + + nr_shadow_pages = mem_data->nr_pages >> KASAN_SHADOW_SCALE_SHIFT; + start_kaddr = (unsigned long)pfn_to_kaddr(mem_data->start_pfn); + shadow_start = (unsigned long)kasan_mem_to_shadow((void *)start_kaddr); + shadow_size = nr_shadow_pages << PAGE_SHIFT; + shadow_end = shadow_start + shadow_size; + + if (WARN_ON(mem_data->nr_pages % KASAN_GRANULE_SIZE) || + WARN_ON(start_kaddr % (KASAN_GRANULE_SIZE << PAGE_SHIFT))) + return NOTIFY_BAD; + + switch (action) { + case MEM_GOING_ONLINE: { + void *ret; + + /* + * If shadow is mapped already than it must have been mapped + * during the boot. This could happen if we onlining previously + * offlined memory. + */ + if (shadow_mapped(shadow_start)) + return NOTIFY_OK; + + ret = __vmalloc_node_range(shadow_size, PAGE_SIZE, shadow_start, + shadow_end, GFP_KERNEL, + PAGE_KERNEL, VM_NO_GUARD, + pfn_to_nid(mem_data->start_pfn), + __builtin_return_address(0)); + if (!ret) + return NOTIFY_BAD; + + kmemleak_ignore(ret); + return NOTIFY_OK; + } + case MEM_CANCEL_ONLINE: + case MEM_OFFLINE: { + struct vm_struct *vm; + + /* + * shadow_start was either mapped during boot by kasan_init() + * or during memory online by __vmalloc_node_range(). + * In the latter case we can use vfree() to free shadow. + * Non-NULL result of the find_vm_area() will tell us if + * that was the second case. + * + * Currently it's not possible to free shadow mapped + * during boot by kasan_init(). It's because the code + * to do that hasn't been written yet. So we'll just + * leak the memory. + */ + vm = find_vm_area((void *)shadow_start); + if (vm) + vfree((void *)shadow_start); + } + } + + return NOTIFY_OK; +} + +static int __init kasan_memhotplug_init(void) +{ + hotplug_memory_notifier(kasan_mem_notifier, 0); + + return 0; +} + +core_initcall(kasan_memhotplug_init); +#endif + +#ifdef CONFIG_KASAN_VMALLOC + +static int kasan_populate_vmalloc_pte(pte_t *ptep, unsigned long addr, + void *unused) +{ + unsigned long page; + pte_t pte; + + if (likely(!pte_none(*ptep))) + return 0; + + page = __get_free_page(GFP_KERNEL); + if (!page) + return -ENOMEM; + + memset((void *)page, KASAN_VMALLOC_INVALID, PAGE_SIZE); + pte = pfn_pte(PFN_DOWN(__pa(page)), PAGE_KERNEL); + + spin_lock(&init_mm.page_table_lock); + if (likely(pte_none(*ptep))) { + set_pte_at(&init_mm, addr, ptep, pte); + page = 0; + } + spin_unlock(&init_mm.page_table_lock); + if (page) + free_page(page); + return 0; +} + +int kasan_populate_vmalloc(unsigned long addr, unsigned long size) +{ + unsigned long shadow_start, shadow_end; + int ret; + + if (!is_vmalloc_or_module_addr((void *)addr)) + return 0; + + shadow_start = (unsigned long)kasan_mem_to_shadow((void *)addr); + shadow_start = ALIGN_DOWN(shadow_start, PAGE_SIZE); + shadow_end = (unsigned long)kasan_mem_to_shadow((void *)addr + size); + shadow_end = ALIGN(shadow_end, PAGE_SIZE); + + ret = apply_to_page_range(&init_mm, shadow_start, + shadow_end - shadow_start, + kasan_populate_vmalloc_pte, NULL); + if (ret) + return ret; + + flush_cache_vmap(shadow_start, shadow_end); + + /* + * We need to be careful about inter-cpu effects here. Consider: + * + * CPU#0 CPU#1 + * WRITE_ONCE(p, vmalloc(100)); while (x = READ_ONCE(p)) ; + * p[99] = 1; + * + * With compiler instrumentation, that ends up looking like this: + * + * CPU#0 CPU#1 + * // vmalloc() allocates memory + * // let a = area->addr + * // we reach kasan_populate_vmalloc + * // and call kasan_unpoison_memory: + * STORE shadow(a), unpoison_val + * ... + * STORE shadow(a+99), unpoison_val x = LOAD p + * // rest of vmalloc process + * STORE p, a LOAD shadow(x+99) + * + * If there is no barrier between the end of unpoisioning the shadow + * and the store of the result to p, the stores could be committed + * in a different order by CPU#0, and CPU#1 could erroneously observe + * poison in the shadow. + * + * We need some sort of barrier between the stores. + * + * In the vmalloc() case, this is provided by a smp_wmb() in + * clear_vm_uninitialized_flag(). In the per-cpu allocator and in + * get_vm_area() and friends, the caller gets shadow allocated but + * doesn't have any pages mapped into the virtual address space that + * has been reserved. Mapping those pages in will involve taking and + * releasing a page-table lock, which will provide the barrier. + */ + + return 0; +} + +/* + * Poison the shadow for a vmalloc region. Called as part of the + * freeing process at the time the region is freed. + */ +void kasan_poison_vmalloc(const void *start, unsigned long size) +{ + if (!is_vmalloc_or_module_addr(start)) + return; + + size = round_up(size, KASAN_GRANULE_SIZE); + kasan_poison_memory(start, size, KASAN_VMALLOC_INVALID); +} + +void kasan_unpoison_vmalloc(const void *start, unsigned long size) +{ + if (!is_vmalloc_or_module_addr(start)) + return; + + kasan_unpoison_memory(start, size); +} + +static int kasan_depopulate_vmalloc_pte(pte_t *ptep, unsigned long addr, + void *unused) +{ + unsigned long page; + + page = (unsigned long)__va(pte_pfn(*ptep) << PAGE_SHIFT); + + spin_lock(&init_mm.page_table_lock); + + if (likely(!pte_none(*ptep))) { + pte_clear(&init_mm, addr, ptep); + free_page(page); + } + spin_unlock(&init_mm.page_table_lock); + + return 0; +} + +/* + * Release the backing for the vmalloc region [start, end), which + * lies within the free region [free_region_start, free_region_end). + * + * This can be run lazily, long after the region was freed. It runs + * under vmap_area_lock, so it's not safe to interact with the vmalloc/vmap + * infrastructure. + * + * How does this work? + * ------------------- + * + * We have a region that is page aligned, labelled as A. + * That might not map onto the shadow in a way that is page-aligned: + * + * start end + * v v + * |????????|????????|AAAAAAAA|AA....AA|AAAAAAAA|????????| < vmalloc + * -------- -------- -------- -------- -------- + * | | | | | + * | | | /-------/ | + * \-------\|/------/ |/---------------/ + * ||| || + * |??AAAAAA|AAAAAAAA|AA??????| < shadow + * (1) (2) (3) + * + * First we align the start upwards and the end downwards, so that the + * shadow of the region aligns with shadow page boundaries. In the + * example, this gives us the shadow page (2). This is the shadow entirely + * covered by this allocation. + * + * Then we have the tricky bits. We want to know if we can free the + * partially covered shadow pages - (1) and (3) in the example. For this, + * we are given the start and end of the free region that contains this + * allocation. Extending our previous example, we could have: + * + * free_region_start free_region_end + * | start end | + * v v v v + * |FFFFFFFF|FFFFFFFF|AAAAAAAA|AA....AA|AAAAAAAA|FFFFFFFF| < vmalloc + * -------- -------- -------- -------- -------- + * | | | | | + * | | | /-------/ | + * \-------\|/------/ |/---------------/ + * ||| || + * |FFAAAAAA|AAAAAAAA|AAF?????| < shadow + * (1) (2) (3) + * + * Once again, we align the start of the free region up, and the end of + * the free region down so that the shadow is page aligned. So we can free + * page (1) - we know no allocation currently uses anything in that page, + * because all of it is in the vmalloc free region. But we cannot free + * page (3), because we can't be sure that the rest of it is unused. + * + * We only consider pages that contain part of the original region for + * freeing: we don't try to free other pages from the free region or we'd + * end up trying to free huge chunks of virtual address space. + * + * Concurrency + * ----------- + * + * How do we know that we're not freeing a page that is simultaneously + * being used for a fresh allocation in kasan_populate_vmalloc(_pte)? + * + * We _can_ have kasan_release_vmalloc and kasan_populate_vmalloc running + * at the same time. While we run under free_vmap_area_lock, the population + * code does not. + * + * free_vmap_area_lock instead operates to ensure that the larger range + * [free_region_start, free_region_end) is safe: because __alloc_vmap_area and + * the per-cpu region-finding algorithm both run under free_vmap_area_lock, + * no space identified as free will become used while we are running. This + * means that so long as we are careful with alignment and only free shadow + * pages entirely covered by the free region, we will not run in to any + * trouble - any simultaneous allocations will be for disjoint regions. + */ +void kasan_release_vmalloc(unsigned long start, unsigned long end, + unsigned long free_region_start, + unsigned long free_region_end) +{ + void *shadow_start, *shadow_end; + unsigned long region_start, region_end; + unsigned long size; + + region_start = ALIGN(start, PAGE_SIZE * KASAN_GRANULE_SIZE); + region_end = ALIGN_DOWN(end, PAGE_SIZE * KASAN_GRANULE_SIZE); + + free_region_start = ALIGN(free_region_start, + PAGE_SIZE * KASAN_GRANULE_SIZE); + + if (start != region_start && + free_region_start < region_start) + region_start -= PAGE_SIZE * KASAN_GRANULE_SIZE; + + free_region_end = ALIGN_DOWN(free_region_end, + PAGE_SIZE * KASAN_GRANULE_SIZE); + + if (end != region_end && + free_region_end > region_end) + region_end += PAGE_SIZE * KASAN_GRANULE_SIZE; + + shadow_start = kasan_mem_to_shadow((void *)region_start); + shadow_end = kasan_mem_to_shadow((void *)region_end); + + if (shadow_end > shadow_start) { + size = shadow_end - shadow_start; + apply_to_existing_page_range(&init_mm, + (unsigned long)shadow_start, + size, kasan_depopulate_vmalloc_pte, + NULL); + flush_tlb_kernel_range((unsigned long)shadow_start, + (unsigned long)shadow_end); + } +} + +#else /* CONFIG_KASAN_VMALLOC */ + +int kasan_module_alloc(void *addr, size_t size) +{ + void *ret; + size_t scaled_size; + size_t shadow_size; + unsigned long shadow_start; + + shadow_start = (unsigned long)kasan_mem_to_shadow(addr); + scaled_size = (size + KASAN_GRANULE_SIZE - 1) >> + KASAN_SHADOW_SCALE_SHIFT; + shadow_size = round_up(scaled_size, PAGE_SIZE); + + if (WARN_ON(!PAGE_ALIGNED(shadow_start))) + return -EINVAL; + + ret = __vmalloc_node_range(shadow_size, 1, shadow_start, + shadow_start + shadow_size, + GFP_KERNEL, + PAGE_KERNEL, VM_NO_GUARD, NUMA_NO_NODE, + __builtin_return_address(0)); + + if (ret) { + __memset(ret, KASAN_SHADOW_INIT, shadow_size); + find_vm_area(addr)->flags |= VM_KASAN; + kmemleak_ignore(ret); + return 0; + } + + return -ENOMEM; +} + +void kasan_free_shadow(const struct vm_struct *vm) +{ + if (vm->flags & VM_KASAN) + vfree(kasan_mem_to_shadow(vm->addr)); +} + +#endif From patchwork Wed Nov 4 23:18:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883327 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D4CFC00A89 for ; Thu, 5 Nov 2020 05:37:21 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3CE332083B for ; Thu, 5 Nov 2020 05:37:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="suyH9GOL"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="VPoiPwwK"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="pZCGPEAL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3CE332083B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Xd7N6pO4emDUGXn7FukCVxo8oQHDG+GyYEM2S/eUE/g=; b=suyH9GOLWW/HM3v+Bim6IEIae s01jUCEprwQAf8REIdaIx0n7wj6QNNI6PDb2lLVOfP56MgwlB2WHRM3eJZMzxTUJ8HpopMFXFBqTB 1klAnrvl3VZgSFaaS5L0ROG4NYteZ/W+PJsossgHXI6jZ2Cy2CO6s9B3RkLWTp338esmB8pdKubT7 ha0eSB3qTulE/QX05Fl/Xcs2fgfLkeh5aWdykNJ0Wy4AvVofv0Jh4KqTuabBxNfWsNOrOCtzYto45 U7UWd6x1vi8/72+lyHj+a6vDmc79lQ60A17JqMUh0AY6sliznTPjjxlLG00I+1TPCdS9CP1RYaZ5X YepDtI8Ng==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXvv-00026M-JS; Thu, 05 Nov 2020 05:35:39 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5K-00016k-Oa for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=iTj7fpm+BobKW7u0A61d/nWdaAxx5isZjXZgphVDAO4=; b=VPoiPwwKBxIAN9woDoP7LGbhk1 zvZ5XVCGmKe5jxEbZHD7IW+47we6w5jAoYfc+vjGWU95TR7KJ3KnReEwPf1rXQyncPdSP1wJzrZXl 9ERGX4zjfZzFgK8JB/j9vV03/+B2zxcBTm3m5A+Lf5LEKtorO5lhfnn+3HVh0/ztRee2cEGMCJe3Q /Lbdl5BWV2o3bGz9svttnGqQJ8SWx56vzrcewpmhlTMNPsLm9KGr5aEQH5IVpqiBI9KyZDP6TJJg3 f06TX4pRfWPDlKbb8ax+GbK7rdce2RnEwPdY4sAzXsSeboa2u7DTRyaFoPuSakXzJZxdYn0ZIvwOK q4U+T9Lw==; Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS4u-0003y1-PC for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:35 +0000 Received: by mail-wr1-x449.google.com with SMTP id t11so42847wrv.10 for ; Wed, 04 Nov 2020 15:20:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=iTj7fpm+BobKW7u0A61d/nWdaAxx5isZjXZgphVDAO4=; b=pZCGPEALURF9qvNKNiouUsOOaMFvnfTqPZfISRsx9Gv8YL4XC25ZlkabaVxFQnxtda JniU/RWyvW5sz1Cp7PwjI9T4ATwvEotwBSBe4W6vuAI2hN+e0PKQCoiolmQ6lcG+blt+ HOeBTJXFvF+sehpBZNzzT4bJ5tuG/0FQnjUtIaWiT9RNMc3i8ygnHi5qCcmVRpooerIC Fh2Re66piQ7mJxUCFj+4DtlaJsS3ONA4VNbsf4MIiVyIUtquAssf8SnVrNWxuKje5d/S t24UaHpigDQZtk62gUawX5t9nQF9Oj6xOQb8lfUak0DFUCrvcJC/Lf6DRFUt9bn0xucU ftdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=iTj7fpm+BobKW7u0A61d/nWdaAxx5isZjXZgphVDAO4=; b=YWAaKerx3X4NRgnpqpjbF1mIr10grFoRGxgKGuHfzvxlE1UOCNIxsO6Wt3MtqMtzQs Czi/iFA4/bB3SEv382v0qtGGkjuakqZKrpWBRH+TAMfXk0YD7mbkGR6s8tiqzzMdMkgL vFjNJ/NtKaQQvZJcMZHGX4HnMX0qEXng1OHzLRex1m3dTbgM2DF/fSgNbvr54/BuAYbc mBoaPH0nZO1UlGH/taaOcEB15xJjC63gA91syu8lVqro6GKghqkNxqK1Hb7velXjMx6Z 9rUzHwQCBYwzFOoF/oACoAFymjhEXQs4wXVyngmaPtH6LG6jX9rblU/ZiZSZBR2hFApE lT0A== X-Gm-Message-State: AOAM533neLwVt6o7NN7kEIvPj9qnBs2HjpeeD+VxRL8yVwTTw3oYffUi Or0rjM1dQ7EIlghirQZ5RgXss1oF/xUaoA4C X-Google-Smtp-Source: ABdhPJy0s7P+oksyUF6owVkfOw0CWj9t5xPS6BM514kb6jywGyKo9+//R+8Y+xTOOzGtZzfo2eaT9VWMBZG7Ggp3 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:ce0e:: with SMTP id m14mr76917wmc.17.1604531970440; Wed, 04 Nov 2020 15:19:30 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:25 +0100 In-Reply-To: Message-Id: <0f3b5013869f74b2d8e74aba5ec816c117129f9c.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 10/43] kasan: define KASAN_GRANULE_PAGE From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232032_968098_4413BE7D X-CRM114-Status: GOOD ( 13.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Define KASAN_GRANULE_PAGE as (KASAN_GRANULE_SIZE << PAGE_SHIFT), which is the same as (KASAN_GRANULE_SIZE * PAGE_SIZE), and use it across KASAN code to simplify it. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: I0b627b24187d06c8b9bb2f1d04d94b3d06945e73 --- mm/kasan/init.c | 10 ++++------ mm/kasan/kasan.h | 1 + mm/kasan/shadow.c | 16 +++++++--------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/mm/kasan/init.c b/mm/kasan/init.c index 1a71eaa8c5f9..26b2663b3a42 100644 --- a/mm/kasan/init.c +++ b/mm/kasan/init.c @@ -441,9 +441,8 @@ void kasan_remove_zero_shadow(void *start, unsigned long size) addr = (unsigned long)kasan_mem_to_shadow(start); end = addr + (size >> KASAN_SHADOW_SCALE_SHIFT); - if (WARN_ON((unsigned long)start % - (KASAN_GRANULE_SIZE * PAGE_SIZE)) || - WARN_ON(size % (KASAN_GRANULE_SIZE * PAGE_SIZE))) + if (WARN_ON((unsigned long)start % KASAN_GRANULE_PAGE) || + WARN_ON(size % KASAN_GRANULE_PAGE)) return; for (; addr < end; addr = next) { @@ -476,9 +475,8 @@ int kasan_add_zero_shadow(void *start, unsigned long size) shadow_start = kasan_mem_to_shadow(start); shadow_end = shadow_start + (size >> KASAN_SHADOW_SCALE_SHIFT); - if (WARN_ON((unsigned long)start % - (KASAN_GRANULE_SIZE * PAGE_SIZE)) || - WARN_ON(size % (KASAN_GRANULE_SIZE * PAGE_SIZE))) + if (WARN_ON((unsigned long)start % KASAN_GRANULE_PAGE) || + WARN_ON(size % KASAN_GRANULE_PAGE)) return -EINVAL; ret = kasan_populate_early_shadow(shadow_start, shadow_end); diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index c31e2c739301..1865bb92d47a 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -7,6 +7,7 @@ #define KASAN_GRANULE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT) #define KASAN_GRANULE_MASK (KASAN_GRANULE_SIZE - 1) +#define KASAN_GRANULE_PAGE (KASAN_GRANULE_SIZE << PAGE_SHIFT) #define KASAN_TAG_KERNEL 0xFF /* native kernel pointers tag */ #define KASAN_TAG_INVALID 0xFE /* inaccessible memory tag */ diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index ca0cc4c31454..1fadd4930d54 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -161,7 +161,7 @@ static int __meminit kasan_mem_notifier(struct notifier_block *nb, shadow_end = shadow_start + shadow_size; if (WARN_ON(mem_data->nr_pages % KASAN_GRANULE_SIZE) || - WARN_ON(start_kaddr % (KASAN_GRANULE_SIZE << PAGE_SHIFT))) + WARN_ON(start_kaddr % KASAN_GRANULE_PAGE)) return NOTIFY_BAD; switch (action) { @@ -432,22 +432,20 @@ void kasan_release_vmalloc(unsigned long start, unsigned long end, unsigned long region_start, region_end; unsigned long size; - region_start = ALIGN(start, PAGE_SIZE * KASAN_GRANULE_SIZE); - region_end = ALIGN_DOWN(end, PAGE_SIZE * KASAN_GRANULE_SIZE); + region_start = ALIGN(start, KASAN_GRANULE_PAGE); + region_end = ALIGN_DOWN(end, KASAN_GRANULE_PAGE); - free_region_start = ALIGN(free_region_start, - PAGE_SIZE * KASAN_GRANULE_SIZE); + free_region_start = ALIGN(free_region_start, KASAN_GRANULE_PAGE); if (start != region_start && free_region_start < region_start) - region_start -= PAGE_SIZE * KASAN_GRANULE_SIZE; + region_start -= KASAN_GRANULE_PAGE; - free_region_end = ALIGN_DOWN(free_region_end, - PAGE_SIZE * KASAN_GRANULE_SIZE); + free_region_end = ALIGN_DOWN(free_region_end, KASAN_GRANULE_PAGE); if (end != region_end && free_region_end > region_end) - region_end += PAGE_SIZE * KASAN_GRANULE_SIZE; + region_end += KASAN_GRANULE_PAGE; shadow_start = kasan_mem_to_shadow((void *)region_start); shadow_end = kasan_mem_to_shadow((void *)region_end); From patchwork Wed Nov 4 23:18:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883175 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CAE0C00A89 for ; Thu, 5 Nov 2020 04:35:04 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DE5232083B for ; Thu, 5 Nov 2020 04:35:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="L9oUtqtk"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="p/X3TzAx"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="HMlGt5Zq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DE5232083B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Es8dyR8jp7VG4y2PijpILm6qt0acs66x26qUyqcFcvM=; b=L9oUtqtksSL4DGkVETOeyKhWU 5SqQsyqxJVxleOmfKEvm8BSdudjpUsKFLHZ0q6QTUpitaSb6VxKLuquggbEBo0fUsjsoM1XVRAiy3 SBWw9xn1BKtlLwo73+/110zqqlZpHnWt5Yg5iPkHkdYx6ZEMXVhihMQZRxp6wItT9cbZz53PK48Mq 0/BowR7LCmblgOzcM8a/hVooHvI+XwMmbizj1m/X+tp2xKbeMfRFCvNQlRnEBu+3StPuzd1sXz82A drdUniDvXqWpv8Ip2l9xiT92yK+g3F7HcZIFkQQdHpviEzAa0LGjgLokTqjB2CJsLNE12A8M/J8Y+ yAzkheiNA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWyd-0003AP-QU; Thu, 05 Nov 2020 04:34:23 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5J-00016k-RD for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=m4Rd6JEchDCdHagjRChT+nQsGKSwHG57Cfn+FHFZG50=; b=p/X3TzAxxHddbRVeQ8Fr1y81yn KgoDDQC7PouNKgLkQduA4FL5LOsrp6siY55R/t833eBanUSM5rSt3WSc8pqynVglC+GPD4qn9Ll5A 0JYFm2gEBVqv8M6CAVvEK642Ku3MJRE8ai/3EscIG8XeBRsGfUVvpvS99Zss3QA4INhh4JeNCOpuG SWdfPYaRceDi4iizjRLg5vtr6Jl9RcqEVjpccPqCVfUzKwqY/ecNjZZJ1fpfCR9LyZ8BaGyqBd6N8 YXGWYJIAnoM7r1DOLFZlJ3HajfTgLhExpvd8T13p7CFuDrX69wXjwrAatkmlyVYxsyyO1dMN0KMzL M4iXQsQw==; Received: from mail-qv1-xf49.google.com ([2607:f8b0:4864:20::f49]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS4y-0003yj-Ne for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:39 +0000 Received: by mail-qv1-xf49.google.com with SMTP id a1so6734qvj.3 for ; Wed, 04 Nov 2020 15:20:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=m4Rd6JEchDCdHagjRChT+nQsGKSwHG57Cfn+FHFZG50=; b=HMlGt5ZqnSiNBvIh5bwZVolMGMfVTi7ELGS8vTm7KSH2BIfWEHL3AEmTfbJjq48SsM akUQuVQpcOZLReg3iUKqkoC0QuY5/TkpoKmv7/fmGPvSNRWVWVMLm2q3RzUU7RJxgrVS D/Y/6L/nMZUkKBLVPRO3WRQM2HtiVTZawvInIKx/RNMdgixQMbQqv1yz2uOpiQB9qzqK DuL8B2eHCUbwPLRSJzlGS/4wQq+MlnFabB75xkwConsdwKmm9kA2yG2Fu3+B1O+vAs9i UBMeGmcfY40E2KaecbfD0JciuHtChHkqSnB9XThlcyo8J7wZP65XrLS5f1qbEKcNp922 7kPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=m4Rd6JEchDCdHagjRChT+nQsGKSwHG57Cfn+FHFZG50=; b=VA2PJGVsHXEmhzj8bO4iyFd6dpXrucV3ePHlm8IufSTs3wgdWg/020Aq7GznK5/A93 X8HYGIx1ThubB3l2NbS2o9Y5FJJr2GSd5XnxxEL4xFhlksvHE6ntIKsiibgaV+3Zk20b WBVQptO2AFbbakolohU6TBYqnuO33sSnsQEW2RxEvNKEjDcLE2bxp+l3hdZAmEKzqXha oOosOj3KjNj0k0brjVQRgbuurKAyCj6cWQKoqqi3Cv4RuFR9CuwFWquekVcRXj622kFF gqLgbx33iBUOjE7Rh0SutW5YrHRjJ6CPgQ8cUs+ihsAxxCyn1kAYB4Sv5q5cIk7La64w pWmg== X-Gm-Message-State: AOAM5308Zql0UI9zAM/W6A6+LYxR847lYHkHod1UZp1wQ1N61moeo6BO 8cpKuB2OiEcXdO9z2utcysAX1d+jZ2nUxuyy X-Google-Smtp-Source: ABdhPJyd5HqqqtZolYywu7sBTqxmYBCrDpWY9xQKZ5Br/36r9jAXsxLGx1pZMYa/+oPNpftRrbVrOW1uae6XIFZ7 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:fd4c:: with SMTP id j12mr428967qvs.22.1604531972889; Wed, 04 Nov 2020 15:19:32 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:26 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 11/43] kasan: rename report and tags files From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232036_905019_5F6523D9 X-CRM114-Status: GOOD ( 10.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Rename generic_report.c to report_generic.c and tags_report.c to report_sw_tags.c, as their content is more relevant to report.c file. Also rename tags.c to sw_tags.c to better reflect that this file contains code for software tag-based mode. No functional changes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: If77d21f655d52ef3e58c4c37fd6621a07f505f18 --- mm/kasan/Makefile | 16 ++++++++-------- mm/kasan/report.c | 2 +- mm/kasan/{generic_report.c => report_generic.c} | 0 mm/kasan/{tags_report.c => report_sw_tags.c} | 0 mm/kasan/{tags.c => sw_tags.c} | 0 5 files changed, 9 insertions(+), 9 deletions(-) rename mm/kasan/{generic_report.c => report_generic.c} (100%) rename mm/kasan/{tags_report.c => report_sw_tags.c} (100%) rename mm/kasan/{tags.c => sw_tags.c} (100%) diff --git a/mm/kasan/Makefile b/mm/kasan/Makefile index 7cc1031e1ef8..f1d68a34f3c9 100644 --- a/mm/kasan/Makefile +++ b/mm/kasan/Makefile @@ -6,13 +6,13 @@ KCOV_INSTRUMENT := n # Disable ftrace to avoid recursion. CFLAGS_REMOVE_common.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_generic.o = $(CC_FLAGS_FTRACE) -CFLAGS_REMOVE_generic_report.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_init.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_quarantine.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_report_generic.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_report_sw_tags.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_shadow.o = $(CC_FLAGS_FTRACE) -CFLAGS_REMOVE_tags.o = $(CC_FLAGS_FTRACE) -CFLAGS_REMOVE_tags_report.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_sw_tags.o = $(CC_FLAGS_FTRACE) # Function splitter causes unnecessary splits in __asan_load1/__asan_store1 # see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63533 @@ -23,14 +23,14 @@ CC_FLAGS_KASAN_RUNTIME += -DDISABLE_BRANCH_PROFILING CFLAGS_common.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_generic.o := $(CC_FLAGS_KASAN_RUNTIME) -CFLAGS_generic_report.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_init.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_quarantine.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_report.o := $(CC_FLAGS_KASAN_RUNTIME) +CFLAGS_report_generic.o := $(CC_FLAGS_KASAN_RUNTIME) +CFLAGS_report_sw_tags.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_shadow.o := $(CC_FLAGS_KASAN_RUNTIME) -CFLAGS_tags.o := $(CC_FLAGS_KASAN_RUNTIME) -CFLAGS_tags_report.o := $(CC_FLAGS_KASAN_RUNTIME) +CFLAGS_sw_tags.o := $(CC_FLAGS_KASAN_RUNTIME) obj-$(CONFIG_KASAN) := common.o report.o -obj-$(CONFIG_KASAN_GENERIC) += init.o generic.o generic_report.o shadow.o quarantine.o -obj-$(CONFIG_KASAN_SW_TAGS) += init.o shadow.o tags.o tags_report.o +obj-$(CONFIG_KASAN_GENERIC) += init.o generic.o report_generic.o shadow.o quarantine.o +obj-$(CONFIG_KASAN_SW_TAGS) += init.o report_sw_tags.o shadow.o sw_tags.o diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 7b8dcb799a78..fff0c7befbfe 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * This file contains common generic and tag-based KASAN error reporting code. + * This file contains common KASAN error reporting code. * * Copyright (c) 2014 Samsung Electronics Co., Ltd. * Author: Andrey Ryabinin diff --git a/mm/kasan/generic_report.c b/mm/kasan/report_generic.c similarity index 100% rename from mm/kasan/generic_report.c rename to mm/kasan/report_generic.c diff --git a/mm/kasan/tags_report.c b/mm/kasan/report_sw_tags.c similarity index 100% rename from mm/kasan/tags_report.c rename to mm/kasan/report_sw_tags.c diff --git a/mm/kasan/tags.c b/mm/kasan/sw_tags.c similarity index 100% rename from mm/kasan/tags.c rename to mm/kasan/sw_tags.c From patchwork Wed Nov 4 23:18:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883147 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EF48C00A89 for ; Thu, 5 Nov 2020 04:32:43 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DC36C20729 for ; Thu, 5 Nov 2020 04:32:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="XPvxpd/K"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="XoDa505D"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="VzWDrHAu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DC36C20729 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=sp95Sh4d5ndaxLqxAy26eu1maVs5qF15Egz17jP5hy0=; b=XPvxpd/KT8c/3TW5jLqbQxhJ/ IOHlJn79/alVSWPC4C+XCGaQ/NH1IJxV86GCEZzbVba5N1xLHH+r1kFOGMMbvk6w3hNeKn9G3jXG1 Ju0zxgXNlRyVcmbm8TATFM6M0ubwYGvyyespFflP87HvlgH0yJCPb4xZpBtnrYZmLHPk7Z/9qDylI zsyoBa6wtK/ojJ0Ztx95YNC9nX6VGv/FXfG4dxBcfKfHFc3/+EeffOgPu7+tH6ScsFaSLT6oix8P4 8OK4koxkPObvO7kAIxokheQpyI+fmABz+5K0bgyJ7nwmZ+Chi8dh7ukQGDtUKC/7qaU+Uw2uBm0Ub j6b5i/btg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWwO-0002EC-Pk; Thu, 05 Nov 2020 04:32:04 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5I-00016k-VX for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=n8TE6VLWWv4zp+ZnErvJoE/L5oOe+Pde/aeeJYIsZf4=; b=XoDa505DHh2cPXJG7h63EC+7SW 3eOZ+qe4FRpLmeTzc9FKlRdEDjbJVCKfcf01HoOJjO2a0fqCHaJ40PS0yEU9pfcaWOhHxXRv0/Ep+ WFGdMRtKxofBPf7M1Li1G5h5d7QrtKQQREOmFMYXW8gNk+OJ0mGcFisQkv3Vy/xUyC7UhTF3qetsd +WM1bZrWSOzLqP2KTn7ghMsIUjfpiD5cmp/1Oy/Pt/COlRg94ymYJYPQITB4ZjuI7NBSpuwbBLbXR pu6fdVVKcr4r87NM8p1D00ZEZCIAYbbpMRCJrr2RmDc7Kw1v8ELd626o5yB+iLZ3KXslclMn09N5Y z7NGwsrg==; Received: from mail-qv1-xf4a.google.com ([2607:f8b0:4864:20::f4a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS51-0003z5-J4 for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:43 +0000 Received: by mail-qv1-xf4a.google.com with SMTP id d14so4851601qvz.16 for ; Wed, 04 Nov 2020 15:20:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=n8TE6VLWWv4zp+ZnErvJoE/L5oOe+Pde/aeeJYIsZf4=; b=VzWDrHAu8PcZDpVqfwqHHsr0grdBxINSFib8aaW6NKowRtNq8XtPgqCJ3wZRd6Kh5o DO4OeACbYe+qGI0qx5hBcDkHyonu+e76XoqWrb8O1DUIpLvq6DzQk+9FEtE/I5w1h7n0 AsTtUAhNQphVlieXp5Wh/bJwER/NjeGHzsNslo8Mq/+ges76CcYlXreJH+5tA+6+vTx5 POSR5YoJa7lHs/OOUZJ2Zx26KoBySgb3Vlj3A4NnblyOFWWyasJY1yEyj2onrUBjXPp/ 5DpxEuXn81Le0VqDzzzVenVdsr7gBjcrSG0mV7F/85Og6C+fBSxjdR7vN1KenILx4GCQ hZBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=n8TE6VLWWv4zp+ZnErvJoE/L5oOe+Pde/aeeJYIsZf4=; b=UrD2Wk/DWv2xNgBfOfGREf5gAwq8yv/tsXuq3BWZlIN3kfBM56HobS1r6zA01Condw MF0i+LrrNgz49b3z/pgDtZGRm1pdqTwqc5lVWQw9cPT0+qE28zQTa0tzxbV70mRH8fuz YIi/WnzTx1i6vf/q5DP9nNtc624UAMHPXOA43arCFFZooBHhtvUIXKp242+QeMU+0p1T DZvcrs0G50xeJNW/4hDwteMl4IdJt3601qqjLLy/vC810dmvZQmxTsSO6wpyLi3SxdJ8 I7mjTJh8ebzFXDeL8GAIA9ZH07KT78XQMAVYzSPiI0EJf9q4bXrSDnFIE9qCoZkLlNCs NieA== X-Gm-Message-State: AOAM530QxLXCObduQ9NOpKmNMQTFcEY6tD/3qSpwihXiUmzEczaBeke+ b2PaK68Xr7HA7MRC76lCgZqzmQXa5I++EAJx X-Google-Smtp-Source: ABdhPJyWE83nSB/5cwbEd4BXNUcn6UEVGVrwqQr7OlMpHVeaEJXPYKrKILj5zgwt3f29RpGPROwrke/5Ez6Y2GlM X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6214:1586:: with SMTP id m6mr249436qvw.15.1604531975177; Wed, 04 Nov 2020 15:19:35 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:27 +0100 In-Reply-To: Message-Id: <6320e83ab93e0ae574426e5ad36ee3e52dcadf35.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 12/43] kasan: don't duplicate config dependencies From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232039_808968_05565A82 X-CRM114-Status: GOOD ( 10.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Both KASAN_GENERIC and KASAN_SW_TAGS have common dependencies, move those to KASAN. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: I77e475802e8f1750b9154fe4a6e6da4456054fcd --- lib/Kconfig.kasan | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan index 8f0742a0f23e..ec59a0e26d09 100644 --- a/lib/Kconfig.kasan +++ b/lib/Kconfig.kasan @@ -24,6 +24,8 @@ menuconfig KASAN (HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS) depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB) depends on CC_HAS_WORKING_NOSANITIZE_ADDRESS + select CONSTRUCTORS + select STACKDEPOT help Enables KASAN (KernelAddressSANitizer) - runtime memory debugger, designed to find out-of-bounds accesses and use-after-free bugs. @@ -46,10 +48,7 @@ choice config KASAN_GENERIC bool "Generic mode" depends on HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC - depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB) select SLUB_DEBUG if SLUB - select CONSTRUCTORS - select STACKDEPOT help Enables generic KASAN mode. @@ -70,10 +69,7 @@ config KASAN_GENERIC config KASAN_SW_TAGS bool "Software tag-based mode" depends on HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS - depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB) select SLUB_DEBUG if SLUB - select CONSTRUCTORS - select STACKDEPOT help Enables software tag-based KASAN mode. From patchwork Wed Nov 4 23:18:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883177 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15BFBC00A89 for ; Thu, 5 Nov 2020 04:34:50 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 61AC020729 for ; Thu, 5 Nov 2020 04:34:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="TJtqiNmi"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="BT7VSTZw"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="kkZxgHLi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 61AC020729 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=VrmScR5Hb8kuyTBqeGOk3wSQLWQLGcbKijnqeevnLEE=; b=TJtqiNmiHoIA0b6sGJR1HCsld 82hR89U/TWTFOqhAZpAtNyyh+MKXG6wjKJroz99S7h6L57rauOayyOeJ56FwB/XAOioCCmNpSWzke DER4V76wfTfc/m0J++FemK8THkcnEFakdER/p62uajOh60Ecpq3e8SmUrb6qfeU58k+1xQeYKPGL7 6Uj8senn2H2FXoNdNuwk/b5S95ZUFLlBsQdPrjP78IiNUb/Lm/GyCeagEzDqOTOgFwPgwY8opj3Vs w9hjpDirArp1AUpKWCoQFSDIRIw/QkU4fu+21CK8P1uw8lZZ6tKoNoc65EdTrnPA1ipnvi0KdYg0R kBc7NnMrA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWyR-00036i-S0; Thu, 05 Nov 2020 04:34:11 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5J-000145-26 for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=KbFeAZ0fCuPi+p3+zRj17HQjRaGn7T9HM7M+MvodvIE=; b=BT7VSTZwduHxhVF3a6Xiefgsc4 H1aSog/GGDUoch32wThgeYLRwuFKwMGjwuUhRE1DboRQ+XwVfb5v8U6lAh/EPPBlqDvyXmk8M35tx MnXzQc+7MIbhYgR73CviQizcTtsj6pfJGDkb0lTVecz6AjgeWpjkwnpmrUn5u8cQ/HNBrPT/+v1qO C7qXh/O+djOtjayLZs90ojWNiUjO2ERO8lTgR8Cq+zWOKUd8Wyqy5rogtMjQdev+I2f03wZK1dnMm KFxJHJ9QZvFxBUMnmMQ5Aw7woykwWm5m8HfimQ7LslsJUVZDnylkNtOlvWF1Ivwhx10zKthRa9DWJ NYCJBrUA==; Received: from mail-ed1-x549.google.com ([2a00:1450:4864:20::549]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS51-0003z4-HC for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:42 +0000 Received: by mail-ed1-x549.google.com with SMTP id a73so16035edf.16 for ; Wed, 04 Nov 2020 15:20:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=KbFeAZ0fCuPi+p3+zRj17HQjRaGn7T9HM7M+MvodvIE=; b=kkZxgHLi8E6+8WINef706wMtuOi52H0wp4uRiV0SrMVYLwWxjhBDSmwWATsCm8SBV4 ihJeRsvpAzMgJ+rVrlev+QbTaEtnVtJH1tJ0UzEQ7LWzDfnQCYTgshJNrYK8TMe8EXxv f91IhDc4KbTIhhkPjqYS9WMjDPEYmcGylg5VBa2NJ21Wqip+nyR8fLCm8+AqWvAC7q1S HBXwOF1yiXvyDOfs1GWuZhhLHwGnTn+M5yOoeDPlq12TFZc8n+k6IoMKoOVKI8vLDEXT udZXVN90mVjv0OD08oKlWjyVxslINVc3wRjaRt8//bRXufK3xVKm1ukaZ5bi2a1uR17F exVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=KbFeAZ0fCuPi+p3+zRj17HQjRaGn7T9HM7M+MvodvIE=; b=s6UReo2B7gY3mLT8WRr+y6Tj7rnSbECgNPpQYxWpjSNOUWhm9nii55VYFUQzpgpavM MTS+D7LIxQJAQVdZ9N7aN3L6c2lJicIqaeU/O8K91+dMgowzKtLWaxEQdi+QrXjcpdfE 7KzE9CZGZ5Zbf/HZ3RD0EG1rLUj5uFOO/szqSOd2GX2rS29MovlMfsB3qJ6fSmvZJzX2 gwT7l3a8w7nDQeEGvBy+Nm4CVLpwc7fXKJx9v1Mq9XzJft8n5teocrh8UWmjYt4dc28A mDDaJHGsImOX7sSubiIawh5bLln8jQ6LR4l+AR6zk9lL97ADla/nFxG9RrI0vW+eHxaG LT9g== X-Gm-Message-State: AOAM533DHN0FsmkHlZwoftrXMAdwsH45dg7XfWzDtRLK2ks1TnHv4NfD z3CFuSUTDS7/vovxA8UEuv6zCxfisZM0EdFy X-Google-Smtp-Source: ABdhPJyeynchU+B2StC/j5HyMg/W0mhgdCL2wRr0XlfTUsWP11EHOKULobOTxCDxoCElKltT9ByCyurYRGiQny+b X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6402:759:: with SMTP id p25mr215552edy.22.1604531977800; Wed, 04 Nov 2020 15:19:37 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:28 +0100 In-Reply-To: Message-Id: <7366c8102820448b082445924a7a014976e1f252.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 13/43] kasan: hide invalid free check implementation From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232039_779474_8CB3B7F5 X-CRM114-Status: GOOD ( 14.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. For software KASAN modes the check is based on the value in the shadow memory. Hardware tag-based KASAN won't be using shadow, so hide the implementation of the check in check_invalid_free(). Also simplify the code for software tag-based mode. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: I5fae9531c9fc948eb4d4e0c589744032fc5a0789 --- mm/kasan/common.c | 19 +------------------ mm/kasan/generic.c | 7 +++++++ mm/kasan/kasan.h | 2 ++ mm/kasan/sw_tags.c | 9 +++++++++ 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 123abfb760d4..543e6bf2168f 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -272,25 +272,9 @@ void * __must_check kasan_init_slab_obj(struct kmem_cache *cache, return (void *)object; } -static inline bool shadow_invalid(u8 tag, s8 shadow_byte) -{ - if (IS_ENABLED(CONFIG_KASAN_GENERIC)) - return shadow_byte < 0 || - shadow_byte >= KASAN_GRANULE_SIZE; - - /* else CONFIG_KASAN_SW_TAGS: */ - if ((u8)shadow_byte == KASAN_TAG_INVALID) - return true; - if ((tag != KASAN_TAG_KERNEL) && (tag != (u8)shadow_byte)) - return true; - - return false; -} - static bool __kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip, bool quarantine) { - s8 shadow_byte; u8 tag; void *tagged_object; unsigned long rounded_up_size; @@ -309,8 +293,7 @@ static bool __kasan_slab_free(struct kmem_cache *cache, void *object, if (unlikely(cache->flags & SLAB_TYPESAFE_BY_RCU)) return false; - shadow_byte = READ_ONCE(*(s8 *)kasan_mem_to_shadow(object)); - if (shadow_invalid(tag, shadow_byte)) { + if (check_invalid_free(tagged_object)) { kasan_report_invalid_free(tagged_object, ip); return true; } diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index ec4417156943..e1af3b6c53b8 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -187,6 +187,13 @@ bool check_memory_region(unsigned long addr, size_t size, bool write, return check_memory_region_inline(addr, size, write, ret_ip); } +bool check_invalid_free(void *addr) +{ + s8 shadow_byte = READ_ONCE(*(s8 *)kasan_mem_to_shadow(addr)); + + return shadow_byte < 0 || shadow_byte >= KASAN_GRANULE_SIZE; +} + void kasan_cache_shrink(struct kmem_cache *cache) { quarantine_remove_cache(cache); diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 1865bb92d47a..3eff57e71ff5 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -164,6 +164,8 @@ void kasan_poison_memory(const void *address, size_t size, u8 value); bool check_memory_region(unsigned long addr, size_t size, bool write, unsigned long ret_ip); +bool check_invalid_free(void *addr); + void *find_first_bad_addr(void *addr, size_t size); const char *get_bug_type(struct kasan_access_info *info); diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c index 4bdd7dbd6647..b2638c2cd58a 100644 --- a/mm/kasan/sw_tags.c +++ b/mm/kasan/sw_tags.c @@ -121,6 +121,15 @@ bool check_memory_region(unsigned long addr, size_t size, bool write, return true; } +bool check_invalid_free(void *addr) +{ + u8 tag = get_tag(addr); + u8 shadow_byte = READ_ONCE(*(u8 *)kasan_mem_to_shadow(reset_tag(addr))); + + return (shadow_byte == KASAN_TAG_INVALID) || + (tag != KASAN_TAG_KERNEL && tag != shadow_byte); +} + #define DEFINE_HWASAN_LOAD_STORE(size) \ void __hwasan_load##size##_noabort(unsigned long addr) \ { \ From patchwork Wed Nov 4 23:18:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883257 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A64CC00A89 for ; Thu, 5 Nov 2020 05:07:08 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 999F92151B for ; Thu, 5 Nov 2020 05:07:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ezsTid7W"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="v6gXw354"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="FPOiVHLr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 999F92151B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vXfEpfExQIfXjq1fr7vON/eqCJFLjiam3kPSEqYLpEw=; b=ezsTid7WWWgEiWV85YpELfCRm N11gnP/AH3rO7AS6Zvy25lqhkfbcL0MmqLxxVyhFbW4PjqVIn4ChHU5yvdSrcP2Ntqxu3gwkYuY/+ 4HrepuPRWMdhdeU6n91s9HYLsLEtZbJlDJ8MuJEUfIb4zue/U+JBdVorr/BXkxZCAgCBvzJdh8SB3 FxlXGX1TPTHDtwx3Dqdlq1Kk0rHNwwk9SQZi0M0eAhACAKe6LcteELD+El4BD1tl4ktd5zZXzAtWQ Xwxi5opA+KqqWY2WuNojTxUSnSL4IBcxH0RVpE5mphBB3i6VyUOOVsV05TH2W371dCmz7SEdQnFRL h7fSH35Xw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXS5-0004fu-PY; Thu, 05 Nov 2020 05:04:49 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5H-00016k-SE for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=QvkWNjZ+pTIeP6RaRR5npkr/lxVIyBDfgnO8C41H6j4=; b=v6gXw354Gfgm8h63Wehyec55Gy KsPvOgS8DXMbrnrLTUHqwtlMFnHHOELzLqMj0lflowM2+pql//6+V2exGh7+wUJ8T9H8fL72MUYE6 /VpABS/wRTvfqOzhBYHOSXROGI7raLl03snrVteJxMPrTm7TqnO67go0ezI4Bt1Q3tbyMV4A7X5uw dtDKw1Q1woPdcFTCbPT9Kew7einoqREmaGBiWaex2Yr3lD51w+F6/+CmmS00ZN5I6iwJQAc5YQV8j BesZ+3co+SlfDtXNKELntpdZv9SCyG0wb8RDW+GU+kpW2EIsP07CPt7Llc1VDnMynZp+s1aewbHiO OREbN2eA==; Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS57-00040C-AC for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:48 +0000 Received: by mail-qt1-x849.google.com with SMTP id 22so65670qtp.9 for ; Wed, 04 Nov 2020 15:20:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=QvkWNjZ+pTIeP6RaRR5npkr/lxVIyBDfgnO8C41H6j4=; b=FPOiVHLrNyZzAS8cCsLhPQUBneD6Rzq+2mOsf2aIPZ+DtgevtfpcKnWCJtQUf4Y6Y4 UqFQYnwcJffAeqh0ajIyYoC7JzjSlNJtdlxctAhCYuGE380tosfO/yFbVgCmnxozKg65 buUyFJEgMkYdJodOwLc7GuYHBaJSrpgtVmm0cx8n3rgrjzjvi1yL9pCtwnSGVggUE20B 5zua/HVNa/7XDJeZzs2MTeFXOETXHHeScPleChiFXAXOJTTKtbj48F5TfdmjSr5P1LSd B24d95EiZLXy6ytNek4Iblrjy2f4KaZx3jsoN/sRUVXJmurJNFhuNl6HmH6pxH6gXtee Eepw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=QvkWNjZ+pTIeP6RaRR5npkr/lxVIyBDfgnO8C41H6j4=; b=KeLzhcj7NW2C6SoqaL8vqROTCG3YUFZo6b37FHXbCaJXbJUYMcXRbDyoEyu5XeST+9 HuoFR9l62zpZWstgwmM5cDCkjuMY7hYoS6CIxAq6+LbMh8YYc5RSNlnJLNCQpJFLq73I Jy9Nf6lmX+DXlGpewPfz6UuuRQh+T1rTEsebFPy0ULr78+LfbVUIktRTr7/prrlIiUgD P+3mIq6MP/kZ1BLEkDSxY1sZkLT4HI1D4VKkdIhETZYhN07qwcto+WUxVveIfEKHx105 Li0m+QGjQ7zmSQY3Rh28oXyt4diwGajHjISl8pBoWG02o0ra0A2T9yTEt6exa7rlOTI4 xgDg== X-Gm-Message-State: AOAM532tYsdMpsZEWQyBxMgfWjiY25cNqJLRhFf52CMKhhKeQaqCx9XX Hpj0YCSKnu8+du053bk9GO91LDZXYacFZ4U4 X-Google-Smtp-Source: ABdhPJwy9BzOIUe47zQmeDLcn8sLC1vb8Xr7prxUDzWCvbtJhql+T9lgjZonYAJb8PzRElwFFpEjtJaPeCS9zOa/ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:4f22:: with SMTP id fc2mr186570qvb.28.1604531980350; Wed, 04 Nov 2020 15:19:40 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:29 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 14/43] kasan: decode stack frame only with KASAN_STACK_ENABLE From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232045_676411_AD55E478 X-CRM114-Status: GOOD ( 21.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Decoding routines aren't needed when CONFIG_KASAN_STACK_ENABLE is not enabled. Currently only generic KASAN mode implements stack error reporting. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: I084e3214f2b40dc0bef7c5a9fafdc6f5c42b06a2 --- mm/kasan/kasan.h | 6 ++ mm/kasan/report.c | 162 -------------------------------------- mm/kasan/report_generic.c | 162 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+), 162 deletions(-) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 3eff57e71ff5..d0cf61d4d70d 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -169,6 +169,12 @@ bool check_invalid_free(void *addr); void *find_first_bad_addr(void *addr, size_t size); const char *get_bug_type(struct kasan_access_info *info); +#if defined(CONFIG_KASAN_GENERIC) && CONFIG_KASAN_STACK +void print_address_stack_frame(const void *addr); +#else +static inline void print_address_stack_frame(const void *addr) { } +#endif + bool kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip); void kasan_report_invalid_free(void *object, unsigned long ip); diff --git a/mm/kasan/report.c b/mm/kasan/report.c index fff0c7befbfe..b18d193f7f58 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -211,168 +211,6 @@ static inline bool init_task_stack_addr(const void *addr) sizeof(init_thread_union.stack)); } -static bool __must_check tokenize_frame_descr(const char **frame_descr, - char *token, size_t max_tok_len, - unsigned long *value) -{ - const char *sep = strchr(*frame_descr, ' '); - - if (sep == NULL) - sep = *frame_descr + strlen(*frame_descr); - - if (token != NULL) { - const size_t tok_len = sep - *frame_descr; - - if (tok_len + 1 > max_tok_len) { - pr_err("KASAN internal error: frame description too long: %s\n", - *frame_descr); - return false; - } - - /* Copy token (+ 1 byte for '\0'). */ - strlcpy(token, *frame_descr, tok_len + 1); - } - - /* Advance frame_descr past separator. */ - *frame_descr = sep + 1; - - if (value != NULL && kstrtoul(token, 10, value)) { - pr_err("KASAN internal error: not a valid number: %s\n", token); - return false; - } - - return true; -} - -static void print_decoded_frame_descr(const char *frame_descr) -{ - /* - * We need to parse the following string: - * "n alloc_1 alloc_2 ... alloc_n" - * where alloc_i looks like - * "offset size len name" - * or "offset size len name:line". - */ - - char token[64]; - unsigned long num_objects; - - if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), - &num_objects)) - return; - - pr_err("\n"); - pr_err("this frame has %lu %s:\n", num_objects, - num_objects == 1 ? "object" : "objects"); - - while (num_objects--) { - unsigned long offset; - unsigned long size; - - /* access offset */ - if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), - &offset)) - return; - /* access size */ - if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), - &size)) - return; - /* name length (unused) */ - if (!tokenize_frame_descr(&frame_descr, NULL, 0, NULL)) - return; - /* object name */ - if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), - NULL)) - return; - - /* Strip line number; without filename it's not very helpful. */ - strreplace(token, ':', '\0'); - - /* Finally, print object information. */ - pr_err(" [%lu, %lu) '%s'", offset, offset + size, token); - } -} - -static bool __must_check get_address_stack_frame_info(const void *addr, - unsigned long *offset, - const char **frame_descr, - const void **frame_pc) -{ - unsigned long aligned_addr; - unsigned long mem_ptr; - const u8 *shadow_bottom; - const u8 *shadow_ptr; - const unsigned long *frame; - - BUILD_BUG_ON(IS_ENABLED(CONFIG_STACK_GROWSUP)); - - /* - * NOTE: We currently only support printing frame information for - * accesses to the task's own stack. - */ - if (!object_is_on_stack(addr)) - return false; - - aligned_addr = round_down((unsigned long)addr, sizeof(long)); - mem_ptr = round_down(aligned_addr, KASAN_GRANULE_SIZE); - shadow_ptr = kasan_mem_to_shadow((void *)aligned_addr); - shadow_bottom = kasan_mem_to_shadow(end_of_stack(current)); - - while (shadow_ptr >= shadow_bottom && *shadow_ptr != KASAN_STACK_LEFT) { - shadow_ptr--; - mem_ptr -= KASAN_GRANULE_SIZE; - } - - while (shadow_ptr >= shadow_bottom && *shadow_ptr == KASAN_STACK_LEFT) { - shadow_ptr--; - mem_ptr -= KASAN_GRANULE_SIZE; - } - - if (shadow_ptr < shadow_bottom) - return false; - - frame = (const unsigned long *)(mem_ptr + KASAN_GRANULE_SIZE); - if (frame[0] != KASAN_CURRENT_STACK_FRAME_MAGIC) { - pr_err("KASAN internal error: frame info validation failed; invalid marker: %lu\n", - frame[0]); - return false; - } - - *offset = (unsigned long)addr - (unsigned long)frame; - *frame_descr = (const char *)frame[1]; - *frame_pc = (void *)frame[2]; - - return true; -} - -static void print_address_stack_frame(const void *addr) -{ - unsigned long offset; - const char *frame_descr; - const void *frame_pc; - - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) - return; - - if (!get_address_stack_frame_info(addr, &offset, &frame_descr, - &frame_pc)) - return; - - /* - * get_address_stack_frame_info only returns true if the given addr is - * on the current task's stack. - */ - pr_err("\n"); - pr_err("addr %px is located in stack of task %s/%d at offset %lu in frame:\n", - addr, current->comm, task_pid_nr(current), offset); - pr_err(" %pS\n", frame_pc); - - if (!frame_descr) - return; - - print_decoded_frame_descr(frame_descr); -} - static void print_address_description(void *addr, u8 tag) { struct page *page = kasan_addr_to_page(addr); diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c index 7d5b9e5c7cfe..b543a1ed6078 100644 --- a/mm/kasan/report_generic.c +++ b/mm/kasan/report_generic.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -122,6 +123,167 @@ const char *get_bug_type(struct kasan_access_info *info) return get_wild_bug_type(info); } +#if CONFIG_KASAN_STACK +static bool __must_check tokenize_frame_descr(const char **frame_descr, + char *token, size_t max_tok_len, + unsigned long *value) +{ + const char *sep = strchr(*frame_descr, ' '); + + if (sep == NULL) + sep = *frame_descr + strlen(*frame_descr); + + if (token != NULL) { + const size_t tok_len = sep - *frame_descr; + + if (tok_len + 1 > max_tok_len) { + pr_err("KASAN internal error: frame description too long: %s\n", + *frame_descr); + return false; + } + + /* Copy token (+ 1 byte for '\0'). */ + strlcpy(token, *frame_descr, tok_len + 1); + } + + /* Advance frame_descr past separator. */ + *frame_descr = sep + 1; + + if (value != NULL && kstrtoul(token, 10, value)) { + pr_err("KASAN internal error: not a valid number: %s\n", token); + return false; + } + + return true; +} + +static void print_decoded_frame_descr(const char *frame_descr) +{ + /* + * We need to parse the following string: + * "n alloc_1 alloc_2 ... alloc_n" + * where alloc_i looks like + * "offset size len name" + * or "offset size len name:line". + */ + + char token[64]; + unsigned long num_objects; + + if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), + &num_objects)) + return; + + pr_err("\n"); + pr_err("this frame has %lu %s:\n", num_objects, + num_objects == 1 ? "object" : "objects"); + + while (num_objects--) { + unsigned long offset; + unsigned long size; + + /* access offset */ + if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), + &offset)) + return; + /* access size */ + if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), + &size)) + return; + /* name length (unused) */ + if (!tokenize_frame_descr(&frame_descr, NULL, 0, NULL)) + return; + /* object name */ + if (!tokenize_frame_descr(&frame_descr, token, sizeof(token), + NULL)) + return; + + /* Strip line number; without filename it's not very helpful. */ + strreplace(token, ':', '\0'); + + /* Finally, print object information. */ + pr_err(" [%lu, %lu) '%s'", offset, offset + size, token); + } +} + +static bool __must_check get_address_stack_frame_info(const void *addr, + unsigned long *offset, + const char **frame_descr, + const void **frame_pc) +{ + unsigned long aligned_addr; + unsigned long mem_ptr; + const u8 *shadow_bottom; + const u8 *shadow_ptr; + const unsigned long *frame; + + BUILD_BUG_ON(IS_ENABLED(CONFIG_STACK_GROWSUP)); + + /* + * NOTE: We currently only support printing frame information for + * accesses to the task's own stack. + */ + if (!object_is_on_stack(addr)) + return false; + + aligned_addr = round_down((unsigned long)addr, sizeof(long)); + mem_ptr = round_down(aligned_addr, KASAN_GRANULE_SIZE); + shadow_ptr = kasan_mem_to_shadow((void *)aligned_addr); + shadow_bottom = kasan_mem_to_shadow(end_of_stack(current)); + + while (shadow_ptr >= shadow_bottom && *shadow_ptr != KASAN_STACK_LEFT) { + shadow_ptr--; + mem_ptr -= KASAN_GRANULE_SIZE; + } + + while (shadow_ptr >= shadow_bottom && *shadow_ptr == KASAN_STACK_LEFT) { + shadow_ptr--; + mem_ptr -= KASAN_GRANULE_SIZE; + } + + if (shadow_ptr < shadow_bottom) + return false; + + frame = (const unsigned long *)(mem_ptr + KASAN_GRANULE_SIZE); + if (frame[0] != KASAN_CURRENT_STACK_FRAME_MAGIC) { + pr_err("KASAN internal error: frame info validation failed; invalid marker: %lu\n", + frame[0]); + return false; + } + + *offset = (unsigned long)addr - (unsigned long)frame; + *frame_descr = (const char *)frame[1]; + *frame_pc = (void *)frame[2]; + + return true; +} + +void print_address_stack_frame(const void *addr) +{ + unsigned long offset; + const char *frame_descr; + const void *frame_pc; + + if (!get_address_stack_frame_info(addr, &offset, &frame_descr, + &frame_pc)) + return; + + /* + * get_address_stack_frame_info only returns true if the given addr is + * on the current task's stack. + */ + pr_err("\n"); + pr_err("addr %px is located in stack of task %s/%d at offset %lu in frame:\n", + addr, current->comm, task_pid_nr(current), offset); + pr_err(" %pS\n", frame_pc); + + if (!frame_descr) + return; + + print_decoded_frame_descr(frame_descr); +} +#endif /* CONFIG_KASAN_STACK */ + #define DEFINE_ASAN_REPORT_LOAD(size) \ void __asan_report_load##size##_noabort(unsigned long addr) \ { \ From patchwork Wed Nov 4 23:18:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91620C00A89 for ; Thu, 5 Nov 2020 04:29:24 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0358320825 for ; Thu, 5 Nov 2020 04:29:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="hrnSTJaM"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="np3qLHK7"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="im6MoqCK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0358320825 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vcpagapbsoTQt06ywyafMRkkuocH3R5e2oJTmyug0fI=; b=hrnSTJaMtxLnhdoucqYfDliCs 91AisBkS/cS6lBjrywpxQaTZ3PFKHf+Ck0u+3MLI9srDtpPlj8WDi45/EWcaUBApNBJ0DnUqxPAnb aciWdoxgzS5j7RhKBVvWIWLW7XKaa52H374OPaz2dZQjBZDKqdQb6ZTGJ+X4exIE2Sidx9AIIMIyE MJ+ytNjZ2wwuMoTzKVBVpiG4kJoVikrvGP1MX8NRT/d+wnrqXrw1rPoL+QZVQg6IVUVX2GoB/JHPf Dr08RKGqERED8ma1YXvDEWmZ6YxjMk/erM9c3IqffP6+7DllBJqqemlffzVEzGDTOE++m/rkTsJwL I+0WL+SrQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWs0-0000Bt-2N; Thu, 05 Nov 2020 04:27:32 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5G-00016k-PJ for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=d4Yc7AItymQNyKGF4tg/i8f/qZM6X5xLr7PA4bM2pG0=; b=np3qLHK76nMvb/H0Zl/uZcLEn5 /5sdCNqws33HiL1w6EF43kMTOeMtii0vIXITk7/jP4S1VBEhbshUOWMySEk+9cBfQQfZBP45vGdFS YRTiTOVR4/doYAjNMAliUJygNxsiMcwg+JsMdePGVdPX/sIqmr0l4qESF+CTwVDQniaWGS23NjFgw K0gR3TP99EMD749R86aXUsBnxXjq/GS4S6cdLwLSv5hwtsS2ZlDphqQi9rGjR2wCQVbUay6h0qY3g OYdeW27LKnBAXHU48j8ekKnyrTkODUixgSdZf1M4Ryk1bhl3GRSC2rm5RRl2YYUHIfio9JFWv4Gin EZBNof1A==; Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS58-00040N-2w for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:49 +0000 Received: by mail-qk1-x74a.google.com with SMTP id t70so14384979qka.11 for ; Wed, 04 Nov 2020 15:20:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=d4Yc7AItymQNyKGF4tg/i8f/qZM6X5xLr7PA4bM2pG0=; b=im6MoqCKBPimqz1qFHzYTKjtM/SP4xbNj9lqr3+UxqrIDbQMPQjwIdXzthS7jpjGO4 3EcJa8vpYK443mb9T3VXyXZ7BOIItSr4fq2re7sZ3t2jvFZWIc0hQAS+2H3OEqC2u7LZ dKT04KNcmFA0bmrZH178cjfaVWiCJ4PZ5Xs5gs/rC6ULLyS5ZLqfftn6OGZJhi5ELmIn j5tNBMwU7QhW6NXZFeB1ffQ3sT6D0/mVpwGLHCk/iMFPaArf+42hWgYqdAwUmUlMd0T/ cC1waSCYw5qKAzMaV8/V5pfZ8vjWLa1kipuN91CKuTYipRSPTnZwhF9GmhgD2Rsrta6H qfOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=d4Yc7AItymQNyKGF4tg/i8f/qZM6X5xLr7PA4bM2pG0=; b=WrnC7T7D0owjagIkzlKfhM+kJLQRfzTXKHBfkzXSTIMKxp7ZuWlzXUuVr7BIsHqew8 vUZ6gTWb5/2l4wDJqaCYAnphlyji//8hEZ1ax4JJDv8UiQYluguX/aFTshByQqh5lty+ IJx/ZJ6V8ggA3cJ8CVH10exH4N7SnD1XRW1Yf1asP881oRKpIdx6Fiq6bQcfIDWdOd+5 lFC2k0ygd5LYR1wYLgnGgyu9ml5bERLBnwPdUwJwbGipqZYLK/Fx8qrVJr6C8if18S9b +Ukab982i2JCBl4xiJCuywGPwWJaoW/WJY0XdrP/QxKA/6KHNCqUDv6mT6w52OGL1+Dq ecqw== X-Gm-Message-State: AOAM532bWAbuUTrTn5G56TEak9qk984JaTYTTzsgo2N6M3DVzYX0Q/4I pb7gDU6LAivlzzQkQ1MHHhFzYdShpS7BQQFW X-Google-Smtp-Source: ABdhPJwX0nXmCdm5STp8GDmlwJmCmGhLQmNoNB8M224tUiklstu8Z5zoEBhqUpAe9orxivGxyeg98JncJ3U1EYl2 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:464f:: with SMTP id y15mr268562qvv.52.1604531982632; Wed, 04 Nov 2020 15:19:42 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:30 +0100 In-Reply-To: Message-Id: <82bba01b005a8a658596a77b2413adc16c8dfac5.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 15/43] kasan, arm64: only init shadow for software modes From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232046_262488_7A55F8F3 X-CRM114-Status: GOOD ( 14.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Hardware tag-based KASAN won't be using shadow memory. Only initialize it when one of the software KASAN modes are enabled. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Catalin Marinas --- Change-Id: I055e0651369b14d3e54cdaa8c48e6329b2e8952d --- arch/arm64/include/asm/kasan.h | 8 ++++++-- arch/arm64/mm/kasan_init.c | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kasan.h b/arch/arm64/include/asm/kasan.h index b0dc4abc3589..f7ea70d02cab 100644 --- a/arch/arm64/include/asm/kasan.h +++ b/arch/arm64/include/asm/kasan.h @@ -13,6 +13,12 @@ #define arch_kasan_get_tag(addr) __tag_get(addr) #ifdef CONFIG_KASAN +void kasan_init(void); +#else +static inline void kasan_init(void) { } +#endif + +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) /* * KASAN_SHADOW_START: beginning of the kernel virtual addresses. @@ -33,12 +39,10 @@ #define _KASAN_SHADOW_START(va) (KASAN_SHADOW_END - (1UL << ((va) - KASAN_SHADOW_SCALE_SHIFT))) #define KASAN_SHADOW_START _KASAN_SHADOW_START(vabits_actual) -void kasan_init(void); void kasan_copy_shadow(pgd_t *pgdir); asmlinkage void kasan_early_init(void); #else -static inline void kasan_init(void) { } static inline void kasan_copy_shadow(pgd_t *pgdir) { } #endif diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index b24e43d20667..ffeb80d5aa8d 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -21,6 +21,8 @@ #include #include +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) + static pgd_t tmp_pg_dir[PTRS_PER_PGD] __initdata __aligned(PGD_SIZE); /* @@ -208,7 +210,7 @@ static void __init clear_pgds(unsigned long start, set_pgd(pgd_offset_k(start), __pgd(0)); } -void __init kasan_init(void) +static void __init kasan_init_shadow(void) { u64 kimg_shadow_start, kimg_shadow_end; u64 mod_shadow_start, mod_shadow_end; @@ -269,6 +271,17 @@ void __init kasan_init(void) memset(kasan_early_shadow_page, KASAN_SHADOW_INIT, PAGE_SIZE); cpu_replace_ttbr1(lm_alias(swapper_pg_dir)); +} + +#else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) */ + +static inline void __init kasan_init_shadow(void) { } + +#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ + +void __init kasan_init(void) +{ + kasan_init_shadow(); /* At this point kasan is fully initialized. Enable error messages */ init_task.kasan_depth = 0; From patchwork Wed Nov 4 23:18:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED3BCC4742C for ; Thu, 5 Nov 2020 04:30:22 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4362E22227 for ; Thu, 5 Nov 2020 04:30:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="petN2FMh"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="A5VL6uL9"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="HyGuQZMp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4362E22227 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=jVeNZax7am88i5XRfYVkUsaSFbfbFX8hRcinDGsT5PE=; b=petN2FMhm4XjYLVXe7qo/A9A5 z0HLQ8zY7Ppm52HSIEojjoyrzJb1mmPCmQ5CNTJXkUBJO0TBGd9K0F5+8AViDqxd7RvWOaPlujY4/ 4HgoFX6qDsFge0SMX32t8j76Gd3QYDaIl3I6rYhLsOpT2v/obJ/OK6ZCCi4DS6bp7f/lQYK5R/lq8 mwN+BecBVJawC+9IrtHb8EihzUnDw6IO1BeykKIyffvhh6YLbDxlSLxHHCkeO93ITXf+Ddp4ygyvS /rjklFovifLHAJSbBEUmsMaXi0Bfovn3VZULJcXO6AdSag6StVQJvOrsZbQfv04c4h53il2Wjiq6P 9TmOD8Unw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWsn-0000aw-OJ; Thu, 05 Nov 2020 04:28:22 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5G-000145-PU for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=tnERJLSQMkNYv5nCg28tzBY5cjIpAsRRs2aOHq8rTuk=; b=A5VL6uL9UwVZTvzuVdDfxOBnde VvsFWGGG/R0fNEiE3UOiFi2o2zvSDx3AxaQHISPncQeo5y5cIKKYf1m5sVp9lnh8rhTdpSe/JunNg ofm0+mVFwMTX4mJhu6+seHrXfAxhdASb25lnZWKf3kGUF13CAgdNNuxSz0/9WKHJNKAw2l6p+iwij 1WSHHrBgrHUdKEcCqGxRoyYyYIISmt3qHMqfxcQ1tVTq9y35D2q3h8Xtm7mE5ofLFGnrN49thDdXt qEjoWt99G92Cw3roOyRBToEii/baBZkx9jAIxaCk+aaVNRseLWyrCG6zkMq5dRA9rmjdTJOH4dYCv VY1hsnHA==; Received: from mail-ed1-x549.google.com ([2a00:1450:4864:20::549]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5A-00041D-F2 for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:51 +0000 Received: by mail-ed1-x549.google.com with SMTP id b68so23835edf.9 for ; Wed, 04 Nov 2020 15:20:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=tnERJLSQMkNYv5nCg28tzBY5cjIpAsRRs2aOHq8rTuk=; b=HyGuQZMpQk+CJ5S+nBSByMdy3x2m1S7l9um7C0ebvb3INVZhZZKGpnoPXDoDetTWde 8isHTWfKQeUt0qNNTue0qTv2s0CtpxeE8h6Piz/qkZ1J4k+B9rL7qsTX3pR8NPns9vrJ xw6ljoZSJWR5FqTMuHrcTlTUg030KK6onV2uUy6NThLqymox3m1jZJIVYlAs57reDs7k HxfSk/EVditVRieaY4ecmSk2Ba1Qlp1U+kAOezEiBF+oa+V6/QSKw3XWW9tHpwmu/WL9 QL/FxHTJ4EbH2PYB0I5vPG7HXYhiKYoIKcHoOKxWf5eWmgaIk1+wp1iH/y9ruIZ5gvbX 3RQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=tnERJLSQMkNYv5nCg28tzBY5cjIpAsRRs2aOHq8rTuk=; b=BOzV1O6NydPqHTa22Pudcj8dicRyux6To826zzoYTLhY/MUbWhXyE1yMuTYXhVLvS4 OrQPBUEBA1AB+HAlJvxUHP0yYcseET3ClFLQjuFQ47Kqk5F0f7eMexD7x8jVoXPYoKC7 CAiZKcK4bwdogktJXy5qzR2b4L0mEqhSCd4F5T1A/mHKPisdH+BUHYg88gncY6cLuLs/ Z3UDw6E9SBOjiBMQH6p4HRiC4qXTL0/V667/o31tREmlsTotvS205UF5BQkCh8t02jcw dYRG3ms3pvp5vAUn0iNuHMJpctvnhPOsvjKCXEIgb1XQS5Yp/R6uiDQ0X0NR2fFZlcDY Kweg== X-Gm-Message-State: AOAM533pOmDS5Jnaq8dDHqvglvPFjaB5xdryURrxsh1GMdkP3uA68Dhl 5wnmpwfXhukBrvZFxjZYgnXdiMqrqzTm7Sze X-Google-Smtp-Source: ABdhPJxVtsuYBox3ePrSsEvjI1qOT6r/u+DFGn747FXEgRreZEaoaEtPTyLgL+L/uzTnkLFIpYzmx6+a1SIxGwR6 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a17:906:3acd:: with SMTP id z13mr472324ejd.118.1604531985052; Wed, 04 Nov 2020 15:19:45 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:31 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 16/43] kasan, arm64: only use kasan_depth for software modes From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232048_729058_739F9F47 X-CRM114-Status: GOOD ( 15.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Hardware tag-based KASAN won't use kasan_depth. Only define and use it when one of the software KASAN modes are enabled. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Catalin Marinas --- Change-Id: I6109ea96c8df41ef6d75ad71bf22c1c8fa234a9a --- arch/arm64/mm/kasan_init.c | 11 ++++++++--- include/linux/kasan.h | 18 +++++++++--------- include/linux/sched.h | 2 +- init/init_task.c | 2 +- mm/kasan/common.c | 2 ++ mm/kasan/report.c | 2 ++ 6 files changed, 23 insertions(+), 14 deletions(-) diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index ffeb80d5aa8d..5172799f831f 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -273,17 +273,22 @@ static void __init kasan_init_shadow(void) cpu_replace_ttbr1(lm_alias(swapper_pg_dir)); } +static void __init kasan_init_depth(void) +{ + init_task.kasan_depth = 0; +} + #else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) */ static inline void __init kasan_init_shadow(void) { } +static inline void __init kasan_init_depth(void) { } + #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ void __init kasan_init(void) { kasan_init_shadow(); - - /* At this point kasan is fully initialized. Enable error messages */ - init_task.kasan_depth = 0; + kasan_init_depth(); pr_info("KernelAddressSanitizer initialized\n"); } diff --git a/include/linux/kasan.h b/include/linux/kasan.h index bfb21d5fd279..8d3d3c21340d 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -49,6 +49,12 @@ static inline void *kasan_mem_to_shadow(const void *addr) int kasan_add_zero_shadow(void *start, unsigned long size); void kasan_remove_zero_shadow(void *start, unsigned long size); +/* Enable reporting bugs after kasan_disable_current() */ +extern void kasan_enable_current(void); + +/* Disable reporting bugs for current task */ +extern void kasan_disable_current(void); + #else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ static inline int kasan_add_zero_shadow(void *start, unsigned long size) @@ -59,16 +65,13 @@ static inline void kasan_remove_zero_shadow(void *start, unsigned long size) {} +static inline void kasan_enable_current(void) {} +static inline void kasan_disable_current(void) {} + #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ #ifdef CONFIG_KASAN -/* Enable reporting bugs after kasan_disable_current() */ -extern void kasan_enable_current(void); - -/* Disable reporting bugs for current task */ -extern void kasan_disable_current(void); - void kasan_unpoison_memory(const void *address, size_t size); void kasan_unpoison_task_stack(struct task_struct *task); @@ -119,9 +122,6 @@ static inline void kasan_unpoison_memory(const void *address, size_t size) {} static inline void kasan_unpoison_task_stack(struct task_struct *task) {} -static inline void kasan_enable_current(void) {} -static inline void kasan_disable_current(void) {} - static inline void kasan_alloc_pages(struct page *page, unsigned int order) {} static inline void kasan_free_pages(struct page *page, unsigned int order) {} diff --git a/include/linux/sched.h b/include/linux/sched.h index 063cd120b459..81b09bd31186 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1197,7 +1197,7 @@ struct task_struct { u64 timer_slack_ns; u64 default_timer_slack_ns; -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) unsigned int kasan_depth; #endif diff --git a/init/init_task.c b/init/init_task.c index a56f0abb63e9..39703b4ef1f1 100644 --- a/init/init_task.c +++ b/init/init_task.c @@ -176,7 +176,7 @@ struct task_struct init_task .numa_group = NULL, .numa_faults = NULL, #endif -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) .kasan_depth = 1, #endif #ifdef CONFIG_KCSAN diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 543e6bf2168f..d0b3ff410b0c 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -46,6 +46,7 @@ void kasan_set_track(struct kasan_track *track, gfp_t flags) track->stack = kasan_save_stack(flags); } +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) void kasan_enable_current(void) { current->kasan_depth++; @@ -55,6 +56,7 @@ void kasan_disable_current(void) { current->kasan_depth--; } +#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ static void __kasan_unpoison_stack(struct task_struct *task, const void *sp) { diff --git a/mm/kasan/report.c b/mm/kasan/report.c index b18d193f7f58..af9138ea54ad 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -292,8 +292,10 @@ static void print_shadow_for_address(const void *addr) static bool report_enabled(void) { +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) if (current->kasan_depth) return false; +#endif if (test_bit(KASAN_BIT_MULTI_SHOT, &kasan_flags)) return true; return !test_and_set_bit(KASAN_BIT_REPORTED, &kasan_flags); From patchwork Wed Nov 4 23:18:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883237 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D399EC00A89 for ; Thu, 5 Nov 2020 05:02:50 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 39ECD2083B for ; Thu, 5 Nov 2020 05:02:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NF265wBP"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="EXdT/vIN"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="wU1V8lsO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 39ECD2083B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LLQH4a6cluNc1xFHfv9y4NeHGF+dWkuU0xDceWc2t84=; b=NF265wBPlJDCpTCtjR8GAzeak 0tvy/d/55p/WN0Boe3cA0czBOJrtLYQtPy7HmsaUS468+p+/nyF6tv5CcQ0AWnryxl8nPO6v9TgOo hmCItZf38/OmVkOdHSR5CgDwrxGiuWbWXx0NMXxsAODcxfDyk7rxQjb1aQ0Vzpkg5UnZt8jm9d0FD iym3od0rRXW6cDDujbbWT3nD5D2eT9fumu2IVD+95L+8rV3fqMTzhbPNu9+F07oZWfDvCm98nfdgL 1aV8zPSDotNmJ+qCQCDc8+Z2SydhXZkEqmniWsecto9tpAS+X/EfoT2xe1DEEgHR+Gj6ogkT+6sfh pkgfrOGOA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXOc-0002vR-Gc; Thu, 05 Nov 2020 05:01:14 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5F-00016k-O2 for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=NNpPR5seN/69hYJxiJpAYFp3W8/rjpHZNnZx8Fjl6mI=; b=EXdT/vINagSX7ZehZBCAJOGdIx GAopJ/dBSuT03085LY0LD1xIfv7lLHC9cvA16v14hatcGk7fvXFsJ7cG6PxSS5aEhx1/kChLnOtOt nH8BBi4Oaxx25vJTLjVLcsj3+KPRso/5vor78vWApiNRvXi2mccTWwVAeweN6Oqyoa/BAoxM5LAL/ DAtCfONdKlgW8/hYpzeWpXEpHYFRIwvKimbqjsK5PmXIkADuAKf5mrHf9mUw6Y5D6f2Tqe3JvZI2w kgXT68ai0b1vmowCmPQSAkk/lD2/NJjV/U5JEYjd+xv1X0VJdKFe2seX37nsHCVx4maxTTZPAhJBr 2mW1wqkA==; Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5D-00042H-MF for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:54 +0000 Received: by mail-wm1-x349.google.com with SMTP id f70so18210wme.7 for ; Wed, 04 Nov 2020 15:20:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=NNpPR5seN/69hYJxiJpAYFp3W8/rjpHZNnZx8Fjl6mI=; b=wU1V8lsOAkGo3pNPWnHU6mO7WX0LIPMeVGitcBvkjWHQ8P6vVXjIUcGsKPT1RJTjau 82vzDogOhtwGxKyQCIdosDuHCtfsuIl7uxpWmo6Pn1TUvIqJxymwGsGAkaGODghphrjt HgZP0dpaZ6wF4lEJKbG8ohtm2c6atQyQF78H/NkBG1vcUtr5Y5yzdq0JVO5nCnfpXyHx U393yQI1+3HzEGRBKUSwd0OlQXiL0+BTnVXtEaJlK8ZJ1k6o03Arf/Z3ygWKHwsjc+4B VvQQCiuuqJ/qmAn6C3606noEHQleg1fRtvMeckYCAxYMb5iHuwTf4SqLihPvMbnhMrLr nWgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=NNpPR5seN/69hYJxiJpAYFp3W8/rjpHZNnZx8Fjl6mI=; b=Wu2hByTmV9mFaON4ZpUoVex5Kr/1OwBeg20qU9S7RMITAZBAI/DVaHWZdZ+99lObpv 97sVjSMdHNHqQtJ1yBfAxvSX9ybGF3iTXnA9FRkCMnHXDVc3RpVkyE3jABwr0hkt4p4l TemeAu72GRN15kQROei1haZ8GLShl7bUrOrjpbgif81XpAlc2QI5HigcW+Pxhhex9knu Mn41jy409TmN74vFMAgUFF2NkGl0UGnVRvCEpuN6E80TqIr5J3a2WCYvRqHZpr+9i4xl Frnwqh/bR0lbdjg0FDgv7rPY8yIfGA2IEatpeYBwDa6ybCP9KVg/GSGOX+IZ7tuD3ubo JoiA== X-Gm-Message-State: AOAM533Rp9SoifROsRVqiRfsG63fUhjdXWdlDtZ31F04gwrzsLZr0EV4 lWk2i/gqcvzO86Upqr9CoXtwhD7m1r1tOOoS X-Google-Smtp-Source: ABdhPJzgqb8BbsD1ROqfJK4RnM9S+bQs5oY+EedW0m/ae73swJYXUEDAzaboVoA5x9IhiU9acDjl7af/hSCYzGUa X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:6405:: with SMTP id y5mr82984wmb.150.1604531987731; Wed, 04 Nov 2020 15:19:47 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:32 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 17/43] kasan, arm64: move initialization message From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232051_966110_19EDBECB X-CRM114-Status: GOOD ( 16.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Software tag-based KASAN mode is fully initialized with kasan_init_tags(), while the generic mode only requires kasan_init(). Move the initialization message for tag-based mode into kasan_init_tags(). Also fix pr_fmt() usage for KASAN code: generic.c doesn't need it as it doesn't use any printing functions; tag-based mode should use "kasan:" instead of KBUILD_MODNAME (which stands for file name). Signed-off-by: Andrey Konovalov Reviewed-by: Catalin Marinas --- Change-Id: Iddca9764b30ff0fab1922f26ca9d4f39b6f22673 --- arch/arm64/include/asm/kasan.h | 9 +++------ arch/arm64/mm/kasan_init.c | 13 +++++-------- mm/kasan/generic.c | 2 -- mm/kasan/sw_tags.c | 4 +++- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/arch/arm64/include/asm/kasan.h b/arch/arm64/include/asm/kasan.h index f7ea70d02cab..0aaf9044cd6a 100644 --- a/arch/arm64/include/asm/kasan.h +++ b/arch/arm64/include/asm/kasan.h @@ -12,14 +12,10 @@ #define arch_kasan_reset_tag(addr) __tag_reset(addr) #define arch_kasan_get_tag(addr) __tag_get(addr) -#ifdef CONFIG_KASAN -void kasan_init(void); -#else -static inline void kasan_init(void) { } -#endif - #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) +void kasan_init(void); + /* * KASAN_SHADOW_START: beginning of the kernel virtual addresses. * KASAN_SHADOW_END: KASAN_SHADOW_START + 1/N of kernel virtual addresses, @@ -43,6 +39,7 @@ void kasan_copy_shadow(pgd_t *pgdir); asmlinkage void kasan_early_init(void); #else +static inline void kasan_init(void) { } static inline void kasan_copy_shadow(pgd_t *pgdir) { } #endif diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index 5172799f831f..e35ce04beed1 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -278,17 +278,14 @@ static void __init kasan_init_depth(void) init_task.kasan_depth = 0; } -#else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) */ - -static inline void __init kasan_init_shadow(void) { } - -static inline void __init kasan_init_depth(void) { } - -#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ - void __init kasan_init(void) { kasan_init_shadow(); kasan_init_depth(); +#if defined(CONFIG_KASAN_GENERIC) + /* CONFIG_KASAN_SW_TAGS also requires kasan_init_tags(). */ pr_info("KernelAddressSanitizer initialized\n"); +#endif } + +#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index e1af3b6c53b8..adb254df1b1d 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -9,8 +9,6 @@ * Andrey Konovalov */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - #include #include #include diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c index b2638c2cd58a..d25f8641b7cd 100644 --- a/mm/kasan/sw_tags.c +++ b/mm/kasan/sw_tags.c @@ -6,7 +6,7 @@ * Author: Andrey Konovalov */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#define pr_fmt(fmt) "kasan: " fmt #include #include @@ -41,6 +41,8 @@ void kasan_init_tags(void) for_each_possible_cpu(cpu) per_cpu(prng_state, cpu) = (u32)get_cycles(); + + pr_info("KernelAddressSanitizer initialized\n"); } /* From patchwork Wed Nov 4 23:18:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883239 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76261C00A89 for ; Thu, 5 Nov 2020 05:02:39 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DA1ED2083B for ; Thu, 5 Nov 2020 05:02:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FqSCLuE1"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Gsm+2gvZ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="KrghbXMM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA1ED2083B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=X+vRNKag6WoeriqWlZicHF4JSU2Iu46N9/gy6nThQeU=; b=FqSCLuE1XkqfNENdSxdzuEu3i trh5VKjB9V7WghE7bmjBXV6eq5EheS3Rf3AY7YXtXjxIzD7nV1+PKvUQoj0Ka8Ein3X1inoxK4b75 olQiX23N42YqoU4RODfTRm69uk2ffrV6zPqDU+Cpq+s7sJ+wrCOT2bfALGYCsepVhIxX3aE04VjON uhGfR4FoPttsZaURZiO8fl9ABP3b2GIPS57nXbwYlI8Xy/t52ESS+l7yGYhsceXiXeCXnVlXEVwnJ 341R6uebCepb9NpENAhD1DnvN+xhWBuLt8n2ep+nMHlnYhC/GXD4DAkFFAqK+nzQNH9oqxVQLhCpu 7rqUo0BlA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXOP-0002rc-TP; Thu, 05 Nov 2020 05:01:01 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5F-000145-PM for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ojj9e6SeGShn+CqBq2chujClVFvSwMkEAD8uQAmerxw=; b=Gsm+2gvZnj9mZMIbpu+ta1D/EV mOjAHfKVrn7lQZ5DUQ7tKLqv6dXHBgNYq0Gtxz+4MxPDtekxAb8L1+Rpm1JPIHf0ofj20fkorUzSa 6uIpp9ETEZOJn27k2UXk/EY1gnXFri/HRqeANAKg87N6gSgQLD1ZLpDg8V0L9DBItkQNMOVdAsAlB pcX5gqToD0ik80XOQrPkghfiUP/oviF6dEZhY/hr+VG0UZ+CrCbJmlL+8eqIiRyJ9MujbeR660HGc 6ZgsP1j5GgUjAeZ2UUfeZJ74mh5jR4eLXcnQY0/zggQYTSZGCBOygkRXs9pXAjw6ywx03U/o9Ejvm HOKjzRxA==; Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5D-00042I-EX for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:53 +0000 Received: by mail-wr1-x44a.google.com with SMTP id p12so50015wrx.3 for ; Wed, 04 Nov 2020 15:20:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=ojj9e6SeGShn+CqBq2chujClVFvSwMkEAD8uQAmerxw=; b=KrghbXMM9I87gk5nyKwP68q9D7JmfiGJWPyvcuRP5JhQi4zKJv4x/OQdNK899VZfqz Fl3FdIrNm1+pH2z8nU+0yU3a/m6zzFixZuFzq6Ywp5d02Hxu0YgaCRAnpHe0fyQB5FWy Y/c14XQNtkxh2iATLUSfgdZbaMz+vZbXVmuVrnh2nnpAp0+1STVxyz2Sh98bhr7b1BQK eQjjVuaipiQJIrrByCMPsXUnMpNmFY7tjmF5Na/ENvCa0ba0B6jimHGctfbj5rZWXnd/ xf/7tvFqBWanQqEH6Ns0LXEVcMlySnqa2XGWIs5Ifyr1zCKgYpbS7BOFRlscFme4BgmJ gsNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ojj9e6SeGShn+CqBq2chujClVFvSwMkEAD8uQAmerxw=; b=Z+D5JyinqoAERtVj/Mvg8XiRk7gtd7PGOhxbme1WNZT6mGt+lSXtcx+0apytRagDcc bu5iQJWLnwajocrh01/nDs7XxwCIx5H7lyiGVmYbTqBZ2lyiyAjVmuTLxXPtY6KkUp+8 UtdHU/vxUT9Ct+rxTSSys6PoaMZJ1U1TAqXgq/UOZBh1r86gRVT1gyANexE+auoQRueO dHWxf3QO4kBSlDC+8IJDrZIviyAS5zJ0RonogsLr8huAiX/0j2HWMcH3+BsaKVI5f8qL cJzcc5W8kg/AaN+HH9OEQpNKbqPu8vBZ/GLJqQ8LUHfxEGXJkV/Opy1pSjqr29DmA/72 jyxQ== X-Gm-Message-State: AOAM531P4Jbsp4DM2GvxHSO5Y8L4mBVq9byoTBp+4A0uboYhGMJBzOiS Nq9UvNGyJL52QZdS2eTnDJPnlV+t3rkhr8B8 X-Google-Smtp-Source: ABdhPJz4Hbrh3Ua4QZ0IndrRDGnYifiicCuVPdjCPO/4LNGbo3KP+1XW2gBoZ6BhFx5g1YdGjEGB1Urre7hAN5qv X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:e903:: with SMTP id q3mr97119wmc.42.1604531990350; Wed, 04 Nov 2020 15:19:50 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:33 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 18/43] kasan, arm64: rename kasan_init_tags and mark as __init From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232051_687176_260CA5F4 X-CRM114-Status: GOOD ( 13.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Rename kasan_init_tags() to kasan_init_sw_tags() as the upcoming hardware tag-based KASAN mode will have its own initialization routine. Also similarly to kasan_init() mark kasan_init_tags() as __init. Signed-off-by: Andrey Konovalov Reviewed-by: Catalin Marinas --- Change-Id: I99aa2f7115d38a34ed85b329dadab6c7d6952416 --- arch/arm64/kernel/setup.c | 2 +- arch/arm64/mm/kasan_init.c | 2 +- include/linux/kasan.h | 4 ++-- mm/kasan/sw_tags.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 133257ffd859..bb79b09f73c8 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -358,7 +358,7 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) smp_build_mpidr_hash(); /* Init percpu seeds for random tags after cpus are set up. */ - kasan_init_tags(); + kasan_init_sw_tags(); #ifdef CONFIG_ARM64_SW_TTBR0_PAN /* diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index e35ce04beed1..d8e66c78440e 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -283,7 +283,7 @@ void __init kasan_init(void) kasan_init_shadow(); kasan_init_depth(); #if defined(CONFIG_KASAN_GENERIC) - /* CONFIG_KASAN_SW_TAGS also requires kasan_init_tags(). */ + /* CONFIG_KASAN_SW_TAGS also requires kasan_init_sw_tags(). */ pr_info("KernelAddressSanitizer initialized\n"); #endif } diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 8d3d3c21340d..32b9d283e0a0 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -189,7 +189,7 @@ static inline void kasan_record_aux_stack(void *ptr) {} #ifdef CONFIG_KASAN_SW_TAGS -void kasan_init_tags(void); +void __init kasan_init_sw_tags(void); void *kasan_reset_tag(const void *addr); @@ -198,7 +198,7 @@ bool kasan_report(unsigned long addr, size_t size, #else /* CONFIG_KASAN_SW_TAGS */ -static inline void kasan_init_tags(void) { } +static inline void kasan_init_sw_tags(void) { } static inline void *kasan_reset_tag(const void *addr) { diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c index d25f8641b7cd..b09a2c06abad 100644 --- a/mm/kasan/sw_tags.c +++ b/mm/kasan/sw_tags.c @@ -35,7 +35,7 @@ static DEFINE_PER_CPU(u32, prng_state); -void kasan_init_tags(void) +void __init kasan_init_sw_tags(void) { int cpu; From patchwork Wed Nov 4 23:18:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50914C00A89 for ; Thu, 5 Nov 2020 05:03:46 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B772E2083B for ; Thu, 5 Nov 2020 05:03:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="W35A/90n"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="eSK5X+2C"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="FBI115kS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B772E2083B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=VjvaPOlFzblc2wtJhDMQFzPWCRH99aS3K4z7O44o5uM=; b=W35A/90nB4Bb7BpCPYgxGqPQy bKLpNOj1TsPK2Ye5TfH29P3m0DK4sG0KJvV89bSJMEJwGvoeS2eXrYFKk2Q2aoex2SeRPszw/HGDj t8jNeQQuU9n/XbswxaHr5GOnboKZrTTK2PYFOA3XviByZGbdWSeCRqUCG7EbPFXnRcz/6T+0ulMV4 cSa0FWN5p0HH6Yc20s45YJ4XObLPCj4EebmBf/6elR7wzF6RDxkpRu00Tv0h3KgnuS/CACEyH2rPn 2TYRMTfnH8DWDzsuLIwrQCy9Im+jnaexWSOGgMTsiec9UB+Bn5REv4bQWlwP6oGnvk7GQC7f7tgGB rRmG4hvEw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXPI-0003DJ-Vj; Thu, 05 Nov 2020 05:01:57 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5E-000145-QB for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=71dDjA4AvorvAoOL9VJG2R9YWEBiYEDCkHWbAxU+l2Y=; b=eSK5X+2CrXXSCmbF2qt7JN8gLP ADCmp4MlWX2sAJPvKwvu1o+TNhlT2kKYC7ZDGYkvY+eZ2dzc1PWshcPnn5W1wqpGb8KaATGjX9h83 NHFpMx03M9IRNXEO8sGHsmGbnQL66gksTfQCdep8DJSwSnQNJG7il5/iDkZq4iEksIEWHfNLYvgvg xwywwtLqArkbiNDxcxKMbGf/GnqJKn87Lc5L78vbIGDnXxMbj5rnKsnkM/xI1gzjBh3Rd754wrSnL drgYLmpAyKrbo3fAPGdbS32OWPnMBz/R4rYgwrPuQrmbx3mBf091mGjUP/5J8guvmtMgo+GJKlR7f 2eAEMUyg==; Received: from mail-qt1-x84a.google.com ([2607:f8b0:4864:20::84a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5H-00043T-3g for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:57 +0000 Received: by mail-qt1-x84a.google.com with SMTP id d21so74565qtp.2 for ; Wed, 04 Nov 2020 15:20:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=71dDjA4AvorvAoOL9VJG2R9YWEBiYEDCkHWbAxU+l2Y=; b=FBI115kSl/HZmIpkt1WXy79Z+i//PiEltj41xVsYSu3pxfB6uvCPMeCRU+oAq02d/D 7LIPPK8wd3GJK76/Z+BDYn+b9//x+1d+6CNuvFjeZjdgGSu/oC1EPweJd3+Lzxv5glTp KParHjDWpvGcnPVF8ALnFfigLvYM0k4RQEq4SKir4DLZLItEIrydCxau2ueZFsuk5ey1 wFCmkxmn6P3xvclIkvvcuQ3QgGEOPklAf2B20ejqU0W5hrst28zkEu9Q97OeWYM2+gcZ nKFW6GSy5kAaylxfNizKlF6ufym23h7ZX8sxFQMxH2b9geM9FZ7JUDhzyBe8014S3GZ3 8e4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=71dDjA4AvorvAoOL9VJG2R9YWEBiYEDCkHWbAxU+l2Y=; b=XXPUOECUgdPzLFogQUN/UIddq53oBw/hiSoPWqtim4YMh0TvpT6Z4R5KLSxbVdYC39 eMH9RvokmsFT5pnjXAl2dPD69iv17zzJfujqT25mm7v+jpilCmUa5pcyU630upRI0b0/ TQg95jG/fif4TC/whNjhpJvrSfxHZfBopPsukmavdDVM6CrVejnwYXX6IMlIfm3Y/Fxw Qn6pZ3PsTApD+dx34heG0aX+EETgdAU9VaKDqzzPlnKnAIJnKvyZgCOL/4hX6LKzL9P1 yngJiRBPBHSGKYTxrl2dyq5zlATVmBKjUjPllP3UB174AHoX5Llqgfjdz63UmaFxOO9U rSow== X-Gm-Message-State: AOAM5326/llPVgUixZUL+q3dXTQaYj/fVXVenOvodH5YFrDYt/SHMlhI U/yMpmtUZ4adrfW30Jd3O08+INZ1UY+fTGt9 X-Google-Smtp-Source: ABdhPJxOZwIeUmqI/nV1niN8m+2CkK4H9VN0saYIPGqBloq1ama2UCKlYbsmmzphZXOZDPNwTMjB/REABxyDqsNS X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:4512:: with SMTP id k18mr256501qvu.5.1604531992636; Wed, 04 Nov 2020 15:19:52 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:34 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 19/43] kasan: rename addr_has_shadow to addr_has_metadata From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232055_315941_96CC975D X-CRM114-Status: GOOD ( 13.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Hardware tag-based KASAN won't be using shadow memory, but will reuse this function. Rename "shadow" to implementation-neutral "metadata". No functional changes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: I03706fe34b38da7860c39aa0968e00001a7d1873 --- mm/kasan/kasan.h | 2 +- mm/kasan/report.c | 6 +++--- mm/kasan/report_generic.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index d0cf61d4d70d..f9366dfd94c9 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -146,7 +146,7 @@ static inline const void *kasan_shadow_to_mem(const void *shadow_addr) << KASAN_SHADOW_SCALE_SHIFT); } -static inline bool addr_has_shadow(const void *addr) +static inline bool addr_has_metadata(const void *addr) { return (addr >= kasan_shadow_to_mem((void *)KASAN_SHADOW_START)); } diff --git a/mm/kasan/report.c b/mm/kasan/report.c index af9138ea54ad..2990ca34abaf 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -361,7 +361,7 @@ static void __kasan_report(unsigned long addr, size_t size, bool is_write, untagged_addr = reset_tag(tagged_addr); info.access_addr = tagged_addr; - if (addr_has_shadow(untagged_addr)) + if (addr_has_metadata(untagged_addr)) info.first_bad_addr = find_first_bad_addr(tagged_addr, size); else info.first_bad_addr = untagged_addr; @@ -372,11 +372,11 @@ static void __kasan_report(unsigned long addr, size_t size, bool is_write, start_report(&flags); print_error_description(&info); - if (addr_has_shadow(untagged_addr)) + if (addr_has_metadata(untagged_addr)) print_tags(get_tag(tagged_addr), info.first_bad_addr); pr_err("\n"); - if (addr_has_shadow(untagged_addr)) { + if (addr_has_metadata(untagged_addr)) { print_address_description(untagged_addr, get_tag(tagged_addr)); pr_err("\n"); print_shadow_for_address(info.first_bad_addr); diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c index b543a1ed6078..16ed550850e9 100644 --- a/mm/kasan/report_generic.c +++ b/mm/kasan/report_generic.c @@ -118,7 +118,7 @@ const char *get_bug_type(struct kasan_access_info *info) if (info->access_addr + info->access_size < info->access_addr) return "out-of-bounds"; - if (addr_has_shadow(info->access_addr)) + if (addr_has_metadata(info->access_addr)) return get_shadow_bug_type(info); return get_wild_bug_type(info); } From patchwork Wed Nov 4 23:18:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883249 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D0F5C00A89 for ; Thu, 5 Nov 2020 05:03:54 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 80BD52083B for ; Thu, 5 Nov 2020 05:03:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="w6UOsxNs"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="IbB3ryrL"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="MHsAFWSN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 80BD52083B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YmmtdMhCjD1E2AMLJxsMGcvi8ho7A3bbG6237EAU9Y0=; b=w6UOsxNskmIwfds5HbClThICv ytqRS/QzGmc4tkdFyN1RSTit01XsU3VAgIvGvl7LlrAbd7eK3Y6e0APQ7Z4G3Q6k/JN2DSWlqHrgR lD4l8oXZX8vcIvry1FcZBcwYyGAXfJEw7E+MLD139vQmKfaKUnT5MZPoDK7VqdlJbBifZWhAxvjSf giMOBizfAnifJqriiMHovOTHSF53MbvXkbG0AfTe54hmceiriefYjWu9rwVfIbiZV0rtINV/DflVb mzR8awlwvyo5bzVQR2pS+ZDpJ2FTZIwj83SBOSMt+qcs52ixdrQAqmrqget1KseFnpNLYv7WV/2Nw +eZnsIhKQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXPf-0003NC-7B; Thu, 05 Nov 2020 05:02:19 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5E-00016k-Q0 for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=96T+1f9i/jCV3zB6gHtRoH9MAYIWASsGc4o7euuXITQ=; b=IbB3ryrLNaQv/i1r3lGvL9X4QD cmES0naZFDELPTsxyf6ocHxN777xJzVoqLsL5JG9i3eM7TlmeB9szfsnR24J+jN+R4gNvkjw02Uhw qea3dquTRAXRlh+LWyOvieat29jj7STkEIgPw0fU8aJUCR31547m/G6OkKDBm2XTUjlutiMJXUJHd Isgckcbp56Bt4gV5rhpe7rsd8tQt+WsGWzGRbrBXs0L/TXDWmv5NLqjsrzPuG7QuaCVEG7MfdOxFo k7g+siPPhSNwtKND7wXOfQdRhH3hFtZFWFVKfSfbw+KLCsD0NRJDSOvyGL3fDEY0Wu0UJxjr3emaa VzGarIaQ==; Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5K-00043z-EU for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:00 +0000 Received: by mail-qk1-x74a.google.com with SMTP id k12so14453676qkj.18 for ; Wed, 04 Nov 2020 15:20:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=96T+1f9i/jCV3zB6gHtRoH9MAYIWASsGc4o7euuXITQ=; b=MHsAFWSNNNsmPyRuCRBRe5S5UJlJTgrmBZO2ihBxvYR0I9yYigF63VwzzPho62nZs2 VLtTKG/brXnczBsTg/i2aly4WyjggyM4qk5OgjEXTMS6woyfj8oUQLECz4dnR7CYmlCK P2hAhriFaidiECgnMceqscf76Xp8o3bbo8VrPcMQFeLKrXv1UFPRc6fihUk7uiYivJRY /Psb2wdAmwOpskpJVZWh95yRjI1C5Gce+azuH8yjGwSerALSKQTYVjqWvilB6QagDvv7 yNsYVvfeAHhc4rqWuseztMtgbrSeVVBL0ZtROar7FPeVqCV0fj2xagBhvbamoTlcYhxm Ntrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=96T+1f9i/jCV3zB6gHtRoH9MAYIWASsGc4o7euuXITQ=; b=oepWs+1Odf7bMKETajAqkPeAxVN6MNgjbZ49jyiVqQ1EB7H7TNg255kLKeXtyd7s1K 64+vflH5Fix+wYJH37/TXOvY6RtgyTPogzf25G9hsOxNy+HwYkjxumWetd7GkKgT4Ar0 IkQ2hRYScH5vbh1DrjPTKTKKB5smJ3vh9PYQpLDK3EHN14n+JjJuxP0Zkx0Na66XibzL 4ZTKhZHiZphEm2pHzJlrSkmjfLb/1UAAaF2JNrOSPuccunjlwbiXySfFzCEK/fyYRZpM gnei341PiXsI3kZA918sNM2nEjM7l1nH5h4MH7GszpZF8jJBYRWw7p/7csDYdnez23a7 MIPg== X-Gm-Message-State: AOAM533PVxErcOI9HDszdrfqHCsKPTg6PHXRAbwjY78isWftIiV+GJF5 Wz/KKZ7/rD5JfDIM1c3ZjBIsmR2C8vpT874g X-Google-Smtp-Source: ABdhPJyY4vYywqcrGkIXWcGHdEVetd/tg0ubApwhK74pxGohLkeevkUn1OS+r+BUFIBRiQwZoc1eeXrnVoZyf101 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:a2a6:: with SMTP id g35mr293187qva.4.1604531994786; Wed, 04 Nov 2020 15:19:54 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:35 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 20/43] kasan: rename print_shadow_for_address to print_memory_metadata From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232058_594844_BFBA7A24 X-CRM114-Status: GOOD ( 12.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Hardware tag-based KASAN won't be using shadow memory, but will reuse this function. Rename "shadow" to implementation-neutral "metadata". No functional changes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: I18397dddbed6bc6d365ddcaf063a83948e1150a5 --- mm/kasan/report.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 2990ca34abaf..5d5733831ad7 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -252,7 +252,7 @@ static int shadow_pointer_offset(const void *row, const void *shadow) (shadow - row) / SHADOW_BYTES_PER_BLOCK + 1; } -static void print_shadow_for_address(const void *addr) +static void print_memory_metadata(const void *addr) { int i; const void *shadow = kasan_mem_to_shadow(addr); @@ -338,7 +338,7 @@ void kasan_report_invalid_free(void *object, unsigned long ip) pr_err("\n"); print_address_description(object, tag); pr_err("\n"); - print_shadow_for_address(object); + print_memory_metadata(object); end_report(&flags); } @@ -379,7 +379,7 @@ static void __kasan_report(unsigned long addr, size_t size, bool is_write, if (addr_has_metadata(untagged_addr)) { print_address_description(untagged_addr, get_tag(tagged_addr)); pr_err("\n"); - print_shadow_for_address(info.first_bad_addr); + print_memory_metadata(info.first_bad_addr); } else { dump_stack(); } From patchwork Wed Nov 4 23:18:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883259 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BA2FC00A89 for ; Thu, 5 Nov 2020 05:08:31 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B2D3C21556 for ; Thu, 5 Nov 2020 05:08:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="s6PSVleh"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="IHVPl2+n"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="br613dpy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B2D3C21556 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=fUPWOtLXMSTsvoqTtcTB3bJQyUB7pV/iN8bjRzsmMfk=; b=s6PSVlehXlLxtee/N8K2zJbBT ERPQDXbSg0w6O4+RjMxeIdDsY8RbsQpMy/MJ75mBodMinljAfXqqbLFNmOdZZRfEZO1tguMGBqgut gJCb+5i7p1f7TDQ6MQy+myH2c48BFUoJzTeY62MP8CtF4gUCfffZbQsmFgDWF/t3PehE2wfM3uGm/ ROWm67ShlJAp4+7FPxHIvMiUg7XJVGcv/Z9ncHQv1mN7Hq7mIdJg7Q3rQb9pxyhpyA7jxTCk4FwZY zTaQYGPYKNW2vSldJqLaVrzH8s3du3Yu1agFJzfhXcliCGxs82N2werUstFv3uVNIrI2zbQl/2p7T i8OXS38uQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXTZ-0005FX-9F; Thu, 05 Nov 2020 05:06:21 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5D-00016k-Or for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=oA6gmttblv8OmG3VJbCFTsqSwJTzGphkOsRK2ZeD750=; b=IHVPl2+nKbvM0s37PdRf8jdK0F lwXZtnkz68qcZjRHmKtzH1ptf0+opngzdiGvu7toYWgA2f5wtXNwW1Q7WVGAd8UwpjREQapzZp01M vdgHz/W3sc75/mOPuRXMK0hkxYBy7hnIccYoJT6hR6Ias5bzdWPthKZOaJqfa7b/4A9D9y2wV6/tn T4I2UWAuKn+6JLsC6l5Hq90H5Nzc0AormOllEd1W1lr2QHRrmE/hkgIBOZRBm5Avo0s6sfBZeyjdk xtTbsELConX8qFgxAV6aCU1JjHBwdwMe4ybmlcwsRr9y20MQoeycAdNZz7lKbtepctQxSOkBRmqZ2 C/SUojQA==; Received: from mail-qv1-xf49.google.com ([2607:f8b0:4864:20::f49]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5K-00043y-OD for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:00 +0000 Received: by mail-qv1-xf49.google.com with SMTP id q19so4912qvs.5 for ; Wed, 04 Nov 2020 15:20:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=oA6gmttblv8OmG3VJbCFTsqSwJTzGphkOsRK2ZeD750=; b=br613dpyefM6H17vxZ5Q4p0T39IrkLkDnZLDTiqqPDpFMMgCo+4VFo3LKvZ1P6Dslp Mf0CE4Fw8PeS1fwsbMEmuShN8+EPmelyh7nDN5LzLby357nasoxjb1LANRxkuexwVPYe LwxGSUVFyLKhDH7ttzPPyxGueeWEhdpcVUDqW8ywGJLzVo4fA0K/aUx0n7km3P0JtRv3 Bp90RJW5FmSu2QzXaJFlBCHC5YOHK7dIZG60fFIdPzS0+fZH/bTCh+FrxoeQO07FhrqG RDBlgXLvB97eS/lAALxVKBMD+H2a58tt8HMP59QEf4qm99yP2PbJYpKXnSdMApGfMszG ugBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=oA6gmttblv8OmG3VJbCFTsqSwJTzGphkOsRK2ZeD750=; b=Q/HAGsNRJLE5PY87QknJN08ViFzzYNqHBlfR/M3/lRdYVdv2yP9XDn5zed4fmWbpOS 03j5VeV8dg6NPWG2gBXQFdyTGplShCDkFjXLOD8/6noIu8jKoO8niOLLLw9Z8BokHXgp 6zBkbbhtCMB5/jHIYfZTDxEAi37E8fiVkL+JkOKpM4N/P5ZzuW34uEl1t1YhtwrLSiad bEXQVqLohRFqtpWh1p8KciItCCuGQ5xvMMkRqLrJI6+vQbY2eTCVx/dK1KFJ/j1aPfAX 9HrH9xTTuxPKuT3wAEAOMuO89G1shUd9L3Ledn+vwJOYSWxRzxaBiXv8RcVtRScOtp88 jA2w== X-Gm-Message-State: AOAM531GLz3LCk8lN5B5cgrRVv4kKn9LEI8nUgfTD42mxCmM/wm6vssw v6G5DRlqgBhs6oJBQbAZ0GSYvhziYuwBZjtz X-Google-Smtp-Source: ABdhPJw3SygWDpOISuAZQmg79+TdwGrWwFo7fxBzvvQW4z2e0Vzd9qlw00Tr0XM9KlVC8zJMzixPFDkx2UiyGedC X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:414d:: with SMTP id z13mr147192qvp.37.1604531997034; Wed, 04 Nov 2020 15:19:57 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:36 +0100 In-Reply-To: Message-Id: <45dce4028d9f5e4c5705b481a8ac37bf516caa16.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 21/43] kasan: kasan_non_canonical_hook only for software modes From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232058_945730_7DE9A3CD X-CRM114-Status: GOOD ( 11.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. kasan_non_canonical_hook() is only applicable to KASAN modes that use shadow memory, and won't be needed for hardware tag-based KASAN. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: Icc9f5ef100a2e86f3a4214a0c3131a68266181b2 --- mm/kasan/report.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 5d5733831ad7..594bad2a3a5e 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -403,7 +403,8 @@ bool kasan_report(unsigned long addr, size_t size, bool is_write, return ret; } -#ifdef CONFIG_KASAN_INLINE +#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ + defined(CONFIG_KASAN_INLINE) /* * With CONFIG_KASAN_INLINE, accesses to bogus pointers (outside the high * canonical half of the address space) cause out-of-bounds shadow memory reads From patchwork Wed Nov 4 23:18:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883265 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D7ACC00A89 for ; Thu, 5 Nov 2020 05:11:33 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AA95C206D5 for ; Thu, 5 Nov 2020 05:11:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="mrV3tM1I"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="IRATQeJJ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="ZSx/SUZk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AA95C206D5 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=p/HVdRUMpAN4oGlluJTih86ZyJPVDlJZxI4WS6ZaxEk=; b=mrV3tM1II3MWgsqSzpqUvjt6Z TEdnvWEf1Sg8qK78bc2rSvuglxUEpWrgDVQPfs6XtdE2ZEobjqrEbwIskrkar97dBgNG4rLa4rglt byq/PAxO7GikHHG0px+gptkN3z3OtSDA9/BFbCvEURRJ/GkTSnfhn9PeZT/fO2OmbvDAbVkRsX7Z0 N+1QTmA9UClSeCP91xSHghTSRx7Y6pcQi7WZ/O6Iz9tTQbGQxSUFYvXDon4AgxR/i/CnGG56orDKq ZLjzwo0p/ImYSbY4LNRo4jhSXa+Isdx6seO7xOSBTb7i6bE2P1RHcNQDzJYTKs5gULIzf0vHyqG3V m3pF2zlLA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXWa-0006YW-9a; Thu, 05 Nov 2020 05:09:28 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5D-000145-O8 for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=85BahkB/ARH3bXDyEMCLh1SMwp72o82khunrv9SMNJc=; b=IRATQeJJxmeValWU1A+w6G/NEZ eIlyLk76ZjDvOzDPU/ZUTmiyb15pljL7QFMs93Izf3VhjhRUuUnY11C2sChbhPrVmJFYI9+0i9cvG JF/sr+j+Hvf75+ISJcCanHLasde6P+CfpMmgmQZ9dSqYk9/fYMMgJ32lxaUvXqgdO4NAKoNf4u3xb W54wBwAQ7fgEUu1PNLBi1CCDGViNvR6XVAbmQxG+Us+RwXqgMq2EZyNG8dlrvx90F6fkkpyouoXPW dMbofEgF5Ex6p2gmal37QlA7ZfCaXLNMct2JJho4J6ItxuA5SxNh8p+I+ItOeD5aGd6AjKao1VNMJ QM9SkIag==; Received: from mail-qt1-x84a.google.com ([2607:f8b0:4864:20::84a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5N-00044W-CA for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:03 +0000 Received: by mail-qt1-x84a.google.com with SMTP id l12so47697qtu.22 for ; Wed, 04 Nov 2020 15:21:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=85BahkB/ARH3bXDyEMCLh1SMwp72o82khunrv9SMNJc=; b=ZSx/SUZkoPccCRj9OftK35AirVXNnRtp71K5sDqNMlvALJiDEVVRbRbzni4v+KpEn6 DR5qqfRr/HSb/5m93J1kjvN9bTrwdSivj2gbYskR57KH3/2fnHjS49zgRnf0XLBh7rTs TLIRmN9t69+li/zc8WOODCJDawuxRFoF7JJjpm5OVD4kXwtUqZ64BCR+rdIOLKZHXzaQ aY/VSzpkX3qDkZyveOcv4Yk62lSY8x0QOg95iZjPHujmoFBUFcpb42QtebEUpYUUDvYs fGiNAL0NQynN6Gx32F2eyMAHd93Z8x7NZ1jLXOSvuSzfc4TN6tOuhfaz1zohnDWnSxBI 9TVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=85BahkB/ARH3bXDyEMCLh1SMwp72o82khunrv9SMNJc=; b=lLhG1V8CwUGBqmCAqmmlqvM291RC4rhSQDgGP1viVICwpUASpD5ul6j1RE2HKjM8C8 F7GR2wNK5QubimAMCCbM6fMdYJnpoKbAhNF778ZoGEJdZKICFjBFcZmtqT2GmFgYwKxs vUNTQm4vlC7kydWwqN/4uN2xyGNeZWw7jkFgGjERdevx743XFWv6/f1HYkr8rjOSxWHW O+TYnGH/JuQbokxXRTqG8cmdL/SK6MI+Yp02oQjPQ5pejuKCFMu8AP69riUCwDnqPd2Q v7LJ7kxc+N7YVGoV+m4TuiL2S9xsD9jUOeAtfalp4PeMs5fKgwp9YEdyvaQ2RBuM22kL nv/A== X-Gm-Message-State: AOAM533kdO8Uu8Npo8I7LtRA4X92QjS2DcwS9/OYH7LJpvXEUEkTdOET fkHLMamCcUNNVIx7K6fw6NHtfw1dtczKdQ93 X-Google-Smtp-Source: ABdhPJxfI6kOiOxV7S8W+SnVGnmgLZBRR87caA7tfhL0oTiavOqISUFp7aEvbTK9SlXVrVm0rxc3OyFfrW6Sbyp4 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:a8e4:: with SMTP id h36mr421233qvc.24.1604531999270; Wed, 04 Nov 2020 15:19:59 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:37 +0100 In-Reply-To: Message-Id: <5ec82ee9aaa25e2f15ddfbe292632de1d78b87b5.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 22/43] kasan: rename SHADOW layout macros to META From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232101_522790_166B25EA X-CRM114-Status: GOOD ( 14.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Hardware tag-based KASAN won't be using shadow memory, but will reuse these macros. Rename "SHADOW" to implementation-neutral "META". No functional changes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: Id2d836bf43b401bce1221cc06e745185f17b1cc --- mm/kasan/report.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 594bad2a3a5e..8c588588c88f 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -33,11 +33,11 @@ #include "kasan.h" #include "../slab.h" -/* Shadow layout customization. */ -#define SHADOW_BYTES_PER_BLOCK 1 -#define SHADOW_BLOCKS_PER_ROW 16 -#define SHADOW_BYTES_PER_ROW (SHADOW_BLOCKS_PER_ROW * SHADOW_BYTES_PER_BLOCK) -#define SHADOW_ROWS_AROUND_ADDR 2 +/* Metadata layout customization. */ +#define META_BYTES_PER_BLOCK 1 +#define META_BLOCKS_PER_ROW 16 +#define META_BYTES_PER_ROW (META_BLOCKS_PER_ROW * META_BYTES_PER_BLOCK) +#define META_ROWS_AROUND_ADDR 2 static unsigned long kasan_flags; @@ -240,7 +240,7 @@ static void print_address_description(void *addr, u8 tag) static bool row_is_guilty(const void *row, const void *guilty) { - return (row <= guilty) && (guilty < row + SHADOW_BYTES_PER_ROW); + return (row <= guilty) && (guilty < row + META_BYTES_PER_ROW); } static int shadow_pointer_offset(const void *row, const void *shadow) @@ -249,7 +249,7 @@ static int shadow_pointer_offset(const void *row, const void *shadow) * 3 + (BITS_PER_LONG/8)*2 chars. */ return 3 + (BITS_PER_LONG/8)*2 + (shadow - row)*2 + - (shadow - row) / SHADOW_BYTES_PER_BLOCK + 1; + (shadow - row) / META_BYTES_PER_BLOCK + 1; } static void print_memory_metadata(const void *addr) @@ -259,15 +259,15 @@ static void print_memory_metadata(const void *addr) const void *shadow_row; shadow_row = (void *)round_down((unsigned long)shadow, - SHADOW_BYTES_PER_ROW) - - SHADOW_ROWS_AROUND_ADDR * SHADOW_BYTES_PER_ROW; + META_BYTES_PER_ROW) + - META_ROWS_AROUND_ADDR * META_BYTES_PER_ROW; pr_err("Memory state around the buggy address:\n"); - for (i = -SHADOW_ROWS_AROUND_ADDR; i <= SHADOW_ROWS_AROUND_ADDR; i++) { + for (i = -META_ROWS_AROUND_ADDR; i <= META_ROWS_AROUND_ADDR; i++) { const void *kaddr = kasan_shadow_to_mem(shadow_row); char buffer[4 + (BITS_PER_LONG/8)*2]; - char shadow_buf[SHADOW_BYTES_PER_ROW]; + char shadow_buf[META_BYTES_PER_ROW]; snprintf(buffer, sizeof(buffer), (i == 0) ? ">%px: " : " %px: ", kaddr); @@ -276,17 +276,17 @@ static void print_memory_metadata(const void *addr) * function, because generic functions may try to * access kasan mapping for the passed address. */ - memcpy(shadow_buf, shadow_row, SHADOW_BYTES_PER_ROW); + memcpy(shadow_buf, shadow_row, META_BYTES_PER_ROW); print_hex_dump(KERN_ERR, buffer, - DUMP_PREFIX_NONE, SHADOW_BYTES_PER_ROW, 1, - shadow_buf, SHADOW_BYTES_PER_ROW, 0); + DUMP_PREFIX_NONE, META_BYTES_PER_ROW, 1, + shadow_buf, META_BYTES_PER_ROW, 0); if (row_is_guilty(shadow_row, shadow)) pr_err("%*c\n", shadow_pointer_offset(shadow_row, shadow), '^'); - shadow_row += SHADOW_BYTES_PER_ROW; + shadow_row += META_BYTES_PER_ROW; } } From patchwork Wed Nov 4 23:18:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883085 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 724FCC00A89 for ; Thu, 5 Nov 2020 03:59:39 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F01EB20786 for ; Thu, 5 Nov 2020 03:59:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="IRRJ5F4W"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Vhbuxs5h"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="nlq0ae6l" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F01EB20786 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=yRNvo/IlxI/Y2WI5XjzBTnGSjXeAWY74mzWKsKCp+ps=; b=IRRJ5F4WkEEUHKzpn10RwQON3 tJGdBf/0yEa0D/JB9TO2ttIAhPCdYA3TOU9KiySE3fQzBHv3d7pVFQJEaosQZH0UMIFPxc5lgg9vW fbB98NCvg6Dw+cqnZ0tFe9hkRgBXkPeOzW2LZJ0PZmMeZpbCAg06DKAKET+DQyWXc3/GP8kRJ+4Ig VS4Qr2YN94Gs7oET9SU93jwc2URyNeu7gu7AszNBayPUZnjBLSMd2rNd54CQLhFropa47C1xKbxUb vDRMta3U0HFMxAffEh0kmTETP6b9AUtwYk2AXn7bBPGHm1GVAqPDQmTmCmMaFjbERzbtmDfYayiyb mPCrf2QAg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWPa-0000wN-Nj; Thu, 05 Nov 2020 03:58:10 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5C-00016k-Ie for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=s8weaoqIU+OhPShGjW212iwVWBqAcMiIGQ+gi/SNz/0=; b=Vhbuxs5hVz/wUsfspmW9xw7RPy N6RLq+bRoin2CcdskaufQStqaHqTdYyWhDO0cT4r5+xRTrM8SdDbC1WeVWgI1/ROnxyjaXmsGSypr W1d9FjvDDsubdhYr0/NuS5zrakW3/1aDACHAuxXNE/L4dAVwz0f7lm6OSIomTMnq8vYFiL9KfX/Db XiPjNW2judS6bAdBFaTkvbe21oBrOnqrwkEOC0/dpmqA9jPT2O2Ody6WodIev/tD/AKPn/Yw2K5gL vbIUdPkb5X5gPKbv9JGf/uWqOev6JcqCqrzg0/BUjq/zE2uwxA5ZlwraeqSpWe5DE4gBJbkaeS+Xz a1lBXF5w==; Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5Q-00044o-Gb for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:07 +0000 Received: by mail-qt1-x849.google.com with SMTP id w88so72756qtd.4 for ; Wed, 04 Nov 2020 15:21:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=s8weaoqIU+OhPShGjW212iwVWBqAcMiIGQ+gi/SNz/0=; b=nlq0ae6lZid94lqNLr8O4gac1/jmvUwomgJj3T6yS204lJda44aUnt3HKheYRzmtmO +mG+La7OJeD/MPOLDP4M+gfSKQF3GwPzrk1The3CbXSYcpIt6+73wOXZSbhperEoBipt DjZn84FP5kZJBEb0F8wS1Z8KVPjh1ABMDjZkroq1JfggUsmulP1A4WOBmJfxemc/HVYp DS0HqSPOaWfZK9OnGdsL307wOMMldJPKG+PtC++JRLburAnWoMaQuHmhUkY71Tt6khfQ 6DXA1EPy0wJ64wf+1SdSGElqufHnTsaf2U4tG3t2rgiMOKiNMF9VgneRpCOemow1Ym8l kqKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=s8weaoqIU+OhPShGjW212iwVWBqAcMiIGQ+gi/SNz/0=; b=Dq0wt6IqGki+DQvxcXUwNJwovdNLxt4RK+nnRljo2VXkuvQ3H7caPYV6AvVLI8/0lc bZG7RIXqCRWs0tKUgjKHdyEcATPiKA+287cRHXSPMOQVbe4F4WsnmXZftN2i2ZGE/koh 8Usn8NfqnjGWwzlnFuYCjmeZWTyqOP3ZHFPXP2PswwtjpdQKhhAXY7hmHciHcsj60YUG 8/235kQ/VzTPaLRUOpgohDryP88ee2AIe2z5w9FO4V8rZBXgLhQNIONpoBpwZChl6Ju/ M+fb55QCkmrqc7M1YLC0ANrgz19UupKr+hccRStXfqakxekiDzH7PubJz9nxBUGQoEfq 4+Vg== X-Gm-Message-State: AOAM5310DD3yJOBiAs/s9LW33o07m29ZWINpm/KL8otcC+StUjmUrt6m 1DMcAvSA48Z1XCMfoFlTIY8Ik53djO3ZTk6B X-Google-Smtp-Source: ABdhPJyE1ARDVDcM7koKwX2hKX9N6xkHoXcZYfQz6YvIF3Kljm74T1tHqSzivgQiD0uuXEGs/5iN/b+hEoL3a5+E X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:90e4:: with SMTP id p91mr205477qvp.61.1604532001587; Wed, 04 Nov 2020 15:20:01 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:38 +0100 In-Reply-To: Message-Id: <8282ffd32780b36d85d86c71aac226f485c930cf.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 23/43] kasan: separate metadata_fetch_row for each mode From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232104_856177_A7C13AEC X-CRM114-Status: GOOD ( 20.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Rework print_memory_metadata() to make it agnostic with regard to the way metadata is stored. Allow providing a separate metadata_fetch_row() implementation for each KASAN mode. Hardware tag-based KASAN will provide its own implementation that doesn't use shadow memory. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: I5b0ed1d079ea776e620beca6a529a861e7dced95 --- mm/kasan/kasan.h | 8 ++++++ mm/kasan/report.c | 56 +++++++++++++++++++-------------------- mm/kasan/report_generic.c | 5 ++++ mm/kasan/report_sw_tags.c | 5 ++++ 4 files changed, 45 insertions(+), 29 deletions(-) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index f9366dfd94c9..b5b00bff358f 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -57,6 +57,13 @@ #define KASAN_ABI_VERSION 1 #endif +/* Metadata layout customization. */ +#define META_BYTES_PER_BLOCK 1 +#define META_BLOCKS_PER_ROW 16 +#define META_BYTES_PER_ROW (META_BLOCKS_PER_ROW * META_BYTES_PER_BLOCK) +#define META_MEM_BYTES_PER_ROW (META_BYTES_PER_ROW * KASAN_GRANULE_SIZE) +#define META_ROWS_AROUND_ADDR 2 + struct kasan_access_info { const void *access_addr; const void *first_bad_addr; @@ -168,6 +175,7 @@ bool check_invalid_free(void *addr); void *find_first_bad_addr(void *addr, size_t size); const char *get_bug_type(struct kasan_access_info *info); +void metadata_fetch_row(char *buffer, void *row); #if defined(CONFIG_KASAN_GENERIC) && CONFIG_KASAN_STACK void print_address_stack_frame(const void *addr); diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 8c588588c88f..8afc1a6ab202 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -33,12 +33,6 @@ #include "kasan.h" #include "../slab.h" -/* Metadata layout customization. */ -#define META_BYTES_PER_BLOCK 1 -#define META_BLOCKS_PER_ROW 16 -#define META_BYTES_PER_ROW (META_BLOCKS_PER_ROW * META_BYTES_PER_BLOCK) -#define META_ROWS_AROUND_ADDR 2 - static unsigned long kasan_flags; #define KASAN_BIT_REPORTED 0 @@ -238,55 +232,59 @@ static void print_address_description(void *addr, u8 tag) print_address_stack_frame(addr); } -static bool row_is_guilty(const void *row, const void *guilty) +static bool meta_row_is_guilty(const void *row, const void *addr) { - return (row <= guilty) && (guilty < row + META_BYTES_PER_ROW); + return (row <= addr) && (addr < row + META_MEM_BYTES_PER_ROW); } -static int shadow_pointer_offset(const void *row, const void *shadow) +static int meta_pointer_offset(const void *row, const void *addr) { - /* The length of ">ff00ff00ff00ff00: " is - * 3 + (BITS_PER_LONG/8)*2 chars. + /* + * Memory state around the buggy address: + * ff00ff00ff00ff00: 00 00 00 05 fe fe fe fe fe fe fe fe fe fe fe fe + * ... + * + * The length of ">ff00ff00ff00ff00: " is + * 3 + (BITS_PER_LONG / 8) * 2 chars. + * The length of each granule metadata is 2 bytes + * plus 1 byte for space. */ - return 3 + (BITS_PER_LONG/8)*2 + (shadow - row)*2 + - (shadow - row) / META_BYTES_PER_BLOCK + 1; + return 3 + (BITS_PER_LONG / 8) * 2 + + (addr - row) / KASAN_GRANULE_SIZE * 3 + 1; } static void print_memory_metadata(const void *addr) { int i; - const void *shadow = kasan_mem_to_shadow(addr); - const void *shadow_row; + void *row; - shadow_row = (void *)round_down((unsigned long)shadow, - META_BYTES_PER_ROW) - - META_ROWS_AROUND_ADDR * META_BYTES_PER_ROW; + row = (void *)round_down((unsigned long)addr, META_MEM_BYTES_PER_ROW) + - META_ROWS_AROUND_ADDR * META_MEM_BYTES_PER_ROW; pr_err("Memory state around the buggy address:\n"); for (i = -META_ROWS_AROUND_ADDR; i <= META_ROWS_AROUND_ADDR; i++) { - const void *kaddr = kasan_shadow_to_mem(shadow_row); - char buffer[4 + (BITS_PER_LONG/8)*2]; - char shadow_buf[META_BYTES_PER_ROW]; + char buffer[4 + (BITS_PER_LONG / 8) * 2]; + char metadata[META_BYTES_PER_ROW]; snprintf(buffer, sizeof(buffer), - (i == 0) ? ">%px: " : " %px: ", kaddr); + (i == 0) ? ">%px: " : " %px: ", row); + /* * We should not pass a shadow pointer to generic * function, because generic functions may try to * access kasan mapping for the passed address. */ - memcpy(shadow_buf, shadow_row, META_BYTES_PER_ROW); + metadata_fetch_row(&metadata[0], row); + print_hex_dump(KERN_ERR, buffer, DUMP_PREFIX_NONE, META_BYTES_PER_ROW, 1, - shadow_buf, META_BYTES_PER_ROW, 0); + metadata, META_BYTES_PER_ROW, 0); - if (row_is_guilty(shadow_row, shadow)) - pr_err("%*c\n", - shadow_pointer_offset(shadow_row, shadow), - '^'); + if (meta_row_is_guilty(row, addr)) + pr_err("%*c\n", meta_pointer_offset(row, addr), '^'); - shadow_row += META_BYTES_PER_ROW; + row += META_MEM_BYTES_PER_ROW; } } diff --git a/mm/kasan/report_generic.c b/mm/kasan/report_generic.c index 16ed550850e9..8a9c889872da 100644 --- a/mm/kasan/report_generic.c +++ b/mm/kasan/report_generic.c @@ -123,6 +123,11 @@ const char *get_bug_type(struct kasan_access_info *info) return get_wild_bug_type(info); } +void metadata_fetch_row(char *buffer, void *row) +{ + memcpy(buffer, kasan_mem_to_shadow(row), META_BYTES_PER_ROW); +} + #if CONFIG_KASAN_STACK static bool __must_check tokenize_frame_descr(const char **frame_descr, char *token, size_t max_tok_len, diff --git a/mm/kasan/report_sw_tags.c b/mm/kasan/report_sw_tags.c index c87d5a343b4e..add2dfe6169c 100644 --- a/mm/kasan/report_sw_tags.c +++ b/mm/kasan/report_sw_tags.c @@ -80,6 +80,11 @@ void *find_first_bad_addr(void *addr, size_t size) return p; } +void metadata_fetch_row(char *buffer, void *row) +{ + memcpy(buffer, kasan_mem_to_shadow(row), META_BYTES_PER_ROW); +} + void print_tags(u8 addr_tag, const void *addr) { u8 *shadow = (u8 *)kasan_mem_to_shadow(addr); From patchwork Wed Nov 4 23:18:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883083 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97CB5C00A89 for ; Thu, 5 Nov 2020 03:58:45 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0962520786 for ; Thu, 5 Nov 2020 03:58:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="XSrhwgnO"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="lhhcxjUx"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="C+OLyB6S" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0962520786 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=6AMgKU9ekKnwgGwMnklMMC0FJ7tsl7YsTt5rRabnqTA=; b=XSrhwgnOKuOVw18AabkvkJqZw MCW9D+KMSo0GiuNGRVcrrnvcGH67zbNTS0MLuuVlJd00ThFNdpQQ8zdhakINsXUqLyAZa+Hyq89wH kd/nV66EOwDE/CkpWDfxte1QDPGxMcpl35J6rlfGq1xlun2s0Hfada5gYTcVPfAJnwMB4WimC8igt d6yz9752si8F6FmKX+XdnV7zHdF4mLSPE/Pdt+j9sNo6phDk3ZkJWs2uAoPeiBRmuqC+U8CalH0QM uzx37MFPm5Alql2HQYd/iDUFTMEyu7ZpX1b7K9ief/8cQ4eXhtxnnl+8jmcaTiw1Ur1+NOJ+0jcBf Ku1IyvIsg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWPe-0000xf-R0; Thu, 05 Nov 2020 03:58:14 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5C-000145-IW for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=ePhrCN9LvFC2NG8TKNxFN+Gj7X1gzwcPp9/mgeUcqHQ=; b=lhhcxjUxdX/2R/HcCNiBLMf/cB D0VSL5Kx77r1sypoELUfhgie/uJjiNxMxSjfaPL1FzOBFJ0YtYfuhZrrZvpeb2UxjL2ZAQWqC3T0D qo0JUzPsfi0B2zcgjXEPhmcsSeqFI3Fc3aW9Ha1s+ve5CcvJMaJ3TpMSd6939LNMpCZW7qglrRrYD Ic4cZUpwk2s3IPsPAyfGV1gHJkSOD8sCu9ADltmfnoRw3Aht1BerJb1pRJbyPg9hC7FGHzXN5wyZy OG050LLzidPsgIzkgvGyMCKEZk9ZelmtNxFs6juwH0Ls78mh0LBhSmYMcE0D+ZDeLuktvwAi8k62g EAeyziWA==; Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5T-000455-EI for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:10 +0000 Received: by mail-wm1-x349.google.com with SMTP id u207so24330wmu.4 for ; Wed, 04 Nov 2020 15:21:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=ePhrCN9LvFC2NG8TKNxFN+Gj7X1gzwcPp9/mgeUcqHQ=; b=C+OLyB6Sff9JLLtKbp0uDfc/GKA28DIw6lwW0MLPBglUk4VKzX0PB63iCo0IiN2hmg Mj6O+jer6KakCOqcH4wXBtYO4pzh0TtpF/fJCUzQ+fkDX0DOGsMFTcUhH5WxF8QWgOXj O8dOWG9gSyD0OSZ+jV/oRcGiDs+CLC//f+/v+wBA/hhgb5hrR5J3DpYBpqVcu8GBmKoq lsiMxJfHcMagNgkCypOcmEaDQUCN+NphYLTOeFQjCnEJYK/kcahrCm9/6nYgj++T8xL2 Ci2c3EY0IAEjFDMWhZEd7NkatmoEbTjirFKTYtRZa7adSi3wz6ZVctDX99kVZFTABUQK ONeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=ePhrCN9LvFC2NG8TKNxFN+Gj7X1gzwcPp9/mgeUcqHQ=; b=ZlP3+wlG2RN2h8WpThUwzm5OWJkf6z3a1GiIm7IS3B52YrFNaMICTNytUu0LISfG9I 7rxjUFE6OaxcVdwynPBVO0fV4Q3Kk6fED7lKOo3QeZ0Sx2EztJ5cmKOOn91sgr6hmQSM H0Zf6BeP8MePJ3vFdrZagIqvNMvzhyPT39S+bnBIm78b8F79gOQHAbqR6fg5O/ksLyPf mbCuLrlN+vW1KfT8PtqJhGzBMuoLh9g7eheZODygW+Hq7cBhxgMkgJ0iZF8Nrctb6Rci Nieo2B9nVesXfwMFuTLPKgPv2ti+u2UE/vaA4uZ67toibdvCaWfhE6RfTYttRIhQjpn9 ixbg== X-Gm-Message-State: AOAM532XUvlvfOXfxtEZeee76zgrEIDBPrEJhN9a6IQuv4pTX5bI+QZv s+jByJ/9z7XW+gmLZ9Y6VTxeUHjSUixnO0Yv X-Google-Smtp-Source: ABdhPJwu6we4Z5OBZuGmSUCzF9eUS+7TnL8YtWz4qN7FahMt/MMmSKJRmtsqvh+Dt+lv/3AlAqthZAPUUb6e/BYZ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:600c:216:: with SMTP id 22mr50135wmi.149.1604532004186; Wed, 04 Nov 2020 15:20:04 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:39 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 24/43] kasan, arm64: don't allow SW_TAGS with ARM64_MTE From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232107_627927_5EFEC27E X-CRM114-Status: GOOD ( 11.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Software tag-based KASAN provides its own tag checking machinery that can conflict with MTE. Don't allow enabling software tag-based KASAN when MTE is enabled. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Catalin Marinas --- Change-Id: Icd29bd0c6b1d3d7a0ee3d50c20490f404d34fc97 --- arch/arm64/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 1d466addb078..d58b4dcc6d44 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -134,7 +134,7 @@ config ARM64 select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_JUMP_LABEL_RELATIVE select HAVE_ARCH_KASAN if !(ARM64_16K_PAGES && ARM64_VA_BITS_48) - select HAVE_ARCH_KASAN_SW_TAGS if HAVE_ARCH_KASAN + select HAVE_ARCH_KASAN_SW_TAGS if (HAVE_ARCH_KASAN && !ARM64_MTE) select HAVE_ARCH_KGDB select HAVE_ARCH_MMAP_RND_BITS select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT From patchwork Wed Nov 4 23:18:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883323 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7349FC00A89 for ; Thu, 5 Nov 2020 05:30:53 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D669A2083B for ; Thu, 5 Nov 2020 05:30:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="C1I4nrUl"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="AwGcH0QH"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="rbdAsnkt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D669A2083B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=oRQrUCYtJewJqQq+VdQaal9xLGhuXhGfQxXtXL1Ml3w=; b=C1I4nrUl0EDBa1VT+QV9DTaMh oRuVAsacOXaOPSpi9T8HbHpp1L2O5TE//dxQYYSIyWSZiP0WkNv2yduEym20DgFe6hk4zpS+xLNfq FVv2/CIdxdcVAzHy6NHl2iztoHHgHiYyuDU4etUilvKkecnTHb/lfvn5eKj9WiTG1zAR8lDBXMN7l 3zR4x8dsYrMXgIfmVpcDMIThe331PItesoL/9H1/19GcvpMHWn4c1oDnEDSh/nQ4/vXCpAn87XQtt C3bWC8shg8QIH27Ny+jLZgIu4AtqhyqjOSLvjgbUpmDPPkTtbw5KTuN1sM/Gr2JVV0VpFtIytWOmX obWasSFXA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXpO-000757-Ov; Thu, 05 Nov 2020 05:28:54 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5B-00016k-HR for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=VDtcX23y6dPJZ06sfD07OvqXxdMGED0dxQgWlB1yXT4=; b=AwGcH0QHlaxRGMCXsb+IXH72FV PgS/Lc60BG+0dWTd7w1bOU0tUsum361ksYtq44Hs7J70DXsQP9qpNvEl8ZW+dvxx9pqShsJXts6Ul RvFCe6SH86921R5bj7oaMpL3k0Yp32i5hNuyLtyLrqVDJ39nfsO2giEufohtL4ZgntQuzwvN5DGRT 7d4I8f4CzR95XcpGQRuVMho18GJunSJp5N9IuL6BtETNKhc5zG9dIWy9dQ4OXdiwpFlR30KCG8/0t AN4eHKMLszRYYjuzIlKOA/UaB2pn9/lomBZl49IFYkR6poSGThyWfcPHC5U+RO8FEJ6T/co1/GJtR rgdNGI4A==; Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5W-00045R-LR for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:13 +0000 Received: by mail-qk1-x74a.google.com with SMTP id k188so14555629qke.3 for ; Wed, 04 Nov 2020 15:21:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=VDtcX23y6dPJZ06sfD07OvqXxdMGED0dxQgWlB1yXT4=; b=rbdAsnktHW+COplyrT8WwteGUq+PtKG+Z6DLPTKI4xXXSuGPl3mprkbDXhY1FiRvQ3 lOFtBMhyIyAjzJYsgtFAFViSCR+Uux3prbRaJ6Rd/kq2y636okNqxbGLu9BvjHGZ4MgM rp11KOrVzZtK0gOp1fsopqN49s2jpLCQEOsIXT+oXk150DSYVNHOAANZZ7qhRggXVb1E /kp2juunJ/ty/RM7v/FWNmn6atTQQ2Ki8PI/HFL17LkJtrIjoIWCNXHwQbVCP7V5bsIQ Y1af+YMBsw3/mM5d2u0RIXLtdWKDivpZl3MpQKQHlMNzy3zWsOFVSNL9D+45UdnbNlCy VXPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=VDtcX23y6dPJZ06sfD07OvqXxdMGED0dxQgWlB1yXT4=; b=sIwrgHF8OoMdsnBbzfp4bXHhvpyiYarkr6xsgIZBJtqA0O4i9ZHdEPpGbgjSNJ4Apo 4aHHuWePMByo9tN5anCjnkaFjd750+1VYLvB0DKHwLHszMzdzr/uHp+ic2fNjSVHfc2X M/OSuqdJZQ//TX5+ihf9g+ZOfduei7hnmJzdEfnBjOv+Jq3Uy/EhmkZm7HEccDZtSL6/ SZL2FLubjK1aj/E7R4aj+L3FCbq+bvVldZZBTNL8fj5JtdUF30Evaflo9BItNmn19ddi ufPjBTNQ5DNN6npQLLb+Bu4Lg1l/boRYUpkW3CPt3PvbTQNW8I2C71Bo7ZUQAWMWqJqX /54g== X-Gm-Message-State: AOAM530ooLGm5sWjdp4S4jUExi6wGKni8qelGxpuvBDCKDsUwizRe0+h ZKH7iv0mao77mgJ10Lpynv0NoTWoDn9l5qno X-Google-Smtp-Source: ABdhPJwkMcFjSLjggl+vwC8bp+U0nGH/vjqpJS9bd4kuwlrAD5GaDMGe5HEZmjIL/tnQp4TbhmdQ3t+0OrD/gMMo X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:560d:: with SMTP id ca13mr302386qvb.2.1604532006606; Wed, 04 Nov 2020 15:20:06 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:40 +0100 In-Reply-To: Message-Id: <9a516c6ac375d17eb0ea1cfd4f48e6cbaacdf8eb.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 25/43] kasan: introduce CONFIG_KASAN_HW_TAGS From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232110_841557_89B61398 X-CRM114-Status: GOOD ( 18.23 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This patch adds a configuration option for a new KASAN mode called hardware tag-based KASAN. This mode uses the memory tagging approach like the software tag-based mode, but relies on arm64 Memory Tagging Extension feature for tag management and access checking. Signed-off-by: Andrey Konovalov Co-developed-by: Vincenzo Frascino Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: I246c2def9fffa6563278db1bddfbe742ca7bdefe --- lib/Kconfig.kasan | 58 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan index ec59a0e26d09..e5f27ec8b254 100644 --- a/lib/Kconfig.kasan +++ b/lib/Kconfig.kasan @@ -6,7 +6,10 @@ config HAVE_ARCH_KASAN config HAVE_ARCH_KASAN_SW_TAGS bool -config HAVE_ARCH_KASAN_VMALLOC +config HAVE_ARCH_KASAN_HW_TAGS + bool + +config HAVE_ARCH_KASAN_VMALLOC bool config CC_HAS_KASAN_GENERIC @@ -20,11 +23,11 @@ config CC_HAS_WORKING_NOSANITIZE_ADDRESS menuconfig KASAN bool "KASAN: runtime memory debugger" - depends on (HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC) || \ - (HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS) + depends on (((HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC) || \ + (HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS)) && \ + CC_HAS_WORKING_NOSANITIZE_ADDRESS) || \ + HAVE_ARCH_KASAN_HW_TAGS depends on (SLUB && SYSFS) || (SLAB && !DEBUG_SLAB) - depends on CC_HAS_WORKING_NOSANITIZE_ADDRESS - select CONSTRUCTORS select STACKDEPOT help Enables KASAN (KernelAddressSANitizer) - runtime memory debugger, @@ -37,18 +40,24 @@ choice prompt "KASAN mode" default KASAN_GENERIC help - KASAN has two modes: generic KASAN (similar to userspace ASan, - x86_64/arm64/xtensa, enabled with CONFIG_KASAN_GENERIC) and - software tag-based KASAN (a version based on software memory - tagging, arm64 only, similar to userspace HWASan, enabled with - CONFIG_KASAN_SW_TAGS). + KASAN has three modes: + 1. generic KASAN (similar to userspace ASan, + x86_64/arm64/xtensa, enabled with CONFIG_KASAN_GENERIC), + 2. software tag-based KASAN (arm64 only, based on software + memory tagging (similar to userspace HWASan), enabled with + CONFIG_KASAN_SW_TAGS), and + 3. hardware tag-based KASAN (arm64 only, based on hardware + memory tagging, enabled with CONFIG_KASAN_HW_TAGS). + + All KASAN modes are strictly debugging features. - Both generic and tag-based KASAN are strictly debugging features. + For better error reports enable CONFIG_STACKTRACE. config KASAN_GENERIC bool "Generic mode" depends on HAVE_ARCH_KASAN && CC_HAS_KASAN_GENERIC select SLUB_DEBUG if SLUB + select CONSTRUCTORS help Enables generic KASAN mode. @@ -61,8 +70,6 @@ config KASAN_GENERIC and introduces an overhead of ~x1.5 for the rest of the allocations. The performance slowdown is ~x3. - For better error detection enable CONFIG_STACKTRACE. - Currently CONFIG_KASAN_GENERIC doesn't work with CONFIG_DEBUG_SLAB (the resulting kernel does not boot). @@ -70,11 +77,15 @@ config KASAN_SW_TAGS bool "Software tag-based mode" depends on HAVE_ARCH_KASAN_SW_TAGS && CC_HAS_KASAN_SW_TAGS select SLUB_DEBUG if SLUB + select CONSTRUCTORS help Enables software tag-based KASAN mode. - This mode requires Top Byte Ignore support by the CPU and therefore - is only supported for arm64. This mode requires Clang. + This mode require software memory tagging support in the form of + HWASan-like compiler instrumentation. + + Currently this mode is only implemented for arm64 CPUs and relies on + Top Byte Ignore. This mode requires Clang. This mode consumes about 1/16th of available memory at kernel start and introduces an overhead of ~20% for the rest of the allocations. @@ -82,15 +93,27 @@ config KASAN_SW_TAGS casting and comparison, as it embeds tags into the top byte of each pointer. - For better error detection enable CONFIG_STACKTRACE. - Currently CONFIG_KASAN_SW_TAGS doesn't work with CONFIG_DEBUG_SLAB (the resulting kernel does not boot). +config KASAN_HW_TAGS + bool "Hardware tag-based mode" + depends on HAVE_ARCH_KASAN_HW_TAGS + depends on SLUB + help + Enables hardware tag-based KASAN mode. + + This mode requires hardware memory tagging support, and can be used + by any architecture that provides it. + + Currently this mode is only implemented for arm64 CPUs starting from + ARMv8.5 and relies on Memory Tagging Extension and Top Byte Ignore. + endchoice choice prompt "Instrumentation type" + depends on KASAN_GENERIC || KASAN_SW_TAGS default KASAN_OUTLINE config KASAN_OUTLINE @@ -114,6 +137,7 @@ endchoice config KASAN_STACK_ENABLE bool "Enable stack instrumentation (unsafe)" if CC_IS_CLANG && !COMPILE_TEST + depends on KASAN_GENERIC || KASAN_SW_TAGS help The LLVM stack address sanitizer has a know problem that causes excessive stack usage in a lot of functions, see From patchwork Wed Nov 4 23:18:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883315 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0162CC4741F for ; Thu, 5 Nov 2020 05:29:50 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 68DA820936 for ; Thu, 5 Nov 2020 05:29:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="kSf04OvZ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="EkHfEZTT"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="p5M7LSLa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 68DA820936 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=TD++287Q+IBaBMXtwpHirqy2npv3ZPg1zl+Fo2vGR9I=; b=kSf04OvZz9bXqngC6ayQD7huL TfAl/FgK/tYfzQu0+Kg2O2/8ywWRBtUt8KIVY7H4NeZPpka6JqoEFEilAEUuWjavnieh/22CtHZSc zva0DXASNN6C38xiZAuZNKg/R8sKxnH0c9mNWbmOU8yN3s4z5SlSz1zt7JsNPDs6t/S2KGVWnjMXX 20cuVn3rmn/OhaYn3qjXK2puql9QwfZyvfDu40S7qJIgTxxFmMs2fpcjNDQrDJguM0q6SRXkSz8g9 YBxJurMNBDm5rujHvqcqJMXP7DHzP5gsAJcH6aJ92gXsLciyKTKm5nrhMqGe9YIFgjhraIZtNR/h8 TWDdOtmFA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXoO-0006aV-NT; Thu, 05 Nov 2020 05:27:52 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5B-000145-K1 for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:05 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=FlydYZzkHHsNkirizC6EMfUHVnYCnfRojTwu8q88f10=; b=EkHfEZTTIWcvDLY4Y2/rGyHR+C 5OPEdQb9X+XhVh6oEBsjV532/+BgukzsP+zxBcUDW6mfYxFMSHKpm4iouJ+BUPoOOJ4K/bDfmDCsb rVjP60tVNxdIgH4mRc77+wCVZe13X8Vn0Vwxn2OH7PJohSbQzIBxwOX2xOouy5Klo69KBqSjiO9xc Np5v4ZOuVuxRM50c6OY0TWlbgq1x3FZQ8FymDwSc7I81QFpYyOiWsOxJDOZsG7S1Ch8AmcJk6r4uC fSgRdCfZQShWhayMWN7yeGsa95d6tx8U/Y3+iD6H5ft7l6/IbJBjhnXqurLC3pSkbAun6o2dQf5DK gmM3iN6Q==; Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5W-00045Q-G3 for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:12 +0000 Received: by mail-wr1-x449.google.com with SMTP id u1so46974wri.6 for ; Wed, 04 Nov 2020 15:21:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=FlydYZzkHHsNkirizC6EMfUHVnYCnfRojTwu8q88f10=; b=p5M7LSLaT61WHDadMDBLNAMcGIKvjvrKRYa3SGUEl1sNihBTOSclx5u8f+Qo5EHr+6 /K/M6rYVP0/6LMYQMjak6x8uJ/stlKgFYI8RmUlbytD/YieCCk0bq461xG5vteDbV87h q7zMidrBXX3nA11qkrcEGRENLa+V8q0iOHBSQJnNaRnd43G/QKdtQ33bM1rV8qrK6ASm Fbt5CY4IZb18ynf9AX0rAK7lfLbADrNjjvS5SMVsvNuLWlQgvjWvUaUI3vIwvH/W4zIh /mwKwhzfd2Zbe5xAqaAGbJLjtJmBU54bFSvDGvAv1iwM33/X233VK3eCNfoh3b/h6TXl fO5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=FlydYZzkHHsNkirizC6EMfUHVnYCnfRojTwu8q88f10=; b=Y3j6y3v7G1nyDs1L6DSgYME3HDVH6hc0Vji5djcVBjmpkzNw+gbOSubxO6Fm7h6G8X 5l+SlZeLHa74yh5DCw8lCtlj0zWBwHj3MqzNx2/FlnNSsvUSgJlCQAycizOf9TQ8xAIu 5kDwnz9MHhNji3lALPNKI/Dqj6u/vtX0AJHwkcPv3vu/oybiXemWk2btV3n5gSBt3Pdr QltDJ2jP8hP+uHo8A7fwCWcd/cbNWN8oK4S3DTb7int7+T95pVl6mAF6sR6bznyPF5bn +mySXgnnfuZPD2QZNJYtNpVGg4DuTPyMw9RP7Juc4ND6292qc8HD56z8No7amW1qtxFb qhcA== X-Gm-Message-State: AOAM531KcwQ7jkexUPpCjj5fxKO6TL2dODu0rsRkwMzpvTtziE8YwkBf rjn1CuBaiXoolabCsO8NvhWIxPNG3PycHuME X-Google-Smtp-Source: ABdhPJxKCyurj8TEcTufpfKCp557hhn8rTd9/YuYr5+pEIjMzpppMattzTBc3sQQ5DICUmayYjNCq6hKLBwj/U/V X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:c937:: with SMTP id h23mr66523wml.19.1604532008922; Wed, 04 Nov 2020 15:20:08 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:41 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 26/43] arm64: Enable armv8.5-a asm-arch option From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232110_681560_1FF9A7CF X-CRM114-Status: GOOD ( 11.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vincenzo Frascino Hardware tag-based KASAN relies on Memory Tagging Extension (MTE) which is an armv8.5-a architecture extension. Enable the correct asm option when the compiler supports it in order to allow the usage of ALTERNATIVE()s with MTE instructions. Signed-off-by: Vincenzo Frascino Signed-off-by: Andrey Konovalov Reviewed-by: Catalin Marinas --- Change-Id: I172e15e4c189f073e4c14a10276b276092e76536 --- arch/arm64/Kconfig | 4 ++++ arch/arm64/Makefile | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index d58b4dcc6d44..cebbd07ba27c 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1591,6 +1591,9 @@ endmenu menu "ARMv8.5 architectural features" +config AS_HAS_ARMV8_5 + def_bool $(cc-option,-Wa$(comma)-march=armv8.5-a) + config ARM64_BTI bool "Branch Target Identification support" default y @@ -1665,6 +1668,7 @@ config ARM64_MTE bool "Memory Tagging Extension support" default y depends on ARM64_AS_HAS_MTE && ARM64_TAGGED_ADDR_ABI + depends on AS_HAS_ARMV8_5 select ARCH_USES_HIGH_VMA_FLAGS help Memory Tagging (part of the ARMv8.5 Extensions) provides diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 5789c2d18d43..50ad9cbccb51 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -100,6 +100,11 @@ ifeq ($(CONFIG_AS_HAS_ARMV8_4), y) asm-arch := armv8.4-a endif +ifeq ($(CONFIG_AS_HAS_ARMV8_5), y) +# make sure to pass the newest target architecture to -march. +asm-arch := armv8.5-a +endif + ifdef asm-arch KBUILD_CFLAGS += -Wa,-march=$(asm-arch) \ -DARM64_ASM_ARCH='"$(asm-arch)"' From patchwork Wed Nov 4 23:18:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883291 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67B43C00A89 for ; Thu, 5 Nov 2020 05:20:46 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8B34D2083B for ; Thu, 5 Nov 2020 05:20:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rBvPS+my"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="HsnDSGvJ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="YiLZqyii" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8B34D2083B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=iyjabSToRBZLJkYC/0P2KZatio8BMLvEQo5OxcJ/C14=; b=rBvPS+myqdv/QVvp5uzLcgrmo c1rsimpO1dstMhvZJulwh6Wh7OxJHR28oVnFwXkjp4j13h9pXZc7aW9pSF0E7ipHF4xutQHj/b/aL YD6u2GfkJgwpKCrVwtYU7x/a/et3fpfYzG7sShrZOsSr35TGlqFdVKzuQBz2E+LznXGf6VWqDjkPd k38+aWEc80kViRyjk4AoAGtvZ0r6Mk84qpOwhYe0LmUUtuiHyPxIpgNrUyfiuyWwMSdW0x9i8Ce6i 6tti/KGes4kCwB012KWvu7W0GIc9rB1EU9V/fsRbUVqMyS21Eqkv1rdnEEnBy86PjMVnuiRHSpZTH fP+6cVGIA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXgs-0002tl-MB; Thu, 05 Nov 2020 05:20:06 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5A-000145-MA for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=iKiZmQLw/RkryeoFhlFWSKbY6lm99BwbnzE2uZJZe40=; b=HsnDSGvJGr89+WjHs8TZwacpY3 bb8ysCeAnPMinCJzkHb+Fx4RJ2EqYDU+RnU3v+AHq1mXOjkwnZAuiv+EjKRiDXSFbHBMSxh5CxIHf qr/IEcUDspJxMmgjZWltOEB8iuIwtvH0rYOyHlbugbPsudbt8wORZDt6RVMk5J/eyJdNsEu37RaOg 9zqBCIq7CKg4Nno8Q2oN2xEQN1i4LmlydNVoPim1o0fcjb4Cc8uzdFFIMhxjZF7INJzTDRMjpKKEe VOnCwSjHkhXaRMpW0YD92DrkagxcPTRgx/MxJf6SnrIASXX4HclD44PeZlnshp/mrpfaj8QK5A+sw e2R5gNyw==; Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5Z-000462-68 for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:15 +0000 Received: by mail-wr1-x449.google.com with SMTP id t11so43523wrv.10 for ; Wed, 04 Nov 2020 15:21:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=iKiZmQLw/RkryeoFhlFWSKbY6lm99BwbnzE2uZJZe40=; b=YiLZqyiiZPFZIf1HMpZwCMoPMpzSG28nqumWhl5MoTIxAfX/KYMTDvDaPWTpAdwMND jIyVa2Z/hnvZ2uK1x/nVVApm8NzTsKTmDZmP2b8Ny2OOkqDQuLK4d84ZmoXPe8Amx5TE zW9qYCDjDC1wzH/TDNFxrKcnUrdRhASL3gK7bhxzfpbTPihNMyXn13AfERJGpFDAHuKg XZDMmPZkrAOIyc1vke/YXMw4PEbVl6cWI2c5rrf8bGS2CJuAJ+/Ji2ghlGJFYksRRVYs tWUVZeOpm52MD3o1fy2V6K8CUgm0PTjFTi/c9V9nw9sp9i2UnTTphTtPisMkz+l2yPRV pJbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=iKiZmQLw/RkryeoFhlFWSKbY6lm99BwbnzE2uZJZe40=; b=dy2B4MlQqFNzDOGNaI+cjd2D1Pr7+6m6qUMc6+1lIfHK3I0OHLvMmFHTCTpYX/4KDC 6ug3H0U7aLVupACA0s+LrLH8/oMWCYzKCBd6fUbe1WIacLsCv2YjWfkMdSpfP7I832yM WhUChE//KvxiIyS7/9EW4cVyNCKOvTLYzQcEe+jAlArril58UblReVTo7+0+373ssh+R W0A5evgBqz6lg3gUdNNgm0ymA9LmTr6xJdtzqLtehUcMp+sJ6r7QHqz8Lebw7uVcR7Kq vNSdNRJmbL0TkrrY/0wFCDi5dI+EHC/vAqI+PwaOcJGMYt6VcrigzuEeRzqRZYVRMIDW seZw== X-Gm-Message-State: AOAM5302UJCJfv7lefZIQtzHEDN0ghhW5OS6X5URJ54V9grbPqCEoT+j CZ6wtVQXINtWOMGk6WqRSsJ5XXcNhHdN2gCu X-Google-Smtp-Source: ABdhPJyqDX+dxQ7dgs1dSC7rbFkyKtaOxQjSeQjVrXheFqfJIFh+lkjgUiIkNGpwiPCLf3qXid8oQN0hE/H76iCY X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:cbc8:: with SMTP id n8mr87026wmi.124.1604532011132; Wed, 04 Nov 2020 15:20:11 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:42 +0100 In-Reply-To: Message-Id: <08de7ce49ec38f9dd279f60de78c67e6c8be3316.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 27/43] arm64: mte: Add in-kernel MTE helpers From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232113_457844_6A5113BA X-CRM114-Status: GOOD ( 23.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vincenzo Frascino Provide helper functions to manipulate allocation and pointer tags for kernel addresses. Low-level helper functions (mte_assign_*, written in assembly) operate tag values from the [0x0, 0xF] range. High-level helper functions (mte_get/set_*) use the [0xF0, 0xFF] range to preserve compatibility with normal kernel pointers that have 0xFF in their top byte. MTE_GRANULE_SIZE and related definitions are moved to mte-def.h header that doesn't have any dependencies and is safe to include into any low-level header. Signed-off-by: Vincenzo Frascino Co-developed-by: Andrey Konovalov Signed-off-by: Andrey Konovalov Reviewed-by: Catalin Marinas --- Change-Id: I1b5230254f90dc21a913447cb17f07fea7944ece --- arch/arm64/include/asm/esr.h | 1 + arch/arm64/include/asm/mte-def.h | 15 ++++++++ arch/arm64/include/asm/mte-kasan.h | 56 ++++++++++++++++++++++++++++++ arch/arm64/include/asm/mte.h | 20 +++++++---- arch/arm64/kernel/mte.c | 48 +++++++++++++++++++++++++ arch/arm64/lib/mte.S | 16 +++++++++ 6 files changed, 150 insertions(+), 6 deletions(-) create mode 100644 arch/arm64/include/asm/mte-def.h create mode 100644 arch/arm64/include/asm/mte-kasan.h diff --git a/arch/arm64/include/asm/esr.h b/arch/arm64/include/asm/esr.h index 22c81f1edda2..971c20ddfed4 100644 --- a/arch/arm64/include/asm/esr.h +++ b/arch/arm64/include/asm/esr.h @@ -105,6 +105,7 @@ #define ESR_ELx_FSC (0x3F) #define ESR_ELx_FSC_TYPE (0x3C) #define ESR_ELx_FSC_EXTABT (0x10) +#define ESR_ELx_FSC_MTE (0x11) #define ESR_ELx_FSC_SERROR (0x11) #define ESR_ELx_FSC_ACCESS (0x08) #define ESR_ELx_FSC_FAULT (0x04) diff --git a/arch/arm64/include/asm/mte-def.h b/arch/arm64/include/asm/mte-def.h new file mode 100644 index 000000000000..8401ac5840c7 --- /dev/null +++ b/arch/arm64/include/asm/mte-def.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2020 ARM Ltd. + */ +#ifndef __ASM_MTE_DEF_H +#define __ASM_MTE_DEF_H + +#define MTE_GRANULE_SIZE UL(16) +#define MTE_GRANULE_MASK (~(MTE_GRANULE_SIZE - 1)) +#define MTE_TAG_SHIFT 56 +#define MTE_TAG_SIZE 4 +#define MTE_TAG_MASK GENMASK((MTE_TAG_SHIFT + (MTE_TAG_SIZE - 1)), MTE_TAG_SHIFT) +#define MTE_TAG_MAX (MTE_TAG_MASK >> MTE_TAG_SHIFT) + +#endif /* __ASM_MTE_DEF_H */ diff --git a/arch/arm64/include/asm/mte-kasan.h b/arch/arm64/include/asm/mte-kasan.h new file mode 100644 index 000000000000..3a70fb1807fd --- /dev/null +++ b/arch/arm64/include/asm/mte-kasan.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2020 ARM Ltd. + */ +#ifndef __ASM_MTE_KASAN_H +#define __ASM_MTE_KASAN_H + +#include + +#ifndef __ASSEMBLY__ + +#include + +/* + * The functions below are meant to be used only for the + * KASAN_HW_TAGS interface defined in asm/memory.h. + */ +#ifdef CONFIG_ARM64_MTE + +static inline u8 mte_get_ptr_tag(void *ptr) +{ + /* Note: The format of KASAN tags is 0xF */ + u8 tag = 0xF0 | (u8)(((u64)(ptr)) >> MTE_TAG_SHIFT); + + return tag; +} + +u8 mte_get_mem_tag(void *addr); +u8 mte_get_random_tag(void); +void *mte_set_mem_tag_range(void *addr, size_t size, u8 tag); + +#else /* CONFIG_ARM64_MTE */ + +static inline u8 mte_get_ptr_tag(void *ptr) +{ + return 0xFF; +} + +static inline u8 mte_get_mem_tag(void *addr) +{ + return 0xFF; +} +static inline u8 mte_get_random_tag(void) +{ + return 0xFF; +} +static inline void *mte_set_mem_tag_range(void *addr, size_t size, u8 tag) +{ + return addr; +} + +#endif /* CONFIG_ARM64_MTE */ + +#endif /* __ASSEMBLY__ */ + +#endif /* __ASM_MTE_KASAN_H */ diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h index 1c99fcadb58c..cf1cd181dcb2 100644 --- a/arch/arm64/include/asm/mte.h +++ b/arch/arm64/include/asm/mte.h @@ -5,14 +5,16 @@ #ifndef __ASM_MTE_H #define __ASM_MTE_H -#define MTE_GRANULE_SIZE UL(16) -#define MTE_GRANULE_MASK (~(MTE_GRANULE_SIZE - 1)) -#define MTE_TAG_SHIFT 56 -#define MTE_TAG_SIZE 4 +#include +#include + +#define __MTE_PREAMBLE ARM64_ASM_PREAMBLE ".arch_extension memtag\n" #ifndef __ASSEMBLY__ +#include #include +#include #include @@ -45,7 +47,9 @@ long get_mte_ctrl(struct task_struct *task); int mte_ptrace_copy_tags(struct task_struct *child, long request, unsigned long addr, unsigned long data); -#else +void mte_assign_mem_tag_range(void *addr, size_t size); + +#else /* CONFIG_ARM64_MTE */ /* unused if !CONFIG_ARM64_MTE, silence the compiler */ #define PG_mte_tagged 0 @@ -80,7 +84,11 @@ static inline int mte_ptrace_copy_tags(struct task_struct *child, return -EIO; } -#endif +static inline void mte_assign_mem_tag_range(void *addr, size_t size) +{ +} + +#endif /* CONFIG_ARM64_MTE */ #endif /* __ASSEMBLY__ */ #endif /* __ASM_MTE_H */ diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index 52a0638ed967..8f99c65837fd 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -13,10 +13,13 @@ #include #include #include +#include #include +#include #include #include +#include #include #include @@ -72,6 +75,51 @@ int memcmp_pages(struct page *page1, struct page *page2) return ret; } +u8 mte_get_mem_tag(void *addr) +{ + if (!system_supports_mte()) + return 0xFF; + + asm(__MTE_PREAMBLE "ldg %0, [%0]" + : "+r" (addr)); + + return mte_get_ptr_tag(addr); +} + +u8 mte_get_random_tag(void) +{ + void *addr; + + if (!system_supports_mte()) + return 0xFF; + + asm(__MTE_PREAMBLE "irg %0, %0" + : "+r" (addr)); + + return mte_get_ptr_tag(addr); +} + +void *mte_set_mem_tag_range(void *addr, size_t size, u8 tag) +{ + void *ptr = addr; + + if ((!system_supports_mte()) || (size == 0)) + return addr; + + /* Make sure that size is MTE granule aligned. */ + WARN_ON(size & (MTE_GRANULE_SIZE - 1)); + + /* Make sure that the address is MTE granule aligned. */ + WARN_ON((u64)addr & (MTE_GRANULE_SIZE - 1)); + + tag = 0xF0 | tag; + ptr = (void *)__tag_set(ptr, tag); + + mte_assign_mem_tag_range(ptr, size); + + return ptr; +} + static void update_sctlr_el1_tcf0(u64 tcf0) { /* ISB required for the kernel uaccess routines */ diff --git a/arch/arm64/lib/mte.S b/arch/arm64/lib/mte.S index 03ca6d8b8670..ede1ea65428c 100644 --- a/arch/arm64/lib/mte.S +++ b/arch/arm64/lib/mte.S @@ -149,3 +149,19 @@ SYM_FUNC_START(mte_restore_page_tags) ret SYM_FUNC_END(mte_restore_page_tags) + +/* + * Assign allocation tags for a region of memory based on the pointer tag + * x0 - source pointer + * x1 - size + * + * Note: The address must be non-NULL and MTE_GRANULE_SIZE aligned and + * size must be non-zero and MTE_GRANULE_SIZE aligned. + */ +SYM_FUNC_START(mte_assign_mem_tag_range) +1: stg x0, [x0] + add x0, x0, #MTE_GRANULE_SIZE + subs x1, x1, #MTE_GRANULE_SIZE + b.gt 1b + ret +SYM_FUNC_END(mte_assign_mem_tag_range) From patchwork Wed Nov 4 23:18:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883289 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72F16C00A89 for ; Thu, 5 Nov 2020 05:20:22 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D5EBF2083B for ; Thu, 5 Nov 2020 05:20:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="knOLFmWe"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="CcC0FhHr"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="uWjOaiCp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D5EBF2083B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=PPWCm1tX3+4ebO8Tac/wBwmwWaPWMCmLSoyJIT6HzbE=; b=knOLFmWeNVfF+t5mCceeUOqbv TPH/yDOotOSnZfS0HSxbKVuydyiiHMSpnEWsjgWLdYimHdAT420yexP/dn3BCYu+sD5miYw1E1gqB 3EJOUwIgZszgr9gh4rPjy0DHLGCtDNuMnBZQ+NEfePn3Yjvka4baQYZlYPxxaNqEMKjgk6k+yraaP +HCaITGSO8auUK0DZcCZQ9PDQunlazwVbmxhNN283uZrPd1YD8aZIlC3Jxx+hmbXKv2MOi/lcb6Jc r/ZXpCXCpFOchbgwECizsRmSpQ32Uvv7vmWNYyWSIw+GiWVsJeFydYfRhTGcknm1+rpw10rDLhY7T iu+J8X8Dg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXgP-0002fQ-LF; Thu, 05 Nov 2020 05:19:37 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW5A-00016k-Iq for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=k0rwmvWkh3wc2lbCLJgzaa11WuGN21taMrm4zUJORUQ=; b=CcC0FhHrJm22j6E64n+RqsKczh DMc211VHQyU8xnuy8QdfDLxIAdA61I3e94f4PWtgSuA4P7xaVC+vJbD7WWI4YOqoHQ9DqHCWDqSIE XQfhiLoNjXfvlqH02rL5wSc0xVOctiuvcxU23nUzd3U+la2Yk2y3ZC9bggZeAct6/4RypTPD7XJLn QGPD+YZl51K0R8HNqpCFvttU+VjWbgDs0fk4Ij5Qh1WyKWRUEwwB00vl7l/fiTBoavhQW7iNUt8Z9 DaZF9iCO2jCjBltukagZqDPsKbzS0x4vEI3XKxyRpL6thmkdxlN/852DwYB2hSXKivLzZDRSSVYyo 5vxgrngg==; Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5c-00046Q-Qn for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:19 +0000 Received: by mail-wm1-x349.google.com with SMTP id y187so26404wmy.3 for ; Wed, 04 Nov 2020 15:21:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=k0rwmvWkh3wc2lbCLJgzaa11WuGN21taMrm4zUJORUQ=; b=uWjOaiCp/aQ7tdjvxD3necJ9LlCN2dKAwKwizWGVIexVk50McV5ni5cQWGWku5ZCFK PKvJmCjMn+bQqYqk+j0XNar7WlUsjTEnoXIzxMF5JurlYjxWSpDdiCoPQBrInZe8TepD Leze21ogS5ZK1uctnGaKZEmhAXr44QJ8D4VwFFBrFBnij6FuL5XUR3100Wi8JTT00hTd wr4UClytKAaMQDTNT9WDH3Lz9D+2x2nhJHxJR5F72qz+WLYLlFdlzLOBgJsYDpREFTjZ nZjiqj+jk+NdXsQC57jljwC3G66hiELMb32lHeUy62pZctwzbq9bPvmKHtxO5hbJ15xX lH1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=k0rwmvWkh3wc2lbCLJgzaa11WuGN21taMrm4zUJORUQ=; b=qJwMKh+ikZuPjndteD07TCKxi2AT7ITE98AMdDfK8H1dk1+61H6SHhEVLrUQhZKzTD SUHIf3hpR9zCmtw5phyyxd9vranalFXRBGnMpjOcYwnhoPFX4TG3O9gBIMC4SqZXuzy4 MDVctpy3OV6X9WBKNnYKIpJ3/XNfRstDY8DAti7M/0zF7ghdiquOyUzOyi4VCDZNS4rn A8hJ7tJYPUkYgu8oKVgpRedOHmdeB3byFhGLNYJYZlBacf4/2aX1l7jNlfImecMilfTg Rs34KEVHPh7dqT8bEXhC61gqSXxrhD1a2Whu/5RQFQdUUcljkBPnxso6arVOggoVt/tx qFzg== X-Gm-Message-State: AOAM5318OhdOWFRds3o6W001lITIQKIhU5Zs3lgN6dxvejowLzh7hGBj WahSiOtWt7EUT1YCQfNTacyUxw5ROyUBeWE9 X-Google-Smtp-Source: ABdhPJz0zucCZ65+O5+GurNj337OxWPm/l0D5EwqlzuEn6V6sXz3ts50YYxAk/os0lAiyx4hSptYSHMMX4k918L0 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:4d05:: with SMTP id o5mr87270wmh.94.1604532013713; Wed, 04 Nov 2020 15:20:13 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:43 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 28/43] arm64: mte: Reset the page tag in page->flags From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232117_037855_80C382A3 X-CRM114-Status: GOOD ( 15.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vincenzo Frascino The hardware tag-based KASAN for compatibility with the other modes stores the tag associated to a page in page->flags. Due to this the kernel faults on access when it allocates a page with an initial tag and the user changes the tags. Reset the tag associated by the kernel to a page in all the meaningful places to prevent kernel faults on access. Note: An alternative to this approach could be to modify page_to_virt(). This though could end up being racy, in fact if a CPU checks the PG_mte_tagged bit and decides that the page is not tagged but another CPU maps the same with PROT_MTE and becomes tagged the subsequent kernel access would fail. Signed-off-by: Vincenzo Frascino Signed-off-by: Andrey Konovalov --- Change-Id: I8451d438bb63364de2a3e68041e3a27866921d4e --- arch/arm64/kernel/mte.c | 1 + arch/arm64/mm/copypage.c | 1 + arch/arm64/mm/mteswap.c | 1 + 3 files changed, 3 insertions(+) diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index 8f99c65837fd..06ba6c923ab7 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -34,6 +34,7 @@ static void mte_sync_page_tags(struct page *page, pte_t *ptep, bool check_swap) return; } + page_kasan_tag_reset(page); mte_clear_page_tags(page_address(page)); } diff --git a/arch/arm64/mm/copypage.c b/arch/arm64/mm/copypage.c index 70a71f38b6a9..348f4627da08 100644 --- a/arch/arm64/mm/copypage.c +++ b/arch/arm64/mm/copypage.c @@ -22,6 +22,7 @@ void copy_highpage(struct page *to, struct page *from) copy_page(kto, kfrom); if (system_supports_mte() && test_bit(PG_mte_tagged, &from->flags)) { + page_kasan_tag_reset(to); set_bit(PG_mte_tagged, &to->flags); mte_copy_page_tags(kto, kfrom); } diff --git a/arch/arm64/mm/mteswap.c b/arch/arm64/mm/mteswap.c index c52c1847079c..0e7eccbe598a 100644 --- a/arch/arm64/mm/mteswap.c +++ b/arch/arm64/mm/mteswap.c @@ -53,6 +53,7 @@ bool mte_restore_tags(swp_entry_t entry, struct page *page) if (!tags) return false; + page_kasan_tag_reset(page); mte_restore_page_tags(page_address(page), tags); return true; From patchwork Wed Nov 4 23:18:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883087 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17695C388F9 for ; Thu, 5 Nov 2020 04:09:21 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8887320732 for ; Thu, 5 Nov 2020 04:09:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="B5/kp8mf"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="aihdbuVP"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="dmRgatD+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8887320732 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=xJYPQYdytiZHiZyZ2/Z+v3EYd42/c2cqpESAoeayrH8=; b=B5/kp8mfMf8Hv184PiE/UurHW 4JtRceSq7mM1npa3QmrqKxHQLNcEcaY/ZUvZcC9I17yqeQ6Cn63WS+Id9qaDDiVNiTGpNuHBEKmgI Oc8cB3+uFQvmATEB43cyRTSqA2EmoHKnvWPOTYP1CWg5mJuWA5XsQGKl/W2HkZ28aVho8EGVyZJbt lJXayLeLaQjitJfk3P8YhuOxJ/VGzns8SRCYWgLaQzBeRb1z0N5QqswcgNTOY/8f4tPTVSiOZsPz3 gv3D0WsFhbOEv4C+EjNAAK84rLZzpMO8iwUv65LVgotC/aV2XgmbOfbDUP5xJjHDMwRfPvEAvoFOy Gt+rdAKeg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWZ6-0003ZR-TD; Thu, 05 Nov 2020 04:08:01 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW59-00016k-Em for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=SHQTTAC6Hd6Fbj5acE+XjHaNfSSfd6dVM7XrjREAdfI=; b=aihdbuVPBlsmXXcaqIXDdV3tC8 n6o6k6tUKpkWlclu8no7/PyuFutHjlgOuhG5M+slf2PqlWjKVhnoyVU/z+n0eT5A0KioigLdPT8Rh 6rLl2xJ4hQZhKHVVo9Crg1Sukohjtv8zJbvYN2INZDAElDHZMWlLHSTPWNqrBbhGdHspc63F3P/JC fCvIyFSHwtar6lxs8dLxtk+u4VcvUtvomyR2cwd5JFZIjTWlwTZEtuHd07daYpZTksHdvqOUqyE+A bGCCAMv91dqPW/QEBJkcvWU232faJv6VUgvxA1p5CP92TE28qECRKNIMYt0osSj7LZC0cxOwRqXTP ephJzfvA==; Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5f-00046j-T4 for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:24 +0000 Received: by mail-wm1-x349.google.com with SMTP id y1so22604wma.5 for ; Wed, 04 Nov 2020 15:21:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=SHQTTAC6Hd6Fbj5acE+XjHaNfSSfd6dVM7XrjREAdfI=; b=dmRgatD+4KwlD8vDRkWm1qwcz6X931KBLbs+0dVEVgERYTxh2uCRiAOiLREksLhWty YRoxEP9m369Nn/rrRzymYGAsT9/oPOHVG9kIgPCKtD3fd0eihFwVRLk2ev/OoaTDXwJL MlqVDuKwvRrbL3x7QLaxT9zqdgZE0o9Y3DW9RIYIgwsh6R4pFCoDFd0/vKRzWD0M27fP 2vJ3bNRgRqTGpXiS8tt6D9Lbk3h6JCh1Ph8fQKvWphd07cLOpioQ1pwILZK2nWQv/ybT unUUgmirdG/N4DlbEfkvKbyHUtoX/un96wFkDOnNchFCuDI2WCJWcipCH3m4Ll60cLh0 LqcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=SHQTTAC6Hd6Fbj5acE+XjHaNfSSfd6dVM7XrjREAdfI=; b=GNdrHwHacOPj+EV7QWG6Gm78z5aeKSRFP9hnuNsrQmzJVWaHvxb1oBiR2gUn/WOUmk IDa8YDTdTDa94pppQDcMpfKK0XeFT54V4CzDaVS3EyklnYM8Z/5GyypThf1gggxPRb1M zKYOQRrWQCuk9FlaS059pfaBQ5yo2zZAkMwgUAJiHgAvFGPWW4eAQZx0VBX8yyyHcYoq se8oBJcsK2UySCbJF/FPQN00e4YXLbFRHk2x6qxV3WHgVQfr+6ZSUE8qco5TvPnetQ3k PTOANTlL50EcIIx6rpx8xPehORrDfzDgmeeB9W8bo8PbcsQlDQWFJEJDGzXjzfnEVXkO Lt5g== X-Gm-Message-State: AOAM532pcMLLO4bNYM2GGlUy7BMZ5s8xCFXfMJIB5JZHTlZkmkvvQcSl Uf9BoBlLrkD7YVBGJs+5HRZBNh14mNNPf5LZ X-Google-Smtp-Source: ABdhPJyZlAFM15HsNj8Y27OfWjkPQ5brBiE/WnkgLcu2rjh7UqAl2lowj5bgDZbGEOg2aUmBh32jCZ6uAnaTyF4Z X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:adf:ff82:: with SMTP id j2mr329460wrr.401.1604532016330; Wed, 04 Nov 2020 15:20:16 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:44 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 29/43] arm64: mte: Add in-kernel tag fault handler From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232120_130363_52F25733 X-CRM114-Status: GOOD ( 20.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vincenzo Frascino Add the implementation of the in-kernel fault handler. When a tag fault happens on a kernel address: * MTE is disabled on the current CPU, * the execution continues. When a tag fault happens on a user address: * the kernel executes do_bad_area() and panics. The tag fault handler for kernel addresses is currently empty and will be filled in by a future commit. Signed-off-by: Vincenzo Frascino Co-developed-by: Andrey Konovalov Signed-off-by: Andrey Konovalov Reviewed-by: Catalin Marinas --- Change-Id: I9b8aa79567f7c45f4d6a1290efcf34567e620717 --- arch/arm64/include/asm/uaccess.h | 23 ++++++++++++++++ arch/arm64/mm/fault.c | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 991dd5f031e4..c7fff8daf2a7 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -200,13 +200,36 @@ do { \ CONFIG_ARM64_PAN)); \ } while (0) +/* + * The Tag Check Flag (TCF) mode for MTE is per EL, hence TCF0 + * affects EL0 and TCF affects EL1 irrespective of which TTBR is + * used. + * The kernel accesses TTBR0 usually with LDTR/STTR instructions + * when UAO is available, so these would act as EL0 accesses using + * TCF0. + * However futex.h code uses exclusives which would be executed as + * EL1, this can potentially cause a tag check fault even if the + * user disables TCF0. + * + * To address the problem we set the PSTATE.TCO bit in uaccess_enable() + * and reset it in uaccess_disable(). + * + * The Tag check override (TCO) bit disables temporarily the tag checking + * preventing the issue. + */ static inline void uaccess_disable(void) { + asm volatile(ALTERNATIVE("nop", SET_PSTATE_TCO(0), + ARM64_MTE, CONFIG_KASAN_HW_TAGS)); + __uaccess_disable(ARM64_HAS_PAN); } static inline void uaccess_enable(void) { + asm volatile(ALTERNATIVE("nop", SET_PSTATE_TCO(1), + ARM64_MTE, CONFIG_KASAN_HW_TAGS)); + __uaccess_enable(ARM64_HAS_PAN); } diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 1ee94002801f..fbceb14d93b1 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -296,6 +297,44 @@ static void die_kernel_fault(const char *msg, unsigned long addr, do_exit(SIGKILL); } +static void report_tag_fault(unsigned long addr, unsigned int esr, + struct pt_regs *regs) +{ +} + +static void do_tag_recovery(unsigned long addr, unsigned int esr, + struct pt_regs *regs) +{ + static bool reported = false; + + if (!READ_ONCE(reported)) { + report_tag_fault(addr, esr, regs); + WRITE_ONCE(reported, true); + } + + /* + * Disable MTE Tag Checking on the local CPU for the current EL. + * It will be done lazily on the other CPUs when they will hit a + * tag fault. + */ + sysreg_clear_set(sctlr_el1, SCTLR_ELx_TCF_MASK, SCTLR_ELx_TCF_NONE); + isb(); +} + +static bool is_el1_mte_sync_tag_check_fault(unsigned int esr) +{ + unsigned int ec = ESR_ELx_EC(esr); + unsigned int fsc = esr & ESR_ELx_FSC; + + if (ec != ESR_ELx_EC_DABT_CUR) + return false; + + if (fsc == ESR_ELx_FSC_MTE) + return true; + + return false; +} + static void __do_kernel_fault(unsigned long addr, unsigned int esr, struct pt_regs *regs) { @@ -312,6 +351,12 @@ static void __do_kernel_fault(unsigned long addr, unsigned int esr, "Ignoring spurious kernel translation fault at virtual address %016lx\n", addr)) return; + if (is_el1_mte_sync_tag_check_fault(esr)) { + do_tag_recovery(addr, esr, regs); + + return; + } + if (is_el1_permission_fault(addr, esr, regs)) { if (esr & ESR_ELx_WNR) msg = "write to read-only memory"; From patchwork Wed Nov 4 23:18:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883091 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF586C388F9 for ; Thu, 5 Nov 2020 04:09:25 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 32CAC20732 for ; Thu, 5 Nov 2020 04:09:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="enUXn85G"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="dQd5whzc"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="RkNt0KlM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 32CAC20732 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SdmoOluRf/V9sC6bEgk6XMevVAc6y0w/5OCrAhTn4Zk=; b=enUXn85G38A4R+JvU2YKGZu+A zI4Khnal9oLcOx+4IUJbJ9Pcje1GOxmZwAJRENU6YWUEYxoBtLaM5A0Q6cDGOebfElJgPMG1l/9bH U0TWnaKva/SYzWyAXyOjUGTwapdoNNWCzs/TfyfzIKCZsoUw0VJE+eiNg3zAZcrIZstIoBtPg5+vQ FUlX0jALsxU3v7rQBFbVYRCGYe7zm1g8U9ckDwTKoBrHrA1Vm8yoMW1Cc6JK/BUg2fTKWTn9qt+mY t869PeTLwVAEnyUOUxo+epVacn2VttLBa3JAgNOv/4lMQ81nJEKuAWKLsAJrlDz5knRGMt4dr83La kV7hUtbUA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWZ9-0003aV-Qe; Thu, 05 Nov 2020 04:08:03 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW59-000145-Lr for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=MtscXzxM87FBM4U9jZNGOq87ComGejjIMcvAPHhplUo=; b=dQd5whzcdPdhp4AdvFmdGjxwKv Yr4QBaAsCZEnAlBd6p1kpHaA9YkTi85QEfWcJ010VnkJrqgBoqjb4oCYnwKpqIqMjlPR54x/RZBfu BgvZndaD/o5L7AfXQtc76u65y3LAkEhH6dVVBQ/Q7Bk9Kve+qhD9nvWsk8Bf1ys7EhpFrPgnfdWSp LXu61t+cpNInWbV1FP4e/DBjxkVuzo2iQ9b8AjmyA9vhdiN9Pk6p9aVedVMpkpsZgrtm+EOoogTIM eU0LZTxDLuto7pl22ffT85cCTaEx+/qHeJjPhtU3CHoOn5LdE4JnwWKbcdyMA3fgiWQU8c98ga4CL b5vsFP5A==; Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5f-00046k-Jp for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:24 +0000 Received: by mail-wr1-x44a.google.com with SMTP id u1so47181wri.6 for ; Wed, 04 Nov 2020 15:21:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=MtscXzxM87FBM4U9jZNGOq87ComGejjIMcvAPHhplUo=; b=RkNt0KlMPVKqql5aFoLFHi6rGlddyN9w/V3DFG2q81cETVgCkQ8okQXMMbjNzMQ96I mwU7ZSEhTaXsiUWNNku5hGipjZDcCjWjUI1Ef1y1n+qOALlDfqSVTjUOgAPAXNzcEIjN GXIaoPCgj3a0abb+SjL/2vx6SooAFdwwNdqfwvXbIINa3zBfFHMTTtZVE2+cD2+AGR9j EMc4/uPUzHhKLoZy0ZJsaMlzC4K5IbkfQ24I3WSOdW/ZbJLlMW0ZGpgkqGt4Wc0s4P3i pzQT5WwpOU/al93W15vT/E+oWdj4PuJPwZJDOt5hYzh7XMLfaEc8CJ8Rb4SG0hFV95bI QhoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=MtscXzxM87FBM4U9jZNGOq87ComGejjIMcvAPHhplUo=; b=GC1JdTPc+MGaZQOn5PNYRZgMbyn8eh+ZEWvWmAnmaGiWutvsuUOH8bG4GtmjVNfkmj sERLTdCb31Tgv+u2pZ5m3vA6IbU2zru7XFBqqgz5H5rgorQTltwPkj5HN47fDDRrIjyq 9L+7ghT8ghZ8FDgu693K8kYgbUlyN0lmpQYiqFLTDgBkxdaH4zK6bRLjiLhEadeUqJ15 V0zOQcpRR7VZ6YxzkK/huDyHhhoFW+Zg+Tz1ZaKQO0nrONOv4higCL3+l345ygsBEuCx 972sfquiG6Npla7guLEQKzXnCiHB+P0r4v2lQ5bVNN2M0p4sCQL+MOHX08cDhrizBSvq mUDQ== X-Gm-Message-State: AOAM530iYJ9ZWUmkYWAOz2wjZOopVvrmQoDc+T/VfWYqzH30szmQJ6kA 62O1R0FVYhsnF9EyT2EzeL4InCbYcfi6Z/ft X-Google-Smtp-Source: ABdhPJy5wD9hF4sxdUdmxkMLqPnuuSZnyFIVK724uWXL41j9mgrpkfI3oMqKXHk2SY6X+2USrkMRcnknjIfOPhfW X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:2803:: with SMTP id o3mr59728wmo.97.1604532018890; Wed, 04 Nov 2020 15:20:18 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:45 +0100 In-Reply-To: Message-Id: <5e3c76cac4b161fe39e3fc8ace614400bc2fb5b1.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 30/43] arm64: kasan: Allow enabling in-kernel MTE From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232119_843911_2BC5A30B X-CRM114-Status: GOOD ( 19.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hardware tag-based KASAN relies on Memory Tagging Extension (MTE) feature and requires it to be enabled. MTE supports This patch adds a new mte_init_tags() helper, that enables MTE in Synchronous mode in EL1 and is intended to be called from KASAN runtime during initialization. The Tag Checking operation causes a synchronous data abort as a consequence of a tag check fault when MTE is configured in synchronous mode. As part of this change enable match-all tag for EL1 to allow the kernel to access user pages without faulting. This is required because the kernel does not have knowledge of the tags set by the user in a page. Note: For MTE, the TCF bit field in SCTLR_EL1 affects only EL1 in a similar way as TCF0 affects EL0. MTE that is built on top of the Top Byte Ignore (TBI) feature hence we enable it as part of this patch as well. Signed-off-by: Vincenzo Frascino Co-developed-by: Andrey Konovalov Signed-off-by: Andrey Konovalov --- Change-Id: I4d67497268bb7f0c2fc5dcacefa1e273df4af71d --- arch/arm64/include/asm/mte-kasan.h | 6 ++++++ arch/arm64/kernel/mte.c | 7 +++++++ arch/arm64/mm/proc.S | 23 ++++++++++++++++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/mte-kasan.h b/arch/arm64/include/asm/mte-kasan.h index 3a70fb1807fd..ae75feaea2d4 100644 --- a/arch/arm64/include/asm/mte-kasan.h +++ b/arch/arm64/include/asm/mte-kasan.h @@ -29,6 +29,8 @@ u8 mte_get_mem_tag(void *addr); u8 mte_get_random_tag(void); void *mte_set_mem_tag_range(void *addr, size_t size, u8 tag); +void __init mte_init_tags(u64 max_tag); + #else /* CONFIG_ARM64_MTE */ static inline u8 mte_get_ptr_tag(void *ptr) @@ -49,6 +51,10 @@ static inline void *mte_set_mem_tag_range(void *addr, size_t size, u8 tag) return addr; } +static inline void mte_init_tags(u64 max_tag) +{ +} + #endif /* CONFIG_ARM64_MTE */ #endif /* __ASSEMBLY__ */ diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index 06ba6c923ab7..fcfbefcc3174 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -121,6 +121,13 @@ void *mte_set_mem_tag_range(void *addr, size_t size, u8 tag) return ptr; } +void __init mte_init_tags(u64 max_tag) +{ + /* Enable MTE Sync Mode for EL1. */ + sysreg_clear_set(sctlr_el1, SCTLR_ELx_TCF_MASK, SCTLR_ELx_TCF_SYNC); + isb(); +} + static void update_sctlr_el1_tcf0(u64 tcf0) { /* ISB required for the kernel uaccess routines */ diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 23c326a06b2d..7c3304fb15d9 100644 --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -40,9 +40,15 @@ #define TCR_CACHE_FLAGS TCR_IRGN_WBWA | TCR_ORGN_WBWA #ifdef CONFIG_KASAN_SW_TAGS -#define TCR_KASAN_FLAGS TCR_TBI1 +#define TCR_KASAN_SW_FLAGS TCR_TBI1 #else -#define TCR_KASAN_FLAGS 0 +#define TCR_KASAN_SW_FLAGS 0 +#endif + +#ifdef CONFIG_KASAN_HW_TAGS +#define TCR_KASAN_HW_FLAGS SYS_TCR_EL1_TCMA1 | TCR_TBI1 +#else +#define TCR_KASAN_HW_FLAGS 0 #endif /* @@ -427,6 +433,10 @@ SYM_FUNC_START(__cpu_setup) */ mov_q x5, MAIR_EL1_SET #ifdef CONFIG_ARM64_MTE + mte_tcr .req x20 + + mov mte_tcr, #0 + /* * Update MAIR_EL1, GCR_EL1 and TFSR*_EL1 if MTE is supported * (ID_AA64PFR1_EL1[11:8] > 1). @@ -447,6 +457,9 @@ SYM_FUNC_START(__cpu_setup) /* clear any pending tag check faults in TFSR*_EL1 */ msr_s SYS_TFSR_EL1, xzr msr_s SYS_TFSRE0_EL1, xzr + + /* set the TCR_EL1 bits */ + mov_q mte_tcr, TCR_KASAN_HW_FLAGS 1: #endif msr mair_el1, x5 @@ -456,7 +469,11 @@ SYM_FUNC_START(__cpu_setup) */ mov_q x10, TCR_TxSZ(VA_BITS) | TCR_CACHE_FLAGS | TCR_SMP_FLAGS | \ TCR_TG_FLAGS | TCR_KASLR_FLAGS | TCR_ASID16 | \ - TCR_TBI0 | TCR_A1 | TCR_KASAN_FLAGS + TCR_TBI0 | TCR_A1 | TCR_KASAN_SW_FLAGS +#ifdef CONFIG_ARM64_MTE + orr x10, x10, mte_tcr + .unreq mte_tcr +#endif tcr_clear_errata_bits x10, x9, x5 #ifdef CONFIG_ARM64_VA_BITS_52 From patchwork Wed Nov 4 23:18:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C426C00A89 for ; Thu, 5 Nov 2020 04:41:18 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 727CF2083B for ; Thu, 5 Nov 2020 04:41:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="yWTq7Mmr"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="SzaIUmJF"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="q/Ff3ASA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 727CF2083B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=sTEy38SpJkAIUGOWABHjNkpEmaNu5zi3v3hhbNlG5KU=; b=yWTq7MmrWec6+LrXTrNaBuqwW 8gJEADU0+ZTnZEg6yULhuXxYi0DWw9rzFMn4tId1D66fnBKCaf+9NH7UiTtf7QvnR8U49fQd1JTeo r4MjJ8OAdjG7E9J4Sl3vLV/9lxfpWivSiimPHLyDYmEsG+C6YWeJpSrpg9i0sXgWbPt/fC50PEzu/ 7TDZ9LG0CEL2XG/baZgIxId5vuaTu3pvyBKuMnu6P6ajka2Yie+EpXW58UVCYBigJ37lFq7j6QJQi Yt9lmBwy61d0PARt5dHBWl/ZeHnRNr0TC7L6lAw6JcX9g9v52EvgRgF+A7WxOT9Eqt8oFiX3D+nAL KVy/OYclg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaX4g-0005Ch-TX; Thu, 05 Nov 2020 04:40:38 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW58-000145-NI for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=sU5rZNeX083+m80V53yNOXDsSYa9T2iypaGHB0m7hOE=; b=SzaIUmJFwvwVDlAnRO8rJmSMcH kmRHce8b0FVMQWFfnZAgOYdplS4DYLQpitlwAlSaTRlpdggXkFd8GUMyoiIu6xdcQ/j/i4dTxXF+C LeWa2+ZbZGal+H2B6dtiuag++2AQ3zrtccdqiI01Xv87lDR3KlHPwE3iK5mL9tKuumFOzDStxNH8o FpFvoG/KdM9N9FR9Halha9GSZPr5zFCyamwtYtVUnAvvd9tDZn/3jwN/43B6qoeCzuXZBqlgtE5tv ttJqlTVTkbU88NPk9A4PLcn0XmCJt/LXiusR2eDO93+2Zwxj0zs6Qs9yytXauhM2AIMC8hI+4ArTw +0jyKPkw==; Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5i-00047Z-OO for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:25 +0000 Received: by mail-wm1-x34a.google.com with SMTP id t201so30326wmt.1 for ; Wed, 04 Nov 2020 15:21:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=sU5rZNeX083+m80V53yNOXDsSYa9T2iypaGHB0m7hOE=; b=q/Ff3ASAciRWZb8tsH8KTLoieiRnH7KurmPMylbDP5XZOagsZRqGAr0Yi0qg3eiivZ TvaKD9/du4JTbSGdI5q6L9PY7nLk+Nz3TdUr8quShGDOOfHLLOC3nVbn+LxnT1jfwV1l bMFo+xbGJUmhn2jRI5z9exaPVO/JmTcTiN7bks0x8IasPR4TZOGafb9n4YN6xLEGAplZ Ru9ZscByEvCo7cD00BSlJUmMcAfWjoOY0wr+rsN3SAuHr4TDebcTaHGCo5Uw/lc1xlRM ipr6afQUNVT3FSrBR7sv/HA7Wzq19Hl2Ip0gaPsGYsRrgCoeBXGLs5to0iVS0INuKsC4 HwTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=sU5rZNeX083+m80V53yNOXDsSYa9T2iypaGHB0m7hOE=; b=hfimvxF9UMr946MYPNH+aCt8Y757hcE9klAO4fWm3bIUvOvsREY/YKsAe2xQkDoN8h iP34iaJUvXyajGoCJFXIQzPohDrGe2KyoGOLW/soOpJxUBYHLtYLc/HhxIXlmaMX0dL/ 1v1hhHhuT13QnUP5EkddMTaJtPZ/63J4pb8arEg+usp/+gfvcXlkYmNRKLXafvslbxYh /W3KvifZEUtlAkWUsQyNF4EJ5bOCpBtJMxPBb1KsVxTaJtEENkGJYd6k/L2OnnshEplq JjK7bvVjc4DIf2U7zaAYF77Frla5NiUGBBTKmxGqfaFfztIZt5zona63sW6BmvYiH/Zm az9w== X-Gm-Message-State: AOAM5339CfnVBW1+0SPm5KiUnKqOkawt4yh1GALOhf0cqxrD5G1tUziv WtdzlSBRzQieTk9RQ0D1MYW5hpJbjahUPIP1 X-Google-Smtp-Source: ABdhPJzXaFXqJdDU7XkP+DMecnDkRhOF/rW4w4gZwKN6yZFHfUkvmvl9KpoIQaKf6ID2aoTzsKtlRPzVuGHagwF3 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:2ec6:: with SMTP id u189mr57375wmu.85.1604532021347; Wed, 04 Nov 2020 15:20:21 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:46 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 31/43] arm64: mte: Convert gcr_user into an exclude mask From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232122_961927_64B55092 X-CRM114-Status: GOOD ( 17.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vincenzo Frascino The gcr_user mask is a per thread mask that represents the tags that are excluded from random generation when the Memory Tagging Extension is present and an 'irg' instruction is invoked. gcr_user affects the behavior on EL0 only. Currently that mask is an include mask and it is controlled by the user via prctl() while GCR_EL1 accepts an exclude mask. Convert the include mask into an exclude one to make it easier the register setting. Note: This change will affect gcr_kernel (for EL1) introduced with a future patch. Signed-off-by: Vincenzo Frascino Signed-off-by: Andrey Konovalov Reviewed-by: Catalin Marinas --- Change-Id: Id15c0b47582fb51594bb26fb8353d78c7d0953c1 --- arch/arm64/include/asm/processor.h | 2 +- arch/arm64/kernel/mte.c | 29 +++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/arch/arm64/include/asm/processor.h b/arch/arm64/include/asm/processor.h index fce8cbecd6bc..e8cfc41a92d4 100644 --- a/arch/arm64/include/asm/processor.h +++ b/arch/arm64/include/asm/processor.h @@ -154,7 +154,7 @@ struct thread_struct { #endif #ifdef CONFIG_ARM64_MTE u64 sctlr_tcf0; - u64 gcr_user_incl; + u64 gcr_user_excl; #endif }; diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index fcfbefcc3174..14b0c19a33e3 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -148,23 +148,22 @@ static void set_sctlr_el1_tcf0(u64 tcf0) preempt_enable(); } -static void update_gcr_el1_excl(u64 incl) +static void update_gcr_el1_excl(u64 excl) { - u64 excl = ~incl & SYS_GCR_EL1_EXCL_MASK; /* - * Note that 'incl' is an include mask (controlled by the user via - * prctl()) while GCR_EL1 accepts an exclude mask. + * Note that the mask controlled by the user via prctl() is an + * include while GCR_EL1 accepts an exclude mask. * No need for ISB since this only affects EL0 currently, implicit * with ERET. */ sysreg_clear_set_s(SYS_GCR_EL1, SYS_GCR_EL1_EXCL_MASK, excl); } -static void set_gcr_el1_excl(u64 incl) +static void set_gcr_el1_excl(u64 excl) { - current->thread.gcr_user_incl = incl; - update_gcr_el1_excl(incl); + current->thread.gcr_user_excl = excl; + update_gcr_el1_excl(excl); } void flush_mte_state(void) @@ -179,7 +178,7 @@ void flush_mte_state(void) /* disable tag checking */ set_sctlr_el1_tcf0(SCTLR_EL1_TCF0_NONE); /* reset tag generation mask */ - set_gcr_el1_excl(0); + set_gcr_el1_excl(SYS_GCR_EL1_EXCL_MASK); } void mte_thread_switch(struct task_struct *next) @@ -190,7 +189,7 @@ void mte_thread_switch(struct task_struct *next) /* avoid expensive SCTLR_EL1 accesses if no change */ if (current->thread.sctlr_tcf0 != next->thread.sctlr_tcf0) update_sctlr_el1_tcf0(next->thread.sctlr_tcf0); - update_gcr_el1_excl(next->thread.gcr_user_incl); + update_gcr_el1_excl(next->thread.gcr_user_excl); } void mte_suspend_exit(void) @@ -198,13 +197,14 @@ void mte_suspend_exit(void) if (!system_supports_mte()) return; - update_gcr_el1_excl(current->thread.gcr_user_incl); + update_gcr_el1_excl(current->thread.gcr_user_excl); } long set_mte_ctrl(struct task_struct *task, unsigned long arg) { u64 tcf0; - u64 gcr_incl = (arg & PR_MTE_TAG_MASK) >> PR_MTE_TAG_SHIFT; + u64 gcr_excl = ~((arg & PR_MTE_TAG_MASK) >> PR_MTE_TAG_SHIFT) & + SYS_GCR_EL1_EXCL_MASK; if (!system_supports_mte()) return 0; @@ -225,10 +225,10 @@ long set_mte_ctrl(struct task_struct *task, unsigned long arg) if (task != current) { task->thread.sctlr_tcf0 = tcf0; - task->thread.gcr_user_incl = gcr_incl; + task->thread.gcr_user_excl = gcr_excl; } else { set_sctlr_el1_tcf0(tcf0); - set_gcr_el1_excl(gcr_incl); + set_gcr_el1_excl(gcr_excl); } return 0; @@ -237,11 +237,12 @@ long set_mte_ctrl(struct task_struct *task, unsigned long arg) long get_mte_ctrl(struct task_struct *task) { unsigned long ret; + u64 incl = ~task->thread.gcr_user_excl & SYS_GCR_EL1_EXCL_MASK; if (!system_supports_mte()) return 0; - ret = task->thread.gcr_user_incl << PR_MTE_TAG_SHIFT; + ret = incl << PR_MTE_TAG_SHIFT; switch (task->thread.sctlr_tcf0) { case SCTLR_EL1_TCF0_NONE: From patchwork Wed Nov 4 23:18:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883193 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 404C7C00A89 for ; Thu, 5 Nov 2020 04:41:28 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B342D2087D for ; Thu, 5 Nov 2020 04:41:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="yVxEG4cM"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="D9DBABAP"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="QOLfmd7s" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B342D2087D Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=5w6AVDPWUxdinGOJnJIV30xs1ta4Kgn8vWmKOG8Y3hs=; b=yVxEG4cMR045PoaGKzu2g1+2d Jdj9H87uKpGA/BCyogTLWxE4th5UUxTMn+NzIu4WtnWH/VDpT+OhaJRuFx7udO3LQsXZ5tDEeDARr uKi68gQKv81hyTppGXNNxbH6BSuB7VgVgmkJI8pO9TEM5k2sndDI3lOyuIz9g1/Dy4+x4ECm+0kUQ lv9Y335EO+FR8lZ8e0WLWRJtJUD6C8fHZMHfXmuxCcIc8FVXGMYqyWA0FoUGm4lG4pjLjFXJXHVB0 Bsa8wrkQnGhCOjjapojYUm3cHzKw5M6IA3ElcqJ/tWZbYMDXF9WoisJEvq6t6yBRAQlftVOvFTjuX nvT+squ6g==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaX4n-0005II-1R; Thu, 05 Nov 2020 04:40:45 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW58-00016k-Gg for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=1s7WiGrMcWP0bJ51auKgm3tMrSQZgmfW9W//QveyJyE=; b=D9DBABAPqXMJ1alrYuMzFGjQ1f mWzscZ48BKnotlWKH8SnAzabSsw8pzKVlAWRtsV60y98QDTUz8CqIY+d8i0Lw/zBebpSBjVDmqGHS piW6MHW0rtUS0dyyFvfBoXfIlpoJkw8rmVhi/aR9IaWuTEvXXQqeIqserD+OgzxudI3R8lkBiKhM5 3ovMmVrGoIEaHE+31CdhOthtX/utNyLSXN5ougl8XufnKAVh/1j3lYVw9hVyokQWGBUXVwvDJnDi2 +Ebh2iquXDux55zANS/41WiLUF4t+JzYg6FLpugtAqMQ8VEWybujZt0Zbl4nE6vxvrX83N9OlxLIw ZfG4m3Fg==; Received: from mail-qv1-xf49.google.com ([2607:f8b0:4864:20::f49]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5m-000481-9x for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:28 +0000 Received: by mail-qv1-xf49.google.com with SMTP id z9so13820638qvo.20 for ; Wed, 04 Nov 2020 15:21:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=1s7WiGrMcWP0bJ51auKgm3tMrSQZgmfW9W//QveyJyE=; b=QOLfmd7sbB/uHcXb5wG4vTPM4uHt/1CVewmjlPNqFyzageoNXn4omZNoVnXK8mis6c hRoYAdMud4+BWku4nKx5xtmWuwtV9oLzmGnX2l78tQ3K1WgvBl8dv476ARKMLdVXz78k /gC9aFpeF9KDKEZf8SlvWuPQdu+jhJzPn9dTJiPml6gqrNzw2h9sST6qwYnv1aHmv005 A0mdoleOwTFSoWX/dm5Ge7tYuDIst+yu7t5a8P71me7pYKCkoggtYaYDhWMaDvyAGhUp MEDKzC9vmGMr9INVgMH7pGOxF8FY1/9KpxARjuLdbrlFVeGCOeXq4BthxOzrCg3w4gBs atVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1s7WiGrMcWP0bJ51auKgm3tMrSQZgmfW9W//QveyJyE=; b=Po+NDVHHWeQXcxvA6ngVRBGTVpoi2kJNx/s3vD3eKD18hvPlI+Xlw2SfUn4NNcIRLC mVP3VxHZ5XVfdi7LjdzgtFwNX90CFxnFxLqztONmAdlO/+o5MavewDE9XhcDEDKHIhUz i0VP1nfulxyTvZZz/Y+KBaRFrqXkc1msRQqJ0aeA/7xUNoL0nGExrKWqj/OWyiLbLQYy YykXNRR61nwIAWENxF5XL0rqi+cKB/vmQtVsD8wE9LNBfP13whLUn49TufHwMnG9dMlM LLIBqvqrhlmzuhcHvk32E3ogiplOWl7il1cX76vKgoankCmhyDYHdOpA76zDehbZFWEe 5GPw== X-Gm-Message-State: AOAM5316OdVI1rQyDZuQ4meBbym7QjnDjM+oLlbJYo1CXXm2Vmj11fib BhuI1l56W8kVshLP/jU82GpPZk4XfuRV31rh X-Google-Smtp-Source: ABdhPJyN+NYstL7F4/h7rv7aydUP0ySpi6gyHswA7hqJRVdOqBM8y3b9JxfArhQ8KqMAFVmV39FMkmg/iNsjO9zi X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:55ea:: with SMTP id bu10mr282677qvb.28.1604532023877; Wed, 04 Nov 2020 15:20:23 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:47 +0100 In-Reply-To: Message-Id: <5d9ece04df8e9d60e347a2f6f96b8c52316bfe66.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 32/43] arm64: mte: Switch GCR_EL1 in kernel entry and exit From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232126_505470_588B7EB5 X-CRM114-Status: GOOD ( 21.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vincenzo Frascino When MTE is present, the GCR_EL1 register contains the tags mask that allows to exclude tags from the random generation via the IRG instruction. With the introduction of the new Tag-Based KASAN API that provides a mechanism to reserve tags for special reasons, the MTE implementation has to make sure that the GCR_EL1 setting for the kernel does not affect the userspace processes and viceversa. Save and restore the kernel/user mask in GCR_EL1 in kernel entry and exit. Signed-off-by: Vincenzo Frascino Co-developed-by: Andrey Konovalov Signed-off-by: Andrey Konovalov Reviewed-by: Catalin Marinas --- Change-Id: I0081cba5ace27a9111bebb239075c9a466af4c84 --- arch/arm64/include/asm/mte-def.h | 1 - arch/arm64/include/asm/mte.h | 2 ++ arch/arm64/kernel/asm-offsets.c | 3 +++ arch/arm64/kernel/entry.S | 41 ++++++++++++++++++++++++++++++++ arch/arm64/kernel/mte.c | 28 +++++++++++++++++++--- 5 files changed, 71 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/mte-def.h b/arch/arm64/include/asm/mte-def.h index 8401ac5840c7..2d73a1612f09 100644 --- a/arch/arm64/include/asm/mte-def.h +++ b/arch/arm64/include/asm/mte-def.h @@ -10,6 +10,5 @@ #define MTE_TAG_SHIFT 56 #define MTE_TAG_SIZE 4 #define MTE_TAG_MASK GENMASK((MTE_TAG_SHIFT + (MTE_TAG_SIZE - 1)), MTE_TAG_SHIFT) -#define MTE_TAG_MAX (MTE_TAG_MASK >> MTE_TAG_SHIFT) #endif /* __ASM_MTE_DEF_H */ diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h index cf1cd181dcb2..d02aff9f493d 100644 --- a/arch/arm64/include/asm/mte.h +++ b/arch/arm64/include/asm/mte.h @@ -18,6 +18,8 @@ #include +extern u64 gcr_kernel_excl; + void mte_clear_page_tags(void *addr); unsigned long mte_copy_tags_from_user(void *to, const void __user *from, unsigned long n); diff --git a/arch/arm64/kernel/asm-offsets.c b/arch/arm64/kernel/asm-offsets.c index 7d32fc959b1a..dfe6ed8446ac 100644 --- a/arch/arm64/kernel/asm-offsets.c +++ b/arch/arm64/kernel/asm-offsets.c @@ -47,6 +47,9 @@ int main(void) #ifdef CONFIG_ARM64_PTR_AUTH DEFINE(THREAD_KEYS_USER, offsetof(struct task_struct, thread.keys_user)); DEFINE(THREAD_KEYS_KERNEL, offsetof(struct task_struct, thread.keys_kernel)); +#endif +#ifdef CONFIG_ARM64_MTE + DEFINE(THREAD_GCR_EL1_USER, offsetof(struct task_struct, thread.gcr_user_excl)); #endif BLANK(); DEFINE(S_X0, offsetof(struct pt_regs, regs[0])); diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S index b295fb912b12..07646ef4f184 100644 --- a/arch/arm64/kernel/entry.S +++ b/arch/arm64/kernel/entry.S @@ -173,6 +173,43 @@ alternative_else_nop_endif #endif .endm + .macro mte_set_gcr, tmp, tmp2 +#ifdef CONFIG_ARM64_MTE + /* + * Calculate and set the exclude mask preserving + * the RRND (bit[16]) setting. + */ + mrs_s \tmp2, SYS_GCR_EL1 + bfi \tmp2, \tmp, #0, #16 + msr_s SYS_GCR_EL1, \tmp2 + isb +#endif + .endm + + .macro mte_set_kernel_gcr, tmp, tmp2 +#ifdef CONFIG_KASAN_HW_TAGS +alternative_if_not ARM64_MTE + b 1f +alternative_else_nop_endif + ldr_l \tmp, gcr_kernel_excl + + mte_set_gcr \tmp, \tmp2 +1: +#endif + .endm + + .macro mte_set_user_gcr, tsk, tmp, tmp2 +#ifdef CONFIG_ARM64_MTE +alternative_if_not ARM64_MTE + b 1f +alternative_else_nop_endif + ldr \tmp, [\tsk, #THREAD_GCR_EL1_USER] + + mte_set_gcr \tmp, \tmp2 +1: +#endif + .endm + .macro kernel_entry, el, regsize = 64 .if \regsize == 32 mov w0, w0 // zero upper 32 bits of x0 @@ -212,6 +249,8 @@ alternative_else_nop_endif ptrauth_keys_install_kernel tsk, x20, x22, x23 + mte_set_kernel_gcr x22, x23 + scs_load tsk, x20 .else add x21, sp, #S_FRAME_SIZE @@ -330,6 +369,8 @@ alternative_else_nop_endif /* No kernel C function calls after this as user keys are set. */ ptrauth_keys_install_user tsk, x0, x1, x2 + mte_set_user_gcr tsk, x0, x1 + apply_ssbd 0, x0, x1 .endif diff --git a/arch/arm64/kernel/mte.c b/arch/arm64/kernel/mte.c index 14b0c19a33e3..cc7e0f8707f7 100644 --- a/arch/arm64/kernel/mte.c +++ b/arch/arm64/kernel/mte.c @@ -23,6 +23,8 @@ #include #include +u64 gcr_kernel_excl __ro_after_init; + static void mte_sync_page_tags(struct page *page, pte_t *ptep, bool check_swap) { pte_t old_pte = READ_ONCE(*ptep); @@ -123,6 +125,23 @@ void *mte_set_mem_tag_range(void *addr, size_t size, u8 tag) void __init mte_init_tags(u64 max_tag) { + static bool gcr_kernel_excl_initialized = false; + + if (!gcr_kernel_excl_initialized) { + /* + * The format of the tags in KASAN is 0xFF and in MTE is 0xF. + * This conversion extracts an MTE tag from a KASAN tag. + */ + u64 incl = GENMASK(FIELD_GET(MTE_TAG_MASK >> MTE_TAG_SHIFT, + max_tag), 0); + + gcr_kernel_excl = ~incl & SYS_GCR_EL1_EXCL_MASK; + gcr_kernel_excl_initialized = true; + } + + /* Enable the kernel exclude mask for random tags generation. */ + write_sysreg_s(SYS_GCR_EL1_RRND | gcr_kernel_excl, SYS_GCR_EL1); + /* Enable MTE Sync Mode for EL1. */ sysreg_clear_set(sctlr_el1, SCTLR_ELx_TCF_MASK, SCTLR_ELx_TCF_SYNC); isb(); @@ -163,7 +182,11 @@ static void update_gcr_el1_excl(u64 excl) static void set_gcr_el1_excl(u64 excl) { current->thread.gcr_user_excl = excl; - update_gcr_el1_excl(excl); + + /* + * SYS_GCR_EL1 will be set to current->thread.gcr_user_excl value + * by mte_set_user_gcr() in kernel_exit, + */ } void flush_mte_state(void) @@ -189,7 +212,6 @@ void mte_thread_switch(struct task_struct *next) /* avoid expensive SCTLR_EL1 accesses if no change */ if (current->thread.sctlr_tcf0 != next->thread.sctlr_tcf0) update_sctlr_el1_tcf0(next->thread.sctlr_tcf0); - update_gcr_el1_excl(next->thread.gcr_user_excl); } void mte_suspend_exit(void) @@ -197,7 +219,7 @@ void mte_suspend_exit(void) if (!system_supports_mte()) return; - update_gcr_el1_excl(current->thread.gcr_user_excl); + update_gcr_el1_excl(gcr_kernel_excl); } long set_mte_ctrl(struct task_struct *task, unsigned long arg) From patchwork Wed Nov 4 23:18:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFC96C00A89 for ; Thu, 5 Nov 2020 05:10:22 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 605CD2151B for ; Thu, 5 Nov 2020 05:10:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="3Ml9UBRg"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="espk/a+O"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="mCfoY2cp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 605CD2151B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pYX1B+JzPLoMGVnQVRc2IiXZQ6MgQ8AWI9b0G6tRiJ4=; b=3Ml9UBRg4nr3hOoxy5yHCCOuD 8BEVPSvH0t5rEeFzzIldxg9mjr0IJGS8+E2uPptCZ8hcvSSWh4pSAQyjpnnAstmJW//iXvrSllCJq GKz41s5ibdCatrWWT197mxWR1RfTzxa1CNXrz6CgiM3T+7iJg5hzeVy+ljNoleWY+kk5xjzGzen+b s9qFgBxRHDQFv9ZnDxjvm0bPU8vLpwK/FZzchyDF2MZP1b+VSKF+b6kJAI8Y14zPaYK8RF8BxTjo8 7wJjU4EJWEy6k/cNSgM5Zij2UzZj/xsHMEJRQ3or7Hwh872T8uO42ZtKqn1fwOuzQS6g4puSIo7nl Jt8ofo94A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXVQ-00065W-Kc; Thu, 05 Nov 2020 05:08:16 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW57-000145-Nx for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=G92npUQrDAzWi0FLCRrGsDUgO/xYzB+b9yo7BatUrLQ=; b=espk/a+OlWnlpyX3JNTJ3ZqRtc qSJQmbynz8wUnjQJarSiTyAfb3lIj0dP1AyjDkFNypVxwfAkd6y7WLC74YMXxwoUZDfnk5fm+DYkU ysH0aBOfc3+CgKJAJnEyJjOswAVZb3Y0ZJ8htFp6dvrxB3DIiRr9i+5D3G4nL5baSvaARVo/7pIb0 GtbHcHmb8IIsQwQMasPMficidVAcCrxbksGxlHrJ7omwTwql8lOlrF8wv1yln4DxQusVSYLQM9ayN 4AB2Nz3J+bIp3UG+kBzbpOmXePc+L1aNv5xsEkc73OvhEjFY5jOjolVI8Hzerg8W7NkQaqHzvIVVE Dfkm2lmQ==; Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5p-00048N-8i for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:31 +0000 Received: by mail-wm1-x349.google.com with SMTP id p7so5794wma.9 for ; Wed, 04 Nov 2020 15:21:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=G92npUQrDAzWi0FLCRrGsDUgO/xYzB+b9yo7BatUrLQ=; b=mCfoY2cp4+45Yg/2GkgKRvfDnEDWNJpvWB12xTWK0vuTdueKWw+4z4wH/YMCFxT/l+ Hv0xXY68/PFpfZTv01ziNJVGtDfv6QocTWuS8UhH1dEoLhGPjM4NC57IoonaZnv5R2WJ bdglNw2z26/HvPcCEZcTzjRegrgJm1WqegqASbvaI7bo4AznNU0HAyhU/h9/rK9MQ4r7 gnjWEDF6WvGFU2MMKwwF98nI3nailfbDiLeIVR2MkSI/4Epug2ksDDJeSB38qHs02aPD X/N0+CmLAvsvFNgtpwoGlIo+Dq9vDdn0FtCqeHYwM0uK2EuJLUrKQL/32w3MME18HLSE QNNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=G92npUQrDAzWi0FLCRrGsDUgO/xYzB+b9yo7BatUrLQ=; b=s3LfiXDd05qO+iuUmKTvAwMfTzdAuM5ZXmWWMq5TNsDnmO3x+F5/YfFte5pApOgKLZ LIdpEoInYxL2Y+ozlVVAQ+U5Ch+vY8ZrdpzlCBSGpScIYbqiO70KhFYOEI7+A/BnAPQ5 3XD6YF4flGfQqdn3DP+LNsF/zrhoEo2e6RuTib/z3qvb9RNjWBtFyN/T/sU/bXOks2ar hcLuA9unqA5oFpPqf9aiGwJfqd9c1eWgHLd+YmhI8LY1n2pBbhIJr4MnOBqz3mH6WCjS rFiMmLRDhtkUCbXkHTD+ZtKo/FC8ExGPoSRYaIFYfhSh/1VKFG+cm1sDRTnD6y4EtbHa WIsA== X-Gm-Message-State: AOAM5326kuJwjPsmV32GGWcDxfOp/LLuwexYV/JBoxwAaGgoCx70uhYt jK4jH9GId8RfFCAjpKA09TJyuMaagCBxNyDr X-Google-Smtp-Source: ABdhPJx59gSlNtnljRSf78Gs8PUkWDU/z1CEhdhhdjWGvP1/TZFGc547IHN93oLb7XLzSvMvsn8pTdlZNiT3UTMi X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:c772:: with SMTP id x18mr38926wmk.185.1604532026477; Wed, 04 Nov 2020 15:20:26 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:48 +0100 In-Reply-To: Message-Id: <3efc77f8b7ea2f0820524fddd4caf1a14fda94b9.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 33/43] arm64: kasan: Align allocations for HW_TAGS From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232129_466161_0FA558E2 X-CRM114-Status: GOOD ( 10.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hardware tag-based KASAN uses the memory tagging approach, which requires all allocations to be aligned to the memory granule size. Align the allocations to MTE_GRANULE_SIZE via ARCH_SLAB_MINALIGN when CONFIG_KASAN_HW_TAGS is enabled. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Catalin Marinas --- Change-Id: I51ebd3f9645e6330e5a92973bf7c86b62d632c2b --- arch/arm64/include/asm/cache.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/include/asm/cache.h b/arch/arm64/include/asm/cache.h index 63d43b5f82f6..77cbbe3625f2 100644 --- a/arch/arm64/include/asm/cache.h +++ b/arch/arm64/include/asm/cache.h @@ -6,6 +6,7 @@ #define __ASM_CACHE_H #include +#include #define CTR_L1IP_SHIFT 14 #define CTR_L1IP_MASK 3 @@ -51,6 +52,8 @@ #ifdef CONFIG_KASAN_SW_TAGS #define ARCH_SLAB_MINALIGN (1ULL << KASAN_SHADOW_SCALE_SHIFT) +#elif defined(CONFIG_KASAN_HW_TAGS) +#define ARCH_SLAB_MINALIGN MTE_GRANULE_SIZE #endif #ifndef __ASSEMBLY__ From patchwork Wed Nov 4 23:18:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883089 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AA94C388F9 for ; Thu, 5 Nov 2020 04:09:18 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E6C0A20786 for ; Thu, 5 Nov 2020 04:09:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="E0NCdsDN"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="eXeljIC2"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="MDmPTXJQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E6C0A20786 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=CpsfVXkUE3O+vAiz+B/wgJfsABriPgCspWLUvgQkJuk=; b=E0NCdsDNLHuAMI9tm1IVQPNA+ 28BikVc9m2I2ffSUcDDIfPLRis4sDhBJTg7immCMuxBZftiVh6gtxwHB4dZPY7el02DD1vstfqjkq 51zDQm+2YDewGr9oQX6E+lg1BxopOALTcli7dPzMId6NfV7b4Hk4RIZBsC5YAfS6XSCfyGN/ZUQnC 0wTbZsAgEfSV4SSrbtHBSOqh1FejCz1GTToT3plGsuu4derqcxtSfsbtlWUXxrf9vOYUx33D0/ZnH UQ586xfCxqh9Ih9dFS/o/jaJ1mwAj4h6XzM2zZfKWN1aQxfZPrC0aoVbIhCFEHarvYC9FKi+lEETu jriHNy4kw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWZ1-0003Y9-8N; Thu, 05 Nov 2020 04:07:55 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW56-000145-MU for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=VwB+r0G+nQxE1tuBjegw7DUOaY0AiMb9tMmTZBhg6+8=; b=eXeljIC2raKiOdUVPq1Ycgk806 TQNjTywLkuvo3ic0cQ24niHjSS85S015g9IW8it58LNqTrKo/kNwsRHvbghII+yygszzKq/SQgQTa Yj5t/47hNiVZSB8LzY/YEpDKfP7o+FW7F/L0jcDefaVfMrcst2l2kvPOLp8vZIBamu+YeLyMFKKW0 XNIakO/6TbG4+AlNYfckYcT/gQPvkuOssv0P9ipPU7JTgmMVYg/W5FoMYq69C/gG0Jg0JvxejAkmJ angzbsXsZtXfl35xxHg+9NpDoQEXYrwcFysKPg1ob1jxS91ARxkBXc+ETFqvbKEnhw4XucSnMewHV I9cPqrqg==; Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5s-00048s-6b for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:34 +0000 Received: by mail-wm1-x349.google.com with SMTP id o19so28271wme.2 for ; Wed, 04 Nov 2020 15:21:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=VwB+r0G+nQxE1tuBjegw7DUOaY0AiMb9tMmTZBhg6+8=; b=MDmPTXJQevl3NQ6pPgEvXpSSQtSuvY2cTzhAh3FiI69d33h3RwvxrJF8DhF4f9ozzW 38bGuVV/PLZ/cPT/AlhSH3FfbpQN9mZJ58knWztbqd6E7JMGFYQ7XWAqQyJfnNNNGDFw d5rl22jSmqJvbLqs0mPj/8hYcvCcQFMBIfiWQyKhKZRnxiW4bT/I5A56UDSnrNFCF/vA P6FRc3aJRnfbADBibKj/h59pLcE+PT8sseLnPTzIatx6eW/X7jX8BiGJ6FrffbHcc4/Z 58x0qGiCyUk2TeU4RU2RgD61GpjPYNjkeeQTO/N9ew2p8fegRjyWCv//Rs5tIMfLiwRu GxJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=VwB+r0G+nQxE1tuBjegw7DUOaY0AiMb9tMmTZBhg6+8=; b=HTxdEZWGXsf9660mTThJeXSGC6oOKAIXH6TqDZabXqgl16hsKiw9VSY7lRy+LsbXqu HigSRAvTrsEB9fcEBr/HL92q3sPxluz16SINPrq14CuyjOgtRAOysmJek7xHdOxzn0aD v0t9I/zghDN5XHb+p64D9JoJdD5CEtzQMobPebNCLm+xd2CMSSeVMo3QQu5CK5j4SOiG jHdnlUGpIYQzjYBoSPBZsGa30RsAZN0lgwTJbSCLKaOjJJmljmFr3Z5gjCqeTa7uNsU8 uodfzC6yZDtaeBxq+pw1Mu32OqvGgdk5FjnNZOLKyGXimnEmjHBVG96E+Mxhj0Nncab5 tgrw== X-Gm-Message-State: AOAM533MjJimgr1P/wIbofqNQsekFlwZz+e4Y2YpRawR9VtHyZ08yjlG irRZQktXWX4NY9coAqqLiWTrOq9xcAJVuvXe X-Google-Smtp-Source: ABdhPJxroHsqJ2INmWm39MqryU/d9TuUcrDwnrdfUwfCHfE74IyGC4tjThzYCtzqtdPk9orQeLHnvF6nrHhjcgxf X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:c101:: with SMTP id w1mr80924wmi.170.1604532028927; Wed, 04 Nov 2020 15:20:28 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:49 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 34/43] arm64: kasan: Add arch layer for memory tagging helpers From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232132_398800_4F27D9EF X-CRM114-Status: GOOD ( 13.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This patch add a set of arch_*() memory tagging helpers currently only defined for arm64 when hardware tag-based KASAN is enabled. These helpers will be used by KASAN runtime to implement the hardware tag-based mode. The arch-level indirection level is introduced to simplify adding hardware tag-based KASAN support for other architectures in the future by defining the appropriate arch_*() macros. Signed-off-by: Andrey Konovalov Co-developed-by: Vincenzo Frascino Signed-off-by: Vincenzo Frascino Reviewed-by: Catalin Marinas --- Change-Id: I42b0795a28067872f8308e00c6f0195bca435c2a --- arch/arm64/include/asm/memory.h | 8 ++++++++ mm/kasan/kasan.h | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index cd61239bae8c..580d6ef17079 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -230,6 +230,14 @@ static inline const void *__tag_set(const void *addr, u8 tag) return (const void *)(__addr | __tag_shifted(tag)); } +#ifdef CONFIG_KASAN_HW_TAGS +#define arch_init_tags(max_tag) mte_init_tags(max_tag) +#define arch_get_random_tag() mte_get_random_tag() +#define arch_get_mem_tag(addr) mte_get_mem_tag(addr) +#define arch_set_mem_tag_range(addr, size, tag) \ + mte_set_mem_tag_range((addr), (size), (tag)) +#endif /* CONFIG_KASAN_HW_TAGS */ + /* * Physical vs virtual RAM address space conversion. These are * private definitions which should NOT be used outside memory.h diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index b5b00bff358f..e3cd6a3d2b23 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -241,6 +241,28 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) #define reset_tag(addr) ((void *)arch_kasan_reset_tag(addr)) #define get_tag(addr) arch_kasan_get_tag(addr) +#ifdef CONFIG_KASAN_HW_TAGS + +#ifndef arch_init_tags +#define arch_init_tags(max_tag) +#endif +#ifndef arch_get_random_tag +#define arch_get_random_tag() (0xFF) +#endif +#ifndef arch_get_mem_tag +#define arch_get_mem_tag(addr) (0xFF) +#endif +#ifndef arch_set_mem_tag_range +#define arch_set_mem_tag_range(addr, size, tag) ((void *)(addr)) +#endif + +#define hw_init_tags(max_tag) arch_init_tags(max_tag) +#define hw_get_random_tag() arch_get_random_tag() +#define hw_get_mem_tag(addr) arch_get_mem_tag(addr) +#define hw_set_mem_tag_range(addr, size, tag) arch_set_mem_tag_range((addr), (size), (tag)) + +#endif /* CONFIG_KASAN_HW_TAGS */ + /* * Exported functions for interfaces called from assembly or from generated * code. Declarations here to avoid warning about missing declarations. From patchwork Wed Nov 4 23:18:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883093 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88BB6C00A89 for ; Thu, 5 Nov 2020 04:09:18 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E18CF20732 for ; Thu, 5 Nov 2020 04:09:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="YHmPla+0"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Q4D1Ghv1"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="vNs/tV40" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E18CF20732 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=cuLha6iFQRn21MRa67Ds6ecQbO1FX/2l7Kqn8hUsE8I=; b=YHmPla+0Y1PIOetdEzx/fVzxs QxXSuLVbF7kNdMRaVz0lzC5r1rulLrJHYcujB6214uJgYcNH2gHEpQyZXcUPM60XSJ6B1BRqowlpE ppZW7zE6NI5T/O4Cmf7szkk6/Djd+WP2bD9K8qrKHF9BpGmHOvvWS6+IaES7jIZUIrdNfsMZBXT7l kBpALy0qHr9KqpyUB5KMsJNYcoHyZR2A9ijqWWl7jcg4kKc/o4auabKWafOhsgu8vOkvyvFH/9dmQ 26M/klnp3OtkWqg5YBRPxfqDKBYAIvalMUmBPMOVQMfUjC8EL9MiPMNxIPLUeT8NLxFLz5iP6jFXw cnTRsHLNw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWYy-0003XY-CY; Thu, 05 Nov 2020 04:07:52 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW56-00016k-LF for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=E7M1YMbMIR4yMAYd8ymzpiiG9f9KaGeAaRDscMDAbI8=; b=Q4D1Ghv1SqIRYz7LsNFbduY9gA g7V7NiuIMs7qzR3PhhScE0X+yrfMcY/mKFNqGiUYCRgJApj1tfuOTH1Se9rYNp+uFW8SdiJYvXJjJ 9CzrUAbjbgF93Scd9Ej57+PpirELpufiiQXmiqcGq1xBJ2m269Cy4edc9JE/+d1I7ECnzbfP41Xw2 JgaGQhZ+Lu/E7BEq93jhoOTbqvy+Yb3vBTVwmDdhuRbvYdPokg5XqmndN13b57fGXSZM4cf26qD9b Q7SFcunSKKHREACNzNTMJdqrXNbPL+XohyBopD1knEEhGOlmi8yNqr9oRNKAVg9v5Goj5aQZDoQ/9 RXkTIIgw==; Received: from mail-qk1-x749.google.com ([2607:f8b0:4864:20::749]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5t-00048t-6O for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:35 +0000 Received: by mail-qk1-x749.google.com with SMTP id w189so14481819qkd.6 for ; Wed, 04 Nov 2020 15:21:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=E7M1YMbMIR4yMAYd8ymzpiiG9f9KaGeAaRDscMDAbI8=; b=vNs/tV40nkRYLh+bd2pRN8tnAzZTvTLYqRkQOCW6i0NqSU2MOjkywCmEziyzjFDNbr 1rXXXbldJOqtLhDCWvgATfC+KSCn3Aw1SgcbKhGaY2x/0ad9/WzaRZcunh9SZ9VhdWE+ 93GL/HUwq1B+KUAPEFz5rUbLRIrVBCkQXeDb31FsmrSWnLJ4R1ycm2wOLG0aAjeFzPNd jLN+AusTKOptQ9gIduhkrhSG92OcBcAhl87OkgzMmsZeCPCIffeaaQOvpyCBT3IoQjWh u6V6jH9lhOM7AGfqm48kv9PP2ZoAcIs2IFa3F6C/Ts6nXU4mcYfW9PncMAclN7WOtnNw P00Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=E7M1YMbMIR4yMAYd8ymzpiiG9f9KaGeAaRDscMDAbI8=; b=GKqBZ1RFdNMl+GYKBcoFQBF47XsWH0yaOqn9qXoTO1mnS4PjlAX7WbitOIchWKoIcr /uDYepOEYtf9kdjR+E2R2MZKRp8Lo4Kx3ZLtK4rW8n454bAtOiV8ueTnp4ZKqAs0GJ3t b0dY2D7lJQxHevwOnO5bcVafttYXg4O5uRNEEESE25J/8G9UuNjty4woQZpoQyzqyYRB LCQ57QxPgecrZljopwG0LYlk4jy1OmVunrSq8WC5scofank+QWCGvUXUMyEcCBhZ4w7m iqXeA7ibKRM20GbQJ9WzsshZNEkoAhyd/a4NxVX6otAs4KT9Y/YaiwJfHc+ymCtpSQD/ XBDw== X-Gm-Message-State: AOAM530EbwtqixlHR/o31ucirpbqc5JYwxaue7MqcVuWVsl7mPsDO1bE 2JDxds/WChTV5V1obO0sJm+CaYDj8poxIPsy X-Google-Smtp-Source: ABdhPJzqgs/A05RlcSOyed/F/WMpRLrfZfCyn2cPNSS5rL4ubrhak1Ah1gehiCULAgkww5qluz2BjCh1uVyX/JcV X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:4b32:: with SMTP id s18mr435733qvw.16.1604532031338; Wed, 04 Nov 2020 15:20:31 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:50 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 35/43] kasan: define KASAN_GRANULE_SIZE for HW_TAGS From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232133_380328_3DC25713 X-CRM114-Status: UNSURE ( 9.26 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hardware tag-based KASAN has granules of MTE_GRANULE_SIZE. Define KASAN_GRANULE_SIZE to MTE_GRANULE_SIZE for CONFIG_KASAN_HW_TAGS. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: I5d1117e6a991cbca00d2cfb4ba66e8ae2d8f513a --- mm/kasan/kasan.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index e3cd6a3d2b23..618e69d12f61 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -5,7 +5,13 @@ #include #include +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) #define KASAN_GRANULE_SIZE (1UL << KASAN_SHADOW_SCALE_SHIFT) +#else +#include +#define KASAN_GRANULE_SIZE MTE_GRANULE_SIZE +#endif + #define KASAN_GRANULE_MASK (KASAN_GRANULE_SIZE - 1) #define KASAN_GRANULE_PAGE (KASAN_GRANULE_SIZE << PAGE_SHIFT) From patchwork Wed Nov 4 23:18:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3533CC00A89 for ; Thu, 5 Nov 2020 04:29:53 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6E51620825 for ; Thu, 5 Nov 2020 04:29:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NKb+9J01"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="jsGorweo"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="OANIlywW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E51620825 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8fXeLdOoeqx7NrFnnX9U3bZ8W/6D9lZEigObPnQcsV0=; b=NKb+9J01eIwuAWS88YfZDjwl1 n3J6+quZCPpy3ZGn5gkDJkKQHNVVzr3vjVmzqwbnDwKE0tJSLkMy0Gd/PokkQe0JxoRQAoRn10f2M 7DwH4e1lUgqVCIqqncycVhkJiSmGS+3OoQnuhFh7ix1DVMXoLP18TSmpE9h7s+kLiJb+LSxoOflyo /Y0QLAQfmzGte3jvxOUecCTv9pWPc0270kxoB4kYJCYKsSIvq0nbEMxNRda5cWYhiiahTgFuyFrg2 CrcSdlG4QtqlfbPBC4ysv+axzOSJdBymlc1ImdtAff5TvYJj7WyslD89Kq7Tit2dKmMsiN1xgJqb8 1lUGGMz8A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWsN-0000RT-80; Thu, 05 Nov 2020 04:27:55 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW55-000145-Ni for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:36:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=7ejNZAMa5/1JIms2ONCukWsDh69PgCTWliqLjQNgQ+A=; b=jsGorweo13FJtgXG2V3nemhEE8 5e2eceq1bHa2LhW44uE/uTzXMgCWyiT01531kCMFho94GIFJ+l3mpwX0NNk/33R3CIL49mj4hNqCT xHnVX1NaYbDvmUqs2K5glNUTtlwggpEEwkpo84GT5TrLQaB7VAidgUJhQIxKwOnN/NysC2FZ4NEv5 d5BKFq7Zvu8M7EC5UM0lzOBDv4aqsKd2Hm33+5gV3sA+1D5DW4tG5sZfA3iSYGF6m4oP8jrs87aNo sFntHwC30WtN1TYFELJXRascxSnXrQ2L8YZRf9eXKntMHf3zKAtR36ILDJr4zB0CaJ50z248zPZ6y YQrueeMg==; Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5v-0004Ar-CU for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:37 +0000 Received: by mail-wr1-x44a.google.com with SMTP id i1so35985wrb.18 for ; Wed, 04 Nov 2020 15:21:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=7ejNZAMa5/1JIms2ONCukWsDh69PgCTWliqLjQNgQ+A=; b=OANIlywW0h+etUqkMvJcuxZ3OuQuc0FWR+2EY7sDDa2J4qYPs/EOi2qPBH5yWF/4h4 MDg7mZ+2i/a0GONk70Rod9wKNyIzgKbv0SwcpyA2jnHPIyGVP0NaXFpp9d4w3Of3ZOJ+ Ond0JaaMErwVbx8ixmBT907DBmgt85JJ2j3lnA++zynBfLtWZmhEK8EPP4ocJ7MXmO3W iKz7NrpJqkT75IuVLBvdPnlQ63Uw/NyRITsvGVA9bj9/hPp06xNJ+jW5APlMYBuiP5WO 3SfTsodwzUsVxmj0wgEdveNsYGIqHcMKjW6wxkcJvlvyXbHZf4dDUWPEF2LQ/KHORxn2 cZIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=7ejNZAMa5/1JIms2ONCukWsDh69PgCTWliqLjQNgQ+A=; b=CQ/C9H6XRD+e3JbfcvA76m0VW/CWU0WQc9T3FsNkSVuebWnOplBlY8biFHNmDGiWUU EBYgydFovXEWkl2cZrOm/H6M6ggy+IOMzLLTtrih9+wvb6rFfHDWfG0p/1t7ZnJ+CBAM EUv8T3wSXWKSNooaw3arQthLWXeCyF6n7C2axckt0IOifoyl77VrjEDjDgFhEG6GmupV YETdAA7FU1qAYUkYKtF85gzGyz6PUxVkZPsxm+Z1hBOIvIcio54I3ZEfK7ohfS/0ViuE SsKq1tXojQTMuLmYPn5SEuftEex385c/9V8FnlUlI+m8B/u5iB8OzKzG6Edmkdx2EMYa GY7g== X-Gm-Message-State: AOAM531E+B9fBtnajCbJvSm3L4wUmmNQP3i0mYlXhH0jua0JbVdReHgb c6plZLtmkjiUvc9IT7vjwoqxI67HB7pM0y3v X-Google-Smtp-Source: ABdhPJxt5Cgh2slN/TZHFEWjdksv3wvZX7iIDYDfj3fp74hQ3jBFqoeSWK+4bs4wFYhCSdoLLTba1d510zbvrN3B X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:600c:2252:: with SMTP id a18mr46162wmm.139.1604532033584; Wed, 04 Nov 2020 15:20:33 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:51 +0100 In-Reply-To: Message-Id: <610e97ebe0d46531ca2c988ebb26dd04d08d96c2.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 36/43] kasan, x86, s390: update undef CONFIG_KASAN From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232135_595665_3C346AA6 X-CRM114-Status: GOOD ( 11.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Vasily Gorbik , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With the intoduction of hardware tag-based KASAN some kernel checks of this kind: ifdef CONFIG_KASAN will be updated to: if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) x86 and s390 use a trick to #undef CONFIG_KASAN for some of the code that isn't linked with KASAN runtime and shouldn't have any KASAN annotations. Also #undef CONFIG_KASAN_GENERIC with CONFIG_KASAN. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver Acked-by: Vasily Gorbik --- Change-Id: I2a622db0cb86a8feb60c30d8cb09190075be2a90 --- arch/s390/boot/string.c | 1 + arch/x86/boot/compressed/misc.h | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/s390/boot/string.c b/arch/s390/boot/string.c index b11e8108773a..faccb33b462c 100644 --- a/arch/s390/boot/string.c +++ b/arch/s390/boot/string.c @@ -3,6 +3,7 @@ #include #include #undef CONFIG_KASAN +#undef CONFIG_KASAN_GENERIC #include "../lib/string.c" int strncmp(const char *cs, const char *ct, size_t count) diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h index d9a631c5973c..901ea5ebec22 100644 --- a/arch/x86/boot/compressed/misc.h +++ b/arch/x86/boot/compressed/misc.h @@ -12,6 +12,7 @@ #undef CONFIG_PARAVIRT_XXL #undef CONFIG_PARAVIRT_SPINLOCKS #undef CONFIG_KASAN +#undef CONFIG_KASAN_GENERIC /* cpu_feature_enabled() cannot be used this early */ #define USE_EARLY_PGTABLE_L5 From patchwork Wed Nov 4 23:18:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883295 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C7DFC00A89 for ; Thu, 5 Nov 2020 05:21:54 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A32192083B for ; Thu, 5 Nov 2020 05:21:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="0esqporE"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="CtWAhfi9"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="mjriG4C8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A32192083B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=NVYwV4LbR7/rMk/nqwLXm5K+qVayBaropfJnMNm1WFc=; b=0esqporEmv+uV+pUoXKL68l0U VgfePgtOB1rifZAg7MN9rEyQByf58JK8Gdii+N4JfPOez1N0Duhcb5wGP6iWPg0KFS4pZ91AAoSVu 5GBNQrandylq7/dTkV68YFgnFOEbFpBd4lEz52es8LdvcBwuZN6u8XKyxbuR31SgkNfaDxGhynpbw L7EYC0MB2SznsYZGWAHGGluTWcZzBJ7kErs+8FG9+qRhW1WO61Io8MknZkBCD6LK7zJ2zjo2LoLKf NLr7bi7dUuVtRn1Dmu6fUW75s8l6uMG8qIIE8UuKVmjpW6NMS1Lg1/la/9PHqfnEVH5K4LDyLJvR1 VNVUYK7fQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXhr-0003Ms-FB; Thu, 05 Nov 2020 05:21:07 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW54-000145-Ms for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:36:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=m6NkS/JV603XKUISQAf2uBeN8qEKz+oBJzmJFbJbenA=; b=CtWAhfi9w5mWm9URM9w6kHgWnX V+ciNVV61lwEjR02m2mrrsfYmS9U/Gipehp4q2jA8sYkM5F+4AXzPC6yLWqUWgBCLE7ScMXJfXkhk EN2C0S8RIX9lFwbdZatE9fSRFV+H/tvT1ouaSoYsDM2PbFft1v8v6MOccjOpZUNYyMY9xa7/vaD+b /9ba8qphrbAPBfq+8exeId9paOinFL8S2ix331ry/+CmQN/E/OL5qPCFscbyGI3I1LCaiD/aPfOOH x20bVyUY+95I1Dj/CZVR+b+WzxU75LWgtnXtsL2uEx3akQHySCFES31U3B7Mpb7wUgNS3GzaaBiSE uN0STwzg==; Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS60-0004DY-5o for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:43 +0000 Received: by mail-yb1-xb49.google.com with SMTP id x197so369616ybg.18 for ; Wed, 04 Nov 2020 15:21:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=m6NkS/JV603XKUISQAf2uBeN8qEKz+oBJzmJFbJbenA=; b=mjriG4C8574Aned+d7tRCxJHquPU91P3o4RudihgRFeR17dAoEVMhxq05FLNYkOMT1 vW+ClCkmI3k/taoxRt4ARV9gxLesimT+SOnh3HMpXW5seVIDg0pWm3q03nGfNeZ/Bkrg GiGpFOwVIaWW5CBbAfjnwEnJ92ITnpodfh9ju346K1iXxKbUTx2h3vW8y32rwjmITVKy 9jdxg0APYcWHeY7vttRpcI3ByE4lbWGUMaWGVgUSPRuATqn/iEQ1YeSDuuo53n+lEacl /ifFzPzu5IO8rCCiYmib+ynaTAF+R71MZolr2Yu9nkiI3qkIifTMbaNY6af9My7XgTx+ WoQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=m6NkS/JV603XKUISQAf2uBeN8qEKz+oBJzmJFbJbenA=; b=DReX6t7m8ORtUOUAi0d+5e82jn9oLYGS/iDPpG0hPhj11Q2fC8OcuDj70Fnhlw0JfS 2pHS45viS1Aj4Ekj6WdyNGmXQVk9uOeBv+SoTZodeqL4j6GWoYhp2KM3rbdklZXeT7IJ XmoKzm1X07CE7xZw2XdIiRFTlKCTHexbfvHVxr5s9TVMFWzMkVRx4nrqmI4Pj7oHIvV4 g9K0Ydo38KykKy7XKgiY+4rjURQPCKdaf/Z4PpVVDd5Bo/KH/hJisd0R9idYcjjs77vx Tds5GOA/7U5yUqQ2oiOA7e+AicmPFziS6/1H8zmc9dnmo6KZGT+o0+I4e96Xi1/zjKMB n59Q== X-Gm-Message-State: AOAM532SzMvrPDruWSS4h1tDIJH/OJmcfoHkdpI+zfmtwajge6/eDVTJ xzOSHIjTxLSd0Iqw47lKNkiMJebf0jMmqjN2 X-Google-Smtp-Source: ABdhPJx1yfyIhbtM0BQJ/FHiVt3rjyoFmvsTRGczISLDZGIMa52r6KldqLMMeRpmwoi59PqcONHL4T6m9wl0tljR X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a25:7e82:: with SMTP id z124mr287964ybc.388.1604532035849; Wed, 04 Nov 2020 15:20:35 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:52 +0100 In-Reply-To: Message-Id: <12faf1f7dc2d3f672f856e141dd9542e8a7cc7c1.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 37/43] kasan, arm64: expand CONFIG_KASAN checks From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232140_410428_CAA6697D X-CRM114-Status: GOOD ( 24.07 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Some #ifdef CONFIG_KASAN checks are only relevant for software KASAN modes (either related to shadow memory or compiler instrumentation). Expand those into CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Catalin Marinas --- Change-Id: I91e661e2c1627783cb845d877c6371dfc8779505 --- arch/arm64/Kconfig | 2 +- arch/arm64/Makefile | 2 +- arch/arm64/include/asm/assembler.h | 2 +- arch/arm64/include/asm/memory.h | 2 +- arch/arm64/include/asm/string.h | 5 +++-- arch/arm64/kernel/head.S | 2 +- arch/arm64/kernel/image-vars.h | 2 +- arch/arm64/kernel/kaslr.c | 3 ++- arch/arm64/kernel/module.c | 6 ++++-- arch/arm64/mm/ptdump.c | 6 +++--- include/linux/kasan-checks.h | 2 +- include/linux/kasan.h | 7 ++++--- include/linux/moduleloader.h | 3 ++- include/linux/string.h | 2 +- mm/ptdump.c | 13 ++++++++----- scripts/Makefile.lib | 2 ++ 16 files changed, 36 insertions(+), 25 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index cebbd07ba27c..43702780f28c 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -330,7 +330,7 @@ config BROKEN_GAS_INST config KASAN_SHADOW_OFFSET hex - depends on KASAN + depends on KASAN_GENERIC || KASAN_SW_TAGS default 0xdfffa00000000000 if (ARM64_VA_BITS_48 || ARM64_VA_BITS_52) && !KASAN_SW_TAGS default 0xdfffd00000000000 if ARM64_VA_BITS_47 && !KASAN_SW_TAGS default 0xdffffe8000000000 if ARM64_VA_BITS_42 && !KASAN_SW_TAGS diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile index 50ad9cbccb51..0b31a3f06f15 100644 --- a/arch/arm64/Makefile +++ b/arch/arm64/Makefile @@ -141,7 +141,7 @@ head-y := arch/arm64/kernel/head.o ifeq ($(CONFIG_KASAN_SW_TAGS), y) KASAN_SHADOW_SCALE_SHIFT := 4 -else +else ifeq ($(CONFIG_KASAN_GENERIC), y) KASAN_SHADOW_SCALE_SHIFT := 3 endif diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index ddbe6bf00e33..bf125c591116 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -473,7 +473,7 @@ USER(\label, ic ivau, \tmp2) // invalidate I line PoU #define NOKPROBE(x) #endif -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) #define EXPORT_SYMBOL_NOKASAN(name) #else #define EXPORT_SYMBOL_NOKASAN(name) EXPORT_SYMBOL(name) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 580d6ef17079..507012ed24f4 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -72,7 +72,7 @@ * address space for the shadow region respectively. They can bloat the stack * significantly, so double the (minimum) stack size when they are in use. */ -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) #define KASAN_SHADOW_OFFSET _AC(CONFIG_KASAN_SHADOW_OFFSET, UL) #define KASAN_SHADOW_END ((UL(1) << (64 - KASAN_SHADOW_SCALE_SHIFT)) \ + KASAN_SHADOW_OFFSET) diff --git a/arch/arm64/include/asm/string.h b/arch/arm64/include/asm/string.h index b31e8e87a0db..3a3264ff47b9 100644 --- a/arch/arm64/include/asm/string.h +++ b/arch/arm64/include/asm/string.h @@ -5,7 +5,7 @@ #ifndef __ASM_STRING_H #define __ASM_STRING_H -#ifndef CONFIG_KASAN +#if !(defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) #define __HAVE_ARCH_STRRCHR extern char *strrchr(const char *, int c); @@ -48,7 +48,8 @@ extern void *__memset(void *, int, __kernel_size_t); void memcpy_flushcache(void *dst, const void *src, size_t cnt); #endif -#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) +#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ + !defined(__SANITIZE_ADDRESS__) /* * For files that are not instrumented (e.g. mm/slub.c) we diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index d8d9caf02834..fdcb99d7ba23 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -448,7 +448,7 @@ SYM_FUNC_START_LOCAL(__primary_switched) bl __pi_memset dsb ishst // Make zero page visible to PTW -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) bl kasan_early_init #endif #ifdef CONFIG_RANDOMIZE_BASE diff --git a/arch/arm64/kernel/image-vars.h b/arch/arm64/kernel/image-vars.h index c615b285ff5b..4282edd2fe81 100644 --- a/arch/arm64/kernel/image-vars.h +++ b/arch/arm64/kernel/image-vars.h @@ -37,7 +37,7 @@ __efistub_strncmp = __pi_strncmp; __efistub_strrchr = __pi_strrchr; __efistub___clean_dcache_area_poc = __pi___clean_dcache_area_poc; -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) __efistub___memcpy = __pi_memcpy; __efistub___memmove = __pi_memmove; __efistub___memset = __pi_memset; diff --git a/arch/arm64/kernel/kaslr.c b/arch/arm64/kernel/kaslr.c index b181e0544b79..e8e17e91aa02 100644 --- a/arch/arm64/kernel/kaslr.c +++ b/arch/arm64/kernel/kaslr.c @@ -151,7 +151,8 @@ u64 __init kaslr_early_init(u64 dt_phys) /* use the top 16 bits to randomize the linear region */ memstart_offset_seed = seed >> 48; - if (IS_ENABLED(CONFIG_KASAN)) + if (IS_ENABLED(CONFIG_KASAN_GENERIC) || + IS_ENABLED(CONFIG_KASAN_SW_TAGS)) /* * KASAN does not expect the module region to intersect the * vmalloc region, since shadow memory is allocated for each diff --git a/arch/arm64/kernel/module.c b/arch/arm64/kernel/module.c index 2a1ad95d9b2c..fe21e0f06492 100644 --- a/arch/arm64/kernel/module.c +++ b/arch/arm64/kernel/module.c @@ -30,7 +30,8 @@ void *module_alloc(unsigned long size) if (IS_ENABLED(CONFIG_ARM64_MODULE_PLTS)) gfp_mask |= __GFP_NOWARN; - if (IS_ENABLED(CONFIG_KASAN)) + if (IS_ENABLED(CONFIG_KASAN_GENERIC) || + IS_ENABLED(CONFIG_KASAN_SW_TAGS)) /* don't exceed the static module region - see below */ module_alloc_end = MODULES_END; @@ -39,7 +40,8 @@ void *module_alloc(unsigned long size) NUMA_NO_NODE, __builtin_return_address(0)); if (!p && IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) && - !IS_ENABLED(CONFIG_KASAN)) + !IS_ENABLED(CONFIG_KASAN_GENERIC) && + !IS_ENABLED(CONFIG_KASAN_SW_TAGS)) /* * KASAN can only deal with module allocations being served * from the reserved module region, since the remainder of diff --git a/arch/arm64/mm/ptdump.c b/arch/arm64/mm/ptdump.c index 807dc634bbd2..04137a8f3d2d 100644 --- a/arch/arm64/mm/ptdump.c +++ b/arch/arm64/mm/ptdump.c @@ -29,7 +29,7 @@ enum address_markers_idx { PAGE_OFFSET_NR = 0, PAGE_END_NR, -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) KASAN_START_NR, #endif }; @@ -37,7 +37,7 @@ enum address_markers_idx { static struct addr_marker address_markers[] = { { PAGE_OFFSET, "Linear Mapping start" }, { 0 /* PAGE_END */, "Linear Mapping end" }, -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) { 0 /* KASAN_SHADOW_START */, "Kasan shadow start" }, { KASAN_SHADOW_END, "Kasan shadow end" }, #endif @@ -383,7 +383,7 @@ void ptdump_check_wx(void) static int ptdump_init(void) { address_markers[PAGE_END_NR].start_address = PAGE_END; -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) address_markers[KASAN_START_NR].start_address = KASAN_SHADOW_START; #endif ptdump_initialize(); diff --git a/include/linux/kasan-checks.h b/include/linux/kasan-checks.h index ac6aba632f2d..ca5e89fb10d3 100644 --- a/include/linux/kasan-checks.h +++ b/include/linux/kasan-checks.h @@ -9,7 +9,7 @@ * even in compilation units that selectively disable KASAN, but must use KASAN * to validate access to an address. Never use these in header files! */ -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) bool __kasan_check_read(const volatile void *p, unsigned int size); bool __kasan_check_write(const volatile void *p, unsigned int size); #else diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 32b9d283e0a0..beb699e90e55 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -235,7 +235,8 @@ static inline void kasan_release_vmalloc(unsigned long start, #endif /* CONFIG_KASAN_VMALLOC */ -#if defined(CONFIG_KASAN) && !defined(CONFIG_KASAN_VMALLOC) +#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ + !defined(CONFIG_KASAN_VMALLOC) /* * These functions provide a special case to support backing module @@ -245,12 +246,12 @@ static inline void kasan_release_vmalloc(unsigned long start, int kasan_module_alloc(void *addr, size_t size); void kasan_free_shadow(const struct vm_struct *vm); -#else /* CONFIG_KASAN && !CONFIG_KASAN_VMALLOC */ +#else /* (CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) && !CONFIG_KASAN_VMALLOC */ static inline int kasan_module_alloc(void *addr, size_t size) { return 0; } static inline void kasan_free_shadow(const struct vm_struct *vm) {} -#endif /* CONFIG_KASAN && !CONFIG_KASAN_VMALLOC */ +#endif /* (CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) && !CONFIG_KASAN_VMALLOC */ #ifdef CONFIG_KASAN_INLINE void kasan_non_canonical_hook(unsigned long addr); diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h index 4fa67a8b2265..9e09d11ffe5b 100644 --- a/include/linux/moduleloader.h +++ b/include/linux/moduleloader.h @@ -96,7 +96,8 @@ void module_arch_cleanup(struct module *mod); /* Any cleanup before freeing mod->module_init */ void module_arch_freeing_init(struct module *mod); -#if defined(CONFIG_KASAN) && !defined(CONFIG_KASAN_VMALLOC) +#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ + !defined(CONFIG_KASAN_VMALLOC) #include #define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT) #else diff --git a/include/linux/string.h b/include/linux/string.h index b1f3894a0a3e..016a157e2251 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -266,7 +266,7 @@ void __write_overflow(void) __compiletime_error("detected write beyond size of o #if !defined(__NO_FORTIFY) && defined(__OPTIMIZE__) && defined(CONFIG_FORTIFY_SOURCE) -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) extern void *__underlying_memchr(const void *p, int c, __kernel_size_t size) __RENAME(memchr); extern int __underlying_memcmp(const void *p, const void *q, __kernel_size_t size) __RENAME(memcmp); extern void *__underlying_memcpy(void *p, const void *q, __kernel_size_t size) __RENAME(memcpy); diff --git a/mm/ptdump.c b/mm/ptdump.c index ba88ec43ff21..4354c1422d57 100644 --- a/mm/ptdump.c +++ b/mm/ptdump.c @@ -4,7 +4,7 @@ #include #include -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) /* * This is an optimization for KASAN=y case. Since all kasan page tables * eventually point to the kasan_early_shadow_page we could call note_page() @@ -31,7 +31,8 @@ static int ptdump_pgd_entry(pgd_t *pgd, unsigned long addr, struct ptdump_state *st = walk->private; pgd_t val = READ_ONCE(*pgd); -#if CONFIG_PGTABLE_LEVELS > 4 && defined(CONFIG_KASAN) +#if CONFIG_PGTABLE_LEVELS > 4 && \ + (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) if (pgd_page(val) == virt_to_page(lm_alias(kasan_early_shadow_p4d))) return note_kasan_page_table(walk, addr); #endif @@ -51,7 +52,8 @@ static int ptdump_p4d_entry(p4d_t *p4d, unsigned long addr, struct ptdump_state *st = walk->private; p4d_t val = READ_ONCE(*p4d); -#if CONFIG_PGTABLE_LEVELS > 3 && defined(CONFIG_KASAN) +#if CONFIG_PGTABLE_LEVELS > 3 && \ + (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) if (p4d_page(val) == virt_to_page(lm_alias(kasan_early_shadow_pud))) return note_kasan_page_table(walk, addr); #endif @@ -71,7 +73,8 @@ static int ptdump_pud_entry(pud_t *pud, unsigned long addr, struct ptdump_state *st = walk->private; pud_t val = READ_ONCE(*pud); -#if CONFIG_PGTABLE_LEVELS > 2 && defined(CONFIG_KASAN) +#if CONFIG_PGTABLE_LEVELS > 2 && \ + (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) if (pud_page(val) == virt_to_page(lm_alias(kasan_early_shadow_pmd))) return note_kasan_page_table(walk, addr); #endif @@ -91,7 +94,7 @@ static int ptdump_pmd_entry(pmd_t *pmd, unsigned long addr, struct ptdump_state *st = walk->private; pmd_t val = READ_ONCE(*pmd); -#if defined(CONFIG_KASAN) +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) if (pmd_page(val) == virt_to_page(lm_alias(kasan_early_shadow_pte))) return note_kasan_page_table(walk, addr); #endif diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 94133708889d..213677a5ed33 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -148,10 +148,12 @@ endif # we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE) # ifeq ($(CONFIG_KASAN),y) +ifneq ($(CONFIG_KASAN_HW_TAGS),y) _c_flags += $(if $(patsubst n%,, \ $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \ $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE)) endif +endif ifeq ($(CONFIG_UBSAN),y) _c_flags += $(if $(patsubst n%,, \ From patchwork Wed Nov 4 23:18:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883325 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E13E3C00A89 for ; Thu, 5 Nov 2020 05:32:41 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 374DA2083B for ; Thu, 5 Nov 2020 05:32:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="v5nOXbQJ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="jKr1QXC8"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="rqy67E2U" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 374DA2083B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=yhXyHG/BXxfwn0D/6/QbWJx/uOUNoohLooYe0n20WGI=; b=v5nOXbQJ3E3elrcS5i0vh8l1f pp3MG0rLGxDCtN65F2uOg4s4z4F1oHAlljz4b+uN5v/q//PAZ0sQPiiNkwp2WBfcWx4eFH3pLknkO KdPFCpoDY57GtRSHOYApp7IWxINwH4xhDLlArKHfk5pajpm4FlXWbm1eKbqILbiBn63VxqSsLp83k HPgD0rKSC2nNkKdk+OC3XlFv7PzwDVCUZwCBUBhYTAQ80QHt9bbh8VXyGer3mEarvR/80ZIZfpJeI ZYw5ZIFhhEVIistRqQm9uMOXPbd0SmvMiDJOXF1jci5KMseNR+bbkKt3zVgfkT+F33v2CJA4jZgkl 3kRStWzjw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXr4-0007wO-OT; Thu, 05 Nov 2020 05:30:39 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW53-00016k-Mu for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:36:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=lPY7PJCK16UmR8RN2RBmgmWrbvOdJWJ4hhQCD1C5stE=; b=jKr1QXC84a1NUahuvZpHvEV4NG v/np7eUCJL+isfEM6yD45wP8xJki5pfHy+Ill2iAZIMKAxRYm0KuN1Vh4ccOiC1H0R10BZNieSSws 6sqKqJac2BUQ5w7qqmRkbJnv+4FOfPZX7WVQ8twakv2CpULLojYI7nzyf/KT1Jq7NbOrTDroT9Xn0 haMT9P8V5ObSV0+INd8O2PPgz5Bm+3VyYTMWZePfFQWXOmOcbRMf9os3DfYYONiwDtBnLQlZCZrGW sZ2WN5Pkulx/RUXaABVp5sCt92lhlzWwvjrOiUfae++GWnaT3VI+xq+BreHi53b9WP3ZNTNymHuJC SCJl3V0Q==; Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS61-0004ES-DP for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:44 +0000 Received: by mail-wm1-x34a.google.com with SMTP id t201so30635wmt.1 for ; Wed, 04 Nov 2020 15:21:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=lPY7PJCK16UmR8RN2RBmgmWrbvOdJWJ4hhQCD1C5stE=; b=rqy67E2U7XSTSSdA1kmXbyQ8gR/96UQJz4Ipzhw4VJeEPoL8MhlZ3WdHEncHovCxVK cL0LZHIi5Ze9d17xTlILNXBu2uM+GrLEtOlI1S7RE+fHAmHXq6w6nlzh0yNKD9uAvPcG feIf9k+lwObU99C3fF3ti6N+cyqGZu5OKRStSSg3vZALvVYRDKw+wduIPOVMKyAPmjyo 7ELeY8+A1bi0rwDsZvJBlwAs359hqw2QFTBY/TMfHmWkCaloGi7HyLMHG8wVjgel/RYW TVL22sDh94nGz4u0/+tJkQa6N9vsiObv6SHr07L6jsJdoJE0N37Hg931JBovUU94W8Fa m7WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=lPY7PJCK16UmR8RN2RBmgmWrbvOdJWJ4hhQCD1C5stE=; b=kM9pPszoAwhfKLyZR1trWM5T9VIdQ+h+aKqwvNLCkpmWIoWZbsMYbjz/tAKB0aETvk P4v24ZykScNY8j04MG9RBxVmv1W/OtVH3cGqj8dyZLTglTX/tQ/xhrmGlFSXxclDUvXS GzCLM2HvBaywaVLvOg4jsjqT9hXsx+vs8nhJkwOY5Am5bWcqyvnMyTfz+4NpL/f23XDu +vD/P26lBw39X+xPPe7GcslmsGEF9gGDTfIOoMDj34Lx4odMYnFVh0pXwMV/NRbGkRNG lpbJVkWYHPg/2YXctYzsgXuvkggYxiSsbf98Rr1tG7Hints50oSQqyq3IGMg9HoSHZSI ZGjw== X-Gm-Message-State: AOAM532heSn84Zcnj26gxxaLpVV9byLwvGq6XSFe3kBn0THvhQIMnw4i 26RlQkp7L5ASHt50BO6jx3SV8kcBldnubWL9 X-Google-Smtp-Source: ABdhPJzISmW6zwqqi0yIwBtgyOjdm/4FOIR5X1xkLi8+ImsaS70EF3os3K+FCCd7Nb2pLrKQtrF0Jv8f9TWu2Dzx X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:c3d5:: with SMTP id t21mr63924wmj.37.1604532038336; Wed, 04 Nov 2020 15:20:38 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:53 +0100 In-Reply-To: Message-Id: <9b0c00ddb76e15cdcd86e12f85ce4f8a5e946299.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 38/43] kasan, arm64: implement HW_TAGS runtime From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232141_663519_7FF83683 X-CRM114-Status: GOOD ( 25.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Provide implementation of KASAN functions required for the hardware tag-based mode. Those include core functions for memory and pointer tagging (tags_hw.c) and bug reporting (report_tags_hw.c). Also adapt common KASAN code to support the new mode. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Acked-by: Catalin Marinas --- Change-Id: I8a8689ba098174a4d0ef3f1d008178387c80ee1c --- arch/arm64/include/asm/memory.h | 4 +- arch/arm64/kernel/cpufeature.c | 3 ++ include/linux/kasan.h | 22 ++++++--- include/linux/mm.h | 2 +- include/linux/page-flags-layout.h | 2 +- mm/kasan/Makefile | 5 ++ mm/kasan/common.c | 15 +++--- mm/kasan/hw_tags.c | 76 +++++++++++++++++++++++++++++++ mm/kasan/kasan.h | 17 +++++-- mm/kasan/report_hw_tags.c | 42 +++++++++++++++++ mm/kasan/report_sw_tags.c | 2 +- mm/kasan/shadow.c | 2 +- mm/kasan/sw_tags.c | 2 +- 13 files changed, 169 insertions(+), 25 deletions(-) create mode 100644 mm/kasan/hw_tags.c create mode 100644 mm/kasan/report_hw_tags.c diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 507012ed24f4..b245554984a2 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -214,7 +214,7 @@ static inline unsigned long kaslr_offset(void) (__force __typeof__(addr))__addr; \ }) -#ifdef CONFIG_KASAN_SW_TAGS +#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) #define __tag_shifted(tag) ((u64)(tag) << 56) #define __tag_reset(addr) __untagged_addr(addr) #define __tag_get(addr) (__u8)((u64)(addr) >> 56) @@ -222,7 +222,7 @@ static inline unsigned long kaslr_offset(void) #define __tag_shifted(tag) 0UL #define __tag_reset(addr) (addr) #define __tag_get(addr) 0 -#endif /* CONFIG_KASAN_SW_TAGS */ +#endif /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS */ static inline const void *__tag_set(const void *addr, u8 tag) { diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c index dcc165b3fc04..b66a96525a3e 100644 --- a/arch/arm64/kernel/cpufeature.c +++ b/arch/arm64/kernel/cpufeature.c @@ -70,6 +70,7 @@ #include #include #include +#include #include #include #include @@ -1704,6 +1705,8 @@ static void cpu_enable_mte(struct arm64_cpu_capabilities const *cap) cleared_zero_page = true; mte_clear_page_tags(lm_alias(empty_zero_page)); } + + kasan_init_hw_tags(); } #endif /* CONFIG_ARM64_MTE */ diff --git a/include/linux/kasan.h b/include/linux/kasan.h index beb699e90e55..c6bf762eb88c 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -187,25 +187,33 @@ static inline void kasan_record_aux_stack(void *ptr) {} #endif /* CONFIG_KASAN_GENERIC */ -#ifdef CONFIG_KASAN_SW_TAGS - -void __init kasan_init_sw_tags(void); +#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) void *kasan_reset_tag(const void *addr); bool kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long ip); -#else /* CONFIG_KASAN_SW_TAGS */ - -static inline void kasan_init_sw_tags(void) { } +#else /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS */ static inline void *kasan_reset_tag(const void *addr) { return (void *)addr; } -#endif /* CONFIG_KASAN_SW_TAGS */ +#endif /* CONFIG_KASAN_SW_TAGS || CONFIG_KASAN_HW_TAGS*/ + +#ifdef CONFIG_KASAN_SW_TAGS +void __init kasan_init_sw_tags(void); +#else +static inline void kasan_init_sw_tags(void) { } +#endif + +#ifdef CONFIG_KASAN_HW_TAGS +void __init kasan_init_hw_tags(void); +#else +static inline void kasan_init_hw_tags(void) { } +#endif #ifdef CONFIG_KASAN_VMALLOC diff --git a/include/linux/mm.h b/include/linux/mm.h index db6ae4d3fb4e..0793d03a4183 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1413,7 +1413,7 @@ static inline bool cpupid_match_pid(struct task_struct *task, int cpupid) } #endif /* CONFIG_NUMA_BALANCING */ -#ifdef CONFIG_KASAN_SW_TAGS +#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) static inline u8 page_kasan_tag(const struct page *page) { return (page->flags >> KASAN_TAG_PGSHIFT) & KASAN_TAG_MASK; diff --git a/include/linux/page-flags-layout.h b/include/linux/page-flags-layout.h index e200eef6a7fd..7d4ec26d8a3e 100644 --- a/include/linux/page-flags-layout.h +++ b/include/linux/page-flags-layout.h @@ -77,7 +77,7 @@ #define LAST_CPUPID_SHIFT 0 #endif -#ifdef CONFIG_KASAN_SW_TAGS +#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) #define KASAN_TAG_WIDTH 8 #else #define KASAN_TAG_WIDTH 0 diff --git a/mm/kasan/Makefile b/mm/kasan/Makefile index f1d68a34f3c9..9fe39a66388a 100644 --- a/mm/kasan/Makefile +++ b/mm/kasan/Makefile @@ -10,8 +10,10 @@ CFLAGS_REMOVE_init.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_quarantine.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report_generic.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_report_hw_tags.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_report_sw_tags.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_shadow.o = $(CC_FLAGS_FTRACE) +CFLAGS_REMOVE_hw_tags.o = $(CC_FLAGS_FTRACE) CFLAGS_REMOVE_sw_tags.o = $(CC_FLAGS_FTRACE) # Function splitter causes unnecessary splits in __asan_load1/__asan_store1 @@ -27,10 +29,13 @@ CFLAGS_init.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_quarantine.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_report.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_report_generic.o := $(CC_FLAGS_KASAN_RUNTIME) +CFLAGS_report_hw_tags.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_report_sw_tags.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_shadow.o := $(CC_FLAGS_KASAN_RUNTIME) +CFLAGS_hw_tags.o := $(CC_FLAGS_KASAN_RUNTIME) CFLAGS_sw_tags.o := $(CC_FLAGS_KASAN_RUNTIME) obj-$(CONFIG_KASAN) := common.o report.o obj-$(CONFIG_KASAN_GENERIC) += init.o generic.o report_generic.o shadow.o quarantine.o +obj-$(CONFIG_KASAN_HW_TAGS) += hw_tags.o report_hw_tags.o obj-$(CONFIG_KASAN_SW_TAGS) += init.o report_sw_tags.o shadow.o sw_tags.o diff --git a/mm/kasan/common.c b/mm/kasan/common.c index d0b3ff410b0c..2bb0ef6da6bd 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -113,7 +113,7 @@ void kasan_free_pages(struct page *page, unsigned int order) */ static inline unsigned int optimal_redzone(unsigned int object_size) { - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) + if (!IS_ENABLED(CONFIG_KASAN_GENERIC)) return 0; return @@ -178,14 +178,14 @@ size_t kasan_metadata_size(struct kmem_cache *cache) struct kasan_alloc_meta *get_alloc_info(struct kmem_cache *cache, const void *object) { - return (void *)object + cache->kasan_info.alloc_meta_offset; + return (void *)reset_tag(object) + cache->kasan_info.alloc_meta_offset; } struct kasan_free_meta *get_free_info(struct kmem_cache *cache, const void *object) { BUILD_BUG_ON(sizeof(struct kasan_free_meta) > 32); - return (void *)object + cache->kasan_info.free_meta_offset; + return (void *)reset_tag(object) + cache->kasan_info.free_meta_offset; } void kasan_poison_slab(struct page *page) @@ -267,9 +267,8 @@ void * __must_check kasan_init_slab_obj(struct kmem_cache *cache, alloc_info = get_alloc_info(cache, object); __memset(alloc_info, 0, sizeof(*alloc_info)); - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) - object = set_tag(object, - assign_tag(cache, object, true, false)); + if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) || IS_ENABLED(CONFIG_KASAN_HW_TAGS)) + object = set_tag(object, assign_tag(cache, object, true, false)); return (void *)object; } @@ -337,10 +336,10 @@ static void *__kasan_kmalloc(struct kmem_cache *cache, const void *object, redzone_end = round_up((unsigned long)object + cache->object_size, KASAN_GRANULE_SIZE); - if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) + if (IS_ENABLED(CONFIG_KASAN_SW_TAGS) || IS_ENABLED(CONFIG_KASAN_HW_TAGS)) tag = assign_tag(cache, object, false, keep_tag); - /* Tag is ignored in set_tag without CONFIG_KASAN_SW_TAGS */ + /* Tag is ignored in set_tag without CONFIG_KASAN_SW/HW_TAGS */ kasan_unpoison_memory(set_tag(object, tag), size); kasan_poison_memory((void *)redzone_start, redzone_end - redzone_start, KASAN_KMALLOC_REDZONE); diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c new file mode 100644 index 000000000000..bdb684c65561 --- /dev/null +++ b/mm/kasan/hw_tags.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This file contains core hardware tag-based KASAN code. + * + * Copyright (c) 2020 Google, Inc. + * Author: Andrey Konovalov + */ + +#define pr_fmt(fmt) "kasan: " fmt + +#include +#include +#include +#include +#include +#include + +#include "kasan.h" + +/* kasan_init_hw_tags() is called for each CPU. */ +void __init kasan_init_hw_tags(void) +{ + hw_init_tags(KASAN_TAG_MAX); + + if (smp_processor_id() == 0) + pr_info("KernelAddressSanitizer initialized\n"); +} + +void *kasan_reset_tag(const void *addr) +{ + return reset_tag(addr); +} + +void kasan_poison_memory(const void *address, size_t size, u8 value) +{ + hw_set_mem_tag_range(reset_tag(address), + round_up(size, KASAN_GRANULE_SIZE), value); +} + +void kasan_unpoison_memory(const void *address, size_t size) +{ + hw_set_mem_tag_range(reset_tag(address), + round_up(size, KASAN_GRANULE_SIZE), get_tag(address)); +} + +u8 random_tag(void) +{ + return hw_get_random_tag(); +} + +bool check_invalid_free(void *addr) +{ + u8 ptr_tag = get_tag(addr); + u8 mem_tag = hw_get_mem_tag(addr); + + return (mem_tag == KASAN_TAG_INVALID) || + (ptr_tag != KASAN_TAG_KERNEL && ptr_tag != mem_tag); +} + +void kasan_set_free_info(struct kmem_cache *cache, + void *object, u8 tag) +{ + struct kasan_alloc_meta *alloc_meta; + + alloc_meta = get_alloc_info(cache, object); + kasan_set_track(&alloc_meta->free_track[0], GFP_NOWAIT); +} + +struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, + void *object, u8 tag) +{ + struct kasan_alloc_meta *alloc_meta; + + alloc_meta = get_alloc_info(cache, object); + return &alloc_meta->free_track[0]; +} diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 618e69d12f61..b0a57d8f9803 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -153,6 +153,10 @@ struct kasan_alloc_meta *get_alloc_info(struct kmem_cache *cache, struct kasan_free_meta *get_free_info(struct kmem_cache *cache, const void *object); +void kasan_poison_memory(const void *address, size_t size, u8 value); + +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) + static inline const void *kasan_shadow_to_mem(const void *shadow_addr) { return (void *)(((unsigned long)shadow_addr - KASAN_SHADOW_OFFSET) @@ -164,8 +168,6 @@ static inline bool addr_has_metadata(const void *addr) return (addr >= kasan_shadow_to_mem((void *)KASAN_SHADOW_START)); } -void kasan_poison_memory(const void *address, size_t size, u8 value); - /** * check_memory_region - Check memory region, and report if invalid access. * @addr: the accessed address @@ -177,6 +179,15 @@ void kasan_poison_memory(const void *address, size_t size, u8 value); bool check_memory_region(unsigned long addr, size_t size, bool write, unsigned long ret_ip); +#else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ + +static inline bool addr_has_metadata(const void *addr) +{ + return PageSlab(virt_to_head_page(addr)); +} + +#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ + bool check_invalid_free(void *addr); void *find_first_bad_addr(void *addr, size_t size); @@ -213,7 +224,7 @@ static inline void quarantine_reduce(void) { } static inline void quarantine_remove_cache(struct kmem_cache *cache) { } #endif -#ifdef CONFIG_KASAN_SW_TAGS +#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) void print_tags(u8 addr_tag, const void *addr); diff --git a/mm/kasan/report_hw_tags.c b/mm/kasan/report_hw_tags.c new file mode 100644 index 000000000000..da543eb832cd --- /dev/null +++ b/mm/kasan/report_hw_tags.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * This file contains hardware tag-based KASAN specific error reporting code. + * + * Copyright (c) 2020 Google, Inc. + * Author: Andrey Konovalov + */ + +#include +#include +#include +#include +#include +#include + +#include "kasan.h" + +const char *get_bug_type(struct kasan_access_info *info) +{ + return "invalid-access"; +} + +void *find_first_bad_addr(void *addr, size_t size) +{ + return reset_tag(addr); +} + +void metadata_fetch_row(char *buffer, void *row) +{ + int i; + + for (i = 0; i < META_BYTES_PER_ROW; i++) + buffer[i] = hw_get_mem_tag(row + i * KASAN_GRANULE_SIZE); +} + +void print_tags(u8 addr_tag, const void *addr) +{ + u8 memory_tag = hw_get_mem_tag((void *)addr); + + pr_err("Pointer tag: [%02x], memory tag: [%02x]\n", + addr_tag, memory_tag); +} diff --git a/mm/kasan/report_sw_tags.c b/mm/kasan/report_sw_tags.c index add2dfe6169c..aebc44a29e83 100644 --- a/mm/kasan/report_sw_tags.c +++ b/mm/kasan/report_sw_tags.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * This file contains tag-based KASAN specific error reporting code. + * This file contains software tag-based KASAN specific error reporting code. * * Copyright (c) 2014 Samsung Electronics Co., Ltd. * Author: Andrey Ryabinin diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index 1fadd4930d54..616ac64c4a21 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -107,7 +107,7 @@ void kasan_unpoison_memory(const void *address, size_t size) if (IS_ENABLED(CONFIG_KASAN_SW_TAGS)) *shadow = tag; - else + else /* CONFIG_KASAN_GENERIC */ *shadow = size & KASAN_GRANULE_MASK; } } diff --git a/mm/kasan/sw_tags.c b/mm/kasan/sw_tags.c index b09a2c06abad..dfe707dd8d0d 100644 --- a/mm/kasan/sw_tags.c +++ b/mm/kasan/sw_tags.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* - * This file contains core tag-based KASAN code. + * This file contains core software tag-based KASAN code. * * Copyright (c) 2018 Google, Inc. * Author: Andrey Konovalov From patchwork Wed Nov 4 23:18:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883377 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B3ACC00A89 for ; Thu, 5 Nov 2020 06:36:52 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C256F2071A for ; Thu, 5 Nov 2020 06:36:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="rXA8EnuW"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="WEoh54Vi"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="c0vkrlRI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C256F2071A Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=1Bq43GbtPNoseNeiqVZVcQ5dwWuJqEqfSIO6N8RztLg=; b=rXA8EnuWZb/NkKt/Cq/mfXeA4 CxdbvJCKkPm+UJOiIikTEvUUaeX+y2z8lgsE7lSCxYkir/WS3M5ll2FlMUjjjKn3mApnVKr9/zKxj 9zaKNw2+Gw5YWX5dsiA0M8c53utLD76c0cD4IKlJDcEE59N3GnktdvaStPD6894nykgPWYvCYd4XY 9eMlSaqTMMeuV3wtrRv0Y4otTVPBiahteND82Th84TGpbBJMmIIzj6rGbwxHKtfn5tLZDpZ98ppbm xqqkQvDEcI+qlJHmwGoOksNqPSPw8sSC9fhxJUfOolUVkW8DsfriOQum4KC37VAuPXACx8b6Rvu95 2jus7MCvQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaYs7-0007IZ-GS; Thu, 05 Nov 2020 06:35:47 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW53-000145-JU for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:36:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=35WbJzPGlJ32SG4OmkQQICRjm1+Un7MaGRWzBQ2gFy8=; b=WEoh54Vi5zvGTirImduHP1fwes 25LTTfF4572xbc48AhQhlyC7Oznq+5olMUmmgkVr13CU8WL5HGSaSFDqESYnimKIwl5oEf3pXVM2R WO7P2t4mZU89+gpTDSqEzKW9M/SjqKp8vgfXMNwdBnPe7O8/0pDjY5J9MRHmvtDbEMVMI0hZXZMV/ wfKuAJrSv0AgnDqsq1Qom+62kw77x8R9wINokNxAPl5oH6OT5grc4Cg/PZXgy3NvH4t4iaE37hUXm U3N78i+gCQ04ZJSkpIushugD6tL1HkxMNH3yLYdhlU/fmZa+K9m4i5qeGNEd16qVFaJBG/dJHRzQ5 FEj8yLRw==; Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS62-0004EW-9f for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:46 +0000 Received: by mail-qk1-x74a.google.com with SMTP id u16so14493183qkm.22 for ; Wed, 04 Nov 2020 15:21:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=35WbJzPGlJ32SG4OmkQQICRjm1+Un7MaGRWzBQ2gFy8=; b=c0vkrlRIsEA2zaSNjedAHzaANOS3KnMfQBq5IN41oqi4DjS7urZr6IPPvJz9UxlmEd lW6pqmtub3Nyd6OWE074wEOgDmu0UT4Wg9dLQq1YfyblzwoMhnpPcJPwhNwUztvQe/+s 0qkSYVBHDeocB/8qWuxyOvRYz4+sCZPsYugh312jIOu5bHNCzzWJke/Mc6ofThSTxC0F kHC1EPLi214qaGu9G+uHo4OXCWktBoIvmhhT7MoMSxNbqcFf+PP/FfggLNy6XC2iN0a2 zLYJ1VgM1TTpUY5pGPAdOJ8/uoocPxBXoBWvqK0k0KAfoNZvU2Yl3nomO/+QsmiXyG1b sIIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=35WbJzPGlJ32SG4OmkQQICRjm1+Un7MaGRWzBQ2gFy8=; b=Ha92LADRx+mIPnmaaBEpH/3xwlsVRfKBVQ7C515+hEBJOoGHmXNWzxhNKDxJR6VJJL CwzXSpCBBJFC0Vg/0PUEfRZcOLKDvLrGr7Pv+AuHK+h6VYS0upv9GI9sWhzD6DlJenuN /f2525tuJyMa8NVX0td6Y0T2jVGZUD5pvT7POhCBkiSG9ZtNirbJ0O2FT8HL+X9XSCyp 2wLVQRggBDH+t3gb7qagc3S1k46LWm3kglcDD7VcRkDH732IFLyr3ZC5At2XUQZJv4dB E4/7VN6hEp4izuYNDGozYG3QexttmScJYV/mgbOSXyBcg2YMFIn790/s8ghmLdEr/X9I 8wpw== X-Gm-Message-State: AOAM5323feFtJsLelxFOqNozmHBybjXXfcG9dq1jLwytTSgeFghozN33 3dLjfRjD4/4TBVZbOYrXFWuoUIzkz+7/8R0L X-Google-Smtp-Source: ABdhPJyQywfWKbdX68bSu2ZPlot1uOmCpCTLZwOGAs9Gz57V7Cqqkk2XTA2l7zW1C/0FANx/P7/BsExHxmasuAN6 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:55ea:: with SMTP id bu10mr283554qvb.28.1604532040493; Wed, 04 Nov 2020 15:20:40 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:54 +0100 In-Reply-To: Message-Id: <4bde28cafd5ef30f4caf2bbeca90a9d7ccb73793.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 39/43] kasan, arm64: print report from tag fault handler From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232142_512204_60C818F3 X-CRM114-Status: GOOD ( 14.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add error reporting for hardware tag-based KASAN. When CONFIG_KASAN_HW_TAGS is enabled, print KASAN report from the arm64 tag fault handler. SAS bits aren't set in ESR for all faults reported in EL1, so it's impossible to find out the size of the access the caused the fault. Adapt KASAN reporting code to handle this case. Signed-off-by: Andrey Konovalov Co-developed-by: Vincenzo Frascino Signed-off-by: Vincenzo Frascino Reviewed-by: Catalin Marinas --- Change-Id: I3780fe7db6e075dff2937d3d8508f55c9322b095 --- arch/arm64/mm/fault.c | 14 ++++++++++++++ mm/kasan/report.c | 11 ++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index fbceb14d93b1..7370e822e588 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -297,10 +298,23 @@ static void die_kernel_fault(const char *msg, unsigned long addr, do_exit(SIGKILL); } +#ifdef CONFIG_KASAN_HW_TAGS static void report_tag_fault(unsigned long addr, unsigned int esr, struct pt_regs *regs) { + bool is_write = ((esr & ESR_ELx_WNR) >> ESR_ELx_WNR_SHIFT) != 0; + + /* + * SAS bits aren't set for all faults reported in EL1, so we can't + * find out access size. + */ + kasan_report(addr, 0, is_write, regs->pc); } +#else +/* Tag faults aren't enabled without CONFIG_KASAN_HW_TAGS. */ +static inline void report_tag_fault(unsigned long addr, unsigned int esr, + struct pt_regs *regs) { } +#endif static void do_tag_recovery(unsigned long addr, unsigned int esr, struct pt_regs *regs) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 8afc1a6ab202..ce06005d4052 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -62,9 +62,14 @@ static void print_error_description(struct kasan_access_info *info) { pr_err("BUG: KASAN: %s in %pS\n", get_bug_type(info), (void *)info->ip); - pr_err("%s of size %zu at addr %px by task %s/%d\n", - info->is_write ? "Write" : "Read", info->access_size, - info->access_addr, current->comm, task_pid_nr(current)); + if (info->access_size) + pr_err("%s of size %zu at addr %px by task %s/%d\n", + info->is_write ? "Write" : "Read", info->access_size, + info->access_addr, current->comm, task_pid_nr(current)); + else + pr_err("%s at addr %px by task %s/%d\n", + info->is_write ? "Write" : "Read", + info->access_addr, current->comm, task_pid_nr(current)); } static DEFINE_SPINLOCK(report_lock); From patchwork Wed Nov 4 23:18:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883109 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8352AC388F9 for ; Thu, 5 Nov 2020 04:22:38 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C1E2020795 for ; Thu, 5 Nov 2020 04:22:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="BdV1Oni2"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="XWs2rjtb"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="urLNJdGS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C1E2020795 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=85gIC3CgfVAGdo1SPqwYP2xihFLNB3XYDYWS/wnjrFg=; b=BdV1Oni2/ORh4pmZpGe+TCBua W2Jf7zK3RUKpUF0vgz/52pIr4TS3Gj5WNY5gdPRTjAOI/WH8rnRqJjPqMzd+8vyf0Onth8VWi+n7m JWuGXjQDqRP04Mxsw0rgdD9lOal2OXfBpOBhch/vjbHAiMAmr58KRZU0M1mdlV8kG5tiRUQpTy0fZ wVCIrqYMuTbAWRshSv+zt8E/58YRMk7tNDWgiZuEcCfI1Qf+QFcZiJYUtO4PGGGcP8QFH8kik0pg3 ZR/73pFoq4g+KepN3iJx3oAgFLHNMWMA9VdOiCYokR92LJIv8P/g9XjqmtoZoV/GMzKfrzMzABlmi 7mXOc4a4Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWmf-00068y-Ie; Thu, 05 Nov 2020 04:22:01 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW52-000145-KG for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:36:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=C6Op3yFR6sxPD/1lbh7YRsoWm4fdKowdqrD7aVgHz7A=; b=XWs2rjtb7JGdrkDKHpcpAxjfRA aoi9Afa73mOBZM/KTBy/qLgKvxB1hCH3tUDNDJmdhMOiLi5TVOmg837whKoI5DousbCPGA/Qf86n1 m38WeWm0xWX/V+iDm1ilZL1PeYRYxV7yRcXlQqcMZzpGATyCOVBXMYLhDNoaewFRVLIqKYRNfn0SX LHZ0kyRXRbZrLwa/OM6vzLEyZld+xOZ2ZPX0E8Iyj2v5G7/SM032wQ70CLmrCZPEtjucHJHBjvafq KXi6GfR6W2z7oycSrpneZGZEjDh3j3Yo2eUD+1sRQSzsfwj0ftiCsZHYSZCWV1WEPI92/KMn47Lps 24l76tLA==; Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS64-0004G8-Uv for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:47 +0000 Received: by mail-wr1-x449.google.com with SMTP id m4so31444wrq.23 for ; Wed, 04 Nov 2020 15:21:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=C6Op3yFR6sxPD/1lbh7YRsoWm4fdKowdqrD7aVgHz7A=; b=urLNJdGSUOup2QSd3Xo8K2IAxTAD4dxietwPBoyckjUmP4CteZp8rLtUmfDhg7cqaT 91sVwygPNWlNpkUAJoiivg0+QvRZj3TO8Wrb43cjTxERiNpdAb6ci817hmSubqgKl2Bc fxz1aVjxfud/M3zsEs5/BB+wXnyQHv/Ruo3fJs8Qt7G7php2kpi2YJ1Mv0INw+MHmxXE f/ledyhbcHTBWQXxDowUv1LwE8WIOV6XZJJWgBqbhXSrSTrhCmCfA5ElEAkkJZ28NcjT ll6raxQ/OcE+COdlYmOKrspK1fuZLqm8V8wFf4pp4SZfZtX3NGRlu4pkxUqMVi4nvgcP y9tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=C6Op3yFR6sxPD/1lbh7YRsoWm4fdKowdqrD7aVgHz7A=; b=WozH0UH9V/LmevWDSLp2q5gG6G5H3/R4AGl/0mfzsdVvZGQSIm/V/EG2Ub/lOjxd1u SkX423NxnB55G9YfS/eepPIPTTbJX4d7JUNdXkxyZEjCttcoefjQr24uBjwBxMtYoor3 bEYd3V08Wf8j8sgcT3ieZPB0YQpU4djncQw64yb4cHIukdqJNnYhDxQhw3p3zPypBXYl hfucvTrtup13CER1KkO3pFEm5ua7zI4OfC8iiTog3gdtQTwSdg06v4ThOLTjNM9zOUXU EpamUdEXD7u0n/M0et/6EU8wcsfzlMsVNGf1Y8euYmJjkU/ba/Wm3UdUd1e2Vz77rjUT wSUA== X-Gm-Message-State: AOAM533rsJ5GUnwVW54BLei8au3L2MmBwLMIcLFmWd5iSHXNaZgs+dLY ilSyaLkrEkgjDcMMzgCtDPQoYTC2HyaBpt/Z X-Google-Smtp-Source: ABdhPJzBnouBFsSKxvskBclzmPBIxPEASCVKLTTX8D2WfoMu1h7X9WE1X4orLp0LUTH+zZibNJ/ozADkRrawKBgj X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:2487:: with SMTP id k129mr97091wmk.86.1604532042965; Wed, 04 Nov 2020 15:20:42 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:55 +0100 In-Reply-To: Message-Id: <578dd0990cc6a02fd47d2d0a442db1c628fef91e.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 40/43] kasan, mm: reset tags when accessing metadata From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232145_213957_B50C4646 X-CRM114-Status: GOOD ( 22.75 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Kernel allocator code accesses metadata for slab objects, that may lie out-of-bounds of the object itself, or be accessed when an object is freed. Such accesses trigger tag faults and lead to false-positive reports with hardware tag-based KASAN. Software KASAN modes disable instrumentation for allocator code via KASAN_SANITIZE Makefile macro, and rely on kasan_enable/disable_current() annotations which are used to ignore KASAN reports. With hardware tag-based KASAN neither of those options are available, as it doesn't use compiler instrumetation, no tag faults are ignored, and MTE is disabled after the first one. Instead, reset tags when accessing metadata (currently only for SLUB). Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Acked-by: Marco Elver --- Change-Id: I39f3c4d4f29299d4fbbda039bedf230db1c746fb --- mm/page_alloc.c | 4 +++- mm/page_poison.c | 2 +- mm/slub.c | 29 ++++++++++++++++------------- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 23f5066bd4a5..6231a6e456cf 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1195,8 +1195,10 @@ static void kernel_init_free_pages(struct page *page, int numpages) /* s390's use of memset() could override KASAN redzones. */ kasan_disable_current(); - for (i = 0; i < numpages; i++) + for (i = 0; i < numpages; i++) { + page_kasan_tag_reset(page + i); clear_highpage(page + i); + } kasan_enable_current(); } diff --git a/mm/page_poison.c b/mm/page_poison.c index ae0482cded87..e6c994af7518 100644 --- a/mm/page_poison.c +++ b/mm/page_poison.c @@ -53,7 +53,7 @@ static void poison_page(struct page *page) /* KASAN still think the page is in-use, so skip it. */ kasan_disable_current(); - memset(addr, PAGE_POISON, PAGE_SIZE); + memset(kasan_reset_tag(addr), PAGE_POISON, PAGE_SIZE); kasan_enable_current(); kunmap_atomic(addr); } diff --git a/mm/slub.c b/mm/slub.c index b30be2385d1c..df2fd5b57df1 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -249,7 +249,7 @@ static inline void *freelist_ptr(const struct kmem_cache *s, void *ptr, { #ifdef CONFIG_SLAB_FREELIST_HARDENED /* - * When CONFIG_KASAN_SW_TAGS is enabled, ptr_addr might be tagged. + * When CONFIG_KASAN_SW/HW_TAGS is enabled, ptr_addr might be tagged. * Normally, this doesn't cause any issues, as both set_freepointer() * and get_freepointer() are called with a pointer with the same tag. * However, there are some issues with CONFIG_SLUB_DEBUG code. For @@ -275,6 +275,7 @@ static inline void *freelist_dereference(const struct kmem_cache *s, static inline void *get_freepointer(struct kmem_cache *s, void *object) { + object = kasan_reset_tag(object); return freelist_dereference(s, object + s->offset); } @@ -304,6 +305,7 @@ static inline void set_freepointer(struct kmem_cache *s, void *object, void *fp) BUG_ON(object == fp); /* naive detection of double free or corruption */ #endif + freeptr_addr = (unsigned long)kasan_reset_tag((void *)freeptr_addr); *(void **)freeptr_addr = freelist_ptr(s, fp, freeptr_addr); } @@ -538,8 +540,8 @@ static void print_section(char *level, char *text, u8 *addr, unsigned int length) { metadata_access_enable(); - print_hex_dump(level, text, DUMP_PREFIX_ADDRESS, 16, 1, addr, - length, 1); + print_hex_dump(level, kasan_reset_tag(text), DUMP_PREFIX_ADDRESS, + 16, 1, addr, length, 1); metadata_access_disable(); } @@ -570,7 +572,7 @@ static struct track *get_track(struct kmem_cache *s, void *object, p = object + get_info_end(s); - return p + alloc; + return kasan_reset_tag(p + alloc); } static void set_track(struct kmem_cache *s, void *object, @@ -583,7 +585,8 @@ static void set_track(struct kmem_cache *s, void *object, unsigned int nr_entries; metadata_access_enable(); - nr_entries = stack_trace_save(p->addrs, TRACK_ADDRS_COUNT, 3); + nr_entries = stack_trace_save(kasan_reset_tag(p->addrs), + TRACK_ADDRS_COUNT, 3); metadata_access_disable(); if (nr_entries < TRACK_ADDRS_COUNT) @@ -747,7 +750,7 @@ static __printf(3, 4) void slab_err(struct kmem_cache *s, struct page *page, static void init_object(struct kmem_cache *s, void *object, u8 val) { - u8 *p = object; + u8 *p = kasan_reset_tag(object); if (s->flags & SLAB_RED_ZONE) memset(p - s->red_left_pad, val, s->red_left_pad); @@ -777,7 +780,7 @@ static int check_bytes_and_report(struct kmem_cache *s, struct page *page, u8 *addr = page_address(page); metadata_access_enable(); - fault = memchr_inv(start, value, bytes); + fault = memchr_inv(kasan_reset_tag(start), value, bytes); metadata_access_disable(); if (!fault) return 1; @@ -873,7 +876,7 @@ static int slab_pad_check(struct kmem_cache *s, struct page *page) pad = end - remainder; metadata_access_enable(); - fault = memchr_inv(pad, POISON_INUSE, remainder); + fault = memchr_inv(kasan_reset_tag(pad), POISON_INUSE, remainder); metadata_access_disable(); if (!fault) return 1; @@ -1118,7 +1121,7 @@ void setup_page_debug(struct kmem_cache *s, struct page *page, void *addr) return; metadata_access_enable(); - memset(addr, POISON_INUSE, page_size(page)); + memset(kasan_reset_tag(addr), POISON_INUSE, page_size(page)); metadata_access_disable(); } @@ -1566,10 +1569,10 @@ static inline bool slab_free_freelist_hook(struct kmem_cache *s, * Clear the object and the metadata, but don't touch * the redzone. */ - memset(object, 0, s->object_size); + memset(kasan_reset_tag(object), 0, s->object_size); rsize = (s->flags & SLAB_RED_ZONE) ? s->red_left_pad : 0; - memset((char *)object + s->inuse, 0, + memset((char *)kasan_reset_tag(object) + s->inuse, 0, s->size - s->inuse - rsize); } @@ -2883,10 +2886,10 @@ static __always_inline void *slab_alloc_node(struct kmem_cache *s, stat(s, ALLOC_FASTPATH); } - maybe_wipe_obj_freeptr(s, object); + maybe_wipe_obj_freeptr(s, kasan_reset_tag(object)); if (unlikely(slab_want_init_on_alloc(gfpflags, s)) && object) - memset(object, 0, s->object_size); + memset(kasan_reset_tag(object), 0, s->object_size); slab_post_alloc_hook(s, objcg, gfpflags, 1, &object); From patchwork Wed Nov 4 23:18:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883299 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6C9CC00A89 for ; Thu, 5 Nov 2020 05:23:28 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 088962083B for ; Thu, 5 Nov 2020 05:23:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="BwecJ+bo"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="lHA/HNy3"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="DU5fct66" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 088962083B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=aGCQeg2fnN9CY+g63axKmXbuVHYF8kD3JeXPeq+IYI4=; b=BwecJ+boKyCxQla0or0o5QBWE k9OnyvyXNp7U8GiGIFPgbHfBe8OEJsp1P6ZMaLbdM4MfrNcyeD5V/epsPT3JdeCUxVfTjNmwMYnrv PQcmfOYlTniqrGz+xKdxsxvjHXOl9eTr4OPBD70WLI0Cwe4m/CWn2Hg9mbT8sOnCoBPQ/GeyPeNZb +4AS80t9N275OlvEJg13F6hPxw84DQY6fqceqbrcylgIyBSs19+g0HfNO7Ae4OLzjRVdGz/VjeJnQ XzEIgG7lLYXiMLkb25njbyyTD0Sy6JOCjIFmFKiWyqtkEk40ZyNLDbOyWbNDAHJ+mXafvQIA4k9vJ X3z2UaEUw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXjQ-0004AY-At; Thu, 05 Nov 2020 05:22:44 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW51-000145-Js for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:36:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=hKqfeGmJU17yqcBnh9EcbhWo2RSZMPrdWdsmZezW6Y0=; b=lHA/HNy32vgvRQ/FK+xH90kKRY 0lHLHpp0WD0XVfwzk2XLybqUxDkwUCck2R8f0Tnz7xfxhD83adQ8YbBtc301Y6mp9OcfRK3+ENprg FkY3DpQ6vdoaCFnZ9v4THhcED+PuTTRetCvmHBE0FvQQqt28YQFNLOYuMWCM44Ex3cuzGoGZTRB17 m4r0xLCfyIzsgjWWzt3s7PvNNVVHP5mUakh+dAn8QgWLORpXL8nKfMxaPk6RtowM/Z18zWKdr/9nz q002v660NLKj8lMPuRQSU5Zhf+uAEA74BKwwBiFjvFlYMdYlozKHAhUKeW+OykORii0wsgimr/u1D vf9jvyXA==; Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS67-0004I2-UB for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:50 +0000 Received: by mail-qk1-x74a.google.com with SMTP id t70so14386435qka.11 for ; Wed, 04 Nov 2020 15:21:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=hKqfeGmJU17yqcBnh9EcbhWo2RSZMPrdWdsmZezW6Y0=; b=DU5fct66n5Jm+qp7Y3XPj0DiQRgJhNHW8925iNYcwLI2iSfBAGFQonQ69tRIksD3Eo 3LULKXe1R6fJ8InNE8FCkkmGBHSiiErEJ5eU06/2tlsaiJtpK9poPR2ARandVwj/EslU Bv7p0oT0D4iP9QkISKVxHlJSp64gvk4TzuZCBVepJX95QlkDdIBzYsppzFb1p6Ra3oWz ZSGWyr93ipcEgwvF/yGbnYWu658KDX30/9Y/7bmBC3VGJbnC9ZGWWZcjuf6xYnza3x1T 2Uodg8Xeb+rbiyLqUzm0Cd7JaZ+VmkynrQEOoxe0SK7Qa5grYb471sqU44GARExjXzaw dLDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=hKqfeGmJU17yqcBnh9EcbhWo2RSZMPrdWdsmZezW6Y0=; b=sn6LPanaXp58OHT7pKbxrJtd9RHAGu4NNN2STnpprHEXIP7DhOX3PgYlbSuhAj63zi 2iT5snPOJHCf+OGcuvH7vl7sJZfcvlpMVSjDecph7Mlge/E9AYBXSt0MHCa/9+yayJIC G9/PeGKC7c+jI5l2d16a9BEvQgKEdBXvDYN9lUZoE9Z5ljoB/fymXOF0a1rN/9/zQZvI ekQz6xE8G2VLXO8UwhhXbKVP5qrhkXNqmdgpKcjDFv5mw+1lwpLOFAfbNv8+FRNm+i1i nlpN8lmFCjh+w7UxGzIaF73TRWM7z8GJzAdmxLBJZnBBRn7c0XjnPeEcaM9eTHD8nzZn AoTA== X-Gm-Message-State: AOAM533Nq2MDmM6hGc/dhgRo1wRLNNMoHA+wu2z4W6TDwDXJaHWGfeyN 9fNZ+5bp5v6un6gwt4MM5s9zJZLi/9IbedgM X-Google-Smtp-Source: ABdhPJx+HHvkYwIh6sJ7WWY/Byha2SM4H0CF03j5uewLvlhzz7sNx3WqiWX0omoXFdScFjo7bPiJXDAOM7s7mGPj X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:f3c2:: with SMTP id f2mr271968qvm.24.1604532045303; Wed, 04 Nov 2020 15:20:45 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:56 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 41/43] kasan, arm64: enable CONFIG_KASAN_HW_TAGS From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232148_154299_3E8EF73B X-CRM114-Status: UNSURE ( 9.55 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hardware tag-based KASAN is now ready, enable the configuration option. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Acked-by: Catalin Marinas --- Change-Id: I6eb1eea770e6b61ad71c701231b8d815a7ccc853 --- arch/arm64/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 43702780f28c..0996b5d75046 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -135,6 +135,7 @@ config ARM64 select HAVE_ARCH_JUMP_LABEL_RELATIVE select HAVE_ARCH_KASAN if !(ARM64_16K_PAGES && ARM64_VA_BITS_48) select HAVE_ARCH_KASAN_SW_TAGS if (HAVE_ARCH_KASAN && !ARM64_MTE) + select HAVE_ARCH_KASAN_HW_TAGS if (HAVE_ARCH_KASAN && ARM64_MTE) select HAVE_ARCH_KGDB select HAVE_ARCH_MMAP_RND_BITS select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT From patchwork Wed Nov 4 23:18:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883099 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50088C00A89 for ; Thu, 5 Nov 2020 04:13:24 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A9A7720732 for ; Thu, 5 Nov 2020 04:13:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="kuLZ/IuL"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="XoAzVuaP"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="VtBS5tip" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A9A7720732 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Pyii5edlYysODA1+jooM63XX/AXW7D4IzzVVZgToMu0=; b=kuLZ/IuLNRl8E6dZGfuL51OFc 29Se6a5+3+gmAj4bC17mmTtMT8q5EEnM/8t2oNeiPJvMpJ4YKtVzLr2xiq59vw3iez2P+or5T2hxB InyjIXWO6B8Hz+WIb9fEBXa6Zfx4eymd5F5ZrrovpS1RK+Czl5BuGc4VHHAQN+KbCgoskzh1hCnvc mSI+hw4qznbRWRzH8grOOsVFG/hWn7golbPWv+T8bFH4WUxVxBS1f3cOZ86LxCI3TEX0vWMmUiuwG THYdzL20Sl/v5EeRQuu3CHk4g8Z+mG5veHvdVqzIb6wsGvp8TLURBNze3VYNEDs8OFoFK/6QSwL81 7N8jAVEbA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWcz-0004dS-Q5; Thu, 05 Nov 2020 04:12:01 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW50-000145-He for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:36:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=b9SnV6dyF/NNz3ylZbPzVHyY+ZwsvRStMTdcsqRrxIk=; b=XoAzVuaPXfhom3Mq7+Yj1SzeKJ 4TvBfJ9SMV+AwaWuOixE0cauUmpIxuSWUlzdrYvgT2XtBy7qiryWFFaNPwafHTYvj6ETZ9KT1tcz8 hVFp4trc5gQ2vpqQT+2fWeE9tTpdXMfhvyIUwzgMZilXfoI6TdG+TDl8rhBcpVa5t3/NB+P7oKzN3 SlZ4q87V37SdUBuRgLD3HCiicFuJzCtZi6xYy2/JIl5ffZAOFL5eJI9jSNla+rUTUL3eppp0h2yp/ fOqcEl+IvRU/yWi1NUExfwnbTWMP5DI0NzzykI1rHWjQ10+8I1CaX7icY2F20uMC9eAZiIh/34KIa nsHZf1Uw==; Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS6C-0004Kr-4A for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:56 +0000 Received: by mail-wr1-x44a.google.com with SMTP id t14so51369wrs.2 for ; Wed, 04 Nov 2020 15:21:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=b9SnV6dyF/NNz3ylZbPzVHyY+ZwsvRStMTdcsqRrxIk=; b=VtBS5tiprgeBqyQFeYgQsNsMH9Z8DVIMQnDI9sIuRWgG3aOAEoX/o+uU1bqo4wEuwN xRfkbyerGa1MLHylYZOtl/iWTqO2v4PeyxEmKguvqQd7zDB3hzcVYdRuGmKT2GbUn7Zc V7RSN6ZyWkG9F+qSmzFo0Pf48zARJ3w6a4Kc+yFRdbrE820jo/z7YPgvx6xswqO12q8X QQwCNUiV4IvBr2dVFXvw6LGWC4EG87DRWzm9zckNr6E6LJ0KBqY0XXP7MERR90UXVwgY VPRZmo7F1sAoCyPLmAqu3i9fz6Bxmg3TMvrW07C4lkNGisH2jQO5bYFJZ6pkqTFtWJlw XWxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=b9SnV6dyF/NNz3ylZbPzVHyY+ZwsvRStMTdcsqRrxIk=; b=lQltnpu/6gOEPvrHU4bKFBkbKE9A4nvkuCkGtURxSkVaTSt0ei0PWPy8wUoE/O4vbn Tkx87Ax0f9G3V89BI15X1Z9MT4oA7JfuS7WliydMabtZB7Amks2e+ZUma4S08YvnGSM1 RIFiMXEbG8HJPFsunfcotCkuVDW0UTv1WVmq0f9VUAXeDVlfldhtzmB6TQq9okrT0oWI n1HclLBhjwTxZctaHm9leLT+kw4C6GFbNYSnHKaH2JiO0nAXY041cucA8ULmgyC0AqRs tWXGNwyL4VcaaCUDqCkXq+l6YD/a6UH5Njy/YDBqqh0YRNyklMxMcZp8koTlD9tE/oON OoOA== X-Gm-Message-State: AOAM530HID0pbw9KLWT0kNE8PHkcXTzBWwISlaz/NVhCvTIxKHwOIO50 KDkuLDWYJZllRT3SxcLna4gpPSikY46BLghh X-Google-Smtp-Source: ABdhPJwAU/Tx9QApQADzPSJIxcRre5E1rTj7t3LK/CjmYL8t2M9hDgQHJa9M531Oj5oPKCIfUH7Zf3f17KmQbP5i X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a1c:7418:: with SMTP id p24mr102064wmc.36.1604532047923; Wed, 04 Nov 2020 15:20:47 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:57 +0100 In-Reply-To: Message-Id: <8c7ee6f573ec10f8f5b2ee32b7f649d479691349.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 42/43] kasan: add documentation for hardware tag-based mode From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232152_379836_6B16C433 X-CRM114-Status: GOOD ( 19.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add documentation for hardware tag-based KASAN mode and also add some clarifications for software tag-based mode. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Marco Elver --- Change-Id: Ib46cb444cfdee44054628940a82f5139e10d0258 --- Documentation/dev-tools/kasan.rst | 78 ++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 21 deletions(-) diff --git a/Documentation/dev-tools/kasan.rst b/Documentation/dev-tools/kasan.rst index edca4be5e405..422f8ee1bb17 100644 --- a/Documentation/dev-tools/kasan.rst +++ b/Documentation/dev-tools/kasan.rst @@ -5,12 +5,14 @@ Overview -------- KernelAddressSANitizer (KASAN) is a dynamic memory error detector designed to -find out-of-bound and use-after-free bugs. KASAN has two modes: generic KASAN -(similar to userspace ASan) and software tag-based KASAN (similar to userspace -HWASan). +find out-of-bound and use-after-free bugs. KASAN has three modes: +1. generic KASAN (similar to userspace ASan), +2. software tag-based KASAN (similar to userspace HWASan), +3. hardware tag-based KASAN (based on hardware memory tagging). -KASAN uses compile-time instrumentation to insert validity checks before every -memory access, and therefore requires a compiler version that supports that. +Software KASAN modes (1 and 2) use compile-time instrumentation to insert +validity checks before every memory access, and therefore require a compiler +version that supports that. Generic KASAN is supported in both GCC and Clang. With GCC it requires version 8.3.0 or later. Any supported Clang version is compatible, but detection of @@ -19,7 +21,7 @@ out-of-bounds accesses for global variables is only supported since Clang 11. Tag-based KASAN is only supported in Clang. Currently generic KASAN is supported for the x86_64, arm64, xtensa, s390 and -riscv architectures, and tag-based KASAN is supported only for arm64. +riscv architectures, and tag-based KASAN modes are supported only for arm64. Usage ----- @@ -28,14 +30,16 @@ To enable KASAN configure kernel with:: CONFIG_KASAN = y -and choose between CONFIG_KASAN_GENERIC (to enable generic KASAN) and -CONFIG_KASAN_SW_TAGS (to enable software tag-based KASAN). +and choose between CONFIG_KASAN_GENERIC (to enable generic KASAN), +CONFIG_KASAN_SW_TAGS (to enable software tag-based KASAN), and +CONFIG_KASAN_HW_TAGS (to enable hardware tag-based KASAN). -You also need to choose between CONFIG_KASAN_OUTLINE and CONFIG_KASAN_INLINE. -Outline and inline are compiler instrumentation types. The former produces -smaller binary while the latter is 1.1 - 2 times faster. +For software modes, you also need to choose between CONFIG_KASAN_OUTLINE and +CONFIG_KASAN_INLINE. Outline and inline are compiler instrumentation types. +The former produces smaller binary while the latter is 1.1 - 2 times faster. -Both KASAN modes work with both SLUB and SLAB memory allocators. +Both software KASAN modes work with both SLUB and SLAB memory allocators, +hardware tag-based KASAN currently only support SLUB. For better bug detection and nicer reporting, enable CONFIG_STACKTRACE. To augment reports with last allocation and freeing stack of the physical page, @@ -196,17 +200,24 @@ and the second to last. Software tag-based KASAN ~~~~~~~~~~~~~~~~~~~~~~~~ -Tag-based KASAN uses the Top Byte Ignore (TBI) feature of modern arm64 CPUs to -store a pointer tag in the top byte of kernel pointers. Like generic KASAN it -uses shadow memory to store memory tags associated with each 16-byte memory +Software tag-based KASAN requires software memory tagging support in the form +of HWASan-like compiler instrumentation (see HWASan documentation for details). + +Software tag-based KASAN is currently only implemented for arm64 architecture. + +Software tag-based KASAN uses the Top Byte Ignore (TBI) feature of arm64 CPUs +to store a pointer tag in the top byte of kernel pointers. Like generic KASAN +it uses shadow memory to store memory tags associated with each 16-byte memory cell (therefore it dedicates 1/16th of the kernel memory for shadow memory). -On each memory allocation tag-based KASAN generates a random tag, tags the -allocated memory with this tag, and embeds this tag into the returned pointer. +On each memory allocation software tag-based KASAN generates a random tag, tags +the allocated memory with this tag, and embeds this tag into the returned +pointer. + Software tag-based KASAN uses compile-time instrumentation to insert checks before each memory access. These checks make sure that tag of the memory that is being accessed is equal to tag of the pointer that is used to access this -memory. In case of a tag mismatch tag-based KASAN prints a bug report. +memory. In case of a tag mismatch software tag-based KASAN prints a bug report. Software tag-based KASAN also has two instrumentation modes (outline, that emits callbacks to check memory accesses; and inline, that performs the shadow @@ -215,9 +226,34 @@ simply printed from the function that performs the access check. With inline instrumentation a brk instruction is emitted by the compiler, and a dedicated brk handler is used to print bug reports. -A potential expansion of this mode is a hardware tag-based mode, which would -use hardware memory tagging support instead of compiler instrumentation and -manual shadow memory manipulation. +Software tag-based KASAN uses 0xFF as a match-all pointer tag (accesses through +pointers with 0xFF pointer tag aren't checked). The value 0xFE is currently +reserved to tag freed memory regions. + +Software tag-based KASAN currently only supports tagging of slab memory. + +Hardware tag-based KASAN +~~~~~~~~~~~~~~~~~~~~~~~~ + +Hardware tag-based KASAN is similar to the software mode in concept, but uses +hardware memory tagging support instead of compiler instrumentation and +shadow memory. + +Hardware tag-based KASAN is currently only implemented for arm64 architecture +and based on both arm64 Memory Tagging Extension (MTE) introduced in ARMv8.5 +Instruction Set Architecture, and Top Byte Ignore (TBI). + +Special arm64 instructions are used to assign memory tags for each allocation. +Same tags are assigned to pointers to those allocations. On every memory +access, hardware makes sure that tag of the memory that is being accessed is +equal to tag of the pointer that is used to access this memory. In case of a +tag mismatch a fault is generated and a report is printed. + +Hardware tag-based KASAN uses 0xFF as a match-all pointer tag (accesses through +pointers with 0xFF pointer tag aren't checked). The value 0xFE is currently +reserved to tag freed memory regions. + +Hardware tag-based KASAN currently only supports tagging of slab memory. What memory accesses are sanitised by KASAN? -------------------------------------------- From patchwork Wed Nov 4 23:18:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883103 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31912C4741F for ; Thu, 5 Nov 2020 04:14:52 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9576F20732 for ; Thu, 5 Nov 2020 04:14:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="bzRmsCqn"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="vOn9vKeQ"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="coUp8usP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9576F20732 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=J0NthRtFPW/ncThcWieMoZG1WhutwdETT6SKN5mlalU=; b=bzRmsCqnr2EbMEY86DeFN1wEh 32GIZjUGDQJ7G8+aa03pmYXL7ancFWaY1tkgrag2Gdw0tNF+6dQ1XFc/hxaxSkT7HPv1PEh/OTTQP Cb2/TgeCci2qXnVRc32WjJSXp87ASVgsrZ6W3WH44HcJtOj50X2dU2s0zuEURZOxD4qPQJFd1zcRy PFp7Zct0rC0d7lHuLk5gxGV2qQGjegmU1Qv+C1vY36VTqsbdBOwWITCZ18bHWGrd24AwsbNN9DlGP e0Q9Npp7CCYDYZqdOXECQePKnJdNogH/O5jnhHLzJOZsFtBNwwsv3FxutNHE/qm6zOw4MdWufI/OJ +Nzkaju+Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWfB-0005Ky-Kx; Thu, 05 Nov 2020 04:14:17 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW50-00016k-Fi for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:36:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=DyRPETqC+6C7nrnJCiEiYsvRb/HkPFaD35372QKa3Vk=; b=vOn9vKeQW0gcI9aG/KJmbXG0oM C4o02ijcTmqTjXsGVxtMsOZ9wElX3NkdCZIhX4c9I7oXRHNg6VtrXCoE4065BoBM+yaAqY86PYQpF lSxAbDqJifz2Q8pNTQqv/59yxsHnW70potJ9gegXjSfGoFAGIZdp4rreIGQlaAh+wkyQCs7jp7/Km 3ZOfwce41VkUE+j3Epr437fvIAp4vAhyBENX/+k960TEu5c/AFcPdLuZa9KuWhDu4Snhg9v6DNg3O vm5GfZYa3182YXgF4Fmqcg32p8ol/i1ul0gk3yqOpDahKtPWExLRHrSJlr35C4mzO5Hl5kfWwpQNH TGeWm0bg==; Received: from mail-qk1-x749.google.com ([2607:f8b0:4864:20::749]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS6C-0004Kv-Jl for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:56 +0000 Received: by mail-qk1-x749.google.com with SMTP id x85so14576714qka.14 for ; Wed, 04 Nov 2020 15:21:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=DyRPETqC+6C7nrnJCiEiYsvRb/HkPFaD35372QKa3Vk=; b=coUp8usPwG3tRaZT/czB4IwaENO70bhZYwpPOVmFVE31+gzzFM1eQ4UTkXv5n/Cwx6 HmmXHf7e2Yv2iQl0c/eFCV0eDtFdt+aqYiFbij4bDazub10zadMUBMScNBApOgX2VA2M 1uhVz8MklwM7+riUMg/8+0j7Fi4Bh2qM9bLhWUK6ReMxodoSEFswpWi2kMmZ8Q87CHGp 2BTpkFvNtZjQ22eIAl9d9nUIQU3k/nacre7WR207ivGr7AWJqhJkTyuSxyS+Sa/AD+x3 fzw6/03tLAgh2Aj81Rl+TvGN20JUQneZ9H8VrtmnLsTSYR+SxpV+/eBt1Vr/7rs8v+p0 KW5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=DyRPETqC+6C7nrnJCiEiYsvRb/HkPFaD35372QKa3Vk=; b=PEP4yiNQq7ehjbzRQRr+v6o3ax2pagDzisSe6PzhKO5jk4eyxsnkshEeXovWvn92Kx +7mQdoukt2PyxW6VpgqMzodgMemEjfo2/OXnG8OY7Q+tYZqCE8M9gg9wBtVDXUa3Lzol o/nZgFamYp0r5Dasmw9xpT9MWMwBE7Vm4RoGeD1MbtHDo4NSUA0lOgnKFl3sLxGBns5r z35L15mWlgUC5ncwvdoXQZPG//zTp1WOi07SO7c4eTZ1j4QyrOQGxC8SPXGit4OrejO1 7+vNvLi2JvfOsJtVtpUYwY/pdf06NxduZ0ent5g86bEBRdnYEAtnJwz2ZDs3/0NawecC NXMA== X-Gm-Message-State: AOAM5323reExq8E4vq5Pb5BCaloYiqItMnX92cHAg3kUHnYmJtXHvJsr lVXaHK+5hM6M7Dg5OalaJ/CXX3MBIt5xyDaT X-Google-Smtp-Source: ABdhPJyr9TEssBPzFhk+PU6o+mtfwvl9/Tja+M6tO9w1ZHDXSL5HAtdDJPKKiiOU0eso9TeO61RiAye7zBP4ft8k X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:9bda:: with SMTP id g26mr294283qvf.14.1604532050508; Wed, 04 Nov 2020 15:20:50 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:58 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 43/43] kselftest/arm64: Check GCR_EL1 after context switch From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232153_068875_63AB4FAE X-CRM114-Status: GOOD ( 19.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Vincenzo Frascino This test is specific to MTE and verifies that the GCR_EL1 register is context switched correctly. It spawn 1024 processes and each process spawns 5 threads. Each thread writes a random setting of GCR_EL1 through the prctl() system call and reads it back verifying that it is the same. If the values are not the same it reports a failure. Note: The test has been extended to verify that even SYNC and ASYNC mode setting is preserved correctly over context switching. Signed-off-by: Vincenzo Frascino Signed-off-by: Andrey Konovalov --- Change-Id: Ia917684a2b8e5f29e705ca5cbf360b010df6f61e --- tools/testing/selftests/arm64/mte/Makefile | 2 +- .../arm64/mte/check_gcr_el1_cswitch.c | 152 ++++++++++++++++++ 2 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/arm64/mte/check_gcr_el1_cswitch.c diff --git a/tools/testing/selftests/arm64/mte/Makefile b/tools/testing/selftests/arm64/mte/Makefile index 2480226dfe57..0b3af552632a 100644 --- a/tools/testing/selftests/arm64/mte/Makefile +++ b/tools/testing/selftests/arm64/mte/Makefile @@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 # Copyright (C) 2020 ARM Limited -CFLAGS += -std=gnu99 -I. +CFLAGS += -std=gnu99 -I. -lpthread SRCS := $(filter-out mte_common_util.c,$(wildcard *.c)) PROGS := $(patsubst %.c,%,$(SRCS)) diff --git a/tools/testing/selftests/arm64/mte/check_gcr_el1_cswitch.c b/tools/testing/selftests/arm64/mte/check_gcr_el1_cswitch.c new file mode 100644 index 000000000000..55e33d96794c --- /dev/null +++ b/tools/testing/selftests/arm64/mte/check_gcr_el1_cswitch.c @@ -0,0 +1,152 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (C) 2020 ARM Limited + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kselftest.h" +#include "mte_common_util.h" + +#define PR_SET_TAGGED_ADDR_CTRL 55 +#define PR_GET_TAGGED_ADDR_CTRL 56 +# define PR_TAGGED_ADDR_ENABLE (1UL << 0) +# define PR_MTE_TCF_SHIFT 1 +# define PR_MTE_TCF_NONE (0UL << PR_MTE_TCF_SHIFT) +# define PR_MTE_TCF_SYNC (1UL << PR_MTE_TCF_SHIFT) +# define PR_MTE_TCF_ASYNC (2UL << PR_MTE_TCF_SHIFT) +# define PR_MTE_TCF_MASK (3UL << PR_MTE_TCF_SHIFT) +# define PR_MTE_TAG_SHIFT 3 +# define PR_MTE_TAG_MASK (0xffffUL << PR_MTE_TAG_SHIFT) + +#include "mte_def.h" + +#define NUM_ITERATIONS 1024 +#define MAX_THREADS 5 +#define THREAD_ITERATIONS 1000 + +void *execute_thread(void *x) +{ + pid_t pid = *((pid_t *)x); + pid_t tid = gettid(); + uint64_t prctl_tag_mask; + uint64_t prctl_set; + uint64_t prctl_get; + uint64_t prctl_tcf; + + srand(time(NULL) ^ (pid << 16) ^ (tid << 16)); + + prctl_tag_mask = rand() % 0xffff; + + if (prctl_tag_mask % 2) + prctl_tcf = PR_MTE_TCF_SYNC; + else + prctl_tcf = PR_MTE_TCF_ASYNC; + + prctl_set = PR_TAGGED_ADDR_ENABLE | prctl_tcf | (prctl_tag_mask << PR_MTE_TAG_SHIFT); + + for (int j = 0; j < THREAD_ITERATIONS; j++) { + if (prctl(PR_SET_TAGGED_ADDR_CTRL, prctl_set, 0, 0, 0)) { + perror("prctl() failed"); + goto fail; + } + + prctl_get = prctl(PR_GET_TAGGED_ADDR_CTRL, 0, 0, 0, 0); + + if (prctl_set != prctl_get) { + ksft_print_msg("Error: prctl_set: 0x%lx != prctl_get: 0x%lx\n", + prctl_set, prctl_get); + goto fail; + } + } + + return (void *)KSFT_PASS; + +fail: + return (void *)KSFT_FAIL; +} + +int execute_test(pid_t pid) +{ + pthread_t thread_id[MAX_THREADS]; + int thread_data[MAX_THREADS]; + + for (int i = 0; i < MAX_THREADS; i++) + pthread_create(&thread_id[i], NULL, + execute_thread, (void *)&pid); + + for (int i = 0; i < MAX_THREADS; i++) + pthread_join(thread_id[i], (void *)&thread_data[i]); + + for (int i = 0; i < MAX_THREADS; i++) + if (thread_data[i] == KSFT_FAIL) + return KSFT_FAIL; + + return KSFT_PASS; +} + +int mte_gcr_fork_test() +{ + pid_t pid[NUM_ITERATIONS]; + int results[NUM_ITERATIONS]; + pid_t cpid; + int res; + + for (int i = 0; i < NUM_ITERATIONS; i++) { + pid[i] = fork(); + + if (pid[i] == 0) { + cpid = getpid(); + + res = execute_test(cpid); + + exit(res); + } + } + + for (int i = 0; i < NUM_ITERATIONS; i++) { + wait(&res); + + if(WIFEXITED(res)) + results[i] = WEXITSTATUS(res); + else + --i; + } + + for (int i = 0; i < NUM_ITERATIONS; i++) + if (results[i] == KSFT_FAIL) + return KSFT_FAIL; + + return KSFT_PASS; +} + +int main(int argc, char *argv[]) +{ + int err; + + err = mte_default_setup(); + if (err) + return err; + + ksft_set_plan(1); + + evaluate_test(mte_gcr_fork_test(), + "Verify that GCR_EL1 is set correctly on context switch\n"); + + mte_restore_setup(); + ksft_print_cnts(); + + return ksft_get_fail_cnt() == 0 ? KSFT_PASS : KSFT_FAIL; +} +