From nobody Wed Aug 31 20:30:49 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 4MHwmV0HlKz4bDyp for ; Wed, 31 Aug 2022 20:30:50 +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 4MHwmT4m4qz3blR for ; Wed, 31 Aug 2022 20:30:49 +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 4MHwmT3rfqzFcP for ; Wed, 31 Aug 2022 20:30:49 +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 27VKUnVk076570 for ; Wed, 31 Aug 2022 20:30:49 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 27VKUnuP076569 for bugs@FreeBSD.org; Wed, 31 Aug 2022 20:30:49 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 266142] SNDSTIOC_ADD_USER_DEVS ioctl on /dev/sndstat passes unchecked size from user to malloc() -> potential crash Date: Wed, 31 Aug 2022 20:30:49 +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 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=1661977849; 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=kR6gAZwCAOWVLilFL2GSa5bswPwxcfsMxtglhBBzvTs=; b=MWEBQwRrcCrw0F28sOsq5GdJrPdkvP8V1JcsSfjvjvXfTABiF3VOR5NNn8ZwnPHvt1M6iu cd4+b8pMD18LUlASL+ccijSaeHRs+EIOih3jHkCrkqo5pqkXewJd34dXXjuTg3yqT/7uSl cEtAamgu+xvd3cnd2sok6T9Ns4yU98mmAfCIUwNtrL2kBDJgO7r806CyAainbq7L9wD2bR 6ra7yeuVbZ9VPu+WWPzxknHFt/2QqPGVaJzwyGtVJIG1jxDkyEj6MASZCgwRRzNSiIi83i KZdAS05/CZgq9uxJ9Ia+3p25puKkzDZri2z6sESA7WBT8RkrWTKtm4ERr1gUYg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1661977849; a=rsa-sha256; cv=none; b=XaRS6nn/lbRkay2yaTMb9De/er8k7NoCq3I9dXlKbNP3yEwbBASMyUgkn+XzR0QgWo+Yty dKcSoObTVlrJqooM1zjFNWfqM/tyZw511sxYUxtjWuCan3sICakhfe2svJGI93ngyVLhJ8 yRNeQMTH20lc9J353RXpraYqw4Vd8FixsD7/SnVMcveOfutsrscsIfAfhPlyBvSPILMTsg +3xz7mqid7j79TVTC0Rqe0ne9dA0I2tsg3LB64KKe4kKtM8UsMg59P/m1NLNXca9TeTkwh snh8O58AqwpMSlciaYfIQzq/A1SZj21WlCCrHa5zuZNv4JchCLg1OlG7P44xCw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D266142 Bug ID: 266142 Summary: SNDSTIOC_ADD_USER_DEVS ioctl on /dev/sndstat passes unchecked size from user to malloc() -> potential crash 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 User code specifies a 64-bit length to the SNDSTIOC_ADD_USER_DEVS ioctl, which sndstat_add_user_devs() passes to sndstat_unpack_user_nvlbuf() (as arg->nbytes), which is then passed as the size to malloc(). One way this can go wrong is if the user passes in (size_t)-1, which this line in malloc_large() turns into zero: size =3D roundup(size, PAGE_SIZE); which either causes the MPASS(size > 0) in vmem_alloc() to fail, or (if not INVARIANTS) causes a later kernel page fault. A demo: int main() { int fd =3D open("/dev/sndstat", 2); if(fd < 0) { perror("/dev/sndstat"); exit(1); } char buf[128]; memset(buf, 0xff, sizeof(buf)); ioctl(fd, 0xc0104466, buf); // SNDSTIOC_ADD_USER_DEVS } # uname -a FreeBSD 14.0-CURRENT FreeBSD 14.0-CURRENT #71 main-n250928-b8170f38ccc7-di= rty: Wed Aug 31 16:05:23 EDT 2022=20=20=20=20 rtm@xxx:/usr/obj/usr/rtm/symbsd/src/riscv.riscv64/sys/RTM riscv # cc x.c # ./a.out panic: Fatal page fault at 0xffffffc00039b2be: 0x27fffd000809460 cpuid =3D 0 time =3D 1661976398 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+0x170 panic() at panic+0x2a page_fault_handler() at page_fault_handler+0x1d6 do_trap_supervisor() at do_trap_supervisor+0x76 cpu_exception_handler_supervisor() at cpu_exception_handler_supervisor+0x70 --- exception 13, tval =3D 0x27fffd000809460 vmem_alloc() at vmem_alloc+0x88 kmem_malloc_domain() at kmem_malloc_domain+0x6a kmem_malloc_domainset() at kmem_malloc_domainset+0x36 malloc_large() at malloc_large+0x44 malloc() at malloc+0xf8 sndstat_unpack_user_nvlbuf() at sndstat_unpack_user_nvlbuf+0x26 sndstat_add_user_devs() at sndstat_add_user_devs+0x4a sndstat_ioctl() at sndstat_ioctl+0xae devfs_ioctl() at devfs_ioctl+0xbe VOP_IOCTL_APV() at VOP_IOCTL_APV+0x30 VOP_IOCTL() at VOP_IOCTL+0x36 vn_ioctl() at vn_ioctl+0xba fo_ioctl() at fo_ioctl+0xa kern_ioctl() at kern_ioctl+0x242 sys_ioctl() at sys_ioctl+0x120 syscallenter() at syscallenter+0xec ecall_handler() at ecall_handler+0x18 do_trap_user() at do_trap_user+0xea cpu_exception_handler_user() at cpu_exception_handler_user+0x72 devfs_ioctl_f() at devfs_ioctl_f+0x20 --=20 You are receiving this mail because: You are the assignee for the bug.=