'Permission denied when connected to abstract unix socket

OS: Android L
Server: system server at the server level, service through an abstract socket.
Client: jni in the regular 3rd APK
Get "permission denied" when using the APK to connect the socket.
I thought an abstract socket did not have permissions !

And the same code works when run in the adb shell, the root shell.

Question: where is the permit set ?

code:

char *target_socket_name = "@mobilelogd"; 
int sock_id = 0; 
struct sockaddr_un sun;
int address_len;

sock_id = socket(AF_UNIX, SOCK_STREAM, 0);

if (sock_id < 0) {
    LOG("in %s: Unable to create socket: %s\n", __func__, strerror(errno));
    return -1;
} else {
    LOG("socket created!\n");       
}
memset(&sun, 0, sizeof(sun));
sun.sun_family = AF_UNIX;
strncpy(sun.sun_path, target_socket_name, strlen(target_socket_name));
sun.sun_path[0] = 0;
address_len = offsetof(struct sockaddr_un, sun_path) + strlen(target_socket_name);

if (connect(sock_id, (struct sockaddr *)&sun, address_len) == -1) 
{
    LOG("in %s: Connect to socket failed: (%d),%s\n", __func__, errno, strerror(errno));
    close(sock_id);
    return -1;
}

--- EDIT 1 --- : add the initialization code and change “0” to 0. The same result.

+4
source share
2

Android Linux " " , .

<uses-permission android:name="android.permission.INTERNET" /> 

Android ​​Linux " ", .

, uid ( , uid ) .

0

Source: https://habr.com/ru/post/1618100/


All Articles