Skip to content

Instantly share code, notes, and snippets.

@dnschneid
Last active February 21, 2023 00:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnschneid/5c88a1802868c1be74d4debb5627c8c7 to your computer and use it in GitHub Desktop.
Save dnschneid/5c88a1802868c1be74d4debb5627c8c7 to your computer and use it in GitHub Desktop.
LD_PRELOAD for capping the revision number reported by the uname syscall
/*
* 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