Skip to content

Commit 3ea4331

Browse files
vaverintorvalds
authored andcommitted
check_syslog_permissions() cleanup
Patch fixes drawbacks in heck_syslog_permissions() noticed by AKPM: "from_file handling makes me cry. That's not a boolean - it's an enumerated value with two values currently defined. But the code in check_syslog_permissions() treats it as a boolean and also hardwires the knowledge that SYSLOG_FROM_PROC == 1 (or == `true`). And the name is wrong: it should be called from_proc to match SYSLOG_FROM_PROC." Signed-off-by: Vasily Averin <vvs@virtuozzo.com> Cc: Kees Cook <keescook@chromium.org> Cc: Josh Boyer <jwboyer@redhat.com> Cc: Eric Paris <eparis@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent d194e5d commit 3ea4331

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

‎include/linux/syslog.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@
4747
#define SYSLOG_FROM_READER 0
4848
#define SYSLOG_FROM_PROC 1
4949

50-
int do_syslog(int type, char __user *buf, int count, bool from_file);
50+
int do_syslog(int type, char __user *buf, int count, int source);
5151

5252
#ifdef CONFIG_PRINTK
53-
int check_syslog_permissions(int type, bool from_file);
53+
int check_syslog_permissions(int type, int source);
5454
#else
55-
static inline int check_syslog_permissions(int type, bool from_file)
55+
static inline int check_syslog_permissions(int type, int source)
5656
{
5757
return 0;
5858
}

‎kernel/printk/printk.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,13 @@ static int syslog_action_restricted(int type)
489489
type != SYSLOG_ACTION_SIZE_BUFFER;
490490
}
491491

492-
int check_syslog_permissions(int type, bool from_file)
492+
int check_syslog_permissions(int type, int source)
493493
{
494494
/*
495495
* If this is from /proc/kmsg and we've already opened it, then we've
496496
* already done the capabilities checks at open time.
497497
*/
498-
if (from_file && type != SYSLOG_ACTION_OPEN)
498+
if (source == SYSLOG_FROM_PROC && type != SYSLOG_ACTION_OPEN)
499499
goto ok;
500500

501501
if (syslog_action_restricted(type)) {
@@ -1290,13 +1290,13 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
12901290
return len;
12911291
}
12921292

1293-
int do_syslog(int type, char __user *buf, int len, bool from_file)
1293+
int do_syslog(int type, char __user *buf, int len, int source)
12941294
{
12951295
bool clear = false;
12961296
static int saved_console_loglevel = LOGLEVEL_DEFAULT;
12971297
int error;
12981298

1299-
error = check_syslog_permissions(type, from_file);
1299+
error = check_syslog_permissions(type, source);
13001300
if (error)
13011301
goto out;
13021302

@@ -1379,7 +1379,7 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
13791379
syslog_prev = 0;
13801380
syslog_partial = 0;
13811381
}
1382-
if (from_file) {
1382+
if (source == SYSLOG_FROM_PROC) {
13831383
/*
13841384
* Short-cut for poll(/"proc/kmsg") which simply checks
13851385
* for pending data, not the size; return the count of

0 commit comments

Comments
 (0)