From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60715) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y3IRP-0000Hc-Vt for qemu-devel@nongnu.org; Tue, 23 Dec 2014 00:55:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y3IRD-0001M6-EJ for qemu-devel@nongnu.org; Tue, 23 Dec 2014 00:55:31 -0500 Received: from mail-lb0-x22c.google.com ([2a00:1450:4010:c04::22c]:61035) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y3IRD-0001Lw-7D for qemu-devel@nongnu.org; Tue, 23 Dec 2014 00:55:19 -0500 Received: by mail-lb0-f172.google.com with SMTP id u10so4880659lbd.31 for ; Mon, 22 Dec 2014 21:55:18 -0800 (PST) Date: Tue, 23 Dec 2014 07:52:58 +0200 From: Alex Suykov Message-ID: <20141223055258.GA31531@vostro> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Subject: [Qemu-devel] [PATCH v2] linux-user: support target-to-host SCM_CREDENTIALS List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Riku Voipio When passing ancillary data through a unix socket, handle credentials properly instead of doing a simple copy and issuing a warning. Signed-off-by: Alex Suykov --- v2 fixes 80-column formatting warnings from checkpatch. linux-user/syscall.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index aaac6a2..06f1449 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1214,16 +1214,26 @@ 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); -- 2.0.3