From patchwork Wed Dec 19 21:33:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10738171 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 67BB2161F for ; Wed, 19 Dec 2018 21:34:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 59196286B2 for ; Wed, 19 Dec 2018 21:34:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CF0C286CB; Wed, 19 Dec 2018 21:34:28 +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 89FA2286B4 for ; Wed, 19 Dec 2018 21:34:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 516F28E0001; Wed, 19 Dec 2018 16:34:22 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4CB8F8E001D; Wed, 19 Dec 2018 16:34:22 -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 2FC3B8E0001; Wed, 19 Dec 2018 16:34:22 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by kanga.kvack.org (Postfix) with ESMTP id ACC158E0001 for ; Wed, 19 Dec 2018 16:34:21 -0500 (EST) Received: by mail-lj1-f198.google.com with SMTP id 18-v6so5805876ljn.8 for ; Wed, 19 Dec 2018 13:34:21 -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=SjAzFSoIbClc3Yu72aaENnK9IwoMj4eRGCahSXkkXDY=; b=bKSIarv0w1KwaUu0qi7xx9vxIAPD27FkzBk7lz41z35sv+/sW4qWm/1dDUfdl7nB4a o5D/EllB4/mzvpClIKWapGQnK/rL47ZGRP8LXllv/4NR2R+z+d/5ToXmzYspTsQ+DF5Q o/vx3ruiXESdjxFIxc95eTUTe0vYqlAC01OkUu/jRfhFDFPwZyi3NN+JMPwz3GeTewad /chQV/wlW7R33aceA44lNodWeb7l3WXwGA7JG0lXbqqdYroWbvXm+vDLd0mAtSP+Yyg1 /bkra0Gkwzaka0b9clk9KRdcPCOErpX0QXPm+RV06r3MKFOA7rOAAZOrGhFiQ/TuHspJ vp1Q== X-Gm-Message-State: AA+aEWbBtqd9Dnp9lgEdrs6DHxtdh6G4IUcQckIGfslYlCKPQAOmXBca mM1i08buxt1ymMsW7kje93Kq0VuiufcAnD0dKZBz5SIeqU/jesRTucaKC/G2Er0fDS+4RMFIeCh TLHBTdYLqXWZabE4um15O0dcO8lAhbX0Zf8SLoMoEBfHM4QCmyQywWLcDdvUjkEEVSXw7/n14vm ooBlEPa7t/cF0RhV2SpPCBkKLVCslJ7YJbOe6hPHl7qLW4OgGelCMSQlPLvK7I8vcBT8q7YuK3D Ec7qkukQ6mGM0og5c5mOkxG55xZA0o3co2X1NfOmb9ywSUjPDoaoopdPTx1J+MyJbL8YfJTIdaB Hq8ZytHAMeahHfWLg5TyTwU0uW0itkvR1dFoS4HY3cYdCfJ01uvZ3XytjZXmQf0KTT23ZMwAW6c u X-Received: by 2002:a2e:58b:: with SMTP id 133-v6mr13011681ljf.127.1545255261109; Wed, 19 Dec 2018 13:34:21 -0800 (PST) X-Received: by 2002:a2e:58b:: with SMTP id 133-v6mr13011651ljf.127.1545255259823; Wed, 19 Dec 2018 13:34:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545255259; cv=none; d=google.com; s=arc-20160816; b=S+4t6PtfbFIIqsMpDG03x/n7jYywNhfNANzy761Xq4/7cBbBuq9xMYqxioLQHuCfV5 1ZECpCI0T0H52mgHcxiTaIAwF9iRK+wBAxvExjz4ctjUYNwZED83bQyxtDLI8LoMrk72 Ya4x9OGO9FvY4+dk7S9fXYvR8PtYcoKrIlU0L6M/HDW1pVXBnthmxwbeeQ1TN3doHJ/K tBiSE/Nv2FfkI3O0ZqB7w+SmJXrvdEV5dGbvNMG7vJjGhE00xKo5mNO+3r050t+WkXs7 cMtKQh2i/yPLxQSxuEEwdifTx7erl8nkz2rjZCzRH1DW9hHSa3xEJIwdBwWEFcRn4ltf 1Uvw== 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=SjAzFSoIbClc3Yu72aaENnK9IwoMj4eRGCahSXkkXDY=; b=QmPT1RvB3Wqc9XJ2gM3Rv2MQZjQkEgP6VIXW+W3Zb3OTr5JSALwO+222jfVYTAS8R0 fjrwP/7VS1NygBpqJxcdycmuHyXd/N7wfqUnoXRWPXaNcKZqmWcwtfzCoeI3ZEMHEG3A uRv+9ptoS4y+/SORewYcfCQ/+lbyW9xOg74XbDQ22jUf+/tdzDHCM2mCT4SwwyfAdsne Iz8Ng8144pCdRvZYT+DqGnGTcaSfWenr+/kf5NrfwJKNUai/o/TmTX+Jl8sDWC+7iuRM /1kNHgqzUW0gZfPkaqjGRW0lOClmiDxccG7O7iRRZ0CiyMsu3fgxrHJgv816NJdHLE6v zEag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="poGcWw/a"; 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 j188sor5623375lfj.72.2018.12.19.13.34.19 for (Google Transport Security); Wed, 19 Dec 2018 13:34:19 -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="poGcWw/a"; 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=SjAzFSoIbClc3Yu72aaENnK9IwoMj4eRGCahSXkkXDY=; b=poGcWw/a5dJN1e4IsKUTg9pMbxoGjkckyx8MaSkIr8aVIRng3tIcIrdZ7bIpwBd1aW /Dj6i5fqZOC7b6xeP5q+VcNLiipYZbnUbSanuScQx6ZaQW9f5b2Xc5P/F/qzTZVierGT Rd6CLxydzbm7Mo5/8Hgsx4sm9C32VGSlCBeCSB9A/b18FgE2P5go+U/9Ibz9AFsHQ4YE avQ097RseD5F7PI14K0mNcIC26Xs55WgqRCaGNpums6/2CHHlkW/alMX3lufYGhYovJp I/Fnbo+3KnK1CiTtnCbj4tjLXBQ9xQMrqk97gx2+rBN1d9247ZwYsu/LSWuWqhwEXB+p azjw== X-Google-Smtp-Source: AFSGD/XS2Kzx9OR3BTlvyctmNLbS6bmvi/yoWDfNmmdJC+n2aSmi3aLbOa8u5dUsvtPjgDv0jk8AaA== X-Received: by 2002:a19:5402:: with SMTP id i2mr13050911lfb.128.1545255259391; Wed, 19 Dec 2018 13:34:19 -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 v64sm3996867lfa.48.2018.12.19.13.34.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Dec 2018 13:34:18 -0800 (PST) From: Igor Stoppa X-Google-Original-From: Igor Stoppa To: Andy Lutomirski , Matthew Wilcox , Peter Zijlstra , Dave Hansen , Mimi Zohar Cc: igor.stoppa@huawei.com, Nadav Amit , Kees Cook , 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: Wed, 19 Dec 2018 23:33:34 +0200 Message-Id: <20181219213338.26619-9-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181219213338.26619-1-igor.stoppa@huawei.com> References: <20181219213338.26619-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: 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); }