Skip to content

Commit 09cf16b

Browse files
committed
add: implement function to check for printable C strings in namecache entry
1 parent f1ef453 commit 09cf16b

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

lara/kexploit/vfs.m

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,33 @@ static uint64_t nclookupchild(uint64_t dir_vn, const char *comp) {
238238
}
239239

240240
// Fallback: scan a namecache entry structure for any plausible name pointer.
241+
static bool is_printable_cstring(const char *buf, size_t len) {
242+
if (len == 0) return false;
243+
size_t i = 0;
244+
// must be null-terminated somewhere within len
245+
bool seen_print = false;
246+
for (; i < len; i++) {
247+
unsigned char c = (unsigned char)buf[i];
248+
if (c == 0) break;
249+
if (c < 0x20 || c > 0x7e) return false;
250+
seen_print = true;
251+
}
252+
return seen_print && i < len; // terminated and had printable chars
253+
}
254+
241255
static uint64_t ncentry_find_name_ptr(uint64_t nc, int *found_off) {
242-
for (int off = 0; off < 0x80; off += 8) {
256+
// Scan a larger window within the namecache entry for any pointer-like value
257+
for (int off = 0; off < 0x200; off += 8) {
243258
uint64_t val = kr64(nc + off);
244259
if (!iskpointer(val)) continue;
245-
char nm[4];
246-
krd(val, nm, 3); nm[3] = 0;
247-
// check for printable ascii start
248-
if ((unsigned char)nm[0] >= 0x20 && (unsigned char)nm[0] <= 0x7e) {
260+
261+
// read up to 128 bytes from candidate pointer
262+
char buf[128];
263+
memset(buf, 0, sizeof(buf));
264+
// krd may fail silently; guard with small reads
265+
krd(val, buf, sizeof(buf));
266+
267+
if (is_printable_cstring(buf, sizeof(buf))) {
249268
if (found_off) *found_off = off;
250269
return val;
251270
}

0 commit comments

Comments
 (0)