mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 15:26:04 +00:00
fix(fex): x86 programs reach Unix sockets inside the rootfs (#3097)
* fix(fex): x86 programs reach Unix sockets inside the rootfs * fix(nativeguest): bind uses only the socket path length the caller gives
This commit is contained in:
1 parent
ec31c9e2b6
commit
ba3f840b8d
4 files changed
+64
-8
No files matched your search
@@ -708,6 +708,16 @@ long syscall(long number, ...) {
|
||||
return (long)utimensat((int)arg1, (const char *)arg2, (const struct timespec *)arg3, (int)arg4);
|
||||
}
|
||||
#endif
|
||||
#if defined(__NR_connect)
|
||||
if (number == __NR_connect) {
|
||||
return (long)connect((int)arg1, (const struct sockaddr *)arg2, (socklen_t)arg3);
|
||||
}
|
||||
#endif
|
||||
#if defined(__NR_bind)
|
||||
if (number == __NR_bind) {
|
||||
return (long)bind((int)arg1, (const struct sockaddr *)arg2, (socklen_t)arg3);
|
||||
}
|
||||
#endif
|
||||
#if defined(__NR_truncate)
|
||||
if (number == __NR_truncate) {
|
||||
return (long)truncate((const char *)arg1, (off_t)arg2);
|
||||
|
||||
@@ -94,6 +94,13 @@ int listen(int sockfd, int backlog) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void copy_unix_path(const struct sockaddr_un *sun, socklen_t addrlen, char *out) {
|
||||
size_t max = addrlen - offsetof(struct sockaddr_un, sun_path);
|
||||
if (max > sizeof(sun->sun_path)) max = sizeof(sun->sun_path);
|
||||
memcpy(out, sun->sun_path, max);
|
||||
out[max] = '\0';
|
||||
}
|
||||
|
||||
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
|
||||
static int (*orig_bind)(int, const struct sockaddr *, socklen_t) = NULL;
|
||||
if (!orig_bind) orig_bind = (int (*)(int, const struct sockaddr *, socklen_t))dlsym(RTLD_NEXT, "bind");
|
||||
@@ -104,7 +111,9 @@ int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
|
||||
struct sockaddr_un mod_sun;
|
||||
memset(&mod_sun, 0, sizeof(mod_sun));
|
||||
mod_sun.sun_family = AF_UNIX;
|
||||
rewrite_unix_socket_path(sun->sun_path, mod_sun.sun_path, sizeof(mod_sun.sun_path));
|
||||
char guest[sizeof(sun->sun_path) + 1];
|
||||
copy_unix_path(sun, addrlen, guest);
|
||||
rewrite_unix_socket_path(guest, mod_sun.sun_path, sizeof(mod_sun.sun_path));
|
||||
return orig_bind ? orig_bind(sockfd, (struct sockaddr *)&mod_sun, sizeof(mod_sun)) : -1;
|
||||
}
|
||||
}
|
||||
@@ -133,10 +142,7 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
|
||||
memset(&mod_sun, 0, sizeof(mod_sun));
|
||||
mod_sun.sun_family = AF_UNIX;
|
||||
char guest[sizeof(sun->sun_path) + 1];
|
||||
size_t max = addrlen - offsetof(struct sockaddr_un, sun_path);
|
||||
if (max > sizeof(sun->sun_path)) max = sizeof(sun->sun_path);
|
||||
memcpy(guest, sun->sun_path, max);
|
||||
guest[max] = '\0';
|
||||
copy_unix_path(sun, addrlen, guest);
|
||||
char followed[PATH_MAX];
|
||||
const char *path = guest[0] == '/' ? follow_guest_link(guest, followed, sizeof(followed)) : guest;
|
||||
rewrite_unix_socket_path(path, mod_sun.sun_path, sizeof(mod_sun.sun_path));
|
||||
|
||||
Reference in new issue
Block a user