From patchwork Tue Dec 4 12:17:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Stoppa X-Patchwork-Id: 10711669 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 B375E15A6 for ; Tue, 4 Dec 2018 12:18:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A60CF2A0E0 for ; Tue, 4 Dec 2018 12:18:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 999672A0E7; Tue, 4 Dec 2018 12:18:55 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 6FD482A0E0 for ; Tue, 4 Dec 2018 12:18:53 +0000 (UTC) Received: (qmail 19754 invoked by uid 550); 4 Dec 2018 12:18:52 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 19720 invoked from network); 4 Dec 2018 12:18:51 -0000 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-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:reply-to :mime-version:content-transfer-encoding; bh=EKomztucFdGpdw25mVtPM/fFZFyL6QsN9atK4DfZDNk=; b=eXHyey225skfYcq14i5SjCLzf5ZZ01Xse+J4924aJRklTvbOgl8tLpxO+IQQt0sJ62 t3bc/Qklwn6Tkeya4HILcNdr2vK8jZ7i7U/VfEpEvzP6l4gD1uunuIx5nfr4mnCfrbAp jur6rHDxiO5g1+jKMpdklXUOw5+8BXuWNFrznhYswzTcxeKxRGg9awbvIRk0nRt2A2oP VnGhvEjqKNMByBN1K8isGThHbTwl4qjia6gPGN89fjWfOHXoi/ya1NT4nC05t6oGK3gP 862dmLcxp1H1DNJAF1m3HmTAr1++CwHp03dIDo+QputwV3AumAnGcEIzzXvaJdsfGT+F yTJw== X-Gm-Message-State: AA+aEWYAaoSwLgb1FWxBQXjewuVXuUG80uP2lNzuHsdil2UlqYCQz3Sk kdFj9uOOSOzglbgrF/+gxfY= 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) 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: [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 MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP 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 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 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(-)