From nobody Wed Apr 13 17:56:23 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 2ED2C1B3C7B9 for ; Wed, 13 Apr 2022 17:56:25 +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 4Kdqyw54cPz57kj for ; Wed, 13 Apr 2022 17:56:24 +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 719BA10D88 for ; Wed, 13 Apr 2022 17:56:24 +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 23DHuNuL002240 for ; Wed, 13 Apr 2022 17:56:23 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 23DHuNUa002239 for bugs@FreeBSD.org; Wed, 13 Apr 2022 17:56:23 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 263263] fuse daemon can cause kernel page fault with huge size in write reply Date: Wed, 13 Apr 2022 17:56:23 +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.mimetype 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=1649872584; 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=p1i4MqpbdW2smKMYnbDiXW2FP5jWFVDR9sUx/ZJIEd0=; b=gMAfdUVAJFjV47p9PDrir2OUVEWNPpJcC7oF8hL2K94/QdbyNQBEddf5MHGY6MufRlwc7L ubCgzwodKLdd+Z2iR23CUV5YmxMWFCvUdfjalDRaIhlf34wTuWB3vQN+I3uGDVC5wxoeGi R1SwlCrqVE5y9GIek+qYvUTlD3W09mBa/Xj1aAHHWjWgFdA9MEEyWXDM+h1i0Jcxu3AAxJ OjCHLeCDZ6SoYEG64GbsCZEEJrMJywrz//G83L3z9UV0/tp/fDqgnv0vSfuHjixleJN6ie 1advDUPAXKkbOfCQtA73eAVy6bNa9inbvlOqWv0S45XuCo3o3ae/Nia0HesRWg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1649872584; a=rsa-sha256; cv=none; b=ajHzgY7Jlp3ZGAtCWuuzM00DV7ljkKgHIv6Ec0/TsZjBIcHBU8VsQacg1tKcc8uQNQgxeP 1/wPkCQ6AYjNC77ioC+TZb+uziqn6mgwtT1kZlNAPidZfAqtl6+NfegqfjBoQFKkDHHiDi JWKRzFYSgKSqd4nbYb0/Een/Elj8IeGAf6uy9Avd+0SxVd7i7Kxge8f4t62pjd7BIq11B0 o5Pro24jtgx/Vw6e6ZRiLokSACXggQWyoLW+tQms+bTHLyufilZTPPS82iF5j40f+jiinA z4wnwRtP9p6vGlh1uF+jS65/5qHboXM+crPmbE1TkFgVYB3IQNyWV5UsQkYg5g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D263263 Bug ID: 263263 Summary: fuse daemon can cause kernel page fault with huge size in write reply 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 Attachment #233202 text/plain mime type: Created attachment 233202 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D233202&action= =3Dedit fuse daemon that replies to write with a huge size, causing a kernel page f= ault In fuse_write_directbackend(), there's a check for the case in which the daemon claims more bytes were written than the kernel asked for: diff =3D fwi->size - fwo->size; ...; if (diff < 0) { fuse_warn(data, FSESS_WARN_WROTE_LONG, "wrote more data than we provided it."); But fwi->size and fwo->size are 32-bit unsigned, and diff is 32-bit signed, so if fwi->size is small and fwo->size is huge, diff can end up positive. In that case, a little farther on, this can execute: void *src =3D (char*)fwi_data + fwo->size; memmove(fwi_data, src, diff); which, for a huge fwo->size, can cause a read through a wild pointer. I've included a demo: # uname -a FreeBSD 14.0-CURRENT FreeBSD 14.0-CURRENT #194 main-n250915-a8123f770b1e-dirty: Tue Apr 12 15:44:48 EDT 2022=20=20=20=20 rtm@xxx:/usr/obj/usr/rtm/symbsd/src/riscv.riscv64/sys/RTM riscv # pkg install fusefs-libs # cc -I/usr/local/include/fuse -o futo17a futo17a.c -L/usr/local/lib -lfuse # ./futo17a ... WARNING: FUSE protocol violation for server mounted at /mnt: short writes a= re only allowed with direct_io. This warning will not be repeated. ... panic: Fatal page fault at 0xffffffc000552bc4: 0xffffffd102104a0a 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 page_fault_handler() at page_fault_handler+0x1aa do_trap_supervisor() at do_trap_supervisor+0x76 cpu_exception_handler_supervisor() at cpu_exception_handler_supervisor+0x70 --- exception 13, tval =3D 0xffffffd102104a0a memcpy() at memcpy+0x48 fuse_write_directbackend() at fuse_write_directbackend+0x1f6 fuse_io_strategy() at fuse_io_strategy+0x1c4 fuse_vnop_strategy() at fuse_vnop_strategy+0x46 VOP_STRATEGY_APV() at VOP_STRATEGY_APV+0x32 VOP_STRATEGY() at VOP_STRATEGY+0x26 bufstrategy() at bufstrategy+0x2c bstrategy() at bstrategy+0x14 bufwrite() at bufwrite+0x184 bwrite() at bwrite+0x16 fuse_write_biobackend() at fuse_write_biobackend+0x606 fuse_vnop_write() at fuse_vnop_write+0x16a VOP_WRITE_APV() at VOP_WRITE_APV+0x66 VOP_WRITE() at VOP_WRITE+0x2e vn_write() at vn_write+0x120 vn_io_fault() at vn_io_fault+0xd6 fo_write() at fo_write+0xa dofilewrite() at dofilewrite+0x66 kern_writev() at kern_writev+0x40 sys_write() at sys_write+0x54 syscallenter() at syscallenter+0xf4 ecall_handler() at ecall_handler+0x18 do_trap_user() at do_trap_user+0xea cpu_exception_handler_user() at cpu_exception_handler_user+0x72 --- exception 8, tval =3D 0 KDB: enter: panic [ thread pid 88 tid 100063 ] Stopped at breakpoint+0xa: c.ldsp s0,0(sp) db> --=20 You are receiving this mail because: You are the assignee for the bug.=