From patchwork Fri Dec 21 18:14:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10740825 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 A2703924 for ; Fri, 21 Dec 2018 18:15:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94E692835B for ; Fri, 21 Dec 2018 18:15:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88FEF28622; Fri, 21 Dec 2018 18:15:14 +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 1C20C2835B for ; Fri, 21 Dec 2018 18:15:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF0D88E000D; Fri, 21 Dec 2018 13:15:05 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EA3BA8E0001; Fri, 21 Dec 2018 13:15:05 -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 D41CC8E000D; Fri, 21 Dec 2018 13:15:05 -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 63E208E0001 for ; Fri, 21 Dec 2018 13:15:05 -0500 (EST) Received: by mail-lj1-f199.google.com with SMTP id x18-v6so1903707lji.0 for ; Fri, 21 Dec 2018 10:15:05 -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=hKpBmvKhY62YcE+qk2JyFeoOHJdEVTVCpq3mJ7wKHeo=; b=S6Niv8iZkr92sRy8GcTyPD/w/UVgChWZM6VTBZBNHC5DElCxEUI+XdD7DtS5d6HooW 9w4bJGiqc7i8AbheQQcmGwkFkErJ6U+MMhV4Kzh8mb85ekZlIxoX11eWjWfpjM5l9PIO lYQC5qGV/kAI3enway1ec3x5YVuFUs5YRV/bN3PfhnmVO4JD9YS01hglZK/Ob3fsWL9L KoSJmqSm0DXhA2OoOuySU1R4wja1ylWL+mUefOSt/3Ce1VoS/A0VoMd+oE9ugqvaCiCY BDFqwGuqKTO/uDC2SPhwfHNM0YQSbvqPMUOmUoucxSd5I4dlK2Ao1SlO4IkL6CYftIpt fgbQ== X-Gm-Message-State: AJcUukfcs3qRGKLNLsZSL8rX2Lf7nVJakhjMNF+/bQwsDyM8Xt8GDG7w g1V3MvK4QhuMXPD16vv8v8gPOtET1x87vDpR5qxfVvZZFyp9KiSzcJ2ao5BsB8azTUYN0WKzcAk NbRNP08c1adwwWE2xkVUFaBPU3EgY+HJzhoHceeXCXTET5wCCWTUa2AVrz3Qp7c31fXHLrfkGP9 mS/ocQNsbsz2C0jTiJbiW8AmVqakTdhGaqkNJEB6UGW1i1oMEr26vH0fL1nl9st98O1nbPbAzGz SwHVD8XwYcYqyH0LhE6bi0TBLcZaYD6oqsV6JsBMdF2VNjYCiraKCRLAH07cce+Zc825gWJDA7l osKukgWzriA7pv5tCErXEvtThr5RfFx/ZUFqzuoBWmx0Lnzp3bBOE2oZYURajBwhX0M18TzBWuq O X-Received: by 2002:a2e:3803:: with SMTP id f3-v6mr2252235lja.169.1545416104782; Fri, 21 Dec 2018 10:15:04 -0800 (PST) X-Received: by 2002:a2e:3803:: with SMTP id f3-v6mr2252202lja.169.1545416103971; Fri, 21 Dec 2018 10:15:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545416103; cv=none; d=google.com; s=arc-20160816; b=D4NbBh5NM28UFGS9usa4qm1C5CWYqg88kDaUqwyee66V7PIJI5BAClXlw9qu0jUPF+ psvOb4B0J/GodoUM3q8l3xgwH0YStogCxlXyPTHzDrDEcz7zRsU2wfF5gg9hvifmWBhx t3D72AZPu/L+6taRzIZ1B6/ZgWb7KW+I1lyDTUh3oA0jTKT0sCa7rQ5St7VcJMKur+C9 4rttLAGgR/ZgfE5BY/Q60wE4Ai5jb5Rh2vboej+N3F9SXto5zZ6q5aYzv0E2+WtuIsq/ P4rY2XkZHDWxmj3dGhX4hC85YttSJXvt79ys/b4UVkKEjk+5Jv9W2WrqO+EbbcVfYDru LqPw== 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=hKpBmvKhY62YcE+qk2JyFeoOHJdEVTVCpq3mJ7wKHeo=; b=XZeNYTTKUDTMWyQn/oTcdvQllUHAyRXKO5AmvsGTw+YuBc0c/Sa+IYxMbp4BJcRqaN ECLcZhJbx6+rs9eNFC0zZUJbIzufBS3RhY1RbwL4wLOfANlljPFT0c3Ov6Uw8DJdNf2I cQM9fheV/cB8hcTyKliArqfMitfNNWP3zZBAfL2kahasfODE3IMYpYNP/u/FaQauqizi IhzzV1euqgbpfJ3UU11Rx5S2wH49BJB839Ns2cH2rIcy8LJ9ez0KTSOVLuXKrz2VViu2 M/JDa1OreFE5IP0Fd+ocZlsFUZl1WAGdrNRSb1mPrWrsfPHyeQOJSfzFmlBIXRcU0NsO T1dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="P/5eitQz"; 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 w77sor6921421lff.36.2018.12.21.10.15.03 for (Google Transport Security); Fri, 21 Dec 2018 10:15:03 -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="P/5eitQz"; 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=hKpBmvKhY62YcE+qk2JyFeoOHJdEVTVCpq3mJ7wKHeo=; b=P/5eitQzqF4I/oTbSibobHwdzXYLEAMNbcNPfzS3a+ykbj4p7coiugUW2F9rjhhWMm lsNPk+KqhR4DNi7n4YQ0kjs7Hs/SgxhRaox/StG8MhP71NOi8+e3TtzbjmB19jA/2erO D1y8WK3jRyhpp8TdwUQv12RC02VyzLYGSD3rsfMZvW7goTHwYSCO6SmBy4GXZ0BuOa11 RbKHrcsnPGoXvCQgHf47Vp8mmIlUEp5jwiXap9+Z0uadOJtZti8Z/5aspb3g9vpmjCuE lKXA6AazVT+48O79fX+xuYZAoJVE5lK4GhgfGVWRtbwUwyRsRiB64G/B57fD3b0NkLNj 8nDg== X-Google-Smtp-Source: AFSGD/W1G6Tq7n+hJWkNQlncfqgelqo0DV4gS71OAhO90oATObuU+4gfeMRLnUh0qrb9WRHlqlsVGQ== X-Received: by 2002:a19:2106:: with SMTP id h6mr1979270lfh.29.1545416103579; Fri, 21 Dec 2018 10:15:03 -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.15.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Dec 2018 10:15:02 -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 09/12] rodata_test: add verification for __wr_after_init Date: Fri, 21 Dec 2018 20:14:20 +0200 Message-Id: <20181221181423.20455-10-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 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 }