Skip to contentSkip to conversation

memfd_secret.2: add NOTES section ...

PATCH In review Mike Rapoport 3 participants 3 messages Sep 2, 2021 – Sep 12, 2021 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 memfd_secret.2: add NOTES section ...

From: Mike Rapoport <[email protected]>

... that explains the rationale for the system call

---
 man2/memfd_secret.2 | 61 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)
man2/memfd_secret.2 +61 -0
index f3380818e..869480b48 100644
@@ -147,6 +147,67 @@ system call first appeared in Linux 5.14.
 The
 .BR memfd_secret ()
 system call is Linux-specific.
+.SH NOTES
+.PP
+The
+.BR memfd_secret ()
+system call is designed to allow a user-space process
+to create a range of memory that is inaccessible to anybody else -
+kernel included.
+There is no 100% guarantee that kernel won't be able to access
+memory ranges backed by
+.BR memfd_secret ()
+in any circumstances, but nevertheless,
+it is much harder to exfiltrate data from these regions.
+.PP
+The
+.BR memfd_secret ()
+provides the following protections:
+.IP \(bu 3
+Enhanced protection
+(in conjunction with all the other in-kernel attack prevention systems)
+against ROP attacks.
+Absence of any in-kernel primitive for accessing memory backed by
+.BR memfd_secret ()
+means that one-gadget ROP attack
+can't work to perform data exfiltration.
+The attacker would need to find enough ROP gadgets
+to reconstruct the missing page table entries,
+which significantly increases difficulty of the attack,
+especially when other protections like the kernel stack size limit
+and address space layout randomization are in place.
+.IP \(bu
+Prevent cross-process userspace memory exposures.
+Once a region for a
+.BR memfd_secret ()
+memory mapping is allocated,
+the user can't accidentally pass it into the kernel
+to be transmitted somewhere.
+The memory pages in this region cannot be accessed via the direct map
+and they are disallowed in get_user_pages.
+.IP \(bu
+Harden against exploited kernel flaws.
+In order to access memory areas backed by
+.BR memfd_secret(),
+a kernel-side attack would need to
+either walk the page tables and create new ones,
+or spawn a new privileged userspace process to perform
+secrets exfiltration using
+.BR ptrace (2).
+.PP
+The way
+.BR memfd_secret ()
+allocates and locks the memory may impact overall system performance,
+therefore the system call is disabled by default and only available
+if the system administrator turned it on using
+"secretmem.enable=y" kernel parameter.
+.PP
+To prevent potiential data leaks of memory regions backed by
+.BR memfd_secret()
+from a hybernation image,
+hybernation is prevented when there are active
+.BR memfd_secret ()
+users.
 .SH SEE ALSO
 .BR fcntl (2),
 .BR ftruncate (2),
Signature · 1 line
2.31.1
#1 lore raw

Hi Mike,

Quoted 5 lines · Mike Rapoport

From: Mike Rapoport <[email protected]>

... that explains the rationale for the system call

I found a few formatting/wording issues (see below; but I fixed them myself, so you don't need to worry about them).
In general, I understood the rationale for the system call,
so I applied the patch to my tree. However, there are some parts that I didn't understand well, mostly related to kernel internals, but since Michael knows more about those, I expect him to review those again when I send him the patch.

Thanks!

Alex

Quoted 9 lines
---
  man2/memfd_secret.2 | 61 +++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 61 insertions(+)
man2/memfd_secret.2 +0 -0
index f3380818e..869480b48 100644

man2/memfd_secret.2 system call first appeared in Linux 5.14. · line 151

Quoted 5 lines
man2/memfd_secret.2 +2 -0
@@ -147,6 +147,67 @@ system call first appeared in Linux 5.14.
  The
  .BR memfd_secret ()
  system call is Linux-specific.
+.SH NOTES
+.PP

Unnecessary .PP after .SH or .SS

man2/memfd_secret.2 system call first appeared in Linux 5.14. · line 163

Quoted 12 lines
man2/memfd_secret.2 +12 -0
+The
+.BR memfd_secret ()
+system call is designed to allow a user-space process
+to create a range of memory that is inaccessible to anybody else -
+kernel included.
+There is no 100% guarantee that kernel won't be able to access
+memory ranges backed by
+.BR memfd_secret ()
+in any circumstances, but nevertheless,
+it is much harder to exfiltrate data from these regions.
+.PP
+The

/The/d

Quoted 7 lines
man2/memfd_secret.2 +7 -0
+.BR memfd_secret ()
+provides the following protections:
+.IP \(bu 3
+Enhanced protection
+(in conjunction with all the other in-kernel attack prevention systems)
+against ROP attacks.
+Absence of any in-kernel primitive for accessing memory backed by

man2/memfd_secret.2 system call first appeared in Linux 5.14. · line 180

Quoted 10 lines
man2/memfd_secret.2 +10 -0
+.BR memfd_secret ()
+means that one-gadget ROP attack
+can't work to perform data exfiltration.
+The attacker would need to find enough ROP gadgets
+to reconstruct the missing page table entries,
+which significantly increases difficulty of the attack,
+especially when other protections like the kernel stack size limit
+and address space layout randomization are in place.
+.IP \(bu
+Prevent cross-process userspace memory exposures.

s/userspace/user-space/

Quoted 4 lines
man2/memfd_secret.2 +4 -0
+Once a region for a
+.BR memfd_secret ()
+memory mapping is allocated,
+the user can't accidentally pass it into the kernel

man2/memfd_secret.2 system call first appeared in Linux 5.14. · line 194

Quoted 10 lines
man2/memfd_secret.2 +10 -0
+to be transmitted somewhere.
+The memory pages in this region cannot be accessed via the direct map
+and they are disallowed in get_user_pages.
+.IP \(bu
+Harden against exploited kernel flaws.
+In order to access memory areas backed by
+.BR memfd_secret(),
+a kernel-side attack would need to
+either walk the page tables and create new ones,
+or spawn a new privileged userspace process to perform

s/userspace/user-space/

Quoted 20 lines
man2/memfd_secret.2 +16 -0
+secrets exfiltration using
+.BR ptrace (2).
+.PP
+The way
+.BR memfd_secret ()
+allocates and locks the memory may impact overall system performance,
+therefore the system call is disabled by default and only available
+if the system administrator turned it on using
+"secretmem.enable=y" kernel parameter.
+.PP
+To prevent potiential data leaks of memory regions backed by
+.BR memfd_secret()
+from a hybernation image,
+hybernation is prevented when there are active
+.BR memfd_secret ()
+users.
  .SH SEE ALSO
  .BR fcntl (2),
  .BR ftruncate (2),
Signature · 3 lines
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
#2 lore raw

Hi Alex,

Quoted 11 lines · Alejandro Colomar (man-pages)

Hi Mike,

Quoted 5 lines · Mike Rapoport

From: Mike Rapoport <[email protected]>

... that explains the rationale for the system call

I found a few formatting/wording issues (see below; but I fixed them myself, so you don't need to worry about them).

Thanks a lot!

Quoted 105 lines

In general, I understood the rationale for the system call, so I applied the patch to my tree. However, there are some parts that I didn't understand well, mostly related to kernel internals, but since Michael knows more about those, I expect him to review those again when I send him the patch.

Thanks!

Alex

Quoted 9 lines
---
  man2/memfd_secret.2 | 61 +++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 61 insertions(+)
man2/memfd_secret.2 +0 -0
index f3380818e..869480b48 100644

man2/memfd_secret.2 system call first appeared in Linux 5.14. · line 151

Quoted 5 lines
man2/memfd_secret.2 +2 -0
@@ -147,6 +147,67 @@ system call first appeared in Linux 5.14.
  The
  .BR memfd_secret ()
  system call is Linux-specific.
+.SH NOTES
+.PP

Unnecessary .PP after .SH or .SS

man2/memfd_secret.2 system call first appeared in Linux 5.14. · line 163

Quoted 12 lines
man2/memfd_secret.2 +12 -0
+The
+.BR memfd_secret ()
+system call is designed to allow a user-space process
+to create a range of memory that is inaccessible to anybody else -
+kernel included.
+There is no 100% guarantee that kernel won't be able to access
+memory ranges backed by
+.BR memfd_secret ()
+in any circumstances, but nevertheless,
+it is much harder to exfiltrate data from these regions.
+.PP
+The

/The/d

Quoted 7 lines
man2/memfd_secret.2 +7 -0
+.BR memfd_secret ()
+provides the following protections:
+.IP \(bu 3
+Enhanced protection
+(in conjunction with all the other in-kernel attack prevention systems)
+against ROP attacks.
+Absence of any in-kernel primitive for accessing memory backed by

man2/memfd_secret.2 system call first appeared in Linux 5.14. · line 180

Quoted 10 lines
man2/memfd_secret.2 +10 -0
+.BR memfd_secret ()
+means that one-gadget ROP attack
+can't work to perform data exfiltration.
+The attacker would need to find enough ROP gadgets
+to reconstruct the missing page table entries,
+which significantly increases difficulty of the attack,
+especially when other protections like the kernel stack size limit
+and address space layout randomization are in place.
+.IP \(bu
+Prevent cross-process userspace memory exposures.

s/userspace/user-space/

Quoted 4 lines
man2/memfd_secret.2 +4 -0
+Once a region for a
+.BR memfd_secret ()
+memory mapping is allocated,
+the user can't accidentally pass it into the kernel

man2/memfd_secret.2 system call first appeared in Linux 5.14. · line 194

Quoted 10 lines
man2/memfd_secret.2 +10 -0
+to be transmitted somewhere.
+The memory pages in this region cannot be accessed via the direct map
+and they are disallowed in get_user_pages.
+.IP \(bu
+Harden against exploited kernel flaws.
+In order to access memory areas backed by
+.BR memfd_secret(),
+a kernel-side attack would need to
+either walk the page tables and create new ones,
+or spawn a new privileged userspace process to perform

s/userspace/user-space/

Quoted 20 lines
man2/memfd_secret.2 +16 -0
+secrets exfiltration using
+.BR ptrace (2).
+.PP
+The way
+.BR memfd_secret ()
+allocates and locks the memory may impact overall system performance,
+therefore the system call is disabled by default and only available
+if the system administrator turned it on using
+"secretmem.enable=y" kernel parameter.
+.PP
+To prevent potiential data leaks of memory regions backed by
+.BR memfd_secret()
+from a hybernation image,
+hybernation is prevented when there are active
+.BR memfd_secret ()
+users.
  .SH SEE ALSO
  .BR fcntl (2),
  .BR ftruncate (2),
Signature · 3 lines
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
Signature · 2 lines
Sincerely yours,
Mike.