From nobody Tue Oct 19 17:32:56 2021 X-Original-To: bugs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 36DBE17FC693 for ; Tue, 19 Oct 2021 17:32:56 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HYgn412Hyz4t8X for ; Tue, 19 Oct 2021 17:32:56 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 046F9185FC for ; Tue, 19 Oct 2021 17:32:56 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 19JHWtO2063620 for ; Tue, 19 Oct 2021 17:32:55 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 19JHWteH063619 for bugs@FreeBSD.org; Tue, 19 Oct 2021 17:32:55 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 259280] vtblk_maximum_segments can set nsegs too low, allowing panic on some non-aligned raw disk reads Date: Tue, 19 Oct 2021 17:32:56 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: rtm@lcs.mit.edu X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@freebsd.org MIME-Version: 1.0 X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D259280 Bug ID: 259280 Summary: vtblk_maximum_segments can set nsegs too low, allowing panic on some non-aligned raw disk reads Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: rtm@lcs.mit.edu The virtio block device code's vtblk_maximum_segments() sets nsegs to 3 if the device doesn't have VIRTIO_BLK_F_SEG_MAX set. However, a 4096-byte read() to a non-page-aligned memory address can then panic in vtblk_request_execute() due to using up all the segments, in this code: if (bp->bio_cmd =3D=3D BIO_READ || bp->bio_cmd =3D=3D BIO_WRITE) { error =3D sglist_append_bio(sg, bp); if (error || sg->sg_nseg =3D=3D sg->sg_maxseg) {=20=20=20=20=20=20= =20=20=20=20=20=20 panic("%s: bio %p data buffer too big %d", __func__, bp, error); sg_nseg and sg_maxseg both end up as three, triggering the panic. I actually got this panic, on the tinyemu RISC-V simulator, running e2fsck on a broken ext2 file system. Here's a program that panics on tinyemu (but not qemu, which sets VIRTIO_BLK_F_SEG_MAX): int main() { int fd =3D open("/dev/vtbd0", 0); char buf1[4*4096]; char *buf =3D buf1; while(((unsigned long)buf) % 4096) buf++; read(fd, buf + 0xd00, 4096); } panic: vtblk_request_execute: bio 0xffffffd0019ded38 data buffer too big 0 cpuid =3D 0 time =3D 1634664503 KDB: stack backtrace: db_trace_self() at db_trace_self db_trace_self_wrapper() at db_trace_self_wrapper+0x38 kdb_backtrace() at kdb_backtrace+0x2c vpanic() at vpanic+0x148 panic() at panic+0x2a vtblk_request_execute() at vtblk_request_execute+0x23a vtblk_startio() at vtblk_startio+0x198 vtblk_strategy() at vtblk_strategy+0x66 g_disk_start() at g_disk_start+0x2b0 g_io_schedule_down() at g_io_schedule_down+0x32a g_down_procbody() at g_down_procbody+0x58 fork_exit() at fork_exit+0x68 fork_trampoline() at fork_trampoline+0xa KDB: enter: panic [ thread pid 13 tid 100019 ] --=20 You are receiving this mail because: You are the assignee for the bug.=