Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 19 Apr 2012 19:07:06 GMT
From:      Petr Lampa <lampa@fit.vutbr.cz>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   kern/167107: no kernel malloc size argument check causing system panic
Message-ID:  <201204191907.q3JJ76oT062495@red.freebsd.org>
Resent-Message-ID: <201204191910.q3JJADnr036633@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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 <sys/ioctl.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/uio.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <dev/mfi/mfi_ioctl.h>

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:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201204191907.q3JJ76oT062495>