Last active
December 18, 2015 08:29
-
-
Save wmealing/5754579 to your computer and use it in GitHub Desktop.
Beat up the nfs , expose flip bug.. profit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define MAXLEN 31 | |
#define PATH_PREFIX "/tmp/fhleak-mnt" | |
#define RUNTEST(f) stat_test(f) | |
// #define RUNTEST(f) open_noexist_test(f) | |
// #define RUNTEST(f) open_exists_test(f) | |
/* force a stat on non existant file, work the filp */ | |
void stat_test(char *filepath) { | |
struct stat *buf; | |
stat(filepath, buf); | |
} | |
void create_random_filename(char *s) { | |
int i = 0; | |
static const char alphanum[] = | |
"0123456789" | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
"abcdefghijklmnopqrstuvwxyz"; | |
for(i = 0; i < (MAXLEN - 1); i++) { | |
s[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; | |
} | |
s[MAXLEN] = '\0'; | |
} | |
void get_random_file_in_path(char *p) { | |
char *filename; | |
int len; | |
filename = malloc(sizeof(char) * MAXLEN); | |
len = strlen(PATH_PREFIX) + strlen(filename); | |
memset(filename, MAXLEN, '\0'); | |
create_random_filename(filename); | |
sprintf(p, "%s/%s", PATH_PREFIX, filename); | |
printf("P: %s\n", p); | |
free(filename); | |
} | |
int main(void) { | |
int i = 0; | |
int len = 0; | |
char *fullpath = NULL; | |
while(i <= 100) { | |
len = strlen(PATH_PREFIX) + MAXLEN; | |
fullpath = malloc(len); | |
get_random_file_in_path(fullpath); | |
printf("got path: %s\n",fullpath); | |
RUNTEST(fullpath); | |
free(fullpath); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cat /proc/slabinfo | grep filp Watch filp go up. Can't reproduce this just yet.