Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8175901imu; Tue, 4 Dec 2018 04:20:16 -0800 (PST) X-Google-Smtp-Source: AFSGD/WL/8swvgZaKvlMj/dkUetlzSa2/OUEypTqtF25ekuaC/MXTfwczt0Pw+OoiZP/6WbQlkyR X-Received: by 2002:a62:28c9:: with SMTP id o192mr20248184pfo.57.1543926016281; Tue, 04 Dec 2018 04:20:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543926016; cv=none; d=google.com; s=arc-20160816; b=JpGRuPseXfoVDk0qJj2tjuD1k02FGei9s7jWS+Dt+ER9dAqshqjHKAvfuSmt9vog8v KlwLjtHzTJfxFy+L6DPbfdQFFNPswqB3eh6BS6umFnB4y7z+IVc/acXtij7oB68VkIl9 tCAQfQWr+2uQBw+OQ4d0KZVw2ivvGNd8FJAD87j8iNV4ln4lHTO8xrwegP/bDS3sl7V1 YvkdGVPy5LLNfx7jLkLA4eN54wC/LJmKlSIUscaarFsoK8OLql0IO1P9LumpdFSv8DkR tqsqwWb4TgevxF1Gne+haCsJ/jwCkYJj+ep0LMC9oCSDOxXnkDboNrkRGATkDurmjGl8 umGg== 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=NVdqMmCKQZDysvXYUM4dpuRHk0CW6y96xz6tH9NdrSw=; b=zlRWRfEBuJPSYf0gjJEDOoXpn7TjM9MWdH3bUscx5fEjXbDXb44D8K2ndr6QvfOsO+ pO1F2KfoM4sivzGFDha6flTNCz1W/HAijMOAcEDq3iCLk9S+kggDttKDs3xiz+muCeeZ X9Ok+ryE2LF8VbIx0bFwFESqcjh73XSMsQRH8MQ2xy+K9a9MTR8ivxZVPhNkaMu/w2Bp TtWzRYwk76GptE7wpiSyTrTKBZyIK24/PbhbuRPRWWrMQA+N9v5RbmAKYs9qR6cDjGLp q5OH+YPiP1bQrZJ1DxlNht0QlVKY3b1gOq/uNMOoQsI7SloG0LDdiJ4aNObGganBWqND ib8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HRfrXCFQ; 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 14si16086826pgo.511.2018.12.04.04.20.00; Tue, 04 Dec 2018 04:20:16 -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=HRfrXCFQ; 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 S1726226AbeLDMTH (ORCPT + 99 others); Tue, 4 Dec 2018 07:19:07 -0500 Received: from mail-lj1-f195.google.com ([209.85.208.195]:46170 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726308AbeLDMSv (ORCPT ); Tue, 4 Dec 2018 07:18:51 -0500 Received: by mail-lj1-f195.google.com with SMTP id v15-v6so14662143ljh.13; Tue, 04 Dec 2018 04:18:49 -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=NVdqMmCKQZDysvXYUM4dpuRHk0CW6y96xz6tH9NdrSw=; b=HRfrXCFQvzKgQhKYWkbS/im8+XnLQmGG8ccr5n3DY3AvBzv51R79u/dWJYuhk3Y/QB 5F3PX6ti+fzfyYUTTRkeMeP2Qkk/GOPZC3dVKjWeDjWxzfaNsQWYwv8PUBhakUjEMGpC +3eyvJFkXoEIJcYl3HPC01uHhpdzkuhiE5IctH//w5KYZf8JD/Y7Gole7e9dz6kxhzmW ZC9eXZteiMUUw1lsEK1t4DghxBzJd4NJHIq3xxVBIuqzUX0poFyAOWyUxaemqKC77wOK Ydsd8ZfPrBokXf7ifOd5x8NzNp/7evrgARi/7ve5XNikMvobqmD29jlx6kR0upcm+wRp 8YMA== 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=NVdqMmCKQZDysvXYUM4dpuRHk0CW6y96xz6tH9NdrSw=; b=hcmwnRcYAMEpKVc6dzPRQvqHlsjgKSkry0Rh/Ao44+/D9BLeI0LoBLZqBOb9RL7M2K zmXucjApP4B0aTxwPaA+wjFEl1tZwWt2cgR/Sif3vY1YEyq5WF+kigyVZXMJEjo2AGe2 CeyM5huPdQFAVa0yK7PRNXuJt5HFuvv1X9CBJy7iIViJZXqGzzGWcx0xDYm+HgllTexZ AUvUupSi9PbNKgwbT1zOAQAdQNneWV9GuVIpkTN10WEMvrSwQEuZlIeKKesvIhaH27FE afgClq8S4aUrSM4fQJVf3nJ8LW5dvw8DIQ0CP99FQqhaQq7UksP8u1tGoabdcJbJOEmz 3K9Q== X-Gm-Message-State: AA+aEWao5hC5fdvzkVwHmm03GmXD2ZRkY0OWhJRAgbJ0OWpnp/2UsSjH z1VAPltGfJmWAHbBQIi/68Q= X-Received: by 2002:a2e:9a16:: with SMTP id o22-v6mr3119346lji.112.1543925928237; Tue, 04 Dec 2018 04:18:48 -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.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Dec 2018 04:18:47 -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 6/6] __wr_after_init: lkdtm test Date: Tue, 4 Dec 2018 14:18:05 +0200 Message-Id: <20181204121805.4621-7-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 Verify that trying to modify a variable with the __wr_after_init modifier wil lcause a crash. 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 --- drivers/misc/lkdtm/core.c | 3 +++ drivers/misc/lkdtm/lkdtm.h | 3 +++ drivers/misc/lkdtm/perms.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/drivers/misc/lkdtm/core.c b/drivers/misc/lkdtm/core.c index 2837dc77478e..73c34b17c433 100644 --- a/drivers/misc/lkdtm/core.c +++ b/drivers/misc/lkdtm/core.c @@ -155,6 +155,9 @@ static const struct crashtype crashtypes[] = { CRASHTYPE(ACCESS_USERSPACE), CRASHTYPE(WRITE_RO), CRASHTYPE(WRITE_RO_AFTER_INIT), +#ifdef CONFIG_PRMEM + CRASHTYPE(WRITE_WR_AFTER_INIT), +#endif CRASHTYPE(WRITE_KERN), CRASHTYPE(REFCOUNT_INC_OVERFLOW), CRASHTYPE(REFCOUNT_ADD_OVERFLOW), diff --git a/drivers/misc/lkdtm/lkdtm.h b/drivers/misc/lkdtm/lkdtm.h index 3c6fd327e166..abba2f52ffa6 100644 --- a/drivers/misc/lkdtm/lkdtm.h +++ b/drivers/misc/lkdtm/lkdtm.h @@ -38,6 +38,9 @@ void lkdtm_READ_BUDDY_AFTER_FREE(void); void __init lkdtm_perms_init(void); void lkdtm_WRITE_RO(void); void lkdtm_WRITE_RO_AFTER_INIT(void); +#ifdef CONFIG_PRMEM +void lkdtm_WRITE_WR_AFTER_INIT(void); +#endif void lkdtm_WRITE_KERN(void); void lkdtm_EXEC_DATA(void); void lkdtm_EXEC_STACK(void); diff --git a/drivers/misc/lkdtm/perms.c b/drivers/misc/lkdtm/perms.c index 53b85c9d16b8..f681730aa652 100644 --- a/drivers/misc/lkdtm/perms.c +++ b/drivers/misc/lkdtm/perms.c @@ -9,6 +9,7 @@ #include #include #include +#include #include /* Whether or not to fill the target memory area with do_nothing(). */ @@ -27,6 +28,10 @@ static const unsigned long rodata = 0xAA55AA55; /* This is marked __ro_after_init, so it should ultimately be .rodata. */ static unsigned long ro_after_init __ro_after_init = 0x55AA5500; +/* This is marked __wr_after_init, so it should be in .rodata. */ +static +unsigned long wr_after_init __wr_after_init = 0x55AA5500; + /* * This just returns to the caller. It is designed to be copied into * non-executable memory regions. @@ -104,6 +109,28 @@ void lkdtm_WRITE_RO_AFTER_INIT(void) *ptr ^= 0xabcd1234; } +#ifdef CONFIG_PRMEM + +void lkdtm_WRITE_WR_AFTER_INIT(void) +{ + unsigned long *ptr = &wr_after_init; + + /* + * Verify we were written to during init. Since an Oops + * is considered a "success", a failure is to just skip the + * real test. + */ + if ((*ptr & 0xAA) != 0xAA) { + pr_info("%p was NOT written during init!?\n", ptr); + return; + } + + pr_info("attempting bad wr_after_init write at %p\n", ptr); + *ptr ^= 0xabcd1234; +} + +#endif + void lkdtm_WRITE_KERN(void) { size_t size; @@ -200,4 +227,6 @@ void __init lkdtm_perms_init(void) /* Make sure we can write to __ro_after_init values during __init */ ro_after_init |= 0xAA; + /* Make sure we can write to __wr_after_init during __init */ + wr_after_init |= 0xAA; } -- 2.19.1