From patchwork Fri Dec 21 18:14:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10740815 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 C3B3013AD for ; Fri, 21 Dec 2018 18:15:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B564E284AA for ; Fri, 21 Dec 2018 18:15:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A98F328632; Fri, 21 Dec 2018 18:15:00 +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 46934284AA for ; Fri, 21 Dec 2018 18:15:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AFFF8E0008; Fri, 21 Dec 2018 13:14:54 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 85FB38E0001; Fri, 21 Dec 2018 13:14:54 -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 701FA8E0008; Fri, 21 Dec 2018 13:14:54 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by kanga.kvack.org (Postfix) with ESMTP id 0092F8E0001 for ; Fri, 21 Dec 2018 13:14:54 -0500 (EST) Received: by mail-lj1-f200.google.com with SMTP id j24-v6so1889550lji.20 for ; Fri, 21 Dec 2018 10:14:53 -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=Us5fQxnqAuf6nDTBJO2Qb2w31hoygG1FpkEKlSmx1Kw=; b=E/+5/MyFl/BOOAXFH+UYUz4+7YQWJ3XTl5GSqnWDed4gIooGL6URPqKIO7AXUQPXHU ULXBw08UxczF+fiof8ZzVSdp0TRa4mrVcB/VGTts2X44NToQzDn14DxIKvU3k4oWayyg RGr0J9uZIq3nKO5xEZT60P7smy8wluHkeO9HC5kqADAH09pzK88MrwyR31cGvK4bwHv6 nd1lWhjAlDmMNYb4ssfH5H/WPaXnt4V7B8EjknjNgVXR9h1oRZrcTE/Y7d5d8u84aEjo 8HtMmMN285rV7l7sDha3JIqTjoON/NlpW20xbmICi0AmVdpiEREeZSGl27w9hlHzfLDz ELkw== X-Gm-Message-State: AJcUukf1Wks8sl8+DvveGabZzDlv5GXlnXsvhDLrAqRwftGeia86fSTV SM1iMVwCtcraiEiQBNWi7EzZqfFEpCdxbAf55snVF8Cxgv0tGdFgPqQCT9urtWftqFfXkMFOfWV 3AIG/xJl6NTviqxuQcGx3F0J/ivdScfnkBbaTW4y7kUmq0ejQeX60u/Ab63Kp2r6nmBH6IyqnO5 lzruwm2M+gfyfY/LWseFCZRP4+BGZeHmjrTh5nXhr7poWm2czRc2bDO+HOhkQ13BhAbOoLCENnb lG6h8xKA2WX23vvq+0KO3ME4AK5yl7h59KN9eSzS5GDvIasHQLzqtXtZpMWgGV18g9esviFHePR w3js4+0exVefxe0PlkE1E0QHIVG/s5OV0BhnXsZHSEjYu4dEHg6/rKCgeHxu9pFQvDALwC0IPBT 9 X-Received: by 2002:a2e:4c0a:: with SMTP id z10-v6mr2224507lja.85.1545416093370; Fri, 21 Dec 2018 10:14:53 -0800 (PST) X-Received: by 2002:a2e:4c0a:: with SMTP id z10-v6mr2224475lja.85.1545416092178; Fri, 21 Dec 2018 10:14:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545416092; cv=none; d=google.com; s=arc-20160816; b=h/mP6hQtulsL8FzJHDIs/nwepsAuQlZnGnFuPygy28W3QMo54TkpDdBZFKe0k2vq0w HU/pfKEDmNzxFL1FeGof68e/155KqULbuI9sWlvni5jtWF8TZeeaEwP9BxvRybnBry1f BJ7x9RMmjhpUlMTPaHD7KhwGKpeWgWG1EZDH7OuBwLnGtRfSKElbKEH3ZAscjEqp7yeY Gf7KADCNY3G9QRV0JiojU/NPeghMwVQMpDXLbioH2qdhOW5TjZEh/GPPYYlF98ZkO2sz uU3Rzo43NyKuc8gcIV7S7lM2/wvyahCWAxOG42UmLGOL7JUX3sWxRpj+dW9xDq9uRNql Xa1Q== 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=Us5fQxnqAuf6nDTBJO2Qb2w31hoygG1FpkEKlSmx1Kw=; b=L8m4j6bh6di6AcRV2e9RX8QAg9d3jT/XkGwmSYSyaev5wV3pmQHtiNP/H+EUn1NRLd +GWVsepLdRQ/azzWPE/aCSj42/e3Gnb4jW+Xclz/xGifsbg7UP1yo3ycyzxG1yaWiREI aq8wtbA6KFEyMJYF1ovoUYCI8Jizg5xhBioL44+FgARDBeFa9v3+6Jxe14OlN3E1FX4X Ld//NBKIwNxYloIeVqlkU60i57w2CotAT8KQDSQXKZOMAapo+W1TbSFcbMi/XfVyd1r4 BdJoNuA90JFBe/j07IRlEsds66aMaKc3EV45WTcgblk98i4dun11APzr57Hw7tB+CAzT dJaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HGWfQjb5; 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 w77sor6921307lff.36.2018.12.21.10.14.52 for (Google Transport Security); Fri, 21 Dec 2018 10:14:52 -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=HGWfQjb5; 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=Us5fQxnqAuf6nDTBJO2Qb2w31hoygG1FpkEKlSmx1Kw=; b=HGWfQjb5vbSEU703D7GDZF8gnrJ6CfP1TS1iPmRhSDLGjMliWP2OTU4t9dcTDDLFqv eDAU+7nNdwfcfoz6oYXjJL+HmL0C7ymB9ShJsMj23VqimbB2jkRvrjm8zuQ48p+Nfr75 ZoN6joq84uIn/psO+3Xg9u/0iXRyuQynvLmv/HtqwPCYoNAWC5Faa76BZyDT9FID2Vfu dqlkXt4qfXEYfLfc8I/aX6w3fTxt+HeG3t0yKQFDxfLBtruTGAPQ/XtAuVw0DefC7wLn CshGs3iZ+b8H51siPqXn+F0ztDMm4FEfvmDc8DP/V0wU19fqjPIHsEMvhcM4ZSk9hHIX btxg== X-Google-Smtp-Source: AFSGD/XRk3ffVjosi0KOa8ubOE0z0coXuuRA/SrFAZt3Qg8nlBRGeL4XEqjStoml5nY+Fgm+PFWoDQ== X-Received: by 2002:a19:1994:: with SMTP id 142mr2105273lfz.134.1545416091776; Fri, 21 Dec 2018 10:14:51 -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 m63-v6sm5444564lje.81.2018.12.21.10.14.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Dec 2018 10:14:51 -0800 (PST) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Andy Lutomirski , Matthew Wilcox , Peter Zijlstra , Dave Hansen , Mimi Zohar , Thiago Jung Bauermann Cc: igor.stoppa@huawei.com, Nadav Amit , Kees Cook , Ahmed Soliman , linux-integrity@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/12] __wr_after_init: debug writes Date: Fri, 21 Dec 2018 20:14:15 +0200 Message-Id: <20181221181423.20455-5-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181221181423.20455-1-igor.stoppa@huawei.com> References: <20181221181423.20455-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: Thiago Jung Bauermann CC: Ahmed Soliman CC: linux-integrity@vger.kernel.org CC: kernel-hardening@lists.openwall.com CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org --- mm/Kconfig.debug | 8 ++++++++ mm/prmem.c | 6 ++++++ 2 files changed, 14 insertions(+) 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. diff --git a/mm/prmem.c b/mm/prmem.c index e1c1be3a1171..51f6776e2515 100644 --- a/mm/prmem.c +++ b/mm/prmem.c @@ -61,6 +61,9 @@ void *wr_memcpy(void *p, const void *q, __kernel_size_t size) __wr_enable(&wr_state); __wr_memcpy(wr_poking_addr, q, size); __wr_disable(&wr_state); +#ifdef CONFIG_DEBUG_PRMEM + VM_WARN_ONCE(memcmp(p, q, size), "Failed %s()", __func__); +#endif local_irq_enable(); return p; } @@ -92,6 +95,9 @@ void *wr_memset(void *p, int c, __kernel_size_t len) __wr_enable(&wr_state); __wr_memset(wr_poking_addr, c, len); __wr_disable(&wr_state); +#ifdef CONFIG_DEBUG_PRMEM + VM_WARN_ONCE(memtst(p, c, len), "Failed %s()", __func__); +#endif local_irq_enable(); return p; }