>Synopsis:      non-terminated strings buffer in riscv64/cpu.c
>Category:      kernel
>Environment:
        System      : OpenBSD 7.3
        Details     : OpenBSD 7.3-current (GENERIC.MP) #376: Thu Jul 13 
03:59:40 MDT 2023
                         
dera...@riscv64.openbsd.org:/usr/src/sys/arch/riscv64/compile/GENERIC.MP

        Architecture: OpenBSD.riscv64
        Machine     : riscv64
>Description:
        The cpu detect output is not NUL terminated, this causes *puke* to be
displayed on serial terminals.
>How-To-Repeat:
        Using Qemu for riscv64 arch.

        from a eeprom -p | grep isa output:

            riscv,isa: 
'rv64imafdch_zicsr_zifencei_zihintpause_zba_zbb_zbc_zbs_sstc'
            riscv,isa: 
'rv64imafdch_zicsr_zifencei_zihintpause_zba_zbb_zbc_zbs_sstc'

        I counted this as 60 bytes long.
>Fix:

There is two approaches.  One is to explicitly NUL terminate the 32 byte
buffer or make it bigger.  I give an untested patch of the latter.

Index: cpu.c
===================================================================
RCS file: /cvs/src/sys/arch/riscv64/riscv64/cpu.c,v
retrieving revision 1.14
diff -u -p -u -r1.14 cpu.c
--- cpu.c       15 Jun 2023 22:18:08 -0000      1.14
+++ cpu.c       1 Aug 2023 11:35:28 -0000
@@ -87,7 +87,7 @@ int cpu_errata_sifive_cip_1200;
 void
 cpu_identify(struct cpu_info *ci)
 {
-       char isa[32];
+       char isa[64];
        uint64_t marchid, mimpid;
        uint32_t mvendorid;
        const char *vendor_name = NULL;


dmesg:
OpenBSD 7.3-current (GENERIC.MP) #376: Thu Jul 13 03:59:40 MDT 2023
    dera...@riscv64.openbsd.org:/usr/src/sys/arch/riscv64/compile/GENERIC.MP
real mem  = 2147483648 (2048MB)
avail mem = 2027982848 (1934MB)
SBI: OpenSBI v1.2, SBI Specification Version 1.0
random: good seed from bootblocks
mainbus0 at root: riscv-virtio,qemu
cpu0 at mainbus0: vendor 0 arch 70200 imp 70200 
rv64imafdch_zicsr_zifencei_zihin\M-n\M-#7
intc0 at cpu0
cpu1 at mainbus0: vendor 0 arch 70200 imp 70200 
rv64imafdch_zicsr_zifencei_zihin\M-n\M-#7
syscon0 at mainbus0: "poweroff"
syscon1 at mainbus0: "reboot"
"fw-cfg" at mainbus0 not configured
"flash" at mainbus0 not configured
simplebus0 at mainbus0: "platform-bus"
simplebus1 at mainbus0: "soc"
syscon2 at simplebus1: "test"
plic0 at simplebus1
"pmu" at simplebus1 not configured
gfrtc0 at simplebus1
com0 at simplebus1: ns16550, no working fifo
com0: console
pciecam0 at simplebus1
pci0 at pciecam0
"Red Hat Host" rev 0x00 at pci0 dev 0 function 0 not configured
virtio0 at simplebus1: Virtio Network Device
vio0 at virtio0: address 52:54:00:12:34:56
virtio1 at simplebus1: Virtio Block Device
vioblk0 at virtio1
scsibus0 at vioblk0: 1 targets
sd0 at scsibus0 targ 0 lun 0: <VirtIO, Block Device, >
sd0: 40960MB, 512 bytes/sector, 83886080 sectors
virtio2 at simplebus1: Virtio Unknown (0) Device
virtio3 at simplebus1: Virtio Unknown (0) Device
virtio4 at simplebus1: Virtio Unknown (0) Device
virtio5 at simplebus1: Virtio Unknown (0) Device
virtio6 at simplebus1: Virtio Unknown (0) Device
virtio7 at simplebus1: Virtio Unknown (0) Device
"clint" at simplebus1 not configured
vscsi0 at root
scsibus1 at vscsi0: 256 targets
softraid0 at root
scsibus2 at softraid0: 256 targets
root on sd0a (a44107957d8bed73.a) swap on sd0b dump on sd0b

usbdevs:
usbdevs: no USB controllers found

pcidump:

everything past here is not provided.

Reply via email to