linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] proc: add config to block FOLL_FORCE in mem writes
@ 2024-07-17 11:13 Adrian Ratiu
  2024-07-17 17:22 ` Kees Cook
  2024-07-17 20:53 ` Eric Biggers
  0 siblings, 2 replies; 8+ messages in thread
From: Adrian Ratiu @ 2024-07-17 11:13 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: linux-security-module, linux-kernel, linux-hardening, kernel,
	gbiv, inglorion, ajordanr, Adrian Ratiu, Doug Anderson, Jeff Xu,
	Jann Horn, Kees Cook, Christian Brauner, Linus Torvalds

This simple Kconfig option removes the FOLL_FORCE flag from
procfs write calls because it can be abused.

Enabling it breaks some debuggers like GDB so it defaults off.

Previously we tried a more sophisticated approach allowing
distributions to fine-tune proc/pid/mem behaviour via both
kconfig and boot params, however that got NAK-ed by Linus [1]
who prefers this simpler approach.

Link: https://lore.kernel.org/lkml/CAHk-=wiGWLChxYmUA5HrT5aopZrB7_2VTa0NLZcxORgkUe5tEQ@mail.gmail.com/ [1]
Cc: Doug Anderson <dianders@chromium.org>
Cc: Jeff Xu <jeffxu@google.com>
Cc: Jann Horn <jannh@google.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Christian Brauner <brauner@kernel.org>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
---
 fs/proc/base.c   |  6 +++++-
 security/Kconfig | 14 ++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 72a1acd03675..53ad71d7d785 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -855,7 +855,11 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
 	if (!mmget_not_zero(mm))
 		goto free;
 
-	flags = FOLL_FORCE | (write ? FOLL_WRITE : 0);
+	flags = (write ? FOLL_WRITE : 0);
+
+#ifndef CONFIG_SECURITY_PROC_MEM_RESTRICT_FOLL_FORCE
+	flags |= FOLL_FORCE;
+#endif
 
 	while (count > 0) {
 		size_t this_len = min_t(size_t, count, PAGE_SIZE);
diff --git a/security/Kconfig b/security/Kconfig
index 412e76f1575d..24053b8ff786 100644
--- a/security/Kconfig
+++ b/security/Kconfig
@@ -19,6 +19,20 @@ config SECURITY_DMESG_RESTRICT
 
 	  If you are unsure how to answer this question, answer N.
 
+config SECURITY_PROC_MEM_RESTRICT_FOLL_FORCE
+	bool "Remove FOLL_FORCE usage from /proc/pid/mem writes"
+	default n
+	help
+	  This restricts FOLL_FORCE flag usage in procfs mem write calls
+	  because it bypasses memory permission checks and can be used by
+	  attackers to manipulate process memory contents that would be
+	  otherwise protected.
+
+	  Enabling this will break GDB, gdbserver and other debuggers
+	  which require FOLL_FORCE for basic functionalities.
+
+	  If you are unsure how to answer this question, answer N.
+
 config SECURITY
 	bool "Enable different security models"
 	depends on SYSFS
-- 
2.44.2


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-07-18 15:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-17 11:13 [PATCH] proc: add config to block FOLL_FORCE in mem writes Adrian Ratiu
2024-07-17 17:22 ` Kees Cook
2024-07-17 18:16   ` Linus Torvalds
2024-07-17 22:23     ` Kees Cook
2024-07-18  0:04       ` Linus Torvalds
2024-07-18 15:58         ` Adrian Ratiu
2024-07-17 20:53 ` Eric Biggers
2024-07-17 21:28   ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).