Received: by 10.213.65.68 with SMTP id h4csp607389imn; Tue, 13 Mar 2018 14:48:24 -0700 (PDT) X-Google-Smtp-Source: AG47ELtxBHlm0+KVnrzezY/vOe+fnhacEpj/NVCy6I+N72VEdkIYORMQ/slfBmkAD6dseEgsgiCl X-Received: by 10.98.171.24 with SMTP id p24mr2002044pff.71.1520977704927; Tue, 13 Mar 2018 14:48:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520977704; cv=none; d=google.com; s=arc-20160816; b=MDDzz5q3sE6cGijbkdYnD4eVmuZUrP7TBAdERlMqXy/8VicbcY+JeeLid9miWLxh5Y 5wU5ANz4L750Ake8ezT8XQf1Y/D+SjV9mJdMSbZ2gKqd8lmhUaQ1ElRRD+/1SJCuS8W0 DqT71uCYoVsGaxrSDhsGDD82B9Bols4Ezta1HzSoFzDQMvNELGclHtzZZk+FTLi3WQgv NO8Sfq/rcrAr7C1zQ02WalYqU5W939cn45lYWD1IuBRg0S6k1ExMUspbnFF72+j1Kl1d AzuVZbO4JIwuQG2HFq3voi3MMLhg6GE8dBkFL7P35Bdebk2KvRuTQtw2EiuYcIZdDH4/ 61Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=YUnOBgn7cEFzX6W8/Al+7BDebc644rxBHnUzqagykeU=; b=lq/71grUrvo2YCJPA3WlXxuhknh+Q66My8Cuqc5mwichZs56ouGNubga2zPkEw564T iGMuMA62VhEnQRTZbQFY8WMVhrBiHg1lILx1HkEqpDbRrci8Uj1ER9sV59R0//SCrYXh xvbHucBkRiiXAO1gaowFdaoWzIi8wUmB+AqUpyf2eWPNOCheJpua2Lq6whWq13FKkRES yxcYc9uKb3KEyEwwgMWsuCdpLH3M4yL4tFcw99zGB+cBVJ7QMKk0V8EPAq5q+iJ4lInj Dk0hMSIA29/7QOdQX6LOhSr5WqdQMYGVkC56GC+tqlQE1rASeE3L9FFBD+sZvYBoJjpU moPA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u7si725987pgq.796.2018.03.13.14.48.10; Tue, 13 Mar 2018 14:48:24 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752938AbeCMVrE (ORCPT + 99 others); Tue, 13 Mar 2018 17:47:04 -0400 Received: from lhrrgout.huawei.com ([194.213.3.17]:29176 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751279AbeCMVrC (ORCPT ); Tue, 13 Mar 2018 17:47:02 -0400 Received: from LHREML711-CAH.china.huawei.com (unknown [172.18.7.108]) by Forcepoint Email with ESMTP id 49204290017A1; Tue, 13 Mar 2018 21:46:58 +0000 (GMT) Received: from localhost.localdomain (10.122.225.51) by smtpsuk.huawei.com (10.201.108.34) with Microsoft SMTP Server (TLS) id 14.3.382.0; Tue, 13 Mar 2018 21:46:52 +0000 From: Igor Stoppa To: , , , , CC: , , , , , Igor Stoppa Subject: [RFC PATCH v19 0/8] mm: security: ro protection for dynamic data Date: Tue, 13 Mar 2018 23:45:46 +0200 Message-ID: <20180313214554.28521-1-igor.stoppa@huawei.com> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.122.225.51] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch-set introduces the possibility of protecting memory that has been allocated dynamically. The memory is managed in pools: when a memory pool is turned into R/O, all the memory that is part of it, will become R/O. A R/O pool can be destroyed, to recover its memory, but it cannot be turned back into R/W mode. This is intentional. This feature is meant for data that doesn't need further modifications after initialization. However the data might need to be released, for example as part of module unloading. To do this, the memory must first be freed, then the pool can be destroyed. An example is provided, in the form of self-testing. Changes since v18: [http://www.openwall.com/lists/kernel-hardening/2018/02/28/21] * Code refactoring in pmalloc & genalloc: - simplify the logic for handling pools before and after sysf init - reduced section holding mutex on pmalloc list, when adding a pool - reduced the steps in finding length of an existing allocation - split various functions into smaller ones * clarified in the comments the need for pfree() * Various fixes to the documentation: - remove kerneldoc duplicates - added cross-reference lables - miscellaneous typos * improved error notifications: use WARNs with specific messages * added missing tests for possible error conditions Discussion topics that are unclear if they are closed and would need comment from those who initiated them, if my answers are accepted or not: * @Kees Cook proposed to have first self testing for genalloc, to validate the following patch, adding tracing of allocations My answer was that such tests would also need patching, therefore they could not certify that the functionality is corect both before and after the genalloc bitmap modification. * @Kees Cook proposed to turn the self testing into modules. My answer was that the functionality is intentionally tested very early in the boot phase, to prevent unexplainable errors, should the feature really fail. * @Matthew Wilcox proposed to use a different mechanism for th genalloc bitmap: 2 bitmaps, one for occupation and one for start. And possibly use an rbtree for the starts. My answer was that this solution is less optimized, because it scatters the data of one allocation across multiple words/pages, plus is not a transaction anymore. And the particular distribution of sizes of allocation is likely to eat up much more memory than the bitmap. Igor Stoppa (8): genalloc: track beginning of allocations Add label to genalloc.rst for cross reference genalloc: selftest struct page: add field for vm_struct Protectable Memory Pmalloc selftest lkdtm: crash on overwriting protected pmalloc var Documentation for Pmalloc Documentation/core-api/genalloc.rst | 2 + Documentation/core-api/index.rst | 1 + Documentation/core-api/pmalloc.rst | 111 ++++++ drivers/misc/lkdtm.h | 1 + drivers/misc/lkdtm_core.c | 3 + drivers/misc/lkdtm_perms.c | 28 ++ include/linux/genalloc.h | 116 +++--- include/linux/mm_types.h | 1 + include/linux/pmalloc.h | 163 ++++++++ include/linux/test_genalloc.h | 26 ++ include/linux/test_pmalloc.h | 24 ++ include/linux/vmalloc.h | 1 + init/main.c | 4 + lib/Kconfig | 15 + lib/Makefile | 1 + lib/genalloc.c | 765 ++++++++++++++++++++++++++---------- lib/test_genalloc.c | 410 +++++++++++++++++++ mm/Kconfig | 17 + mm/Makefile | 2 + mm/pmalloc.c | 643 ++++++++++++++++++++++++++++++ mm/test_pmalloc.c | 238 +++++++++++ mm/usercopy.c | 33 ++ mm/vmalloc.c | 2 + 23 files changed, 2352 insertions(+), 255 deletions(-) create mode 100644 Documentation/core-api/pmalloc.rst create mode 100644 include/linux/pmalloc.h create mode 100644 include/linux/test_genalloc.h create mode 100644 include/linux/test_pmalloc.h create mode 100644 lib/test_genalloc.c create mode 100644 mm/pmalloc.c create mode 100644 mm/test_pmalloc.c -- 2.14.1