Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8175756imu; Tue, 4 Dec 2018 04:20:07 -0800 (PST) X-Google-Smtp-Source: AFSGD/XFIkiBrJceBKPBS7ufIr77RA2JSkJ+a9DCLRS9DEymZ90P1puhE6M8m8nkeYG6htxyk7ev X-Received: by 2002:a17:902:1d4a:: with SMTP id u10mr18938863plu.122.1543926007127; Tue, 04 Dec 2018 04:20:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543926007; cv=none; d=google.com; s=arc-20160816; b=vofiHTimHm2U1skP7oDSnGLN9SgUfU/uXfAjo8UG0+qBhEHOJnXj65kVxWx17gZGcu Fck/snz0rFfm3sdwl0fS7HgsR6M2In725gbV733WS3rmMslSa8usJ4I3LMZTZM58Uil8 hg2+h3oSp5AES+jb9s85VKUR+LvzaSqPu5yICEiAD+Yf8htSXMmQ5oIzy4YN9RrzBR7U VGdoVr5fvv9D5b1JfGNw0j6+E18wPaq/mPzsH8RW9QS8JW7rE0H7LW4LkfTmAhMkNFnl Zsx8McScsxTi7W7RyABog4f0FZOy9v4L1Bj+3VOCSWFQ6+XbPHzZe1hIY/J9HCZ+sLP0 tI+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender: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=ZvIBOzdT0a4R6VYXfbM9yDnOs5M2z0JIB5u9fG68FQtAz8ibml9juf5YYIWPJr75zV HzCOxdn0szC0F0A59bln6LLpHLMII6XjRbjQergay3XyPwioYXCUdDVq7jVUQVGJGuTZ KHcO1oTRY2n/PNj+4DVJjAc5dKx/eyO4/p64kijJJiQtly3W/yeKQNi3difGOedTvbVz Yt8POjwrsJKdStjSyXDSmEEdKtL1h+3VecH+zLyjG1hGJgjK2iANseidqGow6xrgY4xs P7NIOkcdB/xc2UTU77ZEcTjlN448eXkFG3ZgYSTjGPEEIprScpa4MPY7Vrn8+Ku2Wr6v fbJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nfKfgur+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l186si15503483pga.498.2018.12.04.04.19.50; Tue, 04 Dec 2018 04:20:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nfKfgur+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726337AbeLDMSw (ORCPT + 99 others); Tue, 4 Dec 2018 07:18:52 -0500 Received: from mail-lj1-f196.google.com ([209.85.208.196]:38225 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725770AbeLDMSs (ORCPT ); Tue, 4 Dec 2018 07:18:48 -0500 Received: by mail-lj1-f196.google.com with SMTP id c19-v6so14695233lja.5; Tue, 04 Dec 2018 04:18:45 -0800 (PST) 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-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=mJMksY6rKhfNGrlxoC/9f5P6S8jnAMH+e8y1ppLmkig=; b=SF3wnHVXqG7cDo1+o+KjBNaixcYQJ/QUk2pG4AiHwmx9p0GHyNP+TkGuGHujyo8DPF TJlgi/pUoY1TLwQhrZbmo6y2zWeEq9ikimebl4gevlYGaS4nsXtnqYlvGJTpX2Y2VpUH 6FI51uVBjJBmipmbcO4dt3xd62Mqs1t+OVXnhsk3TN3wH6lb11O7pNLVtRn4+ypfYuJX 2SqgcP3T1lbR4ZLIxWtWfXGJ6/nP/XDJUoHNPjtjJar1bTQBR8kV0sWeChIdQVdUQs53 6xxiDnlXj8l6WuxUPTcV5KgQcXI2U5HxUzw0vUVRTJrhnsJuazv/KYFtTMFQWqOqAYO1 liRw== X-Gm-Message-State: AA+aEWZpN1OxCrxC16jfEDHvVD2IrHlO4Mfo+EIcHtNbOnZss9Ason8E OE7uFEVuo/HxdEWWjvvH49Y= 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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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"); } -- 2.19.1