From owner-freebsd-bugs@FreeBSD.ORG Thu Apr 19 19:10:13 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 595D5106566B for ; Thu, 19 Apr 2012 19:10:13 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 321EE8FC17 for ; Thu, 19 Apr 2012 19:10:13 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q3JJADZX036634 for ; Thu, 19 Apr 2012 19:10:13 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q3JJADnr036633; Thu, 19 Apr 2012 19:10:13 GMT (envelope-from gnats) Resent-Date: Thu, 19 Apr 2012 19:10:13 GMT Resent-Message-Id: <201204191910.q3JJADnr036633@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Petr Lampa Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 50876106566B for ; Thu, 19 Apr 2012 19:07:07 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 3BA998FC15 for ; Thu, 19 Apr 2012 19:07:07 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q3JJ76oM062496 for ; Thu, 19 Apr 2012 19:07:06 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id q3JJ76oT062495; Thu, 19 Apr 2012 19:07:06 GMT (envelope-from nobody) Message-Id: <201204191907.q3JJ76oT062495@red.freebsd.org> Date: Thu, 19 Apr 2012 19:07:06 GMT From: Petr Lampa To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: kern/167107: no kernel malloc size argument check causing system panic X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Apr 2012 19:10:13 -0000 >Number: 167107 >Category: kern >Synopsis: no kernel malloc size argument check causing system panic >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Apr 19 19:10:12 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Petr Lampa >Release: 9.0-STABLE >Organization: BUT FIT >Environment: FreeBSD temp 9.0-STABLE FreeBSD 9.0-STABLE #0: Thu Apr 19 11:18:42 CEST 2012 root@temp:/usr/obj/usr/src/sys/TEMP amd64 >Description: Kernel malloc() doesn't check size argument, so it's possible to raise kernel panic using system call. Simple demonstration program: #include #include #include #include #include #include #include #include #include #include int main() { struct mfi_ioc_passthru ioc; struct mfi_dcmd_frame *dcmd; char buf[1024]; int fd = open("/dev/mfi0", O_RDONLY); bzero(&ioc, sizeof(ioc)); dcmd = &ioc.ioc_frame; dcmd->header.cmd = MFI_CMD_DCMD; dcmd->header.timeout = 0; dcmd->header.flags = 0; dcmd->header.data_len = -8192; dcmd->opcode = MFI_DCMD_CTRL_GETINFO; ioc.buf = buf; ioc.buf_size = -8192; ioctl(fd, MFIIO_PASSTHRU, &ioc); } Result: panic: kmem_malloc(-8192): kmem_map too small: 103632896 total allocated >How-To-Repeat: >Fix: 1. Check malloc() size argument obtained from user space in mfi_dcmd_command(). 2. Change uma_large_malloc(), uma_small_alloc(), etc. prototypes from int size to size_t size to be consistent with malloc() and kmem_malloc(). 3. Check if size argument is not larger then available memory in kmem_malloc() and fail properly with return 0 and not panic. >Release-Note: >Audit-Trail: >Unformatted: