From patchwork Tue Dec 4 12:18:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10711671 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 44E6D15A6 for ; Tue, 4 Dec 2018 12:18:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35BBB2A0E0 for ; Tue, 4 Dec 2018 12:18:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29E1F2A0E7; Tue, 4 Dec 2018 12:18:57 +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 A583B2A0E0 for ; Tue, 4 Dec 2018 12:18:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 770B16B6EA6; Tue, 4 Dec 2018 07:18:48 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 723C26B6EA7; Tue, 4 Dec 2018 07:18:48 -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 59CD16B6EA8; Tue, 4 Dec 2018 07:18:48 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by kanga.kvack.org (Postfix) with ESMTP id DDEA26B6EA6 for ; Tue, 4 Dec 2018 07:18:47 -0500 (EST) Received: by mail-lf1-f70.google.com with SMTP id y6so1878341lfy.11 for ; Tue, 04 Dec 2018 04:18:47 -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=WBnbM87FYiZB144WHH+WIErpqzF5ZNVsWJfotUGC/To=; b=oJlbVRjrMRM76cjKgli4cxVmFA6rxoXeJN4iKPAGARHhkb2wI2U+w1Nu79xw0Jp+/0 NF03ZpNozzlClFTCtSHLeRm1uR577cQj8kG+0ABWcx+whXcdA2wHeOnpH3k6AbPTOPNU VBpYC14sRGBDossGbFjRsVbabn+DCQHMHNcPnz7LCxJZSfpMGd1Yha3/meylXaVkQ0gm Fz2PuUNgdZ2KCTYY548NVREHVL3+fvluw9axEoGzhteVHQ8yzPjNYEE6p9IVPjdwxfS/ tARLqrnoHRe0TNGEm3cTunlF50pmefzaJ9HAJ9JjZ4Fnamwp2yQ9nAqLNXc7n6j26hPb 9xCA== X-Gm-Message-State: AA+aEWawiuByFFGnBp5oDlYxu0BpLGup9fLvBdIrlV1BMl/dbO7SMdEq 2QjmxzbPNTTquzVqitKm/uwKGcYq/tnrB2AD1KeYEmOJN8SywMPd47YVzHy8TbOgf6G0MernKQT 1wdP6pLrKljzyHewTNX1Z6Y+5Y9MOUNVb5tgV92Nthjdj5t9RUhRZyhMCzicjAtsML6rCRSoPib EEiM48URmiiNE7wyzeDt7DYtcr9VMul8DB238Pw7O7xReLur17sjC3UH48WlviaRm7Uw9ZO77iY pmn36ZOkhO4zRNqWG4LBgrhc61uFIXivMLdV8OyYEArPwEmLbzud3Bg/M+qiGpbjLsQi9mhIkGH WQWGLjimgOcNkGT6z19R+Et0h+QNC/xmm1vsqTh5357+UEGbiIl8HjqvNdSmiJsN+TRbkpu7fed F X-Received: by 2002:a2e:9017:: with SMTP id h23-v6mr10982861ljg.71.1543925927230; Tue, 04 Dec 2018 04:18:47 -0800 (PST) X-Received: by 2002:a2e:9017:: with SMTP id h23-v6mr10982805ljg.71.1543925925831; Tue, 04 Dec 2018 04:18:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543925925; cv=none; d=google.com; s=arc-20160816; b=UDZVD4EEIPxZQjo89Jeol/kvd0soUAQdHuJx4dFbzgz2S8IrfkGtC9uHqGxF9tPIhg klDLdCpIiEX8EuQQ/DuQ/uIbPtjqHS4gAeKjTk3JfEsfVvnu8kjZlLPragH7QejyEQa2 1mwzWpmQT+EVXK7qlW9HJx8QSPZr8a1EmAAf/39f1izUkE6Ryo5jZL1JuOXDR6lSRktj 9N6l8udafqgohEfXyQI5urFcQ+9n/G11s5WscotAxSDHrRSkSgOzdkX3gfBnVYlygWD6 m2927vmFV/fmohI/1zLiXtleEErGt9h3bZdN6mOxPA1hQYBS2vPunnlKsxL9gANUn+V8 BfUw== 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=WBnbM87FYiZB144WHH+WIErpqzF5ZNVsWJfotUGC/To=; b=Cw+QCpsawOiz0vJ5KD9LkD5/hQSvtNveKs9xaxNjagFoll0vdynX1G1t+cSrylVB+g FYuBRIVlMbmsiWBKKsEgXD4V4BvOCFnmoiywS63fkYUktE9LW17hz2sAeK9IiNF/7d/p cWQQYzAf0GceKtKT7w7w5GEaOseZHC/A3BSxh+pyX9Ek6BkiSSQ32Zj7M7X0r3V9KJSk nuMOpA74pL5uokR2+EH/9pts0pnax/qxOB1r9XHuRvBk4BFS6zKyLgmLAlU2x4Sjz4SY 7o9dO0NqHiBGpmkOPIXAZ8JrSUMNYzjR+QK7PDDup12FZsN5NcF8no2t5gg4fDbWHUvN Mz3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=E3RY5vky; 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 m10-v6sor9470107lje.8.2018.12.04.04.18.45 for (Google Transport Security); Tue, 04 Dec 2018 04:18:45 -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=E3RY5vky; 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=WBnbM87FYiZB144WHH+WIErpqzF5ZNVsWJfotUGC/To=; b=E3RY5vkybSvPTIG8UuGMwEVOwkUplL0AFDj1MN9T0ROLaaMBhx3o6sL9qiBqK8cDpF lHokL4Goz61X1sMwWX2rqe8g+i/xkU80XCiz6Keo5mY+N2QwkuztsW8I1TLYVZ36cJL0 cH3fN77tAZGhRIwFjGT/udN/UU2XaH/2piLYSuFcG9+mF0rVBDyJkSqRWN10wU0RGVLp g/U3CKeZCh+PdGUKf8B7AMY64oqIvcBkpDi5JA5HxCI6tSjMn8oOG8MbP/CCJI23fOqP OzTixarbLeKA4neW+891Bwfc31u1LhGzMb0feY22cbNyFQTUMEWbsqO2Kl8cBZC+/vvy QAYw== X-Google-Smtp-Source: AFSGD/Uz5k3knHQnWYcPn5vvfo8l7N0tmCpAv9nXtZVRKiyo8X/OPZgpu0935A98/eCYHI1LGa7rXQ== X-Received: by 2002:a2e:9957:: with SMTP id r23-v6mr12190962ljj.98.1543925925285; Tue, 04 Dec 2018 04:18:45 -0800 (PST) Received: from localhost.localdomain (91-156-179-117.elisa-laajakaista.fi. [91.156.179.117]) by smtp.gmail.com with ESMTPSA id h3sm2899653lfj.25.2018.12.04.04.18.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Dec 2018 04:18:44 -0800 (PST) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Andy Lutomirski , Kees Cook , Matthew Wilcox Cc: igor.stoppa@huawei.com, Nadav Amit , Peter Zijlstra , Dave Hansen , linux-integrity@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/6] rodata_test: add verification for __wr_after_init Date: Tue, 4 Dec 2018 14:18:03 +0200 Message-Id: <20181204121805.4621-5-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181204121805.4621-1-igor.stoppa@huawei.com> References: <20181204121805.4621-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: 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 | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/mm/rodata_test.c b/mm/rodata_test.c index 3c1e515ca9b1..a98d088ad9cc 100644 --- a/mm/rodata_test.c +++ b/mm/rodata_test.c @@ -16,7 +16,19 @@ #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; +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; static bool test_data(char *data_type, const int *data, unsigned long start, unsigned long end) @@ -60,6 +72,9 @@ void rodata_test(void) { if (test_data("rodata", &rodata_test_data, (unsigned long)&__start_rodata, - (unsigned long)&__end_rodata)) + (unsigned long)&__end_rodata) && + test_data("wr after init data", &wr_after_init_test_data, + (unsigned long)&__start_wr_after_init, + (unsigned long)&__end_wr_after_init)) pr_info("all tests were successful\n"); }