Skip to contentSkip to conversation

report size of printk buffer

PATCH In review [email protected] 3 participants 6 messages May 4, 2004 – May 6, 2004

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 report size of printk buffer

In the old days the printk log buffer had a constant size, and dmesg asked for the 4096, later 8192, later 16384 bytes in there. These days the printk log buffer has variable size, and it is not easy for dmesg to do the right thing, especially when doing a "read and clear".
The patch below adds a syslog subfuntion that reports the buffer size.

Andries

kernel/printk.c +4 -0
diff -uprN -X /linux/dontdiff a/kernel/printk.c b/kernel/printk.c
@@ -240,6 +240,7 @@ __setup("log_buf_len=", log_buf_len_setu
  * 	7 -- Enable printk's to console
  *	8 -- Set level of messages printed to console
  *	9 -- Return number of unread characters in the log buffer
+ *     10 -- Return size of the log buffer
  */
 int do_syslog(int type, char __user * buf, int len)
 {
@@ -359,6 +360,9 @@ int do_syslog(int type, char __user * bu
 	case 9:		/* Number of chars in the log buffer */
 		error = log_end - log_start;
 		break;
+	case 10:	/* Size of the log buffer */
+		error = log_buf_len;
+		break;
 	default:
 		error = -EINVAL;
 		break;
#1 lore raw
Quoted 8 lines · On 04-May-04, [email protected] wrote:

In the old days the printk log buffer had a constant size, and dmesg asked for the 4096, later 8192, later 16384 bytes in there. These days the printk log buffer has variable size, and it is not easy for dmesg to do the right thing, especially when doing a "read and clear".
The patch below adds a syslog subfuntion that reports the buffer size.

[...]

Please also consider allowing everyone to read the ring buffer size. This way dmesg will continue to behave the same for users and root when they read the log buffer. (And other options will continue to be denied to the user.)

Please note that users are already allowed to read the ring buffer (case 3).

Short security analysis:
There is no dynamic information provided. So system behaviour cannot be infered from reading the ring buffer size.

The information provided can already be infered from the architecture and release of the distribution. And there are other methods as well.

security/selinux/hooks.c +1 -0
@@ -1467,6 +1467,7 @@
 
 	switch (type) {
 		case 3:         /* Read last kernel messages */
+		case 10:        /* Return size of the log buffer */
 			rc = task_has_system(current, SYSTEM__SYSLOG_READ);
 			break;
 		case 6:         /* Disable logging to console */
security/commoncap.c +1 -1
@@ -293,7 +293,7 @@
 
 int cap_syslog (int type)
 {
-	if ((type != 3) && !capable(CAP_SYS_ADMIN))
+	if ((type != 3 && type != 10) && !capable(CAP_SYS_ADMIN))
 		return -EPERM;
 	return 0;
 }
security/dummy.c +1 -1
@@ -97,7 +97,7 @@
 
 static int dummy_syslog (int type)
 {
-	if ((type != 3) && current->euid)
+	if ((type != 3 && type != 10) && current->euid)
 		return -EPERM;
 	return 0;
 }
Signature · 1 line
Olaf Dabrunz (od/odabrunz), SUSE Linux AG, Nürnberg
#2 lore raw
In reply to [email protected]

Hi,

Quoted 5 lines · On Tue, 4 May 2004 [email protected] wrote:

In the old days the printk log buffer had a constant size, and dmesg asked for the 4096, later 8192, later 16384 bytes in there. These days the printk log buffer has variable size, and it is not easy for dmesg to do the right thing, especially when doing a "read and clear".

Why don't you simply change it into "read and clear read data"? E.g. something like below.

bye, Roman

Index: kernel/printk.c
===================================================================
RCS file: /usr/src/cvsroot/linux-2.6/kernel/printk.c,v retrieving revision 1.1.1.6

kernel/printk.c +1 -1
diff -u -p -r1.1.1.6 printk.c
@@ -305,7 +305,7 @@ int do_syslog(int type, char __user * bu
 		if (count > logged_chars)
 			count = logged_chars;
 		if (do_clear)
-			logged_chars = 0;
+			logged_chars -= count;
 		limit = log_end;
 		/*
 		 * __put_user() could sleep, and while we sleep
#3 lore raw
Quoted 21 lines · Roman Zippel
Quoted 5 lines · On Tue, 4 May 2004 [email protected] wrote:

In the old days the printk log buffer had a constant size, and dmesg asked for the 4096, later 8192, later 16384 bytes in there. These days the printk log buffer has variable size, and it is not easy for dmesg to do the right thing, especially when doing a "read and clear".

Why don't you simply change it into "read and clear read data"? E.g. something like below.

bye, Roman

Index: kernel/printk.c
===================================================================
RCS file: /usr/src/cvsroot/linux-2.6/kernel/printk.c,v retrieving revision 1.1.1.6
diff -u -p -r1.1.1.6 printk.c

kernel/printk.c int do_syslog(int type, char __user * bu · line 310

Quoted 7 lines
kernel/printk.c +1 -1
@@ -305,7 +305,7 @@ int do_syslog(int type, char __user * bu
 		if (count > logged_chars)
 			count = logged_chars;
 		if (do_clear)
-			logged_chars = 0;
+			logged_chars -= count;
 		limit = log_end;
 		/*

No, that is buggy.

If one asks for count bytes, one gets the last count bytes of output, not the first.

Andries

#4 lore raw

Hi,

Quoted 2 lines · Andries Brouwer

If one asks for count bytes, one gets the last count bytes of output, not the first.

That doesn't answer the question, why don't you just clear the data that was read?

bye, Roman

#5 lore raw
Quoted 5 lines · Roman Zippel
Quoted 2 lines

If one asks for count bytes, one gets the last count bytes of output, not the first.

That doesn't answer the question, why don't you just clear the data that was read?

Think about it.
The buffer is 131072 bytes. We read the final 16384 bytes. Now what?

[There are other problems as well, but I do not want to start a complicated conversation for a triviality.]