[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240717111358.415712-1-adrian.ratiu@collabora.com>
Date: Wed, 17 Jul 2024 14:13:58 +0300
From: Adrian Ratiu <adrian.ratiu@...labora.com>
To: linux-fsdevel@...r.kernel.org
Cc: linux-security-module@...r.kernel.org,
linux-kernel@...r.kernel.org,
linux-hardening@...r.kernel.org,
kernel@...labora.com,
gbiv@...gle.com,
inglorion@...gle.com,
ajordanr@...gle.com,
Adrian Ratiu <adrian.ratiu@...labora.com>,
Doug Anderson <dianders@...omium.org>,
Jeff Xu <jeffxu@...gle.com>,
Jann Horn <jannh@...gle.com>,
Kees Cook <kees@...nel.org>,
Christian Brauner <brauner@...nel.org>,
Linus Torvalds <torvalds@...ux-foundation.org>
Subject: [PATCH] proc: add config to block FOLL_FORCE in mem writes
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@...omium.org>
Cc: Jeff Xu <jeffxu@...gle.com>
Cc: Jann Horn <jannh@...gle.com>
Cc: Kees Cook <kees@...nel.org>
Cc: Christian Brauner <brauner@...nel.org>
Suggested-by: Linus Torvalds <torvalds@...ux-foundation.org>
Signed-off-by: Adrian Ratiu <adrian.ratiu@...labora.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
Powered by blists - more mailing lists