fix(desktop): Go programs see the session's identity and paths (#3154)

* fix(desktop): Go programs see the session's identity and paths

Static Go programs now get the session's root identity from getuid and its
relatives, and set*id calls succeed, as C and x86 programs already do. The
added code also takes over Go's second raw system call function (and its
golang.org/x/sys copy), which getuid goes through.

Go programs that link the C library (snapd, gocryptfs, ipp-usb) get the same
code: their Go note is found past the other notes, and the code fits before
a data segment that does not start on a page boundary. snap now reaches the
session's snapd and installs snaps.

* fix(desktop): read every Go note and retry Go programs after a failed scan
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-24 14:07:01 -05:00
1 parent 5f8655b13e
commit e709e1c454
6 files changed
+250 -54

No files matched your search

+9 -3
View File
@@ -212,9 +212,15 @@ static int read_elf_phdrs(int fd, uint16_t *machine, struct ddnatv_phdr *ph, int
static int elf_is_go(int fd, const struct ddnatv_phdr *ph, int n) {
for (int i = 0; i < n; i++) {
if (ph[i].type != 4 /* PT_NOTE */ || ph[i].filesz < 16) continue;
unsigned char note[16];
if (pread(fd, note, sizeof(note), (off_t)ph[i].offset) != sizeof(note)) continue;
if (rd32(note) == 4 && memcmp(note + 12, "Go\0\0", 4) == 0) return 1;
for (uint64_t at = 0; at + 16 <= ph[i].filesz;) {
unsigned char note[16];
if (pread(fd, note, sizeof(note), (off_t)(ph[i].offset + at)) != (ssize_t)sizeof(note)) break;
uint32_t namesz = rd32(note), descsz = rd32(note + 4);
if (namesz == 4 && memcmp(note + 12, "Go\0\0", 4) == 0) return 1;
uint64_t next = at + 12 + (((uint64_t)namesz + 3) & ~3ull) + (((uint64_t)descsz + 3) & ~3ull);
if (next <= at || next > ph[i].filesz) break;
at = next;
}
}
return 0;
}