From patchwork Tue Dec 4 12:18:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10711675 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 7CA7315A6 for ; Tue, 4 Dec 2018 12:19:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E6232A0E3 for ; Tue, 4 Dec 2018 12:19:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62AD62A0F1; Tue, 4 Dec 2018 12:19:03 +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 AF8302A0E3 for ; Tue, 4 Dec 2018 12:19:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 774266B6EA8; Tue, 4 Dec 2018 07:18:51 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6AC5F6B6EA9; Tue, 4 Dec 2018 07:18:51 -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 5C3C46B6EAA; Tue, 4 Dec 2018 07:18:51 -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 E3D766B6EA8 for ; Tue, 4 Dec 2018 07:18:50 -0500 (EST) Received: by mail-lj1-f199.google.com with SMTP id l4-v6so4601425lji.5 for ; Tue, 04 Dec 2018 04:18:50 -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=NVdqMmCKQZDysvXYUM4dpuRHk0CW6y96xz6tH9NdrSw=; b=pBRXphWhQMu1RBA0n3RYl3sWbH4TFa34mazsqr14W3T7TPkl2m31G9r8R7bOYOZl/V 8cYfvmaVJpK8g2KK6nODfphB1FIZCvL9KSNjW2nnUK49he/qFgcVK00ETejKxj4PkOk+ CRVwQQerSYx1Uu2ediKOBaBXhvUWXWvj+3tLWRc88bMlBsf5OFDeYaacdl8cCVVskgdi R1pyFXFBJB4TVNfS04lVu36gbcnteHz+xui+v0s40iPEGpc7Elmy65rGBrb8TkiiHI3X SsmI4LOfEEN6hN02+BP4v/VT2vRL0HVRhtbF69XFBXz1wir7Gq3bJ75QoBUks8iCcAaL aXJg== X-Gm-Message-State: AA+aEWZ+2qaQ8vn4CdWOyugJHm0f9rSlyh/VmbZb6+E8aL6fIK/SxXyI T8wVCWaxGWb89Go6sq6GIsDQyEAz9SXxyTt3t2guzLf5Y7Ff39cKSU6zNPT5+S2eOL3QYOTVsew 3neJKSNitXwna1b8szjOxkJvrMM76xxO8o+iW1vZ5v4EiJogYRDGT8L0+RnC96FRghilkpnktf9 vfa20eqNGEaoaSJWeH0WZbQFRxQwZ+mbRsgA+JOt3znHzrDEpOdSNZSA7p2ojVz36GVFbfYfeJo MIO23DBvtJ6W5ojpv6ECCTZGwz7JMQxAAnKhvkcEQRxBEmGz4/Kz/QyL15Wv5F8Nbg7vKy3eKjz SivxjYHzKu7+/U3iEIjCmXcAzyeytdVsqTljvV6oHoDyIYX2trIsXNf9fBSGyRzbpD3Jd3p0OP6 0 X-Received: by 2002:a19:789:: with SMTP id 131mr8302187lfh.11.1543925930215; Tue, 04 Dec 2018 04:18:50 -0800 (PST) X-Received: by 2002:a19:789:: with SMTP id 131mr8302129lfh.11.1543925928774; Tue, 04 Dec 2018 04:18:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543925928; cv=none; d=google.com; s=arc-20160816; b=kxlW3tnBBIaTPwWE7B9Bew/Vm4cWEeNd6oMmDs+/MUwyuTxwA/HfqrHjCLLydb3fT2 kQCmtg40VWfLDp501xZ1g5nTFSST8dFyeZlYrbTqsXdVoGDD2cTP/KdXrudVYTVWgKUa Ka+hP2D2YsmpisBWuKS7SyZe9Q3xzKOmR6aP4UuuOaKVXssCpTtwKiTeShfyV5b24GsZ 0UiHsoVOL3iZXV3arv2r/2TKXugEX8enqN6Oy7J+/+7EE6fRkPueaIJ/b2H2XxrZBeov g4GP7VB5HQ90ooKSxiYN8AztwiF3ofFIAa1LhmYRppQztMQ1BrZkFLPluYLhP1Nw6E2o jiYQ== 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=NVdqMmCKQZDysvXYUM4dpuRHk0CW6y96xz6tH9NdrSw=; b=bPFeWNVJaxFNTiVTUaafexvfbFJyXvt20H5OHfn9jD/2HMLxVcvJuhQue1BZ2gcJ5C 5bm2jTNcJvzANZGSkoG65FUEUIly2FYDcX8uFPF+NQ9m0M3b0PS2HptAKs6OeY+tDmzr nTqrjcbBpllpaCqwMVYDv47+SQpIYh2J2v8NgfSEDjae1bE7zkDyNBO33Pb3+OXzj0Cc BQ8LKKSaDFXDHQZcZCp/YaYq+QMLd2Nyg4Pt/r6CXrlMaCRskzvRe/U7jjl/Qsl2Dsj5 r/oxFavPXxnGrbSG/8ncb721EljYxCpe4eD9ZnNCDL/qNqHtEcv9BmfkAHftznK/LLJN rP/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HRfrXCFQ; 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 96-v6sor9443421lja.27.2018.12.04.04.18.48 for (Google Transport Security); Tue, 04 Dec 2018 04:18:48 -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=HRfrXCFQ; 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=NVdqMmCKQZDysvXYUM4dpuRHk0CW6y96xz6tH9NdrSw=; b=HRfrXCFQvzKgQhKYWkbS/im8+XnLQmGG8ccr5n3DY3AvBzv51R79u/dWJYuhk3Y/QB 5F3PX6ti+fzfyYUTTRkeMeP2Qkk/GOPZC3dVKjWeDjWxzfaNsQWYwv8PUBhakUjEMGpC +3eyvJFkXoEIJcYl3HPC01uHhpdzkuhiE5IctH//w5KYZf8JD/Y7Gole7e9dz6kxhzmW ZC9eXZteiMUUw1lsEK1t4DghxBzJd4NJHIq3xxVBIuqzUX0poFyAOWyUxaemqKC77wOK Ydsd8ZfPrBokXf7ifOd5x8NzNp/7evrgARi/7ve5XNikMvobqmD29jlx6kR0upcm+wRp 8YMA== X-Google-Smtp-Source: AFSGD/UPXTOGRAw/49T9676bvJ9/1gFe/zO9Lwr0qxwwIUQFs7TARHUmypZrYSVjqRzSte4x5ibGcg== 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 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 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; }