Skip to contentSkip to conversation

console: avoid buffer overrun in guest_console_write()

PATCH In review Jan Beulich 3 participants 3 messages Nov 29, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 console: avoid buffer overrun in guest_console_write()

conring_puts() has been requiring a nul-terminated string, which the local kbuf[] doesn't get set for anymore. Add a length parameter to the function, just like was done for others, thus allowing embedded nul to also be read through XEN_SYSCTL_readconsole.

While there drop a stray cast: Both operands of - are already uint32_t.

Fixes ea601ec9995b ("xen/console: Rework HYPERCALL_console_io interface")
xen/drivers/char/console.c +6 -8
@@ -257,16 +257,14 @@ static void do_dec_thresh(unsigned char
  * ********************************************************
  */
 
-static void conring_puts(const char *str)
+static void conring_puts(const char *str, size_t len)
 {
-    char c;
-
     ASSERT(spin_is_locked(&console_lock));
 
-    while ( (c = *str++) != '\0' )
-        conring[CONRING_IDX_MASK(conringp++)] = c;
+    while ( len-- )
+        conring[CONRING_IDX_MASK(conringp++)] = *str++;
 
-    if ( (uint32_t)(conringp - conringc) > conring_size )
+    if ( conringp - conringc > conring_size )
         conringc = conringp - conring_size;
 }
 
@@ -562,7 +560,7 @@ static long guest_console_write(XEN_GUES
 
             if ( opt_console_to_ring )
             {
-                conring_puts(kbuf);
+                conring_puts(kbuf, kcount);
                 tasklet_schedule(&notify_dom0_con_ring_tasklet);
             }
 
@@ -687,7 +685,7 @@ static void __putstr(const char *str)
     }
 #endif
 
-    conring_puts(str);
+    conring_puts(str, len);
 
     if ( !console_locks_busted )
         tasklet_schedule(&notify_dom0_con_ring_tasklet);

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Jan Beulich

conring_puts() has been requiring a nul-terminated string, which the local kbuf[] doesn't get set for anymore. Add a length parameter to the function, just like was done for others, thus allowing embedded nul to also be read through XEN_SYSCTL_readconsole.

While there drop a stray cast: Both operands of - are already uint32_t.

Fixes ea601ec9995b ("xen/console: Rework HYPERCALL_console_io interface")

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

Acked-by on v1 1/1
#2 lore raw
In reply to Jan Beulich

Hi,

Quoted 8 lines · Jan Beulich

conring_puts() has been requiring a nul-terminated string, which the local kbuf[] doesn't get set for anymore. Add a length parameter to the function, just like was done for others, thus allowing embedded nul to also be read through XEN_SYSCTL_readconsole.

While there drop a stray cast: Both operands of - are already uint32_t.

Fixes ea601ec9995b ("xen/console: Rework HYPERCALL_console_io interface")

Sorry again :(.

Quoted 2 lines

Cheers,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel