Skip to contentSkip to conversation

linux-user: support target-to-host SCM_CREDENTIALS

PATCH Superseded Alex Suykov 2 participants 3 messages Dec 21, 2014 – Dec 23, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: support target-to-host SCM_CREDENTIALS

When passing ancillary data through a unix socket, handle credentials properly instead of doing a simple copy and issuing a warning.

---
 linux-user/syscall.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
linux-user/syscall.c +11 -4
index aaac6a2..b067c5c 100644
@@ -1214,16 +1214,23 @@ static inline abi_long target_to_host_cmsg(struct msghdr *msgh,
         cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type);
         cmsg->cmsg_len = CMSG_LEN(len);
 
-        if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
-            gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
-            memcpy(data, target_data, len);
-        } else {
+        if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
             int *fd = (int *)data;
             int *target_fd = (int *)target_data;
             int i, numfds = len / sizeof(int);
 
             for (i = 0; i < numfds; i++)
                 fd[i] = tswap32(target_fd[i]);
+        } else if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDENTIALS) {
+            struct ucred *cred = (struct ucred *)data;
+            struct target_ucred *target_cred = (struct target_ucred *)target_data;
+
+            __put_user(target_cred->pid, &cred->pid);
+            __put_user(target_cred->uid, &cred->uid);
+            __put_user(target_cred->gid, &cred->gid);
+        } else {
+            gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
+            memcpy(data, target_data, len);
         }
 
         cmsg = CMSG_NXTHDR(msgh, cmsg);
Signature · 1 line
2.0.3
#1 lore raw
Quoted 45 lines · Alex Suykov

When passing ancillary data through a unix socket, handle credentials properly instead of doing a simple copy and issuing a warning.

---
 linux-user/syscall.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
linux-user/syscall.c +11 -4
index aaac6a2..b067c5c 100644
@@ -1214,16 +1214,23 @@ static inline abi_long target_to_host_cmsg(struct msghdr *msgh,
         cmsg->cmsg_type = tswap32(target_cmsg->cmsg_type);
         cmsg->cmsg_len = CMSG_LEN(len);
 
-        if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS) {
-            gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
-            memcpy(data, target_data, len);
-        } else {
+        if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
             int *fd = (int *)data;
             int *target_fd = (int *)target_data;
             int i, numfds = len / sizeof(int);
 
             for (i = 0; i < numfds; i++)
                 fd[i] = tswap32(target_fd[i]);
+        } else if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_CREDENTIALS) {
+            struct ucred *cred = (struct ucred *)data;
+            struct target_ucred *target_cred = (struct target_ucred *)target_data;
+
+            __put_user(target_cred->pid, &cred->pid);
+            __put_user(target_cred->uid, &cred->uid);
+            __put_user(target_cred->gid, &cred->gid);
+        } else {
+            gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);
+            memcpy(data, target_data, len);
         }
 
         cmsg = CMSG_NXTHDR(msgh, cmsg);
Signature · 1 line
2.0.3

I didn't review the code but checkpatch.pl complains about a few lines over 80 characters.

Fam

#2 lore raw
Quoted 7 lines · Fam Zheng
Quoted 6 lines · Alex Suykov

When passing ancillary data through a unix socket, handle credentials properly instead of doing a simple copy and issuing a warning.

---

...

Quoted 1 line
Quoted 1 line

- gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);

...

Quoted 1 line
Quoted 1 line

+ gemu_log("Unsupported ancillary data: %d/%d\n", cmsg->cmsg_level, cmsg->cmsg_type);

...

Quoted 3 lines

I didn't review the code but checkpatch.pl complains about a few lines over 80 characters.

The patch does not change the length of the longest line in that function, just moves it around. So my guess was that mixing semantic changes and reformatting is not a good idea.

Sending checkpatch-compliant v2.