Message ID | 20181204121805.4621-1-igor.stoppa@huawei.com (mailing list archive) |
---|---|
Headers | show
Return-Path: <owner-linux-mm@kvack.org> 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 DBDB515A6 for <patchwork-linux-mm@patchwork.kernel.org>; Tue, 4 Dec 2018 12:18:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE5622A0E0 for <patchwork-linux-mm@patchwork.kernel.org>; Tue, 4 Dec 2018 12:18:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1E982A0E7; Tue, 4 Dec 2018 12:18:46 +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=unavailable 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 897D82A0E3 for <patchwork-linux-mm@patchwork.kernel.org>; Tue, 4 Dec 2018 12:18:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 330E26B6EA2; Tue, 4 Dec 2018 07:18:44 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2B4CB6B6EA3; Tue, 4 Dec 2018 07:18:44 -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 1CAF86B6EA4; Tue, 4 Dec 2018 07:18:44 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by kanga.kvack.org (Postfix) with ESMTP id 9D7DA6B6EA2 for <linux-mm@kvack.org>; Tue, 4 Dec 2018 07:18:43 -0500 (EST) Received: by mail-lj1-f200.google.com with SMTP id e8-v6so4511513ljg.22 for <linux-mm@kvack.org>; Tue, 04 Dec 2018 04:18:43 -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:reply-to:mime-version:content-transfer-encoding; bh=EKomztucFdGpdw25mVtPM/fFZFyL6QsN9atK4DfZDNk=; b=ID5OMz2dgvfWHXozpzPjpZoZ/rORc0gFPWLDOUvV+QzG0D5cnAt+Dj7hjjsB60toSN M0fqtqWx7IrB5tYQRcztLYXwFXoFEyKhcBZ6i6C8ovhSDgUzXre4Iqu8hahBDgpfr2yd LbEy5+qOHDLMohrn8e8AtzqGT/1eK60Eu73yMM3VjjuWiX6eLi+vzXyfO13X4R08xPdp eJtEQ6EFYe4zJvluax83yOHvhPz4dcO8WYnuUozMc7e3HIXTYtQ7m+3CHO5zzLGOJps1 0pOLYmZnlA9F9R0VCN/O9mg1Jz6DJJrC8bdhkwtskF1plH4kvIYnawJWgxHP55V7v1mS pi7A== X-Gm-Message-State: AA+aEWYQkBZzC6T3nPOQCu+1JWNTZStjSe+oFipe5F/5cVcDj0IjxeGy VmY193A2dYmuhgwpCJG34uAf29SZKxzw6YO0z09GcET/kyuwVBtcgL3WleQGKyvy73o4RirWSbb vX16T5Fu1GRg1YEMdIwYuDFJvFrotCa+riLrHTtDhIYUs0Sh+9aQBq8EoQLwdUiGURBH9UvXOyn YIxXmoPysdYCzLIj/1J1j6UNfiYuZF4rUPCCIPOMtC/4Qx0Oed+Pv2Fa47OK11vJGp9mnLeGc9R P5XvFqy/JHqyenqYruiCamq5QXPUc4fkaeBkIauFTXpO/9XbhZ47ve1hvvsZi9MnV/s7B+ledvk tdRVt1D0BqVxJ3wEmzTptAuU4oShmQ3txnu+f2OAGHEALh/F76f7UIlhKRw/nD7AkYILSZKOlxw N X-Received: by 2002:a19:7d42:: with SMTP id y63mr11121785lfc.47.1543925922437; Tue, 04 Dec 2018 04:18:42 -0800 (PST) X-Received: by 2002:a19:7d42:: with SMTP id y63mr11121729lfc.47.1543925920849; Tue, 04 Dec 2018 04:18:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543925920; cv=none; d=google.com; s=arc-20160816; b=Ittw28wbyjZWAJddrsvTPR3uk320Y/GpeRY/+ueggk2GfU8Jcd117BJYD+6RPH7M2h K/V8DKG09GF7Ei2sEZm3Huxy1Xk4DySOJ74mYgNTchjT/r1fazZo0H2c9E6w1N0tEpy9 vGqDeR/PPq4IiQJsxPhanpcPOjqQKDOVL4NdRvCJUE6/IqN6TZK6HSzxObLLYLWANPTa 1s/askzFr1qUGqk3e84mVGDYCzqmFYtpoa7PsM2wyDrH9xUG5MBxmYYZc3krNFIjx0aE nieGZWTSPvowb8EnI9EALSox9nR477+2y8wYn4qYH0+ZwCkgBMHS3qUAZsTbcQBT9sjN Frow== 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:message-id:date :subject:cc:to:from:dkim-signature; bh=EKomztucFdGpdw25mVtPM/fFZFyL6QsN9atK4DfZDNk=; b=y7fbu+Vl/BIlILaFyyqdhlDsX6McPED0jddLHZVxJ/u1rcREI91KzS/v0xMqvDRiak vDHXPz09pJ+pLeUeUy21ZkgNXiMC+CbhoeC0/mubhST/j/oHnkJz6Kye2f/fY3EF0EjU 2SqWVrmxaKz7RwIiqKnl17zUa63dxkT2dzhMO3R8wCLmotzcvDs54DD3gJJT229Z5DcZ 6cGeic9h7Dkko85i/hsAqrfh+ONPMITT7jiSIjvGTFiDAOhTgt+Tiobcv4EgBNfan5yd Us3RxWUv4jL1eIrde53dzA4ZeyD0AbHxbYiAsUpgb7Mn/ShJ/JETB4/dikg5V91MUW9d +Elw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dBmz8p6G; 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 a16sor4252617lfi.3.2018.12.04.04.18.40 for <linux-mm@kvack.org> (Google Transport Security); Tue, 04 Dec 2018 04:18:40 -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=dBmz8p6G; 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:reply-to:mime-version :content-transfer-encoding; bh=EKomztucFdGpdw25mVtPM/fFZFyL6QsN9atK4DfZDNk=; b=dBmz8p6Gj1TniGyArDhrqTvxjff/YpIVbYvKz3HIM/22sCvHedrQGmmk93KLD+qDHq n23SaJV5/fBzfBQgs88D8p15egV7O/OGgG3PZamjm9mf9uFyTYRShbbIFGwQj7zdoErI TxhS97CQapHHQRQrRRD8HnQyBgl3ALg8DlXbxv7R/Qla3c4Ehb9clJVc+iVXcWX6d894 OKDhJTZNJx1IpqB6G0Iiuhc8AMPxxmVFRp65zYYznWwZqCWq5AOqi67TVWteuLyph3CP YntSoTAydAuIzLJaJ9F8KIfnXmfqYuou3x56DprEE5TdzeDsnSOhMQ/s4p8lFD7znBpR TucA== X-Google-Smtp-Source: AFSGD/W8gWphoUuoSjw5YUOeRczkQhI1FHNhM18fBvHXKNRhCUl79/Pygk/pqszc8KF1a/GsEa7y5g== X-Received: by 2002:a19:c396:: with SMTP id t144mr11305526lff.110.1543925920097; Tue, 04 Dec 2018 04:18:40 -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.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Dec 2018 04:18:39 -0800 (PST) From: Igor Stoppa <igor.stoppa@gmail.com> X-Google-Original-From: Igor Stoppa <igor.stoppa@huawei.com> To: Andy Lutomirski <luto@amacapital.net>, Kees Cook <keescook@chromium.org>, Matthew Wilcox <willy@infradead.org> Cc: igor.stoppa@huawei.com, Nadav Amit <nadav.amit@gmail.com>, Peter Zijlstra <peterz@infradead.org>, Dave Hansen <dave.hansen@linux.intel.com>, linux-integrity@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC v1 PATCH 0/6] hardening: statically allocated protected memory Date: Tue, 4 Dec 2018 14:17:59 +0200 Message-Id: <20181204121805.4621-1-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.19.1 Reply-To: Igor Stoppa <igor.stoppa@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: <linux-mm.kvack.org> X-Virus-Scanned: ClamAV using ClamSMTP |
Series |
hardening: statically allocated protected memory
|
expand
|
This patch-set is the first-cut implementation of write-rare memory protection, as previously agreed [1] Its purpose it to keep data write protected kernel data which is seldom modified. There is no read overhead, however writing requires special operations that are probably unsitable for often-changing data. The use is opt-in, by applying the modifier __wr_after_init to a variable declaration. As the name implies, the write protection kicks in only after init() is completed; before that moment, the data is modifiable in the usual way. Current Limitations: * supports only data which is allocated statically, at build time. * supports only x86_64 * might not work for very large amount of data, since it relies on the assumption that said data can be entirely remapped, at init. Some notes: - even if the code is only for x86_64, it is placed in the generic locations, with the intention of extending it also to arm64 - the current section used for collecting wr-after-init data might need to be moved, to work with arm64 MMU - the functionality is in its own c and h files, for now, to ease the introduction (and refactoring) of code dealing with dynamic allocation - recently some updated patches were posted for live-patch on arm64 [2], they might help with adding arm64 support here - to avoid the risk of weakening __ro_after_init, __wr_after_init data is in a separate set of pages, and any invocation will confirm that the memory affected falls within this range. I have modified rodata_test accordingly, to check als othis case. - to avoid replicating the code which does the change of mapping, there is only one function performing multiple, selectable, operations, such as memcpy(), memset(). I have added also rcu_assign_pointer() as further example. But I'm not too fond of this implementation either. I just couldn't think of any that I would like significantly better. - I have left out the patchset from Nadav that these patches depend on, but it can be found here [3] (Should have I resubmitted it?) - I am not sure what is the correct form for giving proper credit wrt the authoring of the wr_after_init mechanism, guidance would be appreciated - In an attempt to spam less people, I have curbed the list of recipients. If I have omitted someone who should have been kept/added, please add them to the thread. [1] https://www.openwall.com/lists/kernel-hardening/2018/11/22/8 [2] https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1793199.html [3] https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1810245.html Signed-off-by: Igor Stoppa <igor.stoppa@huawei.com> CC: Andy Lutomirski <luto@amacapital.net> CC: Nadav Amit <nadav.amit@gmail.com> CC: Matthew Wilcox <willy@infradead.org> CC: Peter Zijlstra <peterz@infradead.org> CC: Kees Cook <keescook@chromium.org> CC: Dave Hansen <dave.hansen@linux.intel.com> CC: linux-integrity@vger.kernel.org CC: kernel-hardening@lists.openwall.com CC: linux-mm@kvack.org CC: linux-kernel@vger.kernel.org Igor Stoppa (6): [PATCH 1/6] __wr_after_init: linker section and label [PATCH 2/6] __wr_after_init: write rare for static allocation [PATCH 3/6] rodata_test: refactor tests [PATCH 4/6] rodata_test: add verification for __wr_after_init [PATCH 5/6] __wr_after_init: test write rare functionality [PATCH 6/6] __wr_after_init: lkdtm test drivers/misc/lkdtm/core.c | 3 + drivers/misc/lkdtm/lkdtm.h | 3 + drivers/misc/lkdtm/perms.c | 29 ++++++++ include/asm-generic/vmlinux.lds.h | 20 ++++++ include/linux/cache.h | 17 +++++ include/linux/prmem.h | 134 +++++++++++++++++++++++++++++++++++++ init/main.c | 2 + mm/Kconfig | 4 ++ mm/Kconfig.debug | 9 +++ mm/Makefile | 2 + mm/prmem.c | 124 ++++++++++++++++++++++++++++++++++ mm/rodata_test.c | 63 ++++++++++++------ mm/test_write_rare.c | 135 ++++++++++++++++++++++++++++++++++++++ 13 files changed, 525 insertions(+), 20 deletions(-)