From patchwork Tue Dec 1 16:16:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 11943221 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=-6.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=no 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 89A29C64E7A for ; Tue, 1 Dec 2020 16:16:44 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BDE422224B for ; Tue, 1 Dec 2020 16:16:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=axtens.net header.i=@axtens.net header.b="pOQ4NjzP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BDE422224B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id ABA858D0003; Tue, 1 Dec 2020 11:16:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A6B028D0001; Tue, 1 Dec 2020 11:16:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 95BD08D0003; Tue, 1 Dec 2020 11:16:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0252.hostedemail.com [216.40.44.252]) by kanga.kvack.org (Postfix) with ESMTP id 7D4DC8D0001 for ; Tue, 1 Dec 2020 11:16:42 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 714003625 for ; Tue, 1 Dec 2020 16:16:41 +0000 (UTC) X-FDA: 77545216602.22.toes31_020fd6d273ab Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 3753018037381 for ; Tue, 1 Dec 2020 16:16:39 +0000 (UTC) X-HE-Tag: toes31_020fd6d273ab X-Filterd-Recvd-Size: 4996 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Tue, 1 Dec 2020 16:16:38 +0000 (UTC) Received: by mail-pj1-f41.google.com with SMTP id l23so1530494pjg.1 for ; Tue, 01 Dec 2020 08:16:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=keKgMbCkoGOXeTFvWr8odCNv42gYD1NHpH65Gpi3cCA=; b=pOQ4NjzPVp6iisrE9P9gGQG6wNSldY4e18fm6iUbeVrUS7EJ37dp6TsrrKURZ/aNde ry5rJrSim0HZoWiOXMWIRmBirNoa7cEORhW5l6j4dxpbpUJT/lQTnPtzP68AnJGbBJU9 kFxi3hT3dbZM32tJteH0PEpmZ3owWh7NtAIf8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=keKgMbCkoGOXeTFvWr8odCNv42gYD1NHpH65Gpi3cCA=; b=RYH980MNH2fHvu7AH4yHaA81Q1FuKay2PrelnCokroo4p+/k3QUeRYEo40lLGt3S4c C+IweaGPMYINm5ulQ4fZTa2Qt0KJ9tWBxlrp9BH/PDYE1XCQk89Z51+Nz4vs/9RccOZL byvOO5lMRAvw3CYFrsEhyuZZrVhGzu7ZFioo8YNXCFdL4HY0q4ruB1aUK2zVXeyfPyyz hp6TrJTdyXFVzZHH34pNcp4dd7k7NDmy+IvlWxtckwQ3PUUFZa8nzXQy5cSwemFUdJEQ SWIfT7Lx0meNqDiEsPt3UG6srAw6ZaqGMS+sDlYhbljMOkYpoiBp+KprVd4BCcoXVZOP sQQA== X-Gm-Message-State: AOAM530IbOV0EQOvqu7VuqLCq4+BSNLEnmMKXl3qiCYMdLlfEnokBDLp ZOc3zVTKkbIRgBSU39mUYALxbg== X-Google-Smtp-Source: ABdhPJw8p/fYmmJr1JIB/2o9aL9RGNVV5xtAOwCWgAXwUflXsCj28scQTc16C3z6SmRwv4gaC0Apuw== X-Received: by 2002:a17:90b:a14:: with SMTP id gg20mr3560478pjb.46.1606839397634; Tue, 01 Dec 2020 08:16:37 -0800 (PST) Received: from localhost (2001-44b8-111e-5c00-f932-2db6-916f-25e2.static.ipv6.internode.on.net. [2001:44b8:111e:5c00:f932:2db6:916f:25e2]) by smtp.gmail.com with ESMTPSA id r11sm82914pgn.26.2020.12.01.08.16.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2020 08:16:37 -0800 (PST) From: Daniel Axtens To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, christophe.leroy@c-s.fr, aneesh.kumar@linux.ibm.com, bsingharora@gmail.com Cc: Daniel Axtens Subject: [PATCH v9 0/6] KASAN for powerpc64 radix Date: Wed, 2 Dec 2020 03:16:26 +1100 Message-Id: <20201201161632.1234753-1-dja@axtens.net> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Building on the work of Christophe, Aneesh and Balbir, I've ported KASAN to 64-bit Book3S kernels running on the Radix MMU. This is a significant reworking of the previous versions. Instead of the previous approach which supported inline instrumentation, this series provides only outline instrumentation. To get around the problem of accessing the shadow region inside code we run with translations off (in 'real mode'), we we restrict checking to when translations are enabled. This is done via a new hook in the kasan core and by excluding larger quantites of arch code from instrumentation. The upside is that we no longer require that you be able to specify the amount of physically contiguous memory on the system at compile time. Hopefully this is a better trade-off. More details in patch 6. kexec works. Both 64k and 4k pages work. Running as a KVM host works, but nothing in arch/powerpc/kvm is instrumented. It's also potentially a bit fragile - if any real mode code paths call out to instrumented code, things will go boom. There are 4 failing KUnit tests: kasan_stack_oob, kasan_alloca_oob_left & kasan_alloca_oob_right - these are due to not supporting inline instrumentation. kasan_global_oob - gcc puts the ASAN init code in a section called '.init_array'. Powerpc64 module loading code goes through and _renames_ any section beginning with '.init' to begin with '_init' in order to avoid some complexities around our 24-bit indirect jumps. This means it renames '.init_array' to '_init_array', and the generic module loading code then fails to recognise the section as a constructor and thus doesn't run it. This hack dates back to 2003 and so I'm not going to try to unpick it in this series. (I suspect this may have previously worked if the code ended up in .ctors rather than .init_array but I don't keep my old binaries around so I have no real way of checking.) Daniel Axtens (6): kasan: allow an architecture to disable inline instrumentation kasan: allow architectures to provide an outline readiness check kasan: define and use MAX_PTRS_PER_* for early shadow tables kasan: Document support on 32-bit powerpc powerpc/mm/kasan: rename kasan_init_32.c to init_32.c powerpc: Book3S 64-bit outline-only KASAN support