Skip to content

Commit 68c4a4f

Browse files
yathaegl
authored andcommitted
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 <[email protected]> Acked-by: Kees Cook <[email protected]> Signed-off-by: Tony Luck <[email protected]>
1 parent a28726b commit 68c4a4f

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

fs/pstore/inode.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <linux/slab.h>
3737
#include <linux/spinlock.h>
3838
#include <linux/uaccess.h>
39+
#include <linux/syslog.h>
3940

4041
#include "internal.h"
4142

@@ -120,6 +121,18 @@ static const struct seq_operations pstore_ftrace_seq_ops = {
120121
.show = pstore_ftrace_seq_show,
121122
};
122123

124+
static 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+
123136
static ssize_t pstore_file_read(struct file *file, char __user *userbuf,
124137
size_t count, loff_t *ppos)
125138
{
@@ -138,6 +151,10 @@ static int pstore_file_open(struct inode *inode, struct file *file)
138151
int err;
139152
const struct seq_operations *sops = NULL;
140153

154+
err = pstore_check_syslog_permissions(ps);
155+
if (err)
156+
return err;
157+
141158
if (ps->type == PSTORE_TYPE_FTRACE)
142159
sops = &pstore_ftrace_seq_ops;
143160

@@ -174,6 +191,11 @@ static const struct file_operations pstore_file_operations = {
174191
static int pstore_unlink(struct inode *dir, struct dentry *dentry)
175192
{
176193
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;
177199

178200
if (p->psi->erase)
179201
p->psi->erase(p->type, p->id, p->count,

include/linux/syslog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,6 @@
4848
#define SYSLOG_FROM_PROC 1
4949

5050
int do_syslog(int type, char __user *buf, int count, bool from_file);
51+
int check_syslog_permissions(int type, bool from_file);
5152

5253
#endif /* _LINUX_SYSLOG_H */

kernel/printk/printk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ static int syslog_action_restricted(int type)
480480
type != SYSLOG_ACTION_SIZE_BUFFER;
481481
}
482482

483-
static int check_syslog_permissions(int type, bool from_file)
483+
int check_syslog_permissions(int type, bool from_file)
484484
{
485485
/*
486486
* If this is from /proc/kmsg and we've already opened it, then we've

0 commit comments

Comments
 (0)