From patchwork Thu Jun 27 22:18:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot for Kobe Wu X-Patchwork-Id: 11020769 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 14EDA924 for ; Thu, 27 Jun 2019 22:18:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AB5F28701 for ; Thu, 27 Jun 2019 22:18:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0F1728708; Thu, 27 Jun 2019 22:18:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 10E5928701 for ; Thu, 27 Jun 2019 22:18:41 +0000 (UTC) Received: (qmail 17927 invoked by uid 550); 27 Jun 2019 22:18:40 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 17875 invoked from network); 27 Jun 2019 22:18:39 -0000 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x5RMIAO2473318 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019061801; t=1561673891; bh=JeYe5M8OdcYKuK4UMRuFplJR52KjbndV9b7BUqLhHlk=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=v9jRMpKcUXuHRJW2Ucgm6eUv+rvQaavCBa9PYEoYm1pwRxDgbMs18f+j+3eJ0vClo 5gWwTXvadc1DaQOwNh+M5hpZvHaB9DFehy9WG4OUj63G0M8tf5lV7e9KF2cEPNhiHo +BYr1rnS8XSOHnNtwF2+tcuc568Yx5PjeE8myP2tExBhRbJ06ARnuLQd0ibHYuvCiY 1SQ71k5sLmzpY49YpPc/mqrNjAqUebNjT5BC6NiCSVRSEwbGk9WU8N7AlnLs0a6ZL6 +LPpkkkIdyFRnlcPREWr2lTN36RroK/lkbPtodUbsfW4WRTfcDqN3dcPoU4WQqZNep JemStwPh5qBGA== Date: Thu, 27 Jun 2019 15:18:10 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f Sender: tip tree robot From: tip-bot for Andy Lutomirski Message-ID: Cc: fweimer@redhat.com, jannh@google.com, peterz@infradead.org, hpa@zytor.com, tglx@linutronix.de, bp@alien8.de, luto@kernel.org, kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org, mingo@kernel.org, keescook@chromium.org In-Reply-To: <0fe34229a9330e8f9de9765967939cc4f1cf26b1.1561610354.git.luto@kernel.org> References: <0fe34229a9330e8f9de9765967939cc4f1cf26b1.1561610354.git.luto@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/entry] selftests/x86: Add a test for process_vm_readv() on the vsyscall page Git-Commit-ID: 7f0a5e0755832301e7b010eab46fb715c483ba60 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Disposition: inline X-Virus-Scanned: ClamAV using ClamSMTP Commit-ID: 7f0a5e0755832301e7b010eab46fb715c483ba60 Gitweb: https://git.kernel.org/tip/7f0a5e0755832301e7b010eab46fb715c483ba60 Author: Andy Lutomirski AuthorDate: Wed, 26 Jun 2019 21:45:09 -0700 Committer: Thomas Gleixner CommitDate: Fri, 28 Jun 2019 00:04:40 +0200 selftests/x86: Add a test for process_vm_readv() on the vsyscall page get_gate_page() is a piece of somewhat alarming code to make get_user_pages() work on the vsyscall page. Test it via process_vm_readv(). Signed-off-by: Andy Lutomirski Signed-off-by: Thomas Gleixner Reviewed-by: Kees Cook Cc: Florian Weimer Cc: Jann Horn Cc: Borislav Petkov Cc: Kernel Hardening Cc: Peter Zijlstra Link: https://lkml.kernel.org/r/0fe34229a9330e8f9de9765967939cc4f1cf26b1.1561610354.git.luto@kernel.org --- tools/testing/selftests/x86/test_vsyscall.c | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tools/testing/selftests/x86/test_vsyscall.c b/tools/testing/selftests/x86/test_vsyscall.c index 34a1d35995ef..4602326b8f5b 100644 --- a/tools/testing/selftests/x86/test_vsyscall.c +++ b/tools/testing/selftests/x86/test_vsyscall.c @@ -18,6 +18,7 @@ #include #include #include +#include #ifdef __x86_64__ # define VSYS(x) (x) @@ -459,6 +460,38 @@ static int test_vsys_x(void) return 0; } +static int test_process_vm_readv(void) +{ +#ifdef __x86_64__ + char buf[4096]; + struct iovec local, remote; + int ret; + + printf("[RUN]\tprocess_vm_readv() from vsyscall page\n"); + + local.iov_base = buf; + local.iov_len = 4096; + remote.iov_base = (void *)0xffffffffff600000; + remote.iov_len = 4096; + ret = process_vm_readv(getpid(), &local, 1, &remote, 1, 0); + if (ret != 4096) { + printf("[OK]\tprocess_vm_readv() failed (ret = %d, errno = %d)\n", ret, errno); + return 0; + } + + if (vsyscall_map_r) { + if (!memcmp(buf, (const void *)0xffffffffff600000, 4096)) { + printf("[OK]\tIt worked and read correct data\n"); + } else { + printf("[FAIL]\tIt worked but returned incorrect data\n"); + return 1; + } + } +#endif + + return 0; +} + #ifdef __x86_64__ #define X86_EFLAGS_TF (1UL << 8) static volatile sig_atomic_t num_vsyscall_traps; @@ -533,6 +566,8 @@ int main(int argc, char **argv) nerrs += test_vsys_r(); nerrs += test_vsys_x(); + nerrs += test_process_vm_readv(); + #ifdef __x86_64__ nerrs += test_emulation(); #endif