From patchwork Wed Dec 19 21:33:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10738199 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 B227214E5 for ; Wed, 19 Dec 2018 21:35:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4847286B2 for ; Wed, 19 Dec 2018 21:35:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98534286B4; Wed, 19 Dec 2018 21:35:10 +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_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,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 AFECE286B2 for ; Wed, 19 Dec 2018 21:35:09 +0000 (UTC) Received: (qmail 31876 invoked by uid 550); 19 Dec 2018 21:34:26 -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 31789 invoked from network); 19 Dec 2018 21:34:24 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=24igech0ckFrxBXxxwQUZIyc9LBZ6R5ZtTba/TaHc04=; b=PsrHxLPqAAOHeNu5dAOofHFnXp1bLF9bdTdCkJocLpMY34bZfpnS8iWf5Dw2UELMym Gs5mW3HgNBDw5r9JwJTc0Fq3/dkKkbXJS7j9ubeXSvaALWLkByds7T+R2raJoj5RB0Us PON54gmyVQYYU1Mhmt0vzo7LMuv0p5iO1KZA6Qk3Upr5Y64fRgaifZvHyDj0R8B9QWJl BH+63gFqXdkbK13Syi/DwqnOPOJoBavpGBrbHbeAijtUwGiWjznREdZkOCpw0ARGA5FE 7YraB7oodasyYu4ih5gVedVO/3YOfqhU5mGxwIyA1M6Q8keXB3YNZROEWIyRN9g1/NkH hOCg== 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:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=24igech0ckFrxBXxxwQUZIyc9LBZ6R5ZtTba/TaHc04=; b=UeuH+IvQag916NEgvyfIvRzEdGWwJveerf5T494ilTPvrfI+hSR1A9tdSRI3aogQKo mI16Dsg+x8tWPW1RbEBpvXKtX5iklf3JQCgfbG+riefowlwocB60LZnxbl13w+nEMpom A3i2rp0YFPa7t6ZTPU6NacyxkNOzFTVmsrdko09XXRUG0I5ucbdPgu9O/M6OvVSAj6d6 siBiBtwtsp8A3dB1fduyHxu8F6eFOuy6ZBdaXNsD9wZKGIdXTT4BqwXKpNNblmi90CQZ 0coi1ZsoKXgq+t32ZnVA+43sNNViJ7kszSGRXG8SFGISYuR+VCDPlvMU9VI9+xqrNtmG WAXg== X-Gm-Message-State: AA+aEWZpTMyzRC2EVss/vAbNqXgPJrfG+Viv6wbU+l+tkbtYJP8JycZC MZf03o95HKeekvd5DYrRK3k= X-Google-Smtp-Source: AFSGD/XZWonxcWlW1GBfKWAbMcZ0oFNcTXt0omhVGDk3miIbt6GEElW3TXO8yTUpmBSwSEymuJbaRw== X-Received: by 2002:a19:910d:: with SMTP id t13mr12712428lfd.98.1545255253625; Wed, 19 Dec 2018 13:34:13 -0800 (PST) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Andy Lutomirski , Matthew Wilcox , Peter Zijlstra , Dave Hansen , Mimi Zohar Cc: igor.stoppa@huawei.com, Nadav Amit , Kees Cook , linux-integrity@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/12] __wr_after_init: x86_64: debug writes Date: Wed, 19 Dec 2018 23:33:31 +0200 Message-Id: <20181219213338.26619-6-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181219213338.26619-1-igor.stoppa@huawei.com> References: <20181219213338.26619-1-igor.stoppa@huawei.com> MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP After each write operation, confirm that it was successful, otherwise generate a warning. Signed-off-by: Igor Stoppa CC: Andy Lutomirski CC: Nadav Amit CC: Matthew Wilcox CC: Peter Zijlstra CC: Kees Cook CC: Dave Hansen CC: Mimi Zohar CC: linux-integrity@vger.kernel.org CC: kernel-hardening@lists.openwall.com CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org --- arch/x86/mm/prmem.c | 9 ++++++++- mm/Kconfig.debug | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/arch/x86/mm/prmem.c b/arch/x86/mm/prmem.c index fc367551e736..9d98525c687a 100644 --- a/arch/x86/mm/prmem.c +++ b/arch/x86/mm/prmem.c @@ -60,7 +60,14 @@ void *__wr_op(unsigned long dst, unsigned long src, __kernel_size_t len, copy_to_user((void __user *)wr_poking_addr, (void *)src, len); else if (op == WR_MEMSET) memset_user((void __user *)wr_poking_addr, (u8)src, len); - +#ifdef CONFIG_DEBUG_PRMEM + if (op == WR_MEMCPY) + VM_WARN_ONCE(memcmp((void *)dst, (void *)src, len), + "Failed wr_memcpy()"); + else if (op == WR_MEMSET) + VM_WARN_ONCE(memtst((void *)dst, (u8)src, len), + "Failed wr_memset()"); +#endif unuse_temporary_mm(prev); local_irq_enable(); return (void *)dst; diff --git a/mm/Kconfig.debug b/mm/Kconfig.debug index 9a7b8b049d04..b10305cfac3c 100644 --- a/mm/Kconfig.debug +++ b/mm/Kconfig.debug @@ -94,3 +94,11 @@ config DEBUG_RODATA_TEST depends on STRICT_KERNEL_RWX ---help--- This option enables a testcase for the setting rodata read-only. + +config DEBUG_PRMEM + bool "Verify each write rare operation." + depends on PRMEM + default n + help + After any write rare operation, compares the data written with the + value provided by the caller.