mm: introduce memfd_secret system call to create "secret" memory areas

Started by Mike Rapoport on Jan 21, 2021 · 78 messages from 10 authors · Last reply Feb 4, 2021

Series

11 patches, 38 files

+947 −82

Subsystems (20)

Show 17 more

Maintainers (27)

Show 23 more
STALE2115d SUPERSEDED

Status: Superseded by v20 (posted 2021-05-18). [go to v20]

Revision v16 (19 revisions archived).

Revisions (19)

page 2 of 2 · open the first message on its own page

  1. [PATCH v16 01/11] mm: add definition of PMD_PAGE_ORDER
    Revisions and related patches
    Revisions (19)
  2. [PATCH v16 02/11] mmap: make mlock_future_check() global
    Revisions and related patches
    Revisions (19)
  3. [PATCH v16 08/11] secretmem: add memcg accounting
    Revisions and related patches
    Revisions (12)
  4. [PATCH v16 07/11] secretmem: use PMD-size pages to amortize direct map fragmentation
    Revisions and related patches
    Revisions (15)
  5. [PATCH v16 11/11] secretmem: test: add basic selftest for memfd_secret(2)
    Revisions and related patches
    Revisions (2)
    1. v15
    2. v16 current [diff against previous]
  6. [PATCH v16 10/11] arch, mm: wire up memfd_secret system call where relevant
    Revisions and related patches
    Revisions (6)
    1. v12
    2. v13 [diff against previous]
    3. v14 [diff against previous]
    4. v15 [diff against previous]
    5. v16 current [diff against previous]
    6. v17 [diff against previous]
  7. [PATCH v16 09/11] PM: hibernate: disable when there are active secretmem users
    Revisions and related patches
    Revisions (11)
  8. [PATCH v16 05/11] set_memory: allow querying whether set_direct_map_*() is actually enabled
    Revisions and related patches
    Revisions (19)
  9. [PATCH v16 06/11] mm: introduce memfd_secret system call to create "secret" memory areas
    Revisions and related patches
    Revisions (18)
  10. [PATCH v16 03/11] riscv/Kconfig: make direct map manipulation options depend on MMU
    Revisions and related patches
    Revisions (19)
  11. [PATCH v16 04/11] set_memory: allow set_direct_map_*_noflush() for multiple pages
    Revisions and related patches
    Revisions (19)

Re: [PATCH v16 07/11] secretmem: use PMD-size pages to amortize direct map fragmentation

Message details and related content
On Wed, Feb 03, 2021 at 01:09:30PM +0100, Michal Hocko wrote:
On Tue 02-02-21 10:55:40, James Bottomley wrote:
quoted
On Tue, 2021-02-02 at 20:15 +0200, Mike Rapoport wrote:
quoted
On Tue, Feb 02, 2021 at 03:34:29PM +0100, David Hildenbrand wrote:
quoted
On 02.02.21 15:32, Michal Hocko wrote:
Well the safest security statement is that we never expose the data to
the kernel because it's a very clean security statement and easy to
enforce. It's also the easiest threat model to analyse.   Once we do
start exposing the secret to the kernel it alters the threat profile
and the analysis and obviously potentially provides the ROP gadget to
an attacker to do the same. Instinct tells me that the loss of
security doesn't really make up for the ability to swap or migrate but
if there were a case for doing the latter, it would have to be a
security policy of the user (i.e. a user should be able to decide their
data is too sensitive to expose to the kernel).
The security/threat model should be documented in the changelog as
well. I am not a security expert but I would tend to agree that not
allowing even temporal mapping for data copying (in the kernel) is the
most robust approach. Whether that is generally necessary for users I do
not know.

From the API POV I think it makes sense to have two
modes. NEVER_MAP_IN_KERNEL which would imply no migrateability, no
copy_{from,to}_user, no gup or any other way for the kernel to access
content of the memory. Maybe even zero the content on the last unmap to
never allow any data leak. ALLOW_TEMPORARY would unmap the page from
the direct mapping but it would still allow temporary mappings for
data copying inside the kernel (thus allow CoW, copy*user, migration).
Which one should be default and which an opt-in I do not know. A less
restrictive mode to be default and the more restrictive an opt-in via
flags makes a lot of sense to me though.
The default is already NEVER_MAP_IN_KERNEL, so there is no explicit flag
for this. ALLOW_TEMPORARY should be opt-in, IMHO, and we can add it on top
later on.

-- 
Sincerely yours,
Mike.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Re: [PATCH v16 06/11] mm: introduce memfd_secret system call to create "secret" memory areas

Message details and related content
On Wed, Feb 03, 2021 at 01:15:58PM +0100, Michal Hocko wrote:
On Thu 21-01-21 14:27:18, Mike Rapoport wrote:
quoted
+static struct file *secretmem_file_create(unsigned long flags)
+{
+	struct file *file = ERR_PTR(-ENOMEM);
+	struct secretmem_ctx *ctx;
+	struct inode *inode;
+
+	inode = alloc_anon_inode(secretmem_mnt->mnt_sb);
+	if (IS_ERR(inode))
+		return ERR_CAST(inode);
+
+	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+	if (!ctx)
+		goto err_free_inode;
+
+	file = alloc_file_pseudo(inode, secretmem_mnt, "secretmem",
+				 O_RDWR, &secretmem_fops);
+	if (IS_ERR(file))
+		goto err_free_ctx;
+
+	mapping_set_unevictable(inode->i_mapping);
Btw. you need also mapping_set_gfp_mask(mapping, GFP_HIGHUSER) because
the default is GFP_HIGHUSER_MOVABLE and you do not support migration so
no pages from movable zones should be allowed.
Ok.

-- 
Sincerely yours,
Mike.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Re: [PATCH v16 07/11] secretmem: use PMD-size pages to amortize direct map fragmentation

Message details and related content
On Thu 04-02-21 11:58:55, Mike Rapoport wrote:
On Wed, Feb 03, 2021 at 10:12:22AM +0100, Michal Hocko wrote:
[...]
quoted
Wrt to the specific syscall, please document why existing interfaces are
not a good fit as well. It would be also great to describe interaction
with mlock itself (I assume the two to be incompatible - mlock will fail
on and mlockall will ignore it).
The interaction with mlock() belongs more to the man page, but I don't mind
adding this to changelog as well.
I would expect this to be explicitly handled in the patch - thus the
changelog rationale.
-- 
Michal Hocko
SUSE Labs

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Previous page

Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help