From patchwork Tue Dec 4 12:18:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10711667 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 E2F3014BD for ; Tue, 4 Dec 2018 12:18:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D56002A0E3 for ; Tue, 4 Dec 2018 12:18:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C8FE42A0EE; Tue, 4 Dec 2018 12:18:54 +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=unavailable 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 9A02B2A0E3 for ; Tue, 4 Dec 2018 12:18:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68B286B6EA5; Tue, 4 Dec 2018 07:18:47 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 63A176B6EA6; Tue, 4 Dec 2018 07:18:47 -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 48E7F6B6EA7; Tue, 4 Dec 2018 07:18:47 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f197.google.com (mail-lj1-f197.google.com [209.85.208.197]) by kanga.kvack.org (Postfix) with ESMTP id CB5746B6EA5 for ; Tue, 4 Dec 2018 07:18:46 -0500 (EST) Received: by mail-lj1-f197.google.com with SMTP id k22-v6so4492764ljk.12 for ; Tue, 04 Dec 2018 04:18:46 -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=mJMksY6rKhfNGrlxoC/9f5P6S8jnAMH+e8y1ppLmkig=; b=tMMIp2DRjIOTx5XbHQPQGoWoDMg0xrz4DbDm3pnFlZZwV9iYQ4zWrpzpECsOgO1lmK CutYd+vCdE/OeiNgckcCrdIwBSZsvVTG7EPt0smaxFp6iKshn8wpRx2BRX2z6oC8j5gy 005RAgSGkWHuxvMW2mUyRLxkXWlRdnM01Qiq/Shy4UU8JjTwX4WPpDEoy39uYGhhsedt cezeIBuMftNz+2s4W21ymufqQDcz1keM42NavAFuFzN8Tk9cj8tTmB17TAPVhDzUuMl+ ucGR779R/v8wvCswJPCG2bbBQIfthUCu519v1sgStTU9TF3MnZCgIYlPwoEVXdVh8P1v icqA== X-Gm-Message-State: AA+aEWZvifKlr8FWTJb7LQWij+7RDvQlsyycQ9uNus7FjOd5sLON5fAo fb+Vm7qyJuoDPSdlMr1qQ9IF3kPuUBFyZaWW/vYAY1TvC9QxKZuTf5DbVtLDH9BS1ORn1OGDfEf Vo5nQbM5KAingdLBD0xsbjEwqwqNrI7sAF+2j/5IOnrl4knXEwbdBWKq2ACVj2mgT+EEwCreJvu w2RkJRxDE8ES1EWPR/SsDWKCvZEQJVC2fJKFCa7eeSq29Bz4apzPy+SrXMM12b7nuyOp7eYSIWV RKZ/7iMOZpPNYoBGiIpRM8jzEUGfKdwIDq1hR0Cjk5T38RpkeaqoI9JEyl/RNP/Ad1WQoXftHj4 aDTpzRHYBsfOpyKytphFiVZVzfktQeyZfmVvFxyxplMUZVIY9xvuxgaaz4lb+xPBt0qwSeqgaO9 L X-Received: by 2002:ac2:4116:: with SMTP id b22mr12166672lfi.19.1543925926077; Tue, 04 Dec 2018 04:18:46 -0800 (PST) X-Received: by 2002:ac2:4116:: with SMTP id b22mr12166614lfi.19.1543925924546; Tue, 04 Dec 2018 04:18:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543925924; cv=none; d=google.com; s=arc-20160816; b=nyvjHcrW9YS1PaaatIfcPt7yOxikHz0/BgSF0Ln+VWh+LSEZ9qLm8YVTAbptHQdBMD qWJwedwm9060s++wL3e2nArbuBy1XHHDRDsVo+aD9xHsDCgICTIAWY1b64Xsp2j2zU+C VtYvRi5sAglxic29u9kl9WQXMuvLlOA9nIvhkRC47R4dg6vACBAZViVYkUv2lsNp1LA1 OVifRMwsRKJkWmxUq1vu20bwuwzD2R/GOJ0rZhedQUJLBGMoMiID4z2p++tR+bTdz8dH EIt+uUY3Be5CNlP0B8M34hAzbv7DW1ouxIdztSwpb7L2vqpjUTzUO5GDOJhcpcs8keBQ JZ9Q== 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=mJMksY6rKhfNGrlxoC/9f5P6S8jnAMH+e8y1ppLmkig=; b=ETLYuJfZYRssRabdRq8AJE5P9HKK7cof2jy1QU5nCs4hsLXTF1N29GuhYEiDsWlDau F5nFnYxVIVAa9hIeTZQztUd2Nqyht2LgtO9166aXAf+qojj8ijSDhT+osWAvS21phII2 BtmEWSVBJX/krORov3FIpdolIVTodupFu5UdTq8ZzQ4tEiTOR6dk8XWIh7MBRKBGiAOS vLdUyBabJlrJ4kF9MJY85PY571ikqJ9QPJwKI1IZEh77trSEXeXUewG/fKNOwre5Tr5z CfFNrP4dy7G2W01MYVoCQDNqbcWCHj+2iCkvLC3uaaCer5K15i+BvCRjOx6nB/FEnzsL Igvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nfKfgur+; 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 a22-v6sor9876491ljd.6.2018.12.04.04.18.44 for (Google Transport Security); Tue, 04 Dec 2018 04:18:44 -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=nfKfgur+; 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=mJMksY6rKhfNGrlxoC/9f5P6S8jnAMH+e8y1ppLmkig=; b=nfKfgur+7NfxEvS1bNr5TrPQffifXufN2M74WYOVBCnHg6RWnRAHN6d1ot1S7MtTFS eY6DtAA8gW2IZoeav6Xcc5AP95lgP/FMR2427gUjvvUKkZBBR3G5NhF+CkCWXT9Gsk4m x9k9BzMQN2TNCkuYtBDF/xYteWxZNp/86VmbYls2v/jcsPvK2fqd5xzHOV5FAOWYnIGz 0WKvrgqSEpNV3438xLguGp0GrrkH6H+tCLK+45XnYElomR2jxOX8lvd5JR14KFSZLfYU YE6/+wD2ec0YztQZ/xtRLG428m5WKqopIB+uMESIKB9u99CVaVDuMQM6y3xclCIqVPpn PVQA== X-Google-Smtp-Source: AFSGD/WWQI8QGsQXXSTC5ZysrJ5U8vMjuWZFjwJ8suURld6RLcFQmBCHttm98abwWPkEAZpczf/7pA== X-Received: by 2002:a2e:63cd:: with SMTP id s74-v6mr12265480lje.117.1543925923947; Tue, 04 Dec 2018 04:18:43 -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.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Dec 2018 04:18:43 -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 3/6] rodata_test: refactor tests Date: Tue, 4 Dec 2018 14:18:02 +0200 Message-Id: <20181204121805.4621-4-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 Refactor the test cases, in preparation for using them also for testing __wr_after_init memory. 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 | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/mm/rodata_test.c b/mm/rodata_test.c index d908c8769b48..3c1e515ca9b1 100644 --- a/mm/rodata_test.c +++ b/mm/rodata_test.c @@ -14,44 +14,52 @@ #include #include -static const int rodata_test_data = 0xC3; +#define INIT_TEST_VAL 0xC3 -void rodata_test(void) +static const int rodata_test_data = INIT_TEST_VAL; + +static bool test_data(char *data_type, const int *data, + unsigned long start, unsigned long end) { - unsigned long start, end; int zero = 0; /* test 1: read the value */ /* If this test fails, some previous testrun has clobbered the state */ - if (!rodata_test_data) { - pr_err("test 1 fails (start data)\n"); - return; + if (*data != INIT_TEST_VAL) { + pr_err("%s: test 1 fails (init data value)\n", data_type); + return false; } /* test 2: write to the variable; this should fault */ - if (!probe_kernel_write((void *)&rodata_test_data, - (void *)&zero, sizeof(zero))) { - pr_err("test data was not read only\n"); - return; + if (!probe_kernel_write((void *)data, (void *)&zero, sizeof(zero))) { + pr_err("%s: test data was not read only\n", data_type); + return false; } /* test 3: check the value hasn't changed */ - if (rodata_test_data == zero) { - pr_err("test data was changed\n"); - return; + if (*data != INIT_TEST_VAL) { + pr_err("%s: test data was changed\n", data_type); + return false; } /* test 4: check if the rodata section is PAGE_SIZE aligned */ - start = (unsigned long)__start_rodata; - end = (unsigned long)__end_rodata; if (start & (PAGE_SIZE - 1)) { - pr_err("start of .rodata is not page size aligned\n"); - return; + pr_err("%s: start of data is not page size aligned\n", + data_type); + return false; } if (end & (PAGE_SIZE - 1)) { - pr_err("end of .rodata is not page size aligned\n"); - return; + pr_err("%s: end of data is not page size aligned\n", + data_type); + return false; } + return true; +} - pr_info("all tests were successful\n"); +void rodata_test(void) +{ + if (test_data("rodata", &rodata_test_data, + (unsigned long)&__start_rodata, + (unsigned long)&__end_rodata)) + pr_info("all tests were successful\n"); }