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: 10738163 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 0568414E5 for ; Wed, 19 Dec 2018 21:34:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9A3F286B2 for ; Wed, 19 Dec 2018 21:34:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDCAA286CB; Wed, 19 Dec 2018 21:34:18 +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=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EE29286B2 for ; Wed, 19 Dec 2018 21:34:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 343328E001B; Wed, 19 Dec 2018 16:34:16 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2F3588E0001; Wed, 19 Dec 2018 16:34:16 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1961E8E001B; Wed, 19 Dec 2018 16:34:16 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) by kanga.kvack.org (Postfix) with ESMTP id 9B21B8E0001 for ; Wed, 19 Dec 2018 16:34:15 -0500 (EST) Received: by mail-lj1-f199.google.com with SMTP id g12-v6so5964139lji.3 for ; Wed, 19 Dec 2018 13:34:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:reply-to:mime-version :content-transfer-encoding; bh=24igech0ckFrxBXxxwQUZIyc9LBZ6R5ZtTba/TaHc04=; b=K1qd1aZR2KQTVV+zbS5hJl8R/gTgxGLt3TGWSatHUyxq2v2oZO/Dy2NMgrdN5AKYIX AhfSNwHzU4MLisa6Ye/fYD06LlPmWGd1QnNQFmPWgCioph9HBHET33UNgRBe/0bCHbnC 8LqoXkUgnGk7dhoLCwoL+31K6vOZ5XZtgmgTsmnK6UcmzDKkcdGW7mPxr0wmixz17eT6 v+jBY0zxEipfGqdjAsH/ZSxk1TI3pApJmqT5l+yBdd2m09r73VATRrSta9WAAJKRJnej VCAeB1xIaAp+84bToSV6tBgecjxUAZhlg2CBmNUCUF+QUijar0AhTDUxRSDchcEiYqI1 5r6g== X-Gm-Message-State: AA+aEWZXceup6oFRHHRrAmwVYEW4Vxa9vk7fOjt7EjeUywH8I5xPHVR2 Y+IiugAJ2vWqfa4juRSTcOjESIPWfJQbHGhJ0mxLsOLwON5V/TitkeYhdE6elyXlQheE7y3Qd5T qDvmzA/KBxrOe+QQ4G43EoxFgStReLf5YQOEasyWVmSlc5mC3FRXKTSdiebJKmBbFlb3UFZt5is u8L9sWCehh9ljh7FxjvKgOnl5Kre8opGg6eEnIso6P+SrDuPNlfCTZSjhm+5o02Y13qwqZKfCN6 Qifh57/LGrXKMd3f/MWMfqiSyYkjkirMh5DZ8iJC9Poc2hntLNMylnlcASu7478jDgTzTPiAoRg 7y4HZek690d5/6ihQzQAKkc7BSRxyD9GGnopkCgwMBl+ZM51fWy2OVV8DJiJts1SqoV7OKjJ9Hp U X-Received: by 2002:a2e:9655:: with SMTP id z21-v6mr3102736ljh.136.1545255255050; Wed, 19 Dec 2018 13:34:15 -0800 (PST) X-Received: by 2002:a2e:9655:: with SMTP id z21-v6mr3102709ljh.136.1545255253998; Wed, 19 Dec 2018 13:34:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545255253; cv=none; d=google.com; s=arc-20160816; b=GfRbzP/v/a1DvXsEFenmaHEzC5biwS4F/5YaKFT79Jcew4Hvz5dLHNfUBOxsj76YpC smnF2arXDDAfTTRP/GmYmzPU9WkK1u4regOiebPF/nPFsFHWL0QxI7qk0AZJEu+OnKEN Nxwu8QJzTkqfMpanUYuLITQorrvgFHioNaY6ejc3Sac1qMPZTLRrs8SVzBovTG0UmWGt COcyff5cUwCYkphg0O9NjEOS84EI7jo4wiWQgSon3OOtWVf+E62k9iDxUqDtEdLcc9YR EttAdPv78KKEPNbg2d9RMQ2ZBSojx6jIABdpHojIawAHm4d2SsaiXnrrXrZ7C9eYyS6r Qb1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=24igech0ckFrxBXxxwQUZIyc9LBZ6R5ZtTba/TaHc04=; b=Wd0o6RxIsItUgMEGw3MvR0RRSVE+eNxsfUsR2LeiKfIqfJfO1Re0eD4jShHGm/f2uS j7/UaDr05E3Fh6Kl6kzN5oTb5eWCVXMLlsFsU0ItIzxE9Ec5L2taIIPPb9SKtSjSHAU/ pKaarK9ePRN8O1yeTehwg28ntWOFxAoKk2VHvdosqYz0zQDuNP7LpyDwfHVr3nPqFMnb A8CnyMJChTzz2UzY5uS2bf2k5FnJH8zpH6qcO95h6zXlnYpKFWwz7WHT3aZQe29FJjQ1 ZaAE4p0pFiVspUSPszxgBNgAPWFyLXgX7bDw/6N61W2jyvMwRKGT9G0+pTckcL9pGHUY sM/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PsrHxLPq; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id f18sor5726516lfa.66.2018.12.19.13.34.13 for (Google Transport Security); Wed, 19 Dec 2018 13:34:13 -0800 (PST) Received-SPF: pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PsrHxLPq; spf=pass (google.com: domain of igor.stoppa@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=igor.stoppa@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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-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) Received: from localhost.localdomain (dmhwpt3bffxn8z3-j6k-4.rev.dnainternet.fi. [2001:14bb:51:a4c8:5c24:24d7:ca5f:e7d2]) by smtp.gmail.com with ESMTPSA id v64sm3996867lfa.48.2018.12.19.13.34.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 13:34:12 -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> Reply-To: Igor Stoppa 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: 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.