proc: force dcache drop on unauthorized access
Subsystems (3)
RFC PATCH 1/2 proc: force dcache drop on unauthorized access
The patch "proc: fix races against execve() of /proc/PID/fd**" is still a partial fix for a setxid problem. link(2) is a yet another way to identify whether a specific fd is opened by a privileged process. By calling link(2) against /proc/PID/fd/* an attacker may identify whether the fd number is valid for PID by analysing link(2) return code.
Both getattr() and link() can be used by the attacker iff the dentry is present in the dcache. In this case ->lookup() is not called and the only way to check ptrace permissions is either operation handler or ->revalidate(). The easiest solution to prevent any unauthorized access to /proc/PID/fd*/ files is to force the dentry drop on each unauthorized access attempt.
If an attacker keeps opened fd of /proc/PID/fd/ and dcache contains a specific dentry for some /proc/PID/fd/XXX, any future attemp to use the dentry by the attacker would lead to the dentry drop as a result of a failed ptrace check in ->revalidate(). Then the attacker cannot spawn a dentry for the specific fd number because of ptrace check in ->lookup().
The dentry drop can be still observed by an attacker by analysing information from /proc/slabinfo, which is addressed in the successive patch.
--- fs/proc/base.c | 42 ++++++------------------------------------ 1 files changed, 6 insertions(+), 36 deletions(-)
--
fs/proc/base.c +6 -36
@@ -1665,46 +1665,12 @@ out:return error; } -static int proc_pid_fd_link_getattr (struct vfsmount *mnt,struct dentry *dentry, -struct kstat *stat) -{ -struct inode *inode = dentry->d_inode; -struct task_struct *task =get_proc_task (inode); -int rc; - -if (task ==NULL ) -return -ESRCH ; - - rc = -EACCES ; -if (lock_trace (task)) - goto out_task; - -generic_fillattr (inode, stat); -unlock_trace (task); - rc =0 ; -out_task: -put_task_struct (task); -return rc; -} -static const struct inode_operations proc_pid_link_inode_operations = { .readlink = proc_pid_readlink, .follow_link = proc_pid_follow_link, .setattr = proc_setattr, }; -static const struct inode_operations proc_fdinfo_link_inode_operations = { - .setattr = proc_setattr, - .getattr = proc_pid_fd_link_getattr, -}; - -static const struct inode_operations proc_fd_link_inode_operations = { - .readlink = proc_pid_readlink, - .follow_link = proc_pid_follow_link, - .setattr = proc_setattr, - .getattr = proc_pid_fd_link_getattr, -}; -/* building an inode */
@@ -2013,6 +1979,11 @@ static int tid_fd_revalidate(struct dentry *dentry, struct nameidata *nd) task =get_proc_task (inode); fd =proc_fd (inode); +if (!ptrace_may_access (task,PTRACE_MODE_READ )) { +put_task_struct (task); + task =NULL ; + } +if (task) { files =get_files_struct (task);if (files) {
@@ -2085,7 +2056,7 @@ static struct dentry *proc_fd_instantiate(struct inode *dir,spin_unlock (&files->file_lock);put_files_struct (files); - inode->i_op = &proc_fd_link_inode_operations; + inode->i_op = &proc_pid_link_inode_operations; inode->i_size =64 ; ei->op.proc_get_link = proc_fd_link;d_set_d_op (dentry, &tid_fd_dentry_operations);
@@ -2267,7 +2238,6 @@ static struct dentry *proc_fdinfo_instantiate(struct inode *dir, ei->fd = fd; inode->i_mode =S_IFREG |S_IRUSR ; inode->i_fop = &proc_fdinfo_file_operations; - inode->i_op = &proc_fdinfo_link_inode_operations;d_set_d_op (dentry, &tid_fd_dentry_operations);d_add (dentry, inode);/* Close the race of the process dying before we return the dentry */
RFC PATCH 2/2 mm: restrict access to /proc/slabinfo
Historically /proc/slabinfo has 0444 permissions and is accessible to the world. slabinfo contains rather private information related both to the kernel and userspace tasks. Depending on the situation, it might reveal either private information per se or information useful to make another targeted attack. Some examples of what can be learned by reading/watching for /proc/slabinfo entries:
1) dentry (and different *inode*) number might reveal other processes fs activity. The number of dentry "active objects" doesn't strictly show file count opened/touched by a process, however, there is a good correlation between them. The patch "proc: force dcache drop on unauthorized access" relies on the privacy of dentry count.
2) different inode entries might reveal the same information as (1), but these are more fine granted counters. If a filesystem is mounted in a private mount point (or even a private namespace) and fs type differs from other mounted fs types, fs activity in this mount point/namespace is revealed. If there is a single ecryptfs mount point, the whole fs activity of a single user is revealed. Number of files in ecryptfs mount point is a private information per se.
3) fuse_* reveals number of files / fs activity of a user in a user private mount point. It is approx. the same severity as ecryptfs infoleak in (2).
4) sysfs_dir_cache similar to (2) reveals devices' addition/removal, which can be otherwise hidden by "chmod 0700 /sys/". With 0444 slabinfo the precise number of sysfs files is known to the world.
5) buffer_head might reveal some kernel activity. With other information leaks an attacker might identify what specific kernel routines generate buffer_head activity.
6) *kmalloc* infoleaks are very situational. Attacker should watch for the specific kmalloc size entry and filter the noise related to the unrelated kernel activity. If an attacker has relatively silent victim system, he might get rather precise counters.
Additional information sources might significantly increase the slabinfo infoleak benefits. E.g. if an attacker knows that the processes activity on the system is very low (only core daemons like syslog and cron), he may run setxid binaries / trigger local daemon activity / trigger network services activity / await sporadic cron jobs activity / etc. and get rather precise counters for fs and network activity of these privileged tasks, which is unknown otherwise.
Also hiding slabinfo is a one step to complicate exploitation of kernel heap overflows (and possibly, other bugs). The related discussion:
http://thread.gmane.org/gmane.linux.kernel/1108378
World readable slabinfo simplifies kernel developers' job of debugging kernel bugs (e.g. memleaks), but I believe it does more harm than benefits. For most users 0444 slabinfo is an unreasonable attack vector.
--- mm/slab.c | 3 ++- mm/slub.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
--
mm/slab.c +2 -1
@@ -4584,7 +4584,8 @@ static const struct file_operations proc_slabstats_operations = {static int __init slab_proc_init (void ) { -proc_create ("slabinfo" ,S_IWUSR |S_IRUGO ,NULL ,&proc_slabinfo_operations); +proc_create ("slabinfo" ,S_IWUSR |S_IRUSR ,NULL , + &proc_slabinfo_operations);#ifdef CONFIG_DEBUG_SLAB_LEAK proc_create ("slab_allocators" ,0 ,NULL , &proc_slabstats_operations);#endif
mm/slub.c +1 -1
@@ -5257,7 +5257,7 @@ static const struct file_operations proc_slabinfo_operations = {static int __init slab_proc_init (void ) { -proc_create ("slabinfo" ,S_IRUGO ,NULL , &proc_slabinfo_operations); +proc_create ("slabinfo" ,S_IRUSR ,NULL , &proc_slabinfo_operations);return 0 ; }module_init (slab_proc_init);
Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 7 lines · Vasiliy Kulikov
Historically
/proc/slabinfohas 0444 permissions and is accessible to the world. slabinfo contains rather private information related both to the kernel and userspace tasks. Depending on the situation, it might reveal either private information per se or information useful to make another targeted attack. Some examples of what can be learned by reading/watching for/proc/slabinfoentries:
...
Since this file is controversy point, probably its permissions might be configurable via setup option?
Cyrill
Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 8 lines · Cyrill Gorcunov
Quoted 7 lines · Vasiliy Kulikov
Historically
/proc/slabinfohas 0444 permissions and is accessible to the world. slabinfo contains rather private information related both to the kernel and userspace tasks. Depending on the situation, it might reveal either private information per se or information useful to make another targeted attack. Some examples of what can be learned by reading/watching for/proc/slabinfoentries:
Quoted 4 lines
...
Since this file is controversy point, probably its permissions might be configurable via setup option?
We could create DEBUG_PROC (of cource, defaults to =n) to keep current relaxed procfs permissions, but I don't think a configure option is needed for a thing which is trivially done via "chmod" in init scripts.
Signature · 2 lines
Vasiliy Kulikov http://www.openwall.com - bringing security into open computing environments
Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
In reply to Vasiliy Kulikov(cc'ed all members of the previous discussion as currently lists might not work as they should)
Quoted 50 lines · Vasiliy Kulikov
Historically
/proc/slabinfohas 0444 permissions and is accessible to the world. slabinfo contains rather private information related both to the kernel and userspace tasks. Depending on the situation, it might reveal either private information per se or information useful to make another targeted attack. Some examples of what can be learned by reading/watching for/proc/slabinfoentries:1) dentry (and different *inode*) number might reveal other processes fs activity. The number of dentry "active objects" doesn't strictly show file count opened/touched by a process, however, there is a good correlation between them. The patch "proc: force dcache drop on unauthorized access" relies on the privacy of dentry count.
2) different inode entries might reveal the same information as (1), but these are more fine granted counters. If a filesystem is mounted in a private mount point (or even a private namespace) and fs type differs from other mounted fs types, fs activity in this mount point/namespace is revealed. If there is a single ecryptfs mount point, the whole fs activity of a single user is revealed. Number of files in ecryptfs mount point is a private information per se.
3) fuse_* reveals number of files / fs activity of a user in a user private mount point. It is approx. the same severity as ecryptfs infoleak in (2).
4)
sysfs_dir_cachesimilar to (2) reveals devices' addition/removal, which can be otherwise hidden by "chmod 0700/sys/". With 0444 slabinfo the precise number of sysfs files is known to the world.5)
buffer_headmight reveal some kernel activity. With other information leaks an attacker might identify what specific kernel routines generatebuffer_headactivity.6) *kmalloc* infoleaks are very situational. Attacker should watch for the specific kmalloc size entry and filter the noise related to the unrelated kernel activity. If an attacker has relatively silent victim system, he might get rather precise counters.
Additional information sources might significantly increase the slabinfo infoleak benefits. E.g. if an attacker knows that the processes activity on the system is very low (only core daemons like syslog and cron), he may run setxid binaries / trigger local daemon activity / trigger network services activity / await sporadic cron jobs activity / etc. and get rather precise counters for fs and network activity of these privileged tasks, which is unknown otherwise.
Also hiding slabinfo is a one step to complicate exploitation of kernel heap overflows (and possibly, other bugs). The related discussion:
Quoted 6 lines
http://thread.gmane.org/gmane.linux.kernel/1108378
World readable slabinfo simplifies kernel developers' job of debugging kernel bugs (e.g. memleaks), but I believe it does more harm than benefits. For most users 0444 slabinfo is an unreasonable attack vector.
Please tell if anybody has complains about the restriction - whether it forces someone besides kernel developers to do "chmod/chgrp". But if someone want to debug the kernel, it shouldn't significantly influence on common users, especially it shouldn't create security issues.
Thanks!
Quoted 34 lines
Signed-off-by Vasiliy Kulikov <[email protected]>--- mm/slab.c | 3 ++- mm/slub.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)--
mm/slab.c +2
-1@@ -4584,7 +4584,8 @@ static const struct file_operations proc_slabstats_operations = {static int __init slab_proc_init (void ) { -proc_create ("slabinfo" ,S_IWUSR |S_IRUGO ,NULL ,&proc_slabinfo_operations); +proc_create ("slabinfo" ,S_IWUSR |S_IRUSR ,NULL , + &proc_slabinfo_operations);#ifdef CONFIG_DEBUG_SLAB_LEAK proc_create ("slab_allocators" ,0 ,NULL , &proc_slabstats_operations);#endif mm/slub.c +1
-1@@ -5257,7 +5257,7 @@ static const struct file_operations proc_slabinfo_operations = {static int __init slab_proc_init (void ) { -proc_create ("slabinfo" ,S_IRUGO ,NULL , &proc_slabinfo_operations); +proc_create ("slabinfo" ,S_IRUSR ,NULL , &proc_slabinfo_operations);return 0 ; }module_init (slab_proc_init);
Signature · 2 lines
Vasiliy Kulikov http://www.openwall.com - bringing security into open computing environments
Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 8 lines · Vasiliy Kulikov
Quoted 3 lines
World readable slabinfo simplifies kernel developers' job of debugging kernel bugs (e.g. memleaks), but I believe it does more harm than benefits. For most users 0444 slabinfo is an unreasonable attack vector.
Please tell if anybody has complains about the restriction - whether it forces someone besides kernel developers to do "chmod/chgrp". But if someone want to debug the kernel, it shouldn't significantly influence on common users, especially it shouldn't create security issues.
Ubuntu ships today with a /etc/init/mounted-proc.conf that does:
chmod 0400 "${MOUNTPOINT}"/slabinfoAfter cursing Kees's name a few times, I commented it out and it hasn't bothered me again.
I expect that the folks that really care about this (and their distros) will probably have a similar mechanism. I guess the sword cuts both ways in this case: it obviously _works_ to have the distros do it, but it was a one-time inconvenience for me to override that.
In other words, I dunno. If we do this in the kernel, can we at least do something like CONFIG_INSECURE to both track these kinds of things and make it easy to get them out of a developer's way?
-- Dave
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Hi Dave,
Quoted 10 lines · Dave Hansen
Quoted 8 lines · Vasiliy Kulikov
Quoted 3 lines
World readable slabinfo simplifies kernel developers' job of debugging kernel bugs (e.g. memleaks), but I believe it does more harm than benefits. For most users 0444 slabinfo is an unreasonable attack vector.
Please tell if anybody has complains about the restriction - whether it forces someone besides kernel developers to do "chmod/chgrp". But if someone want to debug the kernel, it shouldn't significantly influence on common users, especially it shouldn't create security issues.
Quoted 6 lines
Ubuntu ships today with a
/etc/init/mounted-proc.confthat does:chmod 0400 "${MOUNTPOINT}"/slabinfoAfter cursing Kees's name a few times, I commented it out and it hasn't bothered me again.
Another way is chgrp slabinfo to some "admin" group which are privileged in this sense and add your user to this group. But please, sane and secure defaults!
Quoted 8 lines
I expect that the folks that really care about this (and their distros) will probably have a similar mechanism. I guess the sword cuts both ways in this case: it obviously _works_ to have the distros do it, but it was a one-time inconvenience for me to override that.
In other words, I dunno. If we do this in the kernel, can we at least do something like
CONFIG_INSECUREto both track these kinds of things and make it easy to get them out of a developer's way?
What do you think about adding your user to the slabinfo's group or chmod it - quite the opposite Ubuntu currently does? I think it is more generic (e.g. you may chmod 0444 to allow all users to get debug information or just 0440 and chgrp admin to allow only trusted users to do it) and your local policy doesn't touch the kernel.
Thanks,
Signature · 2 lines
Vasiliy Kulikov http://www.openwall.com - bringing security into open computing environments
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
(cc'ed Dave back, sorry for the noise)
Quoted 44 lines · Vasiliy Kulikov
Hi Dave,
Quoted 10 lines · Dave Hansen
Quoted 8 lines · Vasiliy Kulikov
Quoted 3 lines
World readable slabinfo simplifies kernel developers' job of debugging kernel bugs (e.g. memleaks), but I believe it does more harm than benefits. For most users 0444 slabinfo is an unreasonable attack vector.
Please tell if anybody has complains about the restriction - whether it forces someone besides kernel developers to do "chmod/chgrp". But if someone want to debug the kernel, it shouldn't significantly influence on common users, especially it shouldn't create security issues.
Quoted 6 lines
Ubuntu ships today with a
/etc/init/mounted-proc.confthat does:chmod 0400 "${MOUNTPOINT}"/slabinfoAfter cursing Kees's name a few times, I commented it out and it hasn't bothered me again.
Another way is chgrp slabinfo to some "admin" group which are privileged in this sense and add your user to this group. But please, sane and secure defaults!
Quoted 8 lines
I expect that the folks that really care about this (and their distros) will probably have a similar mechanism. I guess the sword cuts both ways in this case: it obviously _works_ to have the distros do it, but it was a one-time inconvenience for me to override that.
In other words, I dunno. If we do this in the kernel, can we at least do something like
CONFIG_INSECUREto both track these kinds of things and make it easy to get them out of a developer's way?What do you think about adding your user to the slabinfo's group or chmod it - quite the opposite Ubuntu currently does? I think it is more generic (e.g. you may chmod 0444 to allow all users to get debug information or just 0440 and chgrp admin to allow only trusted users to do it) and your local policy doesn't touch the kernel.
Thanks,
Signature · 2 lines
Vasiliy Kulikov http://www.openwall.com - bringing security into open computing environments
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
In reply to Vasiliy KulikovQuoted 9 lines · Vasiliy Kulikov
Quoted 3 lines
In other words, I dunno. If we do this in the kernel, can we at least do something like
CONFIG_INSECUREto both track these kinds of things and make it easy to get them out of a developer's way?What do you think about adding your user to the slabinfo's group or chmod it - quite the opposite Ubuntu currently does? I think it is more generic (e.g. you may chmod 0444 to allow all users to get debug information or just 0440 and chgrp admin to allow only trusted users to do it) and your local policy doesn't touch the kernel.
That obviously _works_. I'd be happy to ack your patch. As I said, it's pretty minimally painful, even to folks who care about slabinfo like me.
-- Dave
Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
In reply to Vasiliy Kulikovmm/slab.c static const struct file_operations proc_slabstats_operations = { · line 4590
Quoted 9 lines · Vasiliy Kulikov
mm/slab.c +2
-1@@ -4584,7 +4584,8 @@ static const struct file_operations proc_slabstats_operations = {static int __init slab_proc_init (void ) { -proc_create ("slabinfo" ,S_IWUSR |S_IRUGO ,NULL ,&proc_slabinfo_operations); +proc_create ("slabinfo" ,S_IWUSR |S_IRUSR ,NULL , + &proc_slabinfo_operations);#ifdef CONFIG_DEBUG_SLAB_LEAK proc_create("slab_allocators", 0, NULL, &proc_sla
If you respin this, please don't muck with the whitespace. Otherwise, I'm fine with this. Distros are already starting to do this anyway in userspace.
-- Dave
Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 12 lines · Dave Hansen
mm/slab.c static const struct file_operations proc_slabstats_operations = { · line 4590
Quoted 9 lines · Vasiliy Kulikov
mm/slab.c +2
-1@@ -4584,7 +4584,8 @@ static const struct file_operations proc_slabstats_operations = {static int __init slab_proc_init (void ) { -proc_create ("slabinfo" ,S_IWUSR |S_IRUGO ,NULL ,&proc_slabinfo_operations); +proc_create ("slabinfo" ,S_IWUSR |S_IRUSR ,NULL , + &proc_slabinfo_operations);#ifdef CONFIG_DEBUG_SLAB_LEAK proc_create("slab_allocators", 0, NULL, &proc_slaIf you respin this, please don't muck with the whitespace.
OK, I was just removing checkpatch warnings.
Quoted 5 lines
Otherwise,
I'm fine with this. Distros are already starting to do this anyway in userspace.Reviewed-by Dave Hansen <[email protected]>
Thank you!
Signature · 2 lines
Vasiliy Kulikov http://www.openwall.com - bringing security into open computing environments
Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
In reply to Vasiliy KulikovHi Vasiliy,
Quoted 11 lines · Vasiliy Kulikov
Historically
/proc/slabinfohas 0444 permissions and is accessible to the world. slabinfo contains rather private information related both to the kernel and userspace tasks. Depending on the situation, it might reveal either private information per se or information useful to make another targeted attack. Some examples of what can be learned by reading/watching for/proc/slabinfoentries:
...
World readable slabinfo simplifies kernel developers' job of debugging kernel bugs (e.g. memleaks), but I believe it does more harm than benefits. For most users 0444 slabinfo is an unreasonable attack vector.
Quoted 1 line
Signed-off-by Vasiliy Kulikov <[email protected]>
Haven't had any mass complaints about the 0400 in Ubuntu (sorry Dave!), so I'm obviously for it.
-Kees
Signature · 2 lines
Kees Cook Ubuntu Security Team
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Hi Andrew,
Quoted 12 lines · Kees Cook
Quoted 11 lines · Vasiliy Kulikov
Historically
/proc/slabinfohas 0444 permissions and is accessible to the world. slabinfo contains rather private information related both to the kernel and userspace tasks. Depending on the situation, it might reveal either private information per se or information useful to make another targeted attack. Some examples of what can be learned by reading/watching for/proc/slabinfoentries:
...
World readable slabinfo simplifies kernel developers' job of debugging kernel bugs (e.g. memleaks), but I believe it does more harm than benefits. For most users 0444 slabinfo is an unreasonable attack vector.
Quoted 6 lines
Quoted 1 line
Signed-off-by Vasiliy Kulikov <[email protected]>Haven't had any mass complaints about the 0400 in Ubuntu (sorry Dave!), so I'm obviously for it.
Reviewed-by Kees Cook <[email protected]>
Looks like the members of the previous slabinfo discussion don't object against the patch now and it got two other Reviewed-by responses. Can you merge it as-is or should I probably convince someone else?
Thanks,
Signature · 2 lines
Vasiliy Kulikov http://www.openwall.com - bringing security into open computing environments
Christoph Lameter
reviewerRe: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 5 lines · Vasiliy Kulikov
Quoted 1 line
Reviewed-by Kees Cook <[email protected]>Looks like the members of the previous slabinfo discussion don't object against the patch now and it got two other Reviewed-by responses. Can you merge it as-is or should I probably convince someone else?
The patch is incomplete. If you want to restrict access to this information then /sys/kernel/slab needs to have a similar restriction.
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
In reply to Vasiliy KulikovQuoted 14 lines · Kees Cook
Quoted 13 lines · Vasiliy Kulikov
Quoted 12 lines
Historically
/proc/slabinfohas 0444 permissions and is accessible to the world. slabinfo contains rather private information related both to the kernel and userspace tasks. Depending on the situation, it might reveal either private information per se or information useful to make another targeted attack. Some examples of what can be learned by reading/watching for/proc/slabinfoentries:
...
World readable slabinfo simplifies kernel developers' job of debugging kernel bugs (e.g. memleaks), but I believe it does more harm than benefits. For most users 0444 slabinfo is an unreasonable attack vector.Signed-off-by Vasiliy Kulikov <[email protected]>
Quoted 8 lines · Vasiliy Kulikov
Quoted 4 lines
Haven't had any mass complaints about the 0400 in Ubuntu (sorry Dave!), so I'm obviously for it.
Reviewed-by Kees Cook <[email protected]>Looks like the members of the previous slabinfo discussion don't object against the patch now and it got two other Reviewed-by responses. Can you merge it as-is or should I probably convince someone else?
We discussed this in March (google for 'Make /proc/slabinfo 0400') and concluded that it's not worth it doesn't really protect from anything and causes harm to developers.
Pekka
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Hello Pekka,
Quoted 19 lines · Pekka Enberg
Quoted 14 lines · Kees Cook
Quoted 13 lines · Vasiliy Kulikov
Quoted 12 lines
Historically
/proc/slabinfohas 0444 permissions and is accessible to the world. slabinfo contains rather private information related both to the kernel and userspace tasks. Depending on the situation, it might reveal either private information per se or information useful to make another targeted attack. Some examples of what can be learned by reading/watching for/proc/slabinfoentries:
...
World readable slabinfo simplifies kernel developers' job of debugging kernel bugs (e.g. memleaks), but I believe it does more harm than benefits. For most users 0444 slabinfo is an unreasonable attack vector.Signed-off-by Vasiliy Kulikov <[email protected]>Quoted 3 lines · Vasiliy Kulikov
Quoted 3 lines
Haven't had any mass complaints about the 0400 in Ubuntu (sorry Dave!), so I'm obviously for it.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Reviewed-by Kees Cook <[email protected]>Looks like the members of the previous slabinfo discussion don't object against the patch now and it got two other Reviewed-by responses. Can you merge it as-is or should I probably convince someone else?
We discussed this in March (google for 'Make
/proc/slabinfo0400')
Sure, I've read it and included the link in the patch description :)
Quoted 2 lines
and
concluded that it's not worth it doesn't really protect from anything
Closing only slabinfo doesn't add any significant protection against kernel heap exploits per se, no objections here.
But as said in the desciption, the reason for this patch is not protecting against exploitation heap bugs. It is a source of infoleaks of kernel and userspace activity, which should be forbidden to non-root users.
Quoted 1 line
and causes harm to developers.
One note: only to _kernel_ developers. It means it is a strictly debugging feature, which shouldn't be enabled in the production systems.
Thanks,
Signature · 2 lines
Vasiliy Kulikov http://www.openwall.com - bringing security into open computing environments
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Hi Vasiliy,
Quoted 9 lines · Vasiliy Kulikov
Quoted 2 lines
and
concluded that it's not worth it doesn't really protect from anythingClosing only slabinfo doesn't add any significant protection against kernel heap exploits per se, no objections here.
But as said in the desciption, the reason for this patch is not protecting against exploitation heap bugs. It is a source of infoleaks of kernel and userspace activity, which should be forbidden to non-root users.
Last time we discussed this, the 'extra protection' didn't seem to be significant enough to justify disabling an useful kernel debugging interface by default.
What's different about the patch now?
Quoted 4 lines
Quoted 1 line
and causes harm to developers.
One note: only to _kernel_ developers. It means it is a strictly debugging feature, which shouldn't be enabled in the production systems.
It's pretty much _the_ interface for debugging kernel memory leaks in production systems and we ask users for it along with /proc/meminfo when debugging many memory management related issues. When we temporarily dropped /proc/slabinfo with the introduction of SLUB, people complained pretty loudly.
I'd be willing to consider this patch if it's a config option that's not enabled by default; otherwise you need to find someone else to merge the patch. You can add some nasty warnings to the Kconfig text to scare the users into enabling it. ;-)
Pekka
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 11 lines · Pekka Enberg
Quoted 9 lines · Vasiliy Kulikov
Quoted 2 lines
and
concluded that it's not worth it doesn't really protect from anythingClosing only slabinfo doesn't add any significant protection against kernel heap exploits per se, no objections here.
But as said in the desciption, the reason for this patch is not protecting against exploitation heap bugs. It is a source of infoleaks of kernel and userspace activity, which should be forbidden to non-root users.
Quoted 5 lines
Last time we discussed this, the 'extra protection' didn't seem to be significant enough to justify disabling an useful kernel debugging interface by default.
What's different about the patch now?
The exploitation you're talking about is an exploitation of kernel heap bugs. Dan's previous "make slabinfo 0400" patch tried to complicate attacker's life by hiding information about how many free object are left in the slab. With this information an attacker may compute how he should spray the slab to position slab object to increase his chances of overwriting specific memory areas - pointers, etc.
I don't speak about how much/whether closing slabinfo complicates this task, though. My idea is orthogonal to the Dan's idea. I claim that with 0444 slabinfo any user may get information about in-system activity that he shouldn't learn. In short, one may learn precisely when other user reads directory contents, opens files, how much files there are in the specific _private_ directory, how much files _private_ ecryptfs or fuse mount point contains, etc. This breaks user's assumption that the number of files in a private directory is a private information. There are a bit more thoughts in the patch description.
Quoted 10 lines
Quoted 4 lines
Quoted 1 line
and causes harm to developers.
One note: only to _kernel_ developers. It means it is a strictly debugging feature, which shouldn't be enabled in the production systems.
It's pretty much _the_ interface for debugging kernel memory leaks in production systems and we ask users for it along with
/proc/meminfowhen debugging many memory management related issues. When we temporarily dropped/proc/slabinfowith the introduction of SLUB, people complained pretty loudly.
Could you point to the discussion, please? I cannot find the patch for 0400 slabinfo even in the linux-history repository.
Quoted 4 lines
I'd be willing to consider this patch if it's a config option that's not enabled by default; otherwise you need to find someone else to merge the patch. You can add some nasty warnings to the
Kconfigtext to scare the users into enabling it. ;-)
How do you see this CONFIG_ option? CONFIG_PROCFS_COMPAT_MODES (or _PERMS), defaults to Y? If we find more procfs files with dangerous permissions, we may move it under "ifndef CONFIG_PROCFS_COMPAT_PERMS".
Thanks,
Signature · 2 lines
Vasiliy Kulikov http://www.openwall.com - bringing security into open computing environments
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 25 lines · Vasiliy Kulikov
Quoted 11 lines · Pekka Enberg
Quoted 9 lines · Vasiliy Kulikov
Quoted 2 lines
and
concluded that it's not worth it doesn't really protect from anythingClosing only slabinfo doesn't add any significant protection against kernel heap exploits per se, no objections here.
But as said in the desciption, the reason for this patch is not protecting against exploitation heap bugs. It is a source of infoleaks of kernel and userspace activity, which should be forbidden to non-root users.
Quoted 5 lines
Last time we discussed this, the 'extra protection' didn't seem to be significant enough to justify disabling an useful kernel debugging interface by default.
What's different about the patch now?
The exploitation you're talking about is an exploitation of kernel heap bugs. Dan's previous "make slabinfo 0400" patch tried to complicate attacker's life by hiding information about how many free object are left in the slab. With this information an attacker may compute how he should spray the slab to position slab object to increase his chances of overwriting specific memory areas - pointers, etc.
Quoted 9 lines
I don't speak about how much/whether closing slabinfo complicates this task, though. My idea is orthogonal to the Dan's idea. I claim that with 0444 slabinfo any user may get information about in-system activity that he shouldn't learn. In short, one may learn precisely when other user reads directory contents, opens files, how much files there are in the specific _private_ directory, how much files _private_ ecryptfs or fuse mount point contains, etc. This breaks user's assumption that the number of files in a private directory is a private information. There are a bit more thoughts in the patch description.
Yes, I read your patch description and I think it's convincing enough to warrant a config option but not changing the default.
However, if the encryptfs and infoleaks really are serious enough to hide /proc/slabinfo, I think you should consider switching over to kmalloc() instead of kmem_cache_alloc() to make sure nobody can gain access to the information. Or add a SLAB_ANON flag for kmem_cache_create() that forces SLUB cache merging to existing caches.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
and causes harm to developers.
One note: only to _kernel_ developers. It means it is a strictly debugging feature, which shouldn't be enabled in the production systems.
Quoted 8 lines
Quoted 5 lines
It's pretty much _the_ interface for debugging kernel memory leaks in production systems and we ask users for it along with
/proc/meminfowhen debugging many memory management related issues. When we temporarily dropped/proc/slabinfowith the introduction of SLUB, people complained pretty loudly.Could you point to the discussion, please? I cannot find the patch for 0400 slabinfo even in the linux-history repository.
We dropped the whole file for SLUB:
http://lwn.net/Articles/263337/
[ I didn't find the original discussion that motivated the above
patch but it should be somewhere in LKML archives around that time. ]
Making it root-only will have pretty much the same kind of out-of-the-box behavior.
Quoted 8 lines
Quoted 4 lines
I'd be willing to consider this patch if it's a config option that's not enabled by default; otherwise you need to find someone else to merge the patch. You can add some nasty warnings to the
Kconfigtext to scare the users into enabling it. ;-)How do you see this
CONFIG_option? CONFIG_PROCFS_COMPAT_MODES (or_PERMS), defaults to Y? If we find more procfs files with dangerous permissions, we may move it under "ifndefCONFIG_PROCFS_COMPAT_PERMS".
I guess CONFIG_RESTRICT_PROCFS type of thing makes most sense since the problem is not only about SLAB. If you want to make it slab-only config option, I'm fine with that too.
Please note that you need to restrict sysfs files for SLUB as well.
Pekka
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 19 lines · Pekka Enberg
Quoted 9 lines
Quoted 1 line
What's different about the patch now?
The exploitation you're talking about is an exploitation of kernel heap bugs. Dan's previous "make slabinfo 0400" patch tried to complicate attacker's life by hiding information about how many free object are left in the slab. With this information an attacker may compute how he should spray the slab to position slab object to increase his chances of overwriting specific memory areas - pointers, etc.
Quoted 9 lines
I don't speak about how much/whether closing slabinfo complicates this task, though. My idea is orthogonal to the Dan's idea. I claim that with 0444 slabinfo any user may get information about in-system activity that he shouldn't learn. In short, one may learn precisely when other user reads directory contents, opens files, how much files there are in the specific _private_ directory, how much files _private_ ecryptfs or fuse mount point contains, etc. This breaks user's assumption that the number of files in a private directory is a private information. There are a bit more thoughts in the patch description.
Quoted 7 lines
Yes, I read your patch description and I think it's convincing enough to warrant a config option but not changing the default.
However, if the encryptfs and infoleaks really are serious enough to hide
/proc/slabinfo, I think you should consider switching over tokmalloc()instead ofkmem_cache_alloc()to make sure nobody can gain access to the information.
kmalloc() is still visible in slabinfo as kmalloc-128 or so.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 2 lines
One note: only to _kernel_ developers. It means it is a strictly debugging feature, which shouldn't be enabled in the production systems.
It's pretty much _the_ interface for debugging kernel memory leaks in production systems and we ask users for it along with
/proc/meminfowhen debugging many memory management related issues. When we temporarily dropped/proc/slabinfowith the introduction of SLUB, people complained pretty loudly.
Quoted 6 lines
Quoted 2 lines
Could you point to the discussion, please? I cannot find the patch for 0400 slabinfo even in the linux-history repository.
We dropped the whole file for SLUB:
Ah, I've misunderstood you.
Quoted 12 lines
[ I didn't find the original discussion that motivated the above
patch but it should be somewhere in LKML archives around that time. ]Making it root-only will have pretty much the same kind of out-of-the-box behavior.
Quoted 5 lines
Quoted 4 lines
I'd be willing to consider this patch if it's a config option that's not enabled by default; otherwise you need to find someone else to merge the patch. You can add some nasty warnings to the
Kconfigtext to scare the users into enabling it. ;-)
Quoted 7 lines
Quoted 3 lines
How do you see this
CONFIG_option? CONFIG_PROCFS_COMPAT_MODES (or_PERMS), defaults to Y? If we find more procfs files with dangerous permissions, we may move it under "ifndefCONFIG_PROCFS_COMPAT_PERMS".I guess
CONFIG_RESTRICT_PROCFStype of thing makes most sense since the problem is not only about SLAB. If you want to make it slab-only config option, I'm fine with that too.
OK, then I'll prepare a patch with a configure option, if no other objections.
Quoted 1 line
Please note that you need to restrict sysfs files for SLUB as well.
Sure.
Thank you for the comments!
Signature · 2 lines
Vasiliy Kulikov http://www.openwall.com - bringing security into open computing environments
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 6 lines · Vasiliy Kulikov
Quoted 4 lines
However, if the encryptfs and infoleaks really are serious enough to hide
/proc/slabinfo, I think you should consider switching over tokmalloc()instead ofkmem_cache_alloc()to make sure nobody can gain access to the information.
kmalloc()is still visible in slabinfo as kmalloc-128 or so.
Yes, but there's no way for users to know where the allocations came from if you mix them up with other kmalloc-128 call-sites. That way the number of private files will stay private to the user, no? Doesn't that give you even better protection against the infoleak?
Pekka
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 6 lines · Pekka Enberg
Quoted 5 lines · Vasiliy Kulikov
Quoted 4 lines
However, if the encryptfs and infoleaks really are serious enough to hide
/proc/slabinfo, I think you should consider switching over tokmalloc()instead ofkmem_cache_alloc()to make sure nobody can gain access to the information.
Quoted 6 lines
Quoted 1 line
kmalloc()is still visible in slabinfo as kmalloc-128 or so.Yes, but there's no way for users to know where the allocations came from if you mix them up with other kmalloc-128 call-sites. That way the number of private files will stay private to the user, no? Doesn't that give you even better protection against the infoleak?
No, what it gives us is an obscurity, not a protection. I'm sure it highly depends on the specific situation whether an attacker is able to identify whether the call is from e.g. ecryptfs or from VFS. Also the correlation between the number in slabinfo and the real private actions still exists.
Thanks,
Signature · 2 lines
Vasiliy Kulikov http://www.openwall.com - bringing security into open computing environments
Christoph Lameter
reviewerRe: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 7 lines · Vasiliy Kulikov
Quoted 6 lines
Quoted 1 line
kmalloc()is still visible in slabinfo as kmalloc-128 or so.Yes, but there's no way for users to know where the allocations came from if you mix them up with other kmalloc-128 call-sites. That way the number of private files will stay private to the user, no? Doesn't that give you even better protection against the infoleak?
Quoted 5 lines
No, what it gives us is an obscurity, not a protection. I'm sure it highly depends on the specific situation whether an attacker is able to identify whether the call is from e.g. ecryptfs or from VFS. Also the correlation between the number in slabinfo and the real private actions still exists.
IMHO a restriction of access to slab statistics is reasonable in a hardened environment. Make it dependent on CONFIG_SECURITY or some such thing?
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 3 lines · Christoph Lameter
IMHO a restriction of access to slab statistics is reasonable in a hardened environment. Make it dependent on
CONFIG_SECURITYor some such thing?
Probably need to invent a separate Kconfig variable - CONFIG_SECURITY is probably a way-too-big hammer for this nail. I can see lots of systems that want to enable that, but won't want to tighten access to slab.
Christoph Lameter
reviewerRe: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 9 lines · On Mon, 19 Sep 2011, [email protected] wrote:
Quoted 3 lines · Christoph Lameter
IMHO a restriction of access to slab statistics is reasonable in a hardened environment. Make it dependent on
CONFIG_SECURITYor some such thing?Probably need to invent a separate
Kconfigvariable -CONFIG_SECURITYis probably a way-too-big hammer for this nail. I can see lots of systems that want to enable that, but won't want to tighten access to slab.
There is already CONFIG_SECURITY_DMESG_RESTRICT. Generalize that setting to include all sorts of other kernel statistics?
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 8 lines · Christoph Lameter
Quoted 6 lines · On Mon, 19 Sep 2011, [email protected] wrote:
Quoted 3 lines · Christoph Lameter
IMHO a restriction of access to slab statistics is reasonable in a hardened environment. Make it dependent on
CONFIG_SECURITYor some such thing?
Quoted 6 lines
Quoted 3 lines
Probably need to invent a separate
Kconfigvariable -CONFIG_SECURITYis probably a way-too-big hammer for this nail. I can see lots of systems that want to enable that, but won't want to tighten access to slab.There is already
CONFIG_SECURITY_DMESG_RESTRICT. Generalize that setting to include all sorts of other kernel statistics?
The question becomes "What are the chances that a given site either will or will not agree with using the same setting for all things aggregated under
the same option". I could probably make a good case for a flag
called CONFIG_SECURITY_INFOLEAK_RESTRICT that would be a switch for "standard perms or root only" for all info-leaking files under /proc and /sys.
The problem is that dmesg has *other* info-leakage issues - but it's not internal kernel state, it's stuff like ipfilter messages and potentially Selinux messages if auditd isn't running, and of late things like systemd and crond like to stick crap in there as well.
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
In reply to Vasiliy KulikovQuoted 10 lines · Vasiliy Kulikov
Quoted 4 lines
Yes, but there's no way for users to know where the allocations came from if you mix them up with other kmalloc-128 call-sites. That way the number of private files will stay private to the user, no? Doesn't that give you even better protection against the infoleak?
No, what it gives us is an obscurity, not a protection. I'm sure it highly depends on the specific situation whether an attacker is able to identify whether the call is from e.g. ecryptfs or from VFS. Also the correlation between the number in slabinfo and the real private actions still exists.
How is the attacker able to identify that we kmalloc()'d from ecryptfs or VFS based on non-root /proc/slabinfo when the slab allocator itself does not have that sort of information if you mix up the allocations? Isn't this much stronger protection especially if you combine that with /proc/slabinfo restriction?
Pekka
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 12 lines · Pekka Enberg
Quoted 10 lines · Vasiliy Kulikov
Quoted 4 lines
Yes, but there's no way for users to know where the allocations came from if you mix them up with other kmalloc-128 call-sites. That way the number of private files will stay private to the user, no? Doesn't that give you even better protection against the infoleak?
No, what it gives us is an obscurity, not a protection. I'm sure it highly depends on the specific situation whether an attacker is able to identify whether the call is from e.g. ecryptfs or from VFS. Also the correlation between the number in slabinfo and the real private actions still exists.
Quoted 3 lines
How is the attacker able to identify that we kmalloc()'d from ecryptfs or VFS based on non-root
/proc/slabinfowhen the slab allocator itself does not have that sort of information if you mix up the allocations?
How can you _guarantee_ that they mix?
Quoted 3 lines
Isn't this
much stronger protection especially if you combine that with/proc/slabinforestriction?
I don't see any reason to change allocators if we close slabinfo.
Thanks,
Signature · 2 lines
Vasiliy Kulikov http://www.openwall.com - bringing security into open computing environments
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 5 lines · Vasiliy Kulikov
Quoted 3 lines
Isn't this
much stronger protection especially if you combine that with/proc/slabinforestriction?I don't see any reason to change allocators if we close slabinfo.
OK, so what about /proc/meminfo, sysfs, 'perf kmem', and other kernel interfaces through which you can get direct or indirect information about kernel memory allocations?
Pekka
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 10 lines · Pekka Enberg
Quoted 5 lines · Vasiliy Kulikov
Quoted 3 lines
Isn't this
much stronger protection especially if you combine that with/proc/slabinforestriction?I don't see any reason to change allocators if we close slabinfo.
OK, so what about
/proc/meminfo, sysfs, 'perf kmem', and other kernel interfaces through which you can get direct or indirect information about kernel memory allocations?
Oh, we also have perf... Given these are separate interfaces, I think slab oriented restriction makes more sense.
So, now we have:
/proc/slabinfo/sys/kernel/slab/proc/meminfo
'perf kmem' - not sure what specific files should be guarded
Is there another way to get directly or indirectly the information about slabs?
Thanks,
Signature · 2 lines
Vasiliy Kulikov http://www.openwall.com - bringing security into open computing environments
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 9 lines · Vasiliy Kulikov
Oh, we also have perf... Given these are separate interfaces, I think slab oriented restriction makes more sense.
So, now we have:
/proc/slabinfo/sys/kernel/slab/proc/meminfo
'perf kmem' - not sure what specific files should be guarded
I don't think you can close down 'perf kmem' per se. You need to make sure the attacker is not able to use perf tracing (of which 'perf kmem' is a subset).
Pekka
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
In reply to Vasiliy KulikovQuoted 2 lines · Vasiliy Kulikov
Is there another way to get directly or indirectly the information about slabs?
I didn't check closely but there seems to be some filesystem specific stats under /proc at least. No idea how useful those are as attack vectors.
I also suspect there are per-module knobs under /proc and /sys that can be used to get indirect information. Many subsystems have implemented their own slab wrappers in the past and they keep popping up every now and then.
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
In reply to Pekka EnbergQuoted 4 lines · Pekka Enberg
OK, so what about
/proc/meminfo, sysfs, 'perf kmem', and other kernel interfaces through which you can get direct or indirect information about kernel memory allocations?
Pekka, there are degrees of badness.
Also, quite frankly, your argument that /proc/slabinfo is so important for kernel debugging is bogus. Every time I've complained about the fact that the thing is useless AND ACTIVELY MISLEADING because it mixes up all the slabs (so big numbers for "vm_area_struct" might actually be about some other slab entirely, and *has* been, to the point of people wasting time), the answer has been "whatever".
You can't have it both ways just to argue for the status quo.
Considering how useless /proc/slabinfo actually is today - exactly because of the misleading mixing - I suspect the right thing to do is to make it root-only.
Having some aggregate number in /proc/meminfo would probably be fine.
And yes, we probably should avoid giving page-level granularity in /proc/meminfo too. Do it in megabytes instead. None of the information there is really relevant at a page level, everybody just wants rough aggregates.
Linus
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Hi Linus,
Quoted 8 lines · Linus Torvalds
Also, quite frankly, your argument that
/proc/slabinfois so important for kernel debugging is bogus. Every time I've complained about the fact that the thing is useless AND ACTIVELY MISLEADING because it mixes up all the slabs (so big numbers for "vm_area_struct" might actually be about some other slab entirely, and *has* been, to the point of people wasting time), the answer has been "whatever".You can't have it both ways just to argue for the status quo.
Well, sure. I was actually planning to rip out SLUB merging completely because it makes /proc/slabinfo so useless but never got around doing that. Mixing up allocations makes heap exploits harder but there's no agreement on how much more difficult (i.e. if it matters at all for brute force attacks).
So dunno what's the right thing to do here. Every time I discuss the issues with 'security folks' I'm left with more questions than answers... Everybody seems to be more interested in closing down kernel ABIs rather than making kernel memory allocations more robust against attacks.
But anyway, if you feel about this strongly feel free to pick up Vasiliy's patch. I think my suggestion of introducing a CONFIG_RESTRICT_PROCFS makes most sense because:
- When we've mucked around with /proc/slabinfo in the past, we have broken setups. (That might be less relevant now.)
- /proc/slabinfo is not the only source where you can get information on kernel memory allocations (we have one in sysfs and perf kmem).
Quoted 10 lines · Linus Torvalds
Considering how useless
/proc/slabinfoactually is today - exactly because of the misleading mixing - I suspect the right thing to do is to make it root-only.Having some aggregate number in
/proc/meminfowould probably be fine.And yes, we probably should avoid giving page-level granularity in
/proc/meminfotoo. Do it in megabytes instead. None of the information there is really relevant at a page level, everybody just wants rough aggregates.
We have this in /proc/meminfo:
Slab: 20012 kB
Or did you mean something even more specific?
Pekka
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 7 lines · Pekka Enberg
Quoted 6 lines
Having some aggregate number in
/proc/meminfowould probably be fine.And yes, we probably should avoid giving page-level granularity in
/proc/meminfotoo. Do it in megabytes instead. None of the information there is really relevant at a page level, everybody just wants rough aggregates.
Quoted 5 lines
We have this in
/proc/meminfo:Slab: 20012 kB
Or did you mean something even more specific?
Oh, sorry, I completely misread what you wrote above. Sure, we can round the numbers into megabytes without breaking the ABI.
Pekka
David Rientjes
reviewerRe: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
In reply to Pekka EnbergQuoted 3 lines · Pekka Enberg
Well, sure. I was actually planning to rip out SLUB merging completely because it makes
/proc/slabinfoso useless but never got around doing that.
Ripping out cache merging entirely for the benefit of an interface seems like overkill, it actually allows the allocator to return cache-hot objects that has a small but measurable impact on performance for some networking loads. It would probably be better to increase awareness of slabinfo -a and the use of slub_nomerge on the command line when debugging issues. The most complete solution would be to move everything out of struct kmem_cache except what is necessary for slabinfo and then point to the actual cache data structure that could be shared by merged caches. That's not hard to do, but would add an increment to both the alloc and free fastpaths and require some surgery throughout all of the slub code to understand the new data structures and that would be a pretty big patch.
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
In reply to Pekka EnbergQuoted 5 lines · Pekka Enberg
How is the attacker able to identify that we kmalloc()'d from ecryptfs or VFS based on non-root
/proc/slabinfowhen the slab allocator itself does not have that sort of information if you mix up the allocations? Isn't this much stronger protection especially if you combine that with/proc/slabinforestriction?
Mixing it up just adds noise. It makes the attack somewhat more difficult, but it still leaves open the possibility that the attacker can filter out the noise somehow.
-- Dave
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 5 lines · Pekka Enberg
Quoted 5 lines
How is the attacker able to identify that we kmalloc()'d from ecryptfs or VFS based on non-root
/proc/slabinfowhen the slab allocator itself does not have that sort of information if you mix up the allocations? Isn't this much stronger protection especially if you combine that with/proc/slabinforestriction?
Quoted 3 lines · Dave Hansen
Mixing it up just adds noise. It makes the attack somewhat more difficult, but it still leaves open the possibility that the attacker can filter out the noise somehow.
So that would mean the attacker has somewhat fine-grained control over kernel memory allocations, no? Can they use /proc/meminfo to deduce the same kind of information? Should we close that down too?
Pekka
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
In reply to Vasiliy KulikovQuoted 2 lines · Vasiliy Kulikov
One note: only to _kernel_ developers. It means it is a strictly debugging feature, which shouldn't be enabled in the production systems.
Until somebody at vendor support says "What does 'cat /proc/slabinfo' say?"
Anybody who thinks that debugging tools should be totally disabled on "production" systems probably hasn't spent enough time actually running production systems.
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 6 lines · On Mon, 19 Sep 2011 15:45:07 -0400 [email protected] wrote:
Quoted 3 lines · Vasiliy Kulikov
One note: only to _kernel_ developers. It means it is a strictly debugging feature, which shouldn't be enabled in the production systems.
Quoted 6 lines
Until somebody at vendor support says "What does 'cat
/proc/slabinfo' say?"Anybody who thinks that debugging tools should be totally disabled on "production" systems probably hasn't spent enough time actually running production systems.
Agreed - far better it is simply set root only. At that point if you can read it you've bypassed DAC anyway so either you already control the box or something like SELinux or SMACK is in the way in which case *it* can manage extra policy just fine.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
(I have to increase the CC list by CC'ing Greg and perf guys. The motivation for restricting slabinfo is here:
http://www.openwall.com/lists/kernel-hardening/2011/09/10/4)
Quoted 3 lines
Anybody who thinks that debugging tools should be totally disabled on "production" systems probably hasn't spent enough time actually running production systems.
Quoted 1 line · Alan Cox
Agreed - far better it is simply set root only.
Sorry, I've poorly worded my statement. Of course I mean root-only slabinfo, not totally disable it.
So, where are we now?
Linus, Alan, Kees, and Dave are about to simply restrict slabinfo (and probably similar interfaces) to root. Pekka is OK too.
Christoph and Valdis are about to create new CONFIG_ option to be able to restrict the access to slabinfo/etc., but with old relaxed permissions.
IMO having a compatibility with the old tools using slabinfo/meminfo as non-root for good things is great, but probably a seamless upgrade doesn't worth it in this case. Instead, we can provide a transition instructions to continue to use non-root monitoring tools:
groupadd meminfo
usermod -a -G meminfo $MONITOR_USER
And add these lines to the init scripts between mount /proc and running monitoring daemon, for Ubuntu's upstart it should fit in mountall.conf:
chmod g+r /proc/slabinfo /proc/meminfo
chgrp meminfo /proc/slabinfo /proc/meminfo
Then the daemon may watch for memleaks again. It requires some actions from the sysadmin, but no changes to the daemons and it helps to keep sane kernel defaults.
Are we OK with this solution?
Now about other sources of infoleaks. Pekka has noticed that the same information about slabs is accessible from sysfs and 'perf kmem':
http://www.openwall.com/lists/kernel-hardening/2011/09/19/23
For sysfs the solution is relatively simple - the same __ATTR(..., 0600, ...) for SLAB_ATTR() (all __ATTR* in mm/*.c?) with the same chmod in init scripts.
For the perf the situation differs. AFAICS (please correct me if I'm wrong) all performance events are recorded and passed to userspace without any security checks. IOW, every event happened in the current process' context is signalled to the current task if requested. It contains k*alloc/kfree, which are the subject of this thread, and probably much more infoleaks which simply nobody cared about yet. Probably it's time to develop some rules to identify what events are safe to signal to user and what are dangerous/private to the system/other users (probably, potentially)? I'm not very familiar with perf events and there might be already such mechanisms, but they're just not used for memory things, so this is a question to the perf guys.
Other sources of similar infoleaks are fs-specific and IMO we should fix them after these more "generic" infoleaks (slabinfo, meminfo, sysfs, perf).
Thanks,
Signature · 2 lines
Vasiliy Kulikov http://www.openwall.com - bringing security into open computing environments
Re: [kernel-hardening] Re: [RFC PATCH 2/2] mm: restrict access to /proc/slabinfo
Quoted 2 lines · Vasiliy Kulikov
Sorry, I've poorly worded my statement. Of course I mean root-only slabinfo, not totally disable it.
Oh, that I can live with.. ;)
Quoted 6 lines
Linus, Alan, Kees, and Dave are about to simply restrict slabinfo (and probably similar interfaces) to root. Pekka is OK too.
Christoph and Valdis are about to create new
CONFIG_option to be able to restrict the access to slabinfo/etc., but with old relaxed permissions.
I'm OK with a decision to just make the files mode 400 and be done with it, since I can always stick a chmod in the startup scripts if it's *really* a problem.
Just that *if* we add a CONFIG_ option, it shouldn't be slabinfo-specific, but should cover the *other* identified info-leakers in /proc and /sys as well.
Hello Andrew,
Quoted 19 lines · Vasiliy Kulikov
The patch "proc: fix races against
execve()of/proc/PID/fd**" is still a partial fix for a setxid problem. link(2) is a yet another way to identify whether a specific fd is opened by a privileged process. By calling link(2) against/proc/PID/fd/*an attacker may identify whether the fd number is valid for PID by analysing link(2) return code.Both
getattr()andlink()can be used by the attacker iff the dentry is present in the dcache. In this case ->lookup() is not called and the only way to check ptrace permissions is either operation handler or ->revalidate(). The easiest solution to prevent any unauthorized access to/proc/PID/fd*/files is to force the dentry drop on each unauthorized access attempt.If an attacker keeps opened fd of
/proc/PID/fd/and dcache contains a specific dentry for some/proc/PID/fd/XXX, any future attemp to use the dentry by the attacker would lead to the dentry drop as a result of a failed ptrace check in ->revalidate(). Then the attacker cannot spawn a dentry for the specific fd number because of ptrace check in ->lookup().
Quoted 3 lines
The dentry drop can be still observed by an attacker by analysing information from
/proc/slabinfo, which is addressed in the successive patch.
After (almost) everybody agreed that closing slabinfo and similar is a good thing, should I resend these 2 patches (/proc/PID/fd and slabinfo) with sysfs addition or you'll take these patches and I'll send sysfs patch after them?
Thanks,
Signature · 2 lines
Vasiliy Kulikov http://www.openwall.com - bringing security into open computing environments