From nobody Sat May 14 13:30:38 2022 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 ED6421AE3432 for ; Sat, 14 May 2022 13:30:38 +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 4L0mby4YcJz4h17 for ; Sat, 14 May 2022 13:30:38 +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 7D0F417FD4 for ; Sat, 14 May 2022 13:30:38 +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 24EDUcVO009627 for ; Sat, 14 May 2022 13:30:38 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 24EDUclP009626 for bugs@FreeBSD.org; Sat, 14 May 2022 13:30:38 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 263971] malicious superblock can cause buffer overflow during tasting Date: Sat, 14 May 2022 13:30:38 +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: Unspecified 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1652535038; 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=C5Q8ZiXfh3XkGgVHWSzEDsd0tVPVz2pMLzOM3XB+6vs=; b=kFkhi3PUKRb0CKq1GOXCucz6clZI+6hnExGSfY/8/9xqmMfo2wS0ZHlYn6yK7XXgEaVei+ seqG4pWYD4gTL8nH0aEasaXuxQMXsy9U8pcr9If14L1V82vIuQxcz/QTLctbuFAzH2/ziW reQW2cQOPa7Rq6qkjbBR/xr/QMCH7QWXvBq9MTexb0XyEIsqSLXwO09F/EXaXEa5WRnOI+ F4nbIEXo7f1n+HQXflIMYaEM8Oh8l7h3pvoQuUgOD9f+TyVNLK2wHQlo+U+g95RxKpJg7y 8TCKNPAVA3hCzqAneIR5TGkm1lHARvxnmmeM7SL6cOMczvALpMdeuBEcThuDeg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1652535038; a=rsa-sha256; cv=none; b=W94+KsXTX4PQ2qhiLjq/50r4FBzmxlzXgwX2bFteeoQeJbju1BsgPARpxZCbp5T3y4N3s9 Y9vJhezXL8sqgtozPmotKpAUuCXfcJCSNEDJ9ecaBhNpIlnfQJDcx3UVka2jjoI/mj1aa9 JBzdFK2mqy2cheqR/EbY9vmUgXdDimFpw6ts2cFfq1wx/r6GKZbWs2lCy0bE62sWkAr4Ai RAq7Vn/iA/g8ddk0eWNIQBz0n7Wv0RF1MX3FjoLpiW8+eq71HpVE36OXHpbg2tKZrlc/kp qgFTJC5Nkuy15AIxKGH+wxnlRtoq/8NMJhyhY0e5HjFJiRsrYAfo0rHVu3Qi8A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D263971 Bug ID: 263971 Summary: malicious superblock can cause buffer overflow during tasting Product: Base System Version: Unspecified Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: rtm@lcs.mit.edu Created attachment 233909 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D233909&action= =3Dedit disk image with malicious superblock fields that cause buffer overflow duri= ng tasting ffs_sbget() allocates some memory into which it reads file system information, using fields from the superblock to choose a size: size =3D fs->fs_cssize; if (fs->fs_contigsumsize > 0) size +=3D fs->fs_ncg * sizeof(int32_t); size +=3D fs->fs_ncg * sizeof(u_int8_t); ...; if ((space =3D UFS_MALLOC(size, filltype, M_WAITOK)) =3D=3D NULL) { An attacker can choose values that cause size to be too small, causing subsequent code to write beyond the end of space. The attached disk image has a superblock with fs_cssize -1434999068 fs_contigsumsize 2147483647 fs_ncg 287173615 The calculated size is 869007. Later on: if (fs->fs_contigsumsize > 0) { fs->fs_maxcluster =3D lp =3D (int32_t *)space; for (i =3D 0; i < fs->fs_ncg; i++) *lp++ =3D fs->fs_contigsumsize; Since fs_ncg > size, this loop writes the attacker-chosen fs_contigsumsize beyond the allocated space. What I see when the attached disk image is tasted: # uname -a FreeBSD 14.0-CURRENT FreeBSD 14.0-CURRENT #267 main-n250920-74195f0a7a6c-dirty: Sat May 14 09:04:48 EDT 2022=20=20=20=20 rtm@xxx:/usr/obj/usr/rtm/symbsd/src/riscv.riscv64/sys/RTM riscv # mdconfig -f taste7a.img panic: vm_fault_lookup: fault on nofault entry, addr: 0xffffffc07cb67000 cpuid =3D 0 time =3D 1652523702 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+0x16e panic() at panic+0x2a vm_fault_lookup() at vm_fault_lookup+0x1bc vm_fault() at vm_fault+0x9e vm_fault_trap() at vm_fault_trap+0x68 page_fault_handler() at page_fault_handler+0x13c do_trap_supervisor() at do_trap_supervisor+0x76 cpu_exception_handler_supervisor() at cpu_exception_handler_supervisor+0x70 --- exception 15, tval =3D 0xffffffc07cb67000 ffs_sbget() at ffs_sbget+0x2b0 g_label_ufs_taste_common() at g_label_ufs_taste_common+0x6c g_label_ufs_id_taste() at g_label_ufs_id_taste+0xe g_label_taste() at g_label_taste+0x198 g_new_provider_event() at g_new_provider_event+0xb8 one_event() at one_event+0x106 g_run_events() at g_run_events+0x8a g_event_procbody() at g_event_procbody+0x56 fork_exit() at fork_exit+0x80 fork_trampoline() at fork_trampoline+0xa KDB: enter: panic [ thread pid 13 tid 100017 ] Stopped at breakpoint+0xa: c.ldsp s0,0(sp) db> --=20 You are receiving this mail because: You are the assignee for the bug.=