From patchwork Wed Dec 19 21:33:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10738215 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 440656C5 for ; Wed, 19 Dec 2018 21:36:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 365D5286A4 for ; Wed, 19 Dec 2018 21:36:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29EA8286B4; Wed, 19 Dec 2018 21:36:16 +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=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI 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 22DE12870C for ; Wed, 19 Dec 2018 21:36:02 +0000 (UTC) Received: (qmail 32696 invoked by uid 550); 19 Dec 2018 21:34:33 -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 32594 invoked from network); 19 Dec 2018 21:34:32 -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=wZ8trlwQPC9hiGZKEv5EaYDHKPPRSKQ7DlpYkIOznGo=; b=RU84YQAA9ttAmCj5fwbw1hMbyAy79lr8StEuIYPs9nOgSexZa0zqGJhbGusOBhYRhl xvmpaIiQVWKWaisVJxT3EF8AjHPFUOPsMmvVf0xabzznRPYkn4Ka2csi12L5kF0hjOA2 /YZ4p7KgF6klxJT/Fv9A5bUND4Lp9BrQt1C9Cu+DXoFZTNgZshlgaPpXxwkXJnqUg9BL qrMHZK/pasAsW4YC3x1UFogxA456adKKOJHz1U7syC70Xu0ShrNdgy0ATa0ffanp/ZPa 3YqZPYKxBhicupwqEWngQsDdCleZgY4sTjVKRTlNdvj6EHnv6HhLFbg4pQZAERHbxUTH llTg== 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=wZ8trlwQPC9hiGZKEv5EaYDHKPPRSKQ7DlpYkIOznGo=; b=JALz2aA5GyS6x6pPy4T9Cfoker4HEWKZ8jj4b67/ZHku248HNgP4PgTgZMyuZh0WpO OQfBSmtP/+MhGAJ/QfBeLPAudQNEU5RB9euoM+NmyU6xzPI8nFgg8Znf10MfjzAU8Sgp Wh7MKqjtOZ4HdTlTZSx8024FL5xo+JLXlrJc56n5MFipnemfh+uZsgBisDe7VbarfYdR oLm8dx9hskA4X6sKP8iY/BhTampVNvCViFaqKgu3+8YP1biCrBiq6HC7YudW6eMTkeYa QLEQ76ng+Dnv4MfopMOTfS5wB7G5BtpJsoCaNQLMU39mqH3qrd/PbltZM96vB8CRcHWS kWRg== X-Gm-Message-State: AA+aEWbm096sPwYKHeOh3bKeEBzL75fCyDnzoQo7jIA51eDHubscH/0a U/T08F4i9mJ1sxsfxRYeMlg= X-Google-Smtp-Source: AFSGD/XdC5giLSZrQt/Kv87Ghx67drqER+B1qjvWKaiMHLOdw8yx48gU4/ChW9agrJeuwYmr+pkViQ== X-Received: by 2002:a19:8d01:: with SMTP id p1mr12727200lfd.149.1545255261117; Wed, 19 Dec 2018 13:34:21 -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 09/12] rodata_test: add verification for __wr_after_init Date: Wed, 19 Dec 2018 23:33:35 +0200 Message-Id: <20181219213338.26619-10-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 The write protection of the __wr_after_init data can be verified with the same methodology used for const data. 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 --- mm/rodata_test.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/mm/rodata_test.c b/mm/rodata_test.c index e1349520b436..a669cf9f5a61 100644 --- a/mm/rodata_test.c +++ b/mm/rodata_test.c @@ -16,8 +16,23 @@ #define INIT_TEST_VAL 0xC3 +/* + * Note: __ro_after_init data is, for every practical effect, equivalent to + * const data, since they are even write protected at the same time; there + * is no need for separate testing. + * __wr_after_init data, otoh, is altered also after the write protection + * takes place and it cannot be exploitable for altering more permanent + * data. + */ + static const int rodata_test_data = INIT_TEST_VAL; +#ifdef CONFIG_PRMEM +static int wr_after_init_test_data __wr_after_init = INIT_TEST_VAL; +extern long __start_wr_after_init; +extern long __end_wr_after_init; +#endif + static bool test_data(char *data_type, const int *data, unsigned long start, unsigned long end) { @@ -59,7 +74,13 @@ static bool test_data(char *data_type, const int *data, void rodata_test(void) { - test_data("rodata", &rodata_test_data, - (unsigned long)&__start_rodata, - (unsigned long)&__end_rodata); + if (!test_data("rodata", &rodata_test_data, + (unsigned long)&__start_rodata, + (unsigned long)&__end_rodata)) + return; +#ifdef CONFIG_PRMEM + test_data("wr after init data", &wr_after_init_test_data, + (unsigned long)&__start_wr_after_init, + (unsigned long)&__end_wr_after_init); +#endif }