debugfs: more tightly restrict default mount mode
Subsystems (2)
PATCH 1/1 debugfs: more tightly restrict default mount mode
Since the debugfs is mostly only used by root, make the default mount mode 0700. Most system owners do not need a more permissive value, but they can choose to weaken the restrictions via their fstab.
--- Documentation/filesystems/debugfs.txt | 4 ++-- fs/debugfs/inode.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
Documentation/filesystems/debugfs.txt +2 -2
@@ -15,8 +15,8 @@ Debugfs is typically mounted with a command like: mount -t debugfs none /sys/kernel/debug (Or an equivalent /etc/fstab line). -The debugfs root directory is accessible by anyone by default. To -restrict access to the tree the "uid", "gid" and "mode" mount +The debugfs root directory is accessible only to the root user by +default. To change access to the tree the "uid", "gid" and "mode" mount options can be used. Note that the debugfs API is exported GPL-only to modules.
fs/debugfs/inode.c +1 -1
@@ -28,7 +28,7 @@#include <linux/magic.h> #include <linux/slab.h> -#define DEBUGFS_DEFAULT_MODE 0755 +#define DEBUGFS_DEFAULT_MODE 0700static struct vfsmount *debugfs_mount;static int debugfs_mount_count;
Signature · 6 lines
1.7.0.4 -- Kees Cook Chrome OS Security
Greg Kroah-Hartman
maintainerQuoted 5 lines · Kees Cook
Since the debugfs is mostly only used by root, make the default mount mode 0700. Most system owners do not need a more permissive value, but they can choose to weaken the restrictions via their fstab.
Signed-off-by Kees Cook <[email protected]>
Ok, you've worn me down, let's see how well this works, I'll queue this up for 3.7.
greg k-h
Quoted 3 lines
Since the debugfs is mostly only used by root, make the default mount mode 0700. Most system owners do not need a more permissive value, but they can choose to weaken the restrictions via their fstab.
But if the default is strict, file-completion won't work and most people will run a full root shell instead of sudo to save time. This is a step back in my opinion.
Most administrators of their own machine won't go as far as changing fstab (none of my students would, for example). On the other hand admins of serious sites who are really concerned about doing "ls" over debugfs will be able to customize.
So I vote against, knowing I'm late.
thanks
/alessandro
Hardening debugfs (Was Re: [PATCH] debugfs: more tightly restrict default mount mode)
In reply to Kees CookQuoted 5 lines · Kees Cook
Since the debugfs is mostly only used by root, make the default mount mode 0700. Most system owners do not need a more permissive value, but they can choose to weaken the restrictions via their fstab.
Signed-off-by Kees Cook <[email protected]>
I agree with this patch, but it would also be good if we could try to harden debugfs in general. Some ideas that might be worth discussing, for example?
1) Adding a per-module flag, so things in debugfs only show up if they are explicitly requested (you know, for debugging purposes). If most people are using debugfs for access to ftrace and powertap (my use case), there's no point making directories for other device drivers and file systems visible.
2) Can we find a pattern of common security #fail's with debugfs files, and try to sweep through and fix them?
There may be other ideas, and again, I'm not saying that this means we shouldn't lock down the permissions on debugfs. But a both/and approach might be useful here....
- Ted
Re: Hardening debugfs (Was Re: [PATCH] debugfs: more tightly restrict default mount mode)
Quoted 10 lines · Theodore Ts'o
Quoted 5 lines · Kees Cook
Since the debugfs is mostly only used by root, make the default mount mode 0700. Most system owners do not need a more permissive value, but they can choose to weaken the restrictions via their fstab.
Signed-off-by Kees Cook <[email protected]>I agree with this patch, but it would also be good if we could try to harden debugfs in general. Some ideas that might be worth discussing, for example?
[...]
The problems are apparently larger than specific modules:
http://lists.linux-foundation.org/pipermail/ksummit-2012-discuss/2012-July/000894.html
Ben.
Signature · 2 lines
Ben Hutchings It is a miracle that curiosity survives formal education. - Albert Einstein
Re: Hardening debugfs (Was Re: [PATCH] debugfs: more tightly restrict default mount mode)
Quoted 4 lines · Ben Hutchings
The problems are apparently larger than specific modules:
http://lists.linux-foundation.org/pipermail/ksummit-2012-discuss/2012-July/000894.html
Sure, but most of those problems require root access, or physical access to the hardware. And a number of the "can oops the kernel" assume module disappears out from under the open file descriptor, so
(a) that's a problem that can be fixed, and (b) if we can suppress a random device driver from having its debugfs directory appear by default, it certainly helps things.
- Ted
Greg Kroah-Hartman
maintainerRe: Hardening debugfs (Was Re: [PATCH] debugfs: more tightly restrict default mount mode)
In reply to Theodore Ts'oQuoted 11 lines · Theodore Ts'o
Quoted 5 lines · Kees Cook
Since the debugfs is mostly only used by root, make the default mount mode 0700. Most system owners do not need a more permissive value, but they can choose to weaken the restrictions via their fstab.
Signed-off-by Kees Cook <[email protected]>I agree with this patch, but it would also be good if we could try to harden debugfs in general. Some ideas that might be worth discussing, for example?
Quoted 5 lines
1) Adding a per-module flag, so things in debugfs only show up if they are explicitly requested (you know, for debugging purposes). If most people are using debugfs for access to ftrace and powertap (my use case), there's no point making directories for other device drivers and file systems visible.
The module code is "explicitly requesting" a debugfs file when it makes the call to create it. If you want to depend on a flag for the individual modules to do this or not, sure, go ahead, but that's a module/driver issue, nothing I can do in the debugfs core itself.
Quoted 2 lines
2) Can we find a pattern of common security #fail's with debugfs files, and try to sweep through and fix them?
The only one I know of is the "unload the module with an open file handle" issue. I'm pretty sure this could be fixed up somehow in debugfs, much like it was resolved in sysfs, but it would take a lot of work, for a very limited benefit (in other words, if someone sends me patches for this, great, but it's so low on my TODO list that I'll probably never get to it myself.)
thanks,
greg k-h
Re: Hardening debugfs (Was Re: [PATCH] debugfs: more tightly restrict default mount mode)
Quoted 26 lines · Greg Kroah-Hartman
Quoted 11 lines · Theodore Ts'o
Quoted 5 lines · Kees Cook
Since the debugfs is mostly only used by root, make the default mount mode 0700. Most system owners do not need a more permissive value, but they can choose to weaken the restrictions via their fstab.
Signed-off-by Kees Cook <[email protected]>I agree with this patch, but it would also be good if we could try to harden debugfs in general. Some ideas that might be worth discussing, for example?
Quoted 5 lines
1) Adding a per-module flag, so things in debugfs only show up if they are explicitly requested (you know, for debugging purposes). If most people are using debugfs for access to ftrace and powertap (my use case), there's no point making directories for other device drivers and file systems visible.
The module code is "explicitly requesting" a debugfs file when it makes the call to create it. If you want to depend on a flag for the individual modules to do this or not, sure, go ahead, but that's a module/driver issue, nothing I can do in the debugfs core itself.
Quoted 2 lines
2) Can we find a pattern of common security #fail's with debugfs files, and try to sweep through and fix them?
Quoted 6 lines
The only one I know of is the "unload the module with an open file handle" issue. I'm pretty sure this could be fixed up somehow in debugfs, much like it was resolved in sysfs, but it would take a lot of work, for a very limited benefit (in other words, if someone sends me patches for this, great, but it's so low on my TODO list that I'll probably never get to it myself.)
Staying after world-writable files is probably the biggest deal (though this has been checked for in the past after problems surfaced). I think the main reason I've wanted to push for 0700 was just because the scope of the problems is so large. It could be as simple as leaking kernel (or userspace) address locations (allowing ASLR bypass, or heap location predictability) or other side-effects from world-readable files, all the way to weird ioctl flaws in world-writable files. In general, since debugfs is specifically designed to have unstructured contents, it's not particularly trivial to be able to reason about how those contents can be best protected. As such, I just wanted to isolated it.
-Kees
Signature · 2 lines
Kees Cook Chrome OS Security
Re: Hardening debugfs (Was Re: [PATCH] debugfs: more tightly restrict default mount mode)
In reply to Theodore Ts'oQuoted 11 lines · Theodore Ts'o
Quoted 5 lines · Kees Cook
Since the debugfs is mostly only used by root, make the default mount mode 0700. Most system owners do not need a more permissive value, but they can choose to weaken the restrictions via their fstab.
Signed-off-by Kees Cook <[email protected]>I agree with this patch, but it would also be good if we could try to harden debugfs in general. Some ideas that might be worth discussing, for example?
Quoted 5 lines
1) Adding a per-module flag, so things in debugfs only show up if they are explicitly requested (you know, for debugging purposes). If most people are using debugfs for access to ftrace and powertap (my use case), there's no point making directories for other device drivers and file systems visible.
Are you suggesting "echo 1 > /sys/module/mymod/debug", or are you suggesting "mount -t devfs -o mymod /tmp/mymod", or knobs in devfs?
I've always been a bit confused by the debugfs design, which seems a giant compost heap like /proc where we find a specific styrofoam cup useful and the temporary thing becomes permanent. (Why is there _one_ debugfs?)
Oh well, presumably too late to change it now. (Unless you mount a tmpfs on /sys/kernel/debug and mkdir mount points in there, but in the perpetual absence of union mounts it would probably involve userspace-visible path changes...)
Quoted 6 lines
2) Can we find a pattern of common security #fail's with debugfs files, and try to sweep through and fix them?
There may be other ideas, and again, I'm not saying that this means we shouldn't lock down the permissions on debugfs. But a both/and approach might be useful here....
Plenty of other ideas, but it says "there are no usage rules" right there in the documentation file which makes compatible cleanup hard...
Rob
Signature · 2 lines
GNU/Linux isn't: Linux=GPLv2, GNU=GPLv3+, they can't share code. Either it's "mere aggregation", or a license violation. Pick one.
Greg Kroah-Hartman
maintainerRe: Hardening debugfs (Was Re: [PATCH] debugfs: more tightly restrict default mount mode)
Quoted 4 lines · Rob Landley
I've always been a bit confused by the debugfs design, which seems a giant compost heap like /proc where we find a specific styrofoam cup useful and the temporary thing becomes permanent. (Why is there _one_ debugfs?)
The rules for debugfs are very simple:
There are no rules.
That's it. It's up to the kernel developer to do what they need to do, for debugging stuff, how ever they best see fit.
Yes, it replaces proc for all of the debugging stuff that shouldn't have been there before, how it's structured, is up to the developer adding the code.
greg k-h
Re: Hardening debugfs (Was Re: [PATCH] debugfs: more tightly restrict default mount mode)
Quoted 11 lines · Greg Kroah-Hartman
Quoted 4 lines · Rob Landley
I've always been a bit confused by the debugfs design, which seems a giant compost heap like /proc where we find a specific styrofoam cup useful and the temporary thing becomes permanent. (Why is there _one_ debugfs?)
The rules for debugfs are very simple:
There are no rules.That's it. It's up to the kernel developer to do what they need to do, for debugging stuff, how ever they best see fit.
Emergent de-facto standards with no review or versioning or anything, check. It's the "every driver in the system shares a common resource with no arbitration or guidelines" thing that I have trouble with.
Is it possible to have multiple instances of this filesystem? If so, can they have -o "modulename,modulename,modulename..." so that only certain modules' files get put in this instance?
I understand that /sys/module/$BLAH has rules and we can't have that, but having a giant slush pile and asserting it won't become a new /proc because reasons makes me nervous.
For example, ftrace is already built on top of debugfs. If debugfs has no rules, but ftrace does, can another module put stuff in "tracing"? If a stable API isn't important, will we start bundling whatever userspace tools ftrace needs in with the kernel, along with udev/systemd? Or is the position that ftrace will never have non-debugging uses, just like ptrace?
Quoted 3 lines
Yes, it replaces proc for all of the debugging stuff that shouldn't have been there before, how it's structured, is up to the developer adding the code.
For a definition of "replaces" that does not actually remove any of the existing entries from /proc. (That garbage can's full, here's a new one?)
The problem with /proc is that lots of things used it for different purposes with no rules. The goal of debugfs is to provide something that lots of things use for different purposes, explicitly with no rules.
I'm just wondering why it's a big common hairball instead of separate per-module filesystems. (Other than "Linux will never have a unionfs because the perfect is the enemy of the good".)
Eh, it's your thing, not mine. I just don't understand it.
Quoted 1 line
greg k-h
Rob
Signature · 2 lines
GNU/Linux isn't: Linux=GPLv2, GNU=GPLv3+, they can't share code. Either it's "mere aggregation", or a license violation. Pick one.