Date: Sun, 10 Feb 2002 13:24:25 +0200 (EET) From: Valentin Nechayev <netch@netch.kiev.ua> To: FreeBSD-gnats-submit@freebsd.org Subject: misc/34788: dmesg issues with console output Message-ID: <200202101124.g1ABOPa07227@iv.nn.kiev.ua>
next in thread | raw e-mail | index | archive | help
>Number: 34788
>Category: misc
>Synopsis: dmesg issues with console output
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Sun Feb 10 03:30:01 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Valentin Nechayev
>Release: FreeBSD 4.5-RELEASE i386
>Organization:
home sweet home
>Environment:
System: FreeBSD iv.nn.kiev.ua 4.5-RELEASE FreeBSD 4.5-RELEASE #1: Sat Feb 2 21:46:14 EET 2002 root@iv.nn.kiev.ua:/var/obj/sys4/nn14 i386
AFAIS all fixes are easily-portable to -CURRENT.
>Description:
This is a gathering of problems and annoyances due to new dmesg buffer
implementation which logs console output. It is tagged as `misc' category
because some fixes are for `kern', some for `bin' and, possible, some stuff
is for `conf' also.
1. For now, all console output is put to message buffer. But, that is
possibly ignored that in single-user mode all interactive work of sysadmin
is put to console. As a result,
1) message buffer is spammed with information
which is mainly unuseful in it; in case of sysinstall were run, message buffer
is garbaged with pieces of fullscreen ncurses output, which makes it
totally unreadable;
2) useful stuff from message buffer - e.g. kernel startup
output - is often flushed from message buffer during sysadmin activity;
but kernel startup output is often vital for operations made in
single-user mode.
I suppose the correct fix is to disable console logging during single-user
mode. I can't imagine a real need to log sysadmin activity in single-user
mode; if he wants this, he can use other tools which are more reliable,
particularly, for dealing with fullscreen output.
This also can be important security issue with some circumstances.
2. Dmesg buffer keeps kernel messages and messages to console with
syslog-styled priority tags ("<n> text..."). For now /sbin/dmesg deletes
this tags from all output. There are some situations when it is highly
important to see these tags. Instead of writing own tool, IMO /sbin/dmesg
should be extended to do it upon user's request.
3. Dmesg buffer now is circular buffer of bytes, separated with '\n'.
When old contents is being flushed, almost always some line loses its
beginning, but rest of the line keeps in buffer. As a result, malformed
line is kept at buffer head. A strange result of this misfeature is that
dmesg diff part daily security output regularly contains "hanging" line chunk.
>How-To-Repeat:
>Fix:
Following fixes are in strong correspondence with problems described above:
1. Patch to sys/kern/tty_cons.c allows control whether to log to message
buffer all stuff printed to console. It creates and uses new sysctl variable.
Values 0 and 1 means disabling and enabling controlled by /sbin/init.
Other values are possible; 2,3,... means uncontrolled enabling;
-1,-2,... means uncontrolled disabling (this is why variable is defined as
int, not unsigned or another boolean type). This scheme is almost equal
to one of kern.securelevel.
2. Patch to sbin/init/init.c uses control from paragraph 1 to enable/disable
logging of console output. A most-adoptable scheme is used when logging
is disabled during single user mode and enabled otherwise.
/sbin/init changes only 0 to 1 and 1 to 0.
3. Patch to sbin/dmesg/dmesg.8, sbin/dmesg/dmesg.c provides show of message
buffer with syslog priority tags.
Deleting whole line from message buffer is unimplemented here (yet?)
diff -rNu 0/sbin/dmesg/dmesg.8 1/sbin/dmesg/dmesg.8
--- 0/sbin/dmesg/dmesg.8 Sat Aug 18 16:16:17 2001
+++ 1/sbin/dmesg/dmesg.8 Sat Nov 10 12:37:36 2001
@@ -72,6 +72,11 @@
.It Fl N
Extract the name list from the specified system instead of the default,
which is the kernel image the system has booted from.
+.It Fl p
+Do not suppress syslog priority labels at beginning of each line.
+Implies
+.Fl a
+option.
.El
.Sh FILES
.Bl -tag -width ".Pa /var/run/dmesg.boot" -compact
diff -rNu 0/sbin/dmesg/dmesg.c 1/sbin/dmesg/dmesg.c
--- 0/sbin/dmesg/dmesg.c Sat Aug 18 16:16:17 2001
+++ 1/sbin/dmesg/dmesg.c Sat Nov 10 12:39:52 2001
@@ -82,13 +82,14 @@
kvm_t *kd;
char buf[5];
int all = 0;
+ int withprio = 0;
int pri;
size_t buflen;
int bufpos;
(void) setlocale(LC_CTYPE, "");
memf = nlistf = NULL;
- while ((ch = getopt(argc, argv, "aM:N:")) != -1)
+ while ((ch = getopt(argc, argv, "aM:N:p")) != -1)
switch(ch) {
case 'a':
all++;
@@ -99,6 +100,9 @@
case 'N':
nlistf = optarg;
break;
+ case 'p':
+ withprio = 1;
+ break;
case '?':
default:
usage();
@@ -172,7 +176,7 @@
}
continue;
}
- if (newl && ch == '<') {
+ if (newl && ch == '<' && !withprio) {
pri = 0;
skip = 1;
continue;
diff -rNu 0/sbin/init/init.c 1/sbin/init/init.c
--- 0/sbin/init/init.c Sun Oct 7 22:27:03 2001
+++ 1/sbin/init/init.c Sat Nov 10 12:40:29 2001
@@ -548,6 +548,25 @@
}
/*
+ * Allow/disallow logging of console output to message buffer.
+ */
+void
+set_msgbuf_log_console(int yesno)
+{
+ int oldval;
+ size_t vlen;
+ vlen = sizeof(oldval);
+ if(sysctlbyname("kern.msgbuf_log_allowed", &oldval, &vlen,
+ NULL, 0) == 0) {
+ /* If we don't know this value, skip it. */
+ if(oldval != 0 && oldval != 1)
+ return;
+ sysctlbyname("kern.msgbuf_log_allowed", NULL, 0,
+ &yesno, sizeof(int));
+ }
+}
+
+/*
* Change states in the finite state machine.
* The initial state is passed as an argument.
*/
@@ -555,8 +574,10 @@
transition(s)
state_t s;
{
- for (;;)
+ for (;;) {
+ set_msgbuf_log_console(s != single_user);
s = (state_t) (*s)();
+ }
}
/*
Binary files 0/sbin/init/init.o and 1/sbin/init/init.o differ
diff -rNu 0/sys/kern/tty_cons.c 1/sys/kern/tty_cons.c
--- 0/sys/kern/tty_cons.c Fri Nov 9 19:06:22 2001
+++ 1/sys/kern/tty_cons.c Sat Nov 10 12:41:13 2001
@@ -84,6 +84,11 @@
SYSCTL_OPAQUE(_machdep, CPU_CONSDEV, consdev, CTLFLAG_RD,
&cn_udev_t, sizeof cn_udev_t, "T,dev_t", "");
+static int flag_log_console = 1;
+
+SYSCTL_INT(_kern, OID_AUTO, msgbuf_log_console, CTLFLAG_RW,
+ &flag_log_console, 0, "");
+
static int cn_mute;
int cons_unavail = 0; /* XXX:
@@ -355,7 +360,8 @@
dev = constty->t_dev;
else
dev = cn_tab->cn_dev;
- log_console(uio);
+ if (flag_log_console > 0)
+ log_console(uio);
return ((*devsw(dev)->d_write)(dev, uio, flag));
}
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200202101124.g1ABOPa07227>
