From nobody Fri Mar 01 18:16:27 2024 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 4TmbrX2cMKz5CpxB for ; Fri, 1 Mar 2024 18:16:28 +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 4TmbrX0KzTz4bpW for ; Fri, 1 Mar 2024 18:16:28 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1709316988; a=rsa-sha256; cv=none; b=VWJmpgaZX9QIgZ0ccS2QZ2a6O9croOj045ciJwjGigtEPScUpxf6pgxHJIwjKLPE680JwK f1dVAfeY8XxJKSm0k6DaEp8BRXxHl2H1Pxw5d2QstMzpvXdQYOGSNlAKGfzPMk3P206Yay +x+NR9KdkEOeKLFQUyg3114uhJHkG7Pxoy0mT5slzMfgDrX0KzYch/j1Y769oJrrUX8AXL V7SKMlGkDaSVOXo1Qyu88t7MUoQRExFQRdf5gD5JbhitRA2Q+we+00L4nSYOquDkVJhvvA ngJGl48EYqSvot7D6uO4BUhfx0NQ6d/boSmASBPnuasvvPPTpqGMEN+s5fAtJw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1709316988; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=K6zBg6OORw2lur8vR0jPa2L8ACxSmpBgwLnWM3EW4A4=; b=kHGoFO5EDiXuJ2Dxv+2pjKZXmJgTXE/1EtQiCR5YDQMT/g9awaNlPvTgumNikkjc24qFeW RbDDG6cqgd5mz/ZAFqq+0r7g4xJlqMl9MldzE9ueUZi921BUjoB9kgmu8iHdsWD7iFj8t4 jXZo0tIkVYJzaolrEzLDgthvINJYoMySTkjbDC2fsIU8/jPHNdFgWDJInIqPJxzfS3rICO z0Pt2tjnlfL2j4bjUH6luOI9OvPSRqbYZwQVKAzAsGSlpUSqVs4jW/LPEV3tym+9ekkFU+ lCWLe0Xs/Ei2zhrJ9Xu0HPgNXLhRO5SBf7lIKCmWUZ4HOsVDJJwfAh680SOCLA== 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 4TmbrW6x8RzcHl for ; Fri, 1 Mar 2024 18:16:27 +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 421IGRgS029701 for ; Fri, 1 Mar 2024 18:16:27 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 421IGRSc029694 for bugs@FreeBSD.org; Fri, 1 Mar 2024 18:16:27 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 277420] write outside of buffer in tarfs_alloc_one() due to unchecked len Date: Fri, 01 Mar 2024 18:16:27 +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 Some People 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 attachments.created 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 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D277420 Bug ID: 277420 Summary: write outside of buffer in tarfs_alloc_one() due to unchecked len Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: rtm@lcs.mit.edu Created attachment 248855 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D248855&action= =3Dedit image that causes tarfs_alloc_one() to write outside of a buffer This sequence in tarfs_alloc_one(): size_t len =3D strtoul(line, &sep, 10); ... if (line + len > exthdr + sz) { TARFS_DPF(ALLOC, "%s: exthdr overflow\n", __func__); error =3D EINVAL; goto bad; } eol =3D line + len - 1; *eol =3D '\0'; Can cause the *eol assignment to write outside of the buffer if the length in the tar file is huge enough that line + len wraps, e.g. 0xffffffffffffffff. I've attached a demo image. It causes a redzone error on my machine with patches D44161 and D44166. # uname -a FreeBSD 15.0-CURRENT FreeBSD 15.0-CURRENT #248 main-n250978-0a0623e9c824-dirty: Fri Mar 1 12:38:44 EST 2024=20=20=20=20 rtm@zika:/usr/obj/usr/rtm/symbsd/src/riscv.riscv64/sys/RTM riscv # mount -t tarfs tarfs11b.img /mnt REDZONE: Buffer underflow detected. 1 byte corrupted before 0xffffffd007bd9= 580 (7 bytes allocated). Allocation backtrace: #0 0xffffffc000660432 at redzone_setup+0xac #1 0xffffffc000315a5c at malloc+0xa6 #2 0xffffffc00027220c at tarfs_alloc_mount+0xa96 #3 0xffffffc0002710fc at tarfs_mount+0x584 #4 0xffffffc000404a10 at vfs_domount_first+0x20e #5 0xffffffc000401360 at vfs_domount+0x278 #6 0xffffffc0003ffe58 at vfs_donmount+0x89e #7 0xffffffc0003ff588 at sys_nmount+0x5a #8 0xffffffc0006c15f2 at do_trap_user+0x23a #9 0xffffffc0006b0132 at cpu_exception_handler_user+0x72 Free backtrace: #0 0xffffffc0006606b0 at redzone_check+0x1f8 #1 0xffffffc000316130 at free+0x48 #2 0xffffffc0002729fe at tarfs_alloc_mount+0x1288 #3 0xffffffc0002710fc at tarfs_mount+0x584 #4 0xffffffc000404a10 at vfs_domount_first+0x20e #5 0xffffffc000401360 at vfs_domount+0x278 #6 0xffffffc0003ffe58 at vfs_donmount+0x89e #7 0xffffffc0003ff588 at sys_nmount+0x5a #8 0xffffffc0006c15f2 at do_trap_user+0x23a #9 0xffffffc0006b0132 at cpu_exception_handler_user+0x72 panic: Stopping here. panic() at panic+0x26 redzone_check() at redzone_check+0x382 free() at free+0x48 tarfs_alloc_mount() at tarfs_alloc_mount+0x1288 tarfs_mount() at tarfs_mount+0x584 vfs_domount_first() at vfs_domount_first+0x20e vfs_domount() at vfs_domount+0x278 vfs_donmount() at vfs_donmount+0x89e sys_nmount() at sys_nmount+0x5a do_trap_user() at do_trap_user+0x23a cpu_exception_handler_user() at cpu_exception_handler_user+0x72 --- syscall (378, FreeBSD ELF64, nmount) --=20 You are receiving this mail because: You are the assignee for the bug.=