From patchwork Mon Feb 11 23:27:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10807005 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 B1C556C2 for ; Mon, 11 Feb 2019 23:30:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F5DB2AF1A for ; Mon, 11 Feb 2019 23:30:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CD0D2AF27; Mon, 11 Feb 2019 23:30:15 +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 9E32C2AF1A for ; Mon, 11 Feb 2019 23:30:14 +0000 (UTC) Received: (qmail 1264 invoked by uid 550); 11 Feb 2019 23:28:49 -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 1173 invoked from network); 11 Feb 2019 23:28:48 -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=hKpBmvKhY62YcE+qk2JyFeoOHJdEVTVCpq3mJ7wKHeo=; b=BGYDAnDXfWDwMeK5eSKfBJYIRnmsh1oPx2ZOf8HcWXdmwBIgDVTpuqYUB3KvmHH93e CQ/pUVW9gaxkff/ISmJHvCx/y1ksn3D2ZB0Zl1e1iyNKsyURJCuhYe/XfMWhILPIoQX+ sOSNtcaEc0fNOG4tGaK9bLqGDsUMwDS9dEo/h/3lAczrR4Z9kaLfBvB7RrPofGWyd07Z 87HJ77tPwwo/7W13RnoDCQDElfKTZPRyDBFxrJ719qY6wqsZ65fePWfguFZ20wyR1vzj 2ALjxTWAWngGdiNowfrT+LbQ993RGtjwSm7r04Cwz+BFeQhqMsf1ODGAgbq7iaAYEptt Yxig== 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=hKpBmvKhY62YcE+qk2JyFeoOHJdEVTVCpq3mJ7wKHeo=; b=cK+Olv4onyaCC2yqPcw5Ak86iymVzgPNNY+tYncNwHMlJL2CcThBeIjcMXDDSQPXV4 enCa4UJMvvHV8sFAktI3pzBT10u7uAInU9WxWLwjh3P3UJOE4Pv0RPafVR33B5qiadL9 eVjZLltT2vCpWErvwT0yeOsFirFUID1BY7kMnatsfizSaOaEBJnvxhPulMqLVOw33OOV F3wzRPQn0lFNxRezxnxabhx+qXJ1lXxtCd3J8bsPoXdbA8DhvQHlzhoBfKMkh3APBIIB 84YUgjm+sbTrakQHSD4JcHDEYdBtj6ZOaJjZveVbMeJKg8Rj6WMRaAe3Q+mv6lioTNUA 7cdw== X-Gm-Message-State: AHQUAuaBWTyHBBqUnBn/CEFG/frm7P76EwUF6zsHNdwuPQhmB4VBkdo6 K1VcCfUreXHis3jtZfrmu0s= X-Google-Smtp-Source: AHgI3IaFcGvUdEZKnlRNCrjUqMaXRhiVC7YxDFcfeCy5/2TwxwLp1XrgFxFOCYbNVyOvJEbUKa2RjA== X-Received: by 2002:a7b:ce84:: with SMTP id q4mr490431wmj.105.1549927717395; Mon, 11 Feb 2019 15:28:37 -0800 (PST) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Cc: Igor Stoppa , Andy Lutomirski , Nadav Amit , Matthew Wilcox , Peter Zijlstra , Kees Cook , Dave Hansen , Mimi Zohar , Thiago Jung Bauermann , Ahmed Soliman , linux-integrity@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v4 10/12] __wr_after_init: rodata_test: test __wr_after_init Date: Tue, 12 Feb 2019 01:27:47 +0200 Message-Id: <5b674df65263831006ea27edce2c08fd70ddd6b1.1549927666.git.igor.stoppa@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: 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: 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/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 }