aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Schmidt <yath@yath.de>2014-10-19 14:05:15 -0400
committerTony Luck <tony.luck@intel.com>2014-11-05 12:59:48 -0500
commit68c4a4f8abc60c9440ede9cd123d48b78325f7a3 (patch)
treeef8aefb7d8c3769204116ff65cfa48551464a275
parenta28726b4fb624f81d637a8afb9ea12fc16500f61 (diff)
pstore: Honor dmesg_restrict sysctl on dmesg dumps
When the kernel.dmesg_restrict restriction is in place, only users with CAP_SYSLOG should be able to access crash dumps (like: attacker is trying to exploit a bug, watchdog reboots, attacker can happily read crash dumps and logs). This puts the restriction on console-* types as well as sensitive information could have been leaked there. Other log types are unaffected. Signed-off-by: Sebastian Schmidt <yath@yath.de> Acked-by: Kees Cook <keescook@chromium.org> Signed-off-by: Tony Luck <tony.luck@intel.com>
-rw-r--r--fs/pstore/inode.c22
-rw-r--r--include/linux/syslog.h1
-rw-r--r--kernel/printk/printk.c2
3 files changed, 24 insertions, 1 deletions
diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c
index fafb7a02a5d6..50416602774d 100644
--- a/fs/pstore/inode.c
+++ b/fs/pstore/inode.c
@@ -36,6 +36,7 @@
36#include <linux/slab.h> 36#include <linux/slab.h>
37#include <linux/spinlock.h> 37#include <linux/spinlock.h>
38#include <linux/uaccess.h> 38#include <linux/uaccess.h>
39#include <linux/syslog.h>
39 40
40#include "internal.h" 41#include "internal.h"
41 42
@@ -120,6 +121,18 @@ static const struct seq_operations pstore_ftrace_seq_ops = {
120 .show = pstore_ftrace_seq_show, 121 .show = pstore_ftrace_seq_show,
121}; 122};
122 123
124static int pstore_check_syslog_permissions(struct pstore_private *ps)
125{
126 switch (ps->type) {
127 case PSTORE_TYPE_DMESG:
128 case PSTORE_TYPE_CONSOLE:
129 return check_syslog_permissions(SYSLOG_ACTION_READ_ALL,
130 SYSLOG_FROM_READER);
131 default:
132 return 0;
133 }
134}
135
123static ssize_t pstore_file_read(struct file *file, char __user *userbuf, 136static ssize_t pstore_file_read(struct file *file, char __user *userbuf,
124 size_t count, loff_t *ppos) 137 size_t count, loff_t *ppos)
125{ 138{
@@ -138,6 +151,10 @@ static int pstore_file_open(struct inode *inode, struct file *file)
138 int err; 151 int err;
139 const struct seq_operations *sops = NULL; 152 const struct seq_operations *sops = NULL;
140 153
154 err = pstore_check_syslog_permissions(ps);
155 if (err)
156 return err;
157
141 if (ps->type == PSTORE_TYPE_FTRACE) 158 if (ps->type == PSTORE_TYPE_FTRACE)
142 sops = &pstore_ftrace_seq_ops; 159 sops = &pstore_ftrace_seq_ops;
143 160
@@ -174,6 +191,11 @@ static const struct file_operations pstore_file_operations = {
174static int pstore_unlink(struct inode *dir, struct dentry *dentry) 191static int pstore_unlink(struct inode *dir, struct dentry *dentry)
175{ 192{
176 struct pstore_private *p = dentry->d_inode->i_private; 193 struct pstore_private *p = dentry->d_inode->i_private;
194 int err;
195
196 err = pstore_check_syslog_permissions(p);
197 if (err)
198 return err;
177 199
178 if (p->psi->erase) 200 if (p->psi->erase)
179 p->psi->erase(p->type, p->id, p->count, 201 p->psi->erase(p->type, p->id, p->count,
diff --git a/include/linux/syslog.h b/include/linux/syslog.h
index 98a3153c0f96..9def5297dbb7 100644
--- a/include/linux/syslog.h
+++ b/include/linux/syslog.h
@@ -48,5 +48,6 @@
48#define SYSLOG_FROM_PROC 1 48#define SYSLOG_FROM_PROC 1
49 49
50int do_syslog(int type, char __user *buf, int count, bool from_file); 50int do_syslog(int type, char __user *buf, int count, bool from_file);
51int check_syslog_permissions(int type, bool from_file);
51 52
52#endif /* _LINUX_SYSLOG_H */ 53#endif /* _LINUX_SYSLOG_H */
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index ced2b84b1cb7..c8755e7e1dba 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -480,7 +480,7 @@ static int syslog_action_restricted(int type)
480 type != SYSLOG_ACTION_SIZE_BUFFER; 480 type != SYSLOG_ACTION_SIZE_BUFFER;
481} 481}
482 482
483static int check_syslog_permissions(int type, bool from_file) 483int check_syslog_permissions(int type, bool from_file)
484{ 484{
485 /* 485 /*
486 * If this is from /proc/kmsg and we've already opened it, then we've 486 * If this is from /proc/kmsg and we've already opened it, then we've