Skip to contentSkip to conversation

kvm tools: Sanitize output characters in serial console

PATCH In review Asias He 6 participants 11 messages Aug 9, 2011 – Aug 11, 2011 KVM

lore
Share & tools
lore

Asias He

author
#0 lore raw

PATCH 1/1 kvm tools: Sanitize output characters in serial console

This patch fixes strange characters in serial console.

Before:

[    0.448000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
�[    0.695000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
�[    0.942000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A
�[    1.189000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A
[    1.194000] Non-volatile memory driver v1.3

After:

[    0.541000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[    0.788000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
[    1.041000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A
[    1.294000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A
[    1.309000] Non-volatile memory driver v1.3
---
 tools/kvm/term.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
tools/kvm/term.c +5 -2
index 2a3e1f0..85b41e7 100644
@@ -5,6 +5,7 @@
 #include <unistd.h>
 #include <sys/uio.h>
 #include <signal.h>
+#include <ctype.h>
 
 #include "kvm/read-write.h"
 #include "kvm/term.h"
@@ -57,8 +58,10 @@ int term_putc(int who, char *addr, int cnt)
 	if (who != active_console)
 		return -1;
 
-	while (cnt--)
-		fprintf(stdout, "%c", *addr++);
+	while (cnt--) {
+		if (isascii(*addr))
+			fprintf(stdout, "%c", *addr++);
+	}
 
 	fflush(stdout);
 	return cnt;
Signature · 1 line
1.7.5.4
#1 lore raw
Quoted 36 lines · Asias He

This patch fixes strange characters in serial console.

Before:

[    0.448000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
�[    0.695000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
�[    0.942000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A
�[    1.189000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A
[    1.194000] Non-volatile memory driver v1.3

After:

[    0.541000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[    0.788000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
[    1.041000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A
[    1.294000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A
[    1.309000] Non-volatile memory driver v1.3
---
  tools/kvm/term.c |    7 +++++--
  1 files changed, 5 insertions(+), 2 deletions(-)
tools/kvm/term.c +1 -0
index 2a3e1f0..85b41e7 100644
@@ -5,6 +5,7 @@
  #include<unistd.h>
  #include<sys/uio.h>
  #include<signal.h>
+#include<ctype.h>
 
  #include "kvm/read-write.h"
  #include "kvm/term.h"

tools/kvm/term.c int term_putc(int who, char *addr, int cnt) · line 62

Quoted 7 lines
tools/kvm/term.c +2 -2
@@ -57,8 +58,10 @@ int term_putc(int who, char *addr, int cnt)
  	if (who != active_console)
  		return -1;
 
-	while (cnt--)
-		fprintf(stdout, "%c", *addr++);
+	while (cnt--) {
+		if (isascii(*addr))

Do things like backspace still work with this?

Quoted 5 lines
tools/kvm/term.c +2 -0
+			fprintf(stdout, "%c", *addr++);
+	}
 
  	fflush(stdout);
  	return cnt;
author
#2 lore raw
Quoted 40 lines · Pekka Enberg
Quoted 39 lines · Asias He

This patch fixes strange characters in serial console.

Before:

[    0.448000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
�[    0.695000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
�[    0.942000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A
�[    1.189000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A
[    1.194000] Non-volatile memory driver v1.3

After:

[    0.541000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[    0.788000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
[    1.041000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A
[    1.294000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A
[    1.309000] Non-volatile memory driver v1.3
---
  tools/kvm/term.c |    7 +++++--
  1 files changed, 5 insertions(+), 2 deletions(-)
tools/kvm/term.c +1 -0
index 2a3e1f0..85b41e7 100644
@@ -5,6 +5,7 @@
  #include<unistd.h>
  #include<sys/uio.h>
  #include<signal.h>
+#include<ctype.h>
 
  #include "kvm/read-write.h"
  #include "kvm/term.h"
@@ -57,8 +58,10 @@ int term_putc(int who, char *addr, int cnt)
      if (who != active_console)
          return -1;
 
Quoted 6 lines

tools/kvm/term.c int term_putc(int who, char *addr, int cnt) · line 62

Quoted 4 lines
tools/kvm/term.c +2 -2
-    while (cnt--)
-        fprintf(stdout, "%c", *addr++);
+    while (cnt--) {
+        if (isascii(*addr))

Do things like backspace still work with this?

Sure. Have a try ;-)

http://en.wikipedia.org/wiki/ASCII

Quoted 8 lines
Quoted 6 lines
tools/kvm/term.c +2 -0
+            fprintf(stdout, "%c", *addr++);
+    }
 
      fflush(stdout);
      return cnt;
Signature · 2 lines
Best Regards,
Asias He
#3 lore raw
Quoted 48 lines · Asias He
Quoted 40 lines · Pekka Enberg
Quoted 39 lines · Asias He

This patch fixes strange characters in serial console.

Before:

[    0.448000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled �[    0.695000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A �[    0.942000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A �[    1.189000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A [    1.194000] Non-volatile memory driver v1.3

After:

[    0.541000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled [    0.788000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A [    1.041000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A [    1.294000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A [    1.309000] Non-volatile memory driver v1.3

---
  tools/kvm/term.c |    7 +++++--

  1 files changed, 5 insertions(+), 2 deletions(-)
tools/kvm/term.c +1 -0
index 2a3e1f0..85b41e7 100644
@@ -5,6 +5,7 @@
   #include<unistd.h>
   #include<sys/uio.h>
   #include<signal.h>
+#include<ctype.h>
 
   #include "kvm/read-write.h"
   #include "kvm/term.h"
@@ -57,8 +58,10 @@ int term_putc(int who, char *addr, int cnt)
       if (who != active_console)
           return -1;
 
Quoted 6 lines

tools/kvm/term.c int term_putc(int who, char *addr, int cnt) · line 62

Quoted 4 lines
tools/kvm/term.c +2 -2
-    while (cnt--)
-        fprintf(stdout, "%c", *addr++);
+    while (cnt--) {
+        if (isascii(*addr))

Do things like backspace still work with this?

Quoted 3 lines

Sure. Have a try ;-)

http://en.wikipedia.org/wiki/ASCII

OK, cool. Do we know what the extra characters are and why the guest is sending them?

author
#4 lore raw
Quoted 49 lines · Pekka Enberg
Quoted 48 lines · Asias He
Quoted 46 lines · Pekka Enberg
Quoted 36 lines · Asias He

This patch fixes strange characters in serial console.

Before:

[    0.448000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
�[    0.695000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
�[    0.942000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A
�[    1.189000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A
[    1.194000] Non-volatile memory driver v1.3

After:

[    0.541000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[    0.788000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
[    1.041000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A
[    1.294000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A
[    1.309000] Non-volatile memory driver v1.3
---
  tools/kvm/term.c |    7 +++++--
  1 files changed, 5 insertions(+), 2 deletions(-)
tools/kvm/term.c +1 -0
index 2a3e1f0..85b41e7 100644
@@ -5,6 +5,7 @@
  #include<unistd.h>
  #include<sys/uio.h>
  #include<signal.h>
+#include<ctype.h>
 
  #include "kvm/read-write.h"
  #include "kvm/term.h"

tools/kvm/term.c int term_putc(int who, char *addr, int cnt) · line 62

Quoted 7 lines
tools/kvm/term.c +2 -2
@@ -57,8 +58,10 @@ int term_putc(int who, char *addr, int cnt)
      if (who != active_console)
          return -1;
 
-    while (cnt--)
-        fprintf(stdout, "%c", *addr++);
+    while (cnt--) {
+        if (isascii(*addr))

Do things like backspace still work with this?

Quoted 7 lines
Quoted 3 lines

Sure. Have a try ;-)

http://en.wikipedia.org/wiki/ASCII

OK, cool. Do we know what the extra characters are and why the guest is sending them?

This tells us

        while (cnt--) {
               if (isascii(*addr))
                       fprintf(stdout, "%c", *addr++);
               else
                       fprintf(stdout, "\n---%x---\n", *addr++);
        }

the extra chars is 0xff.

The reason is not understood.

Signature · 2 lines
Best Regards,
Asias He
#5 lore raw
Quoted 68 lines · Asias He
Quoted 49 lines · Pekka Enberg
Quoted 48 lines · Asias He
Quoted 46 lines · Pekka Enberg
Quoted 36 lines · Asias He

This patch fixes strange characters in serial console.

Before:

[    0.448000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
�[    0.695000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
�[    0.942000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A
�[    1.189000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A
[    1.194000] Non-volatile memory driver v1.3

After:

[    0.541000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[    0.788000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
[    1.041000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A
[    1.294000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A
[    1.309000] Non-volatile memory driver v1.3
---
  tools/kvm/term.c |    7 +++++--
  1 files changed, 5 insertions(+), 2 deletions(-)
tools/kvm/term.c +1 -0
index 2a3e1f0..85b41e7 100644
@@ -5,6 +5,7 @@
  #include<unistd.h>
  #include<sys/uio.h>
  #include<signal.h>
+#include<ctype.h>
 
  #include "kvm/read-write.h"
  #include "kvm/term.h"

tools/kvm/term.c int term_putc(int who, char *addr, int cnt) · line 62

Quoted 7 lines
tools/kvm/term.c +2 -2
@@ -57,8 +58,10 @@ int term_putc(int who, char *addr, int cnt)
      if (who != active_console)
          return -1;
 
-    while (cnt--)
-        fprintf(stdout, "%c", *addr++);
+    while (cnt--) {
+        if (isascii(*addr))

Do things like backspace still work with this?

Quoted 7 lines
Quoted 3 lines

Sure. Have a try ;-)

http://en.wikipedia.org/wiki/ASCII

OK, cool. Do we know what the extra characters are and why the guest is sending them?

This tells us

        while (cnt--) {
               if (isascii(*addr))
                       fprintf(stdout, "%c", *addr++);
               else
                       fprintf(stdout, "\n---%x---\n", *addr++);
        }
Quoted 4 lines

the extra chars is 0xff.

The reason is not understood.

They are being printed when the serial device is probed. Can we mistakenly interpret the probe as a print request?

Signature · 1 line
Sasha.
#6 lore raw
In reply to Asias He
Quoted 50 lines · Asias He
Quoted 49 lines · Pekka Enberg
Quoted 48 lines · Asias He
Quoted 46 lines · Pekka Enberg
Quoted 36 lines · Asias He

This patch fixes strange characters in serial console.

Before:

[    0.448000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
�[    0.695000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
�[    0.942000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A
�[    1.189000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A
[    1.194000] Non-volatile memory driver v1.3

After:

[    0.541000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[    0.788000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
[    1.041000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A
[    1.294000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A
[    1.309000] Non-volatile memory driver v1.3
---
  tools/kvm/term.c |    7 +++++--
  1 files changed, 5 insertions(+), 2 deletions(-)
tools/kvm/term.c +1 -0
index 2a3e1f0..85b41e7 100644
@@ -5,6 +5,7 @@
  #include<unistd.h>
  #include<sys/uio.h>
  #include<signal.h>
+#include<ctype.h>
 
  #include "kvm/read-write.h"
  #include "kvm/term.h"

tools/kvm/term.c int term_putc(int who, char *addr, int cnt) · line 62

Quoted 7 lines
tools/kvm/term.c +2 -2
@@ -57,8 +58,10 @@ int term_putc(int who, char *addr, int cnt)
      if (who != active_console)
          return -1;
 
-    while (cnt--)
-        fprintf(stdout, "%c", *addr++);
+    while (cnt--) {
+        if (isascii(*addr))

Do things like backspace still work with this?

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

Sure. Have a try ;-)

http://en.wikipedia.org/wiki/ASCII

OK, cool. Do we know what the extra characters are and why the guest is sending them?

I think the reason is not important here. I use qemu to test and it also outputs that extra characters. They seem to be outputted by driver or kernel of guest os.

It's not sane to change the output of guest os. Suppose if we just want to see what "cat /dev/urandom" prints, then only
allow ascii characters to be outputted? I think that's not what we expect.

walimis

Quoted 23 lines
Quoted 1 line

This tells us

       while (cnt--) {
              if (isascii(*addr))
                      fprintf(stdout, "%c", *addr++);
              else
                      fprintf(stdout, "\n---%x---\n", *addr++);
       }

the extra chars is 0xff.

The reason is not understood.

Signature · 6 lines
Best Regards,
Asias He
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#7 lore raw
Quoted 6 lines · walimis
Quoted 5 lines · Asias He
Quoted 4 lines · Pekka Enberg
Quoted 3 lines · Asias He
Quoted 2 lines · Pekka Enberg
Quoted 1 line · Asias He

This patch fixes strange characters in serial console.

...

Quoted 9 lines
Quoted 2 lines
Quoted 2 lines

OK, cool. Do we know what the extra characters are and why the guest is sending them?

I think the reason is not important here. I use qemu to test and it also outputs that extra characters. They seem to be outputted by driver or kernel of guest os.

It's not sane to change the output of guest os. Suppose if we just want to see what "cat /dev/urandom" prints, then only
allow ascii characters to be outputted? I think that's not what we expect.

So we don't need this patch, otherwise, the possible error would be hidden.

author
#8 lore raw
In reply to walimis
Quoted 57 lines · walimis
Quoted 50 lines · Asias He
Quoted 49 lines · Pekka Enberg
Quoted 48 lines · Asias He
Quoted 46 lines · Pekka Enberg
Quoted 36 lines · Asias He

This patch fixes strange characters in serial console.

Before:

[    0.448000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
�[    0.695000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
�[    0.942000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A
�[    1.189000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A
[    1.194000] Non-volatile memory driver v1.3

After:

[    0.541000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[    0.788000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
[    1.041000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A
[    1.294000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A
[    1.309000] Non-volatile memory driver v1.3
---
  tools/kvm/term.c |    7 +++++--
  1 files changed, 5 insertions(+), 2 deletions(-)
tools/kvm/term.c +1 -0
index 2a3e1f0..85b41e7 100644
@@ -5,6 +5,7 @@
  #include<unistd.h>
  #include<sys/uio.h>
  #include<signal.h>
+#include<ctype.h>
 
  #include "kvm/read-write.h"
  #include "kvm/term.h"

tools/kvm/term.c int term_putc(int who, char *addr, int cnt) · line 62

Quoted 7 lines
tools/kvm/term.c +2 -2
@@ -57,8 +58,10 @@ int term_putc(int who, char *addr, int cnt)
      if (who != active_console)
          return -1;
 
-    while (cnt--)
-        fprintf(stdout, "%c", *addr++);
+    while (cnt--) {
+        if (isascii(*addr))

Do things like backspace still work with this?

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

Sure. Have a try ;-)

http://en.wikipedia.org/wiki/ASCII

OK, cool. Do we know what the extra characters are and why the guest is sending them?

Quoted 7 lines

I think the reason is not important here. I use qemu to test and it also outputs that extra characters. They seem to be outputted by driver or kernel of guest os.

It's not sane to change the output of guest os. Suppose if we just want to see what "cat /dev/urandom" prints, then only
allow ascii characters to be outputted? I think that's not what we expect.

This is a good reason why we should not only allow ascii to be printed.

Anyway, this is really annoying. Maybe it is a serial driver bug?

Quoted 26 lines

walimis

Quoted 23 lines
Quoted 1 line

This tells us

       while (cnt--) {
              if (isascii(*addr))
                      fprintf(stdout, "%c", *addr++);
              else
                      fprintf(stdout, "\n---%x---\n", *addr++);
       }

the extra chars is 0xff.

The reason is not understood.

Signature · 6 lines
Best Regards,
Asias He
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Best Regards,
Asias He
#9 lore raw
Quoted 11 lines · Asias He
Quoted 7 lines

I think the reason is not important here. I use qemu to test and it also outputs that extra characters. They seem to be outputted by driver or kernel of guest os.

It's not sane to change the output of guest os. Suppose if we just want to see what "cat /dev/urandom" prints, then only
allow ascii characters to be outputted? I think that's not what we expect.

This is a good reason why we should not only allow ascii to be printed.

Anyway, this is really annoying. Maybe it is a serial driver bug?

Could be. It's probably best to track down where the byte is being sent in the driver.

Pekka

#10 lore raw
In reply to Asias He
Quoted 38 lines · Asias He

This patch fixes strange characters in serial console.

Before:

[    0.448000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
�[    0.695000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
�[    0.942000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A
�[    1.189000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A
[    1.194000] Non-volatile memory driver v1.3

After:

[    0.541000] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[    0.788000] serial8250: ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A
[    1.041000] serial8250: ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A
[    1.294000] serial8250: ttyS2 at I/O 0x3e8 (irq = 0) is a 16550A
[    1.309000] Non-volatile memory driver v1.3
---
  tools/kvm/term.c |    7 +++++--
  1 files changed, 5 insertions(+), 2 deletions(-)
tools/kvm/term.c +1 -0
index 2a3e1f0..85b41e7 100644
@@ -5,6 +5,7 @@
  #include<unistd.h>
  #include<sys/uio.h>
  #include<signal.h>
+#include<ctype.h>
 
  #include "kvm/read-write.h"
  #include "kvm/term.h"
@@ -57,8 +58,10 @@ int term_putc(int who, char *addr, int cnt)
  	if (who != active_console)
  		return -1;

tools/kvm/term.c int term_putc(int who, char *addr, int cnt) · line 67

Quoted 10 lines
tools/kvm/term.c +4 -2
 
-	while (cnt--)
-		fprintf(stdout, "%c", *addr++);
+	while (cnt--) {
+		if (isascii(*addr))
+			fprintf(stdout, "%c", *addr++);
+	}
 
  	fflush(stdout);
  	return cnt;

This will likely kill UTF-8.

Signature · 1 line
error compiling committee.c: too many arguments to function