Last active
February 21, 2023 00:06
-
-
Save dnschneid/5c88a1802868c1be74d4debb5627c8c7 to your computer and use it in GitHub Desktop.
LD_PRELOAD for capping the revision number reported by the uname syscall
This file contains hidden or 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
/* | |
* LD_PRELOAD that caps the revision reported by uname to 255. | |
* | |
* Compile: | |
* gcc -shared -fpic uname.c -ldl -o uname.so | |
* Usage example: | |
* LD_PRELOAD='/path/to/uname.so' uname -r | |
*/ | |
#define _GNU_SOURCE | |
#include <dlfcn.h> | |
#include <stdlib.h> | |
#include <sys/utsname.h> | |
static int (*orig_uname)(struct utsname *buf); | |
int uname(struct utsname *buf) { | |
char *str; | |
int ret; | |
int vers; | |
if (!orig_uname) { | |
orig_uname = dlsym(RTLD_NEXT, "uname"); | |
} | |
ret = orig_uname(buf); | |
if (ret == 0 && buf && buf->release) { | |
for (vers = 0, str = buf->release; *str && vers < 2; ++str) { | |
if (*str == '.') { | |
++vers; | |
} | |
} | |
if (vers == 2 && *str) { | |
vers = atoi(str); | |
if (vers > 255) { | |
*str++ = '2'; | |
*str++ = '5'; | |
*str++ = '5'; | |
while (*str >= '0' && *str <= '9') { | |
*str++ = '-'; | |
} | |
} | |
} | |
} | |
return ret; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment