From patchwork Fri Dec 21 18:14:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10740823 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 4DBCE924 for ; Fri, 21 Dec 2018 18:15:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4070A2835B for ; Fri, 21 Dec 2018 18:15:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3413328618; Fri, 21 Dec 2018 18:15:10 +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 B5E992835B for ; Fri, 21 Dec 2018 18:15:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 52EBC8E000C; Fri, 21 Dec 2018 13:15:04 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4DBA78E0001; Fri, 21 Dec 2018 13:15:04 -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 3822C8E000C; Fri, 21 Dec 2018 13:15:04 -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 B645E8E0001 for ; Fri, 21 Dec 2018 13:15:03 -0500 (EST) Received: by mail-lj1-f199.google.com with SMTP id v27-v6so1907500ljv.1 for ; Fri, 21 Dec 2018 10:15:03 -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=vgb7J+uzu72a1nLgAIDJQpmIZYI0IWGcwJEvrx3eHk8=; b=fCu/Dvxq5YsXEInvrZ6nOPolYPqmuAppN13/UbAzMzYJ0RyZ+I7klCa6FdhvmtoLOb A4YpB7qy/GFLlBKKUkH640mx4ZGDTYi8Sj1ub8S+DDSDsl0uswBOujpsUMvfY3ZSwNrd fX6gRag8LldbG61IS5CH5TJMb5xwRDwQ1X092IzJgW7Wnl12jQQ597pi6Tws1llQzUUI Q2C/6n//8TibpwBcaBuJ9WiELw+chnxs/KDd/GxxM7Vel2Ww+OyILXBhZn3d9mR8lAQQ 0sBnSZpwff1wpn83nJVJBbGIql3cgbBDHIKR0eMAS/Es6xLObQUt1sPNn4OP1YElUxKl 9iIQ== X-Gm-Message-State: AJcUukewQdlqCVGi0jHen1oP4A2OUGbbD0mE7X+JqbmKUoE82wOBWTMj v/xbVaoGEeDDeNhdgH5iQuPDNjuwl7P9UN6EYYp05sjJIsZCx0DOblRZWkwIU2REw3j0E1ImRUX AfTQ+Mri4mWozzM+3FJKw99+cX+aNkwLYRm4Am2dO8gFb2VA/P7kzIbFOC72U8amffSgBz10GNb SlnVPXso5HWZdi8a8rdgX5F+gybVUnng1deumMKkaPUJ0QZfx+hwrxFkbj+ANokw8WX9uVfVolL Li684AhGsAluueoATi5e6Z8cgllzD7lsRXhPFeUdx61bCPZODUgvMZqmmA/P1tIfbbdWVrZX2EB bHxWbPyYfzbytwd0rcfpKhEqQZ/A/IIQx1vE1cL/imwdx3gIbieIxOzeYPd8/KrQe+Hv9J3Thl2 H X-Received: by 2002:a2e:9256:: with SMTP id v22-v6mr2496709ljg.178.1545416103112; Fri, 21 Dec 2018 10:15:03 -0800 (PST) X-Received: by 2002:a2e:9256:: with SMTP id v22-v6mr2496663ljg.178.1545416101802; Fri, 21 Dec 2018 10:15:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545416101; cv=none; d=google.com; s=arc-20160816; b=t30uovBrhqCr6TrrZmPJJK3ZgZCB4dha7ERUT3+R4hftmEL2RPuGIcEkFmXoAsw9cz D6mQo+POMdAzOZxc8B7SKCDbXY8ACpGAQp/gAj2If5PgQ3GvjOeHM2aATwXwgptlSZl2 HIuShIxqWWmHrUWJn3BdeZfDj8csiEhqSL86fGtWYtlV2Qs80Qjwe50zOKmLxMxE7J/2 F+V0GOv8tcM03mH3ykAtkJBqyMil6mZ4AVHsXDpVqGV/dFlLSSW90kUDsgO+U9J3lJEh A9xSyWLrwJd7xDiE3i1Ur4Wngg40KDZhIa0vrnjX66QpuczXozI5hCX6WcZRx+RIcuvi xAxg== 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=vgb7J+uzu72a1nLgAIDJQpmIZYI0IWGcwJEvrx3eHk8=; b=YbwBE+saxpCaUax6Z4IGD7rrZ5G9O1D3XVCUxs05zS8Xwl5p8YaLlONi1Y/ySfScoY VcUjuo60QHt5jQmff4f6gpAEtOZhjiGb4bKBfTuEYTq/mlbldEioyMDvCzcI0stw1cqX 76GGftpw0h1kuBr3XgnfGB+pa1qpXc8TSjqEHVtqUZzn/WXhgbZkM5Ca8hqVoASjC3JQ UwgBVV4TuwwP1Cq4uBmErAOuiX35cwfZD7QTGQ3sgW/F6EJLxo2ldXFwggLBniybd5rt FkUDPy/0Ac4ZDla3jHenz2SEEwdLvcL+E6DGPkd9B+2r6qTETiy8eaegR0H8IaTvKPOi Jt0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kUeoKzL4; 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 j2-v6sor16550330ljg.42.2018.12.21.10.15.01 for (Google Transport Security); Fri, 21 Dec 2018 10:15:01 -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=kUeoKzL4; 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=vgb7J+uzu72a1nLgAIDJQpmIZYI0IWGcwJEvrx3eHk8=; b=kUeoKzL4DU9YWPEF1gNBKSCW0fL9CgdXq6jjpoupxnO4uLElST2H3S+SZCQgWimXXO YZMohIUO3dmUaPEpq05kR5+UYbdP8y+AIjfcy75gu+74W7d1pcqGXzRoIbVh/NgpQ4Hu XlT/e25pZJJetrF/oy9iRTDdIkBHVWZRayJtOBqc9NF0MTUYxKeUsVGasOcHzSVmNawK taKuwvPiPWuqWrhRKsjrXcBQPTXp8K6wjHW5mb0ZzblTCCVZfJb5fhn+NIqfncqQu0zm 0/IE8fGk5PL2rlOOPxS0vZLGHddhfFG0tPSDSKOTrDWp6euS3mJKoxmuscDdf7TiCAgY X65w== X-Google-Smtp-Source: AFSGD/XswW5dKjiUGmh9wa+v9T60QYxp3Cs4xb9Q4fBCeW4KdXwqXRGKpf7tFOWWuwHHCYc03cVqMQ== X-Received: by 2002:a2e:21a9:: with SMTP id h41-v6mr2233605lji.103.1545416101435; Fri, 21 Dec 2018 10:15:01 -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.14.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Dec 2018 10:15:00 -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 08/12] rodata_test: refactor tests Date: Fri, 21 Dec 2018 20:14:19 +0200 Message-Id: <20181221181423.20455-9-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 Refactor the test cases, in preparation for using them also for testing __wr_after_init memory, when available. 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 | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/mm/rodata_test.c b/mm/rodata_test.c index d908c8769b48..e1349520b436 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; } + pr_info("%s tests were successful", data_type); + return true; +} - pr_info("all tests were successful\n"); +void rodata_test(void) +{ + test_data("rodata", &rodata_test_data, + (unsigned long)&__start_rodata, + (unsigned long)&__end_rodata); }