From owner-freebsd-bugs Sun Feb 10 3:30:26 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id D50AB37B416 for ; Sun, 10 Feb 2002 03:30:02 -0800 (PST) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.6/8.11.6) id g1ABU2W75978; Sun, 10 Feb 2002 03:30:02 -0800 (PST) (envelope-from gnats) Received: from segfault.kiev.ua (segfault.kiev.ua [193.193.193.4]) by hub.freebsd.org (Postfix) with ESMTP id 62F8C37B405 for ; Sun, 10 Feb 2002 03:25:36 -0800 (PST) Received: (from uucp@localhost) by segfault.kiev.ua (8) with UUCP id NJV46438; Sun, 10 Feb 2002 13:25:32 +0200 (EET) (envelope-from netch@iv.nn.kiev.ua) Received: (from netch@localhost) by iv.nn.kiev.ua (8.11.6/8.11.6) id g1ABOPa07227; Sun, 10 Feb 2002 13:24:25 +0200 (EET) (envelope-from netch) Message-Id: <200202101124.g1ABOPa07227@iv.nn.kiev.ua> Date: Sun, 10 Feb 2002 13:24:25 +0200 (EET) From: Valentin Nechayev Reply-To: Valentin Nechayev To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.113 Subject: misc/34788: dmesg issues with console output Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >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 (" 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