From patchwork Wed May 31 13:08:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 100760 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp320538qge; Wed, 31 May 2017 06:21:10 -0700 (PDT) X-Received: by 10.200.43.33 with SMTP id 30mr30918839qtu.210.1496236870021; Wed, 31 May 2017 06:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496236870; cv=none; d=google.com; s=arc-20160816; b=lkbfDHl58eO2hJzxhV1b3kNRMd1txrEne+soRfsXwDy+qtXYt+s5xKzy9LuoVWUCbx vO2qGnKEqt8i2UUsaYWhYcfw9vKJHJ++Gr7E+V3bsDh8DgnTCfIXcOlaSAvT+CcjykF9 hQU8OQkWOevSUtMIES9RA7GaQhVZVbR//8sbbNFbRNhkGJPyxeIzidngtjHZqWAtG12q zgBmV5zylJUhNZwICXgoYMpyggIro7h2WVYMqWr+dYo816j0F+RmoLi8XBgRN3DaO61T LDlYTfXQQtwTdbNDp3EbKksUOEdYnTJwArMy/zLCbwxntLoxPi/fQ5elgbvDJ/L2gbgw 5xAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=Qln/Y/SLcSOZ7IBdcF3riWbOhKW/MenEMZDWin1P/as=; b=QxuoNx14YWwd+TkQ0LqaR9yo4iP5D62mfOLj3zq4ops532V8ntF7UWQlnW6GmdaLZw 4piSaJSReWBnBWUvrFqlfj4Vj/kA6GskXBt7X4rNtjsMdRdFD8RHndn9UE+gO3/fN8QW IhQTtAyLRZTINnF9FxVwS0wwrmI7+8gIBavhxk2UTULEok/1G/LMaVu4FmH0juiVaRIr wiviqFBgD/ViAHVK5m1vS5Amb+FMMNIgSzB7zOfKWjXVGX9eGeCqm4SRAhFcKnWxFzWG 8BxROfYPrCcVh6pg29QHD3xu5VgzFRfiE3wHCTdR1yw+Weu9SgL04lAMqTvQkz9pS/mB SMpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id i51si16755905qtf.0.2017.05.31.06.21.09 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 31 May 2017 06:21:10 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59386 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG3Yh-0001Ow-Iw for patch@linaro.org; Wed, 31 May 2017 09:21:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG3Mu-0007jO-BQ for qemu-devel@nongnu.org; Wed, 31 May 2017 09:08:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG3Ms-0003gk-UQ for qemu-devel@nongnu.org; Wed, 31 May 2017 09:08:56 -0400 Received: from mail-lf0-x22a.google.com ([2a00:1450:4010:c07::22a]:33237) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG3Ms-0003gO-IE for qemu-devel@nongnu.org; Wed, 31 May 2017 09:08:54 -0400 Received: by mail-lf0-x22a.google.com with SMTP id m18so8650218lfj.0 for ; Wed, 31 May 2017 06:08:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qln/Y/SLcSOZ7IBdcF3riWbOhKW/MenEMZDWin1P/as=; b=F9iS11sZFvphtxzdKNdtk0IedELt4KYstHOH5LglT1sgt/0L6ZC0r3Ohhg9IxdoxZJ 4PmS1Df9p5vl65lmcpBHwWCMzoCtGtrmTHHHXHUf3uk6IAGKvsfEd7t5h1+3DoAozjSp 2YpyRqkFY8K3ShT+Hy6VV30k0t5p9N0nSdoPk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qln/Y/SLcSOZ7IBdcF3riWbOhKW/MenEMZDWin1P/as=; b=a2T/3qjMUpxRvXzA10fv1pPiMAICND+c8mqX8qRp5Sypuu34IBusfd94BkBu7YNR3Z jSbnLuCQtQeaFgnuwFwuE0c33mWbfZO6TQrU6bYd7XLRbPAFJMu2317+Yvv9YLRdaI3Q KIrZ+1EDLxY4aUpypWs+CeIk/+NlVgIw/rCmHrYHir/rNwUS8lNeMyqd9RA7vDPaIxhj 3C3Z//h2/qkMGb2OAN904Xr/VJ8xXluvYvoCF4VnYwcAIOuNUVg7hZj+QgvHMQGz+4lr 6AqiiWfhW6B3Bs92g6NglUHmnJPkTo5RhvbOw54y7cnKxjj6Pw916lMT+6ef8bxTJjhV V97g== X-Gm-Message-State: AODbwcCH8uS8O5YoIYyPApeYquBT1rs4ctjNgAktq1DmGtO6Dgj3V9yq X1fmSaR1KQTB4EnqDWltLw== X-Received: by 10.46.13.10 with SMTP id 10mr7917723ljn.58.1496236133085; Wed, 31 May 2017 06:08:53 -0700 (PDT) Received: from localhost.localdomain (91-157-170-157.elisa-laajakaista.fi. [91.157.170.157]) by smtp.gmail.com with ESMTPSA id o101sm3741766lfg.3.2017.05.31.06.08.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 May 2017 06:08:51 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Wed, 31 May 2017 16:08:27 +0300 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::22a Subject: [Qemu-devel] [PULL 15/15] linux-user: add strace support for uinfo structure of rt_sigqueueinfo() and rt_tgsigqueueinfo() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?b?TWlsb8WhIFN0b2phbm92acSH?= , stefanha@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Miloš Stojanović This commit adds support for printing the content of the target_siginfo_t structure in a similar way to how it is printed by the host strace. The pointer to this structure is sent as the last argument of the rt_sigqueueinfo() and rt_tgsigqueueinfo() system calls. For this purpose, print_siginfo() is used and the get_target_siginfo() function is implemented in order to get the information obtained from the pointer into the form that print_siginfo() expects. The get_target_siginfo() function is based on host_to_target_siginfo_noswap() in linux-user mode, but here both arguments are pointers to target_siginfo_t, so instead of converting the information to siginfo_t it just extracts and copies it to a target_siginfo_t structure. Prior to this commit, typical strace output used to look like this: 8307 rt_sigqueueinfo(8307,50,0x00000040007ff6b0) = 0 After this commit, it looks like this: 8307 rt_sigqueueinfo(8307,50,{si_signo=50, si_code=SI_QUEUE, si_pid=8307, si_uid=1000, si_sigval=17716762128}) = 0 Signed-off-by: Miloš Stojanović Signed-off-by: Riku Voipio --- linux-user/strace.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 111 insertions(+), 2 deletions(-) -- 2.11.0 diff --git a/linux-user/strace.c b/linux-user/strace.c index 5fbe067fd5..d821d165ff 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -188,6 +188,93 @@ static void print_si_code(int arg) gemu_log("%s", codename); } +static void get_target_siginfo(target_siginfo_t *tinfo, + const target_siginfo_t *info) +{ + abi_ulong sival_ptr; + + int sig; + int si_errno; + int si_code; + int si_type; + + __get_user(sig, &info->si_signo); + __get_user(si_errno, &tinfo->si_errno); + __get_user(si_code, &info->si_code); + + tinfo->si_signo = sig; + tinfo->si_errno = si_errno; + tinfo->si_code = si_code; + + /* Ensure we don't leak random junk to the guest later */ + memset(tinfo->_sifields._pad, 0, sizeof(tinfo->_sifields._pad)); + + /* This is awkward, because we have to use a combination of + * the si_code and si_signo to figure out which of the union's + * members are valid. (Within the host kernel it is always possible + * to tell, but the kernel carefully avoids giving userspace the + * high 16 bits of si_code, so we don't have the information to + * do this the easy way...) We therefore make our best guess, + * bearing in mind that a guest can spoof most of the si_codes + * via rt_sigqueueinfo() if it likes. + * + * Once we have made our guess, we record it in the top 16 bits of + * the si_code, so that print_siginfo() later can use it. + * print_siginfo() will strip these top bits out before printing + * the si_code. + */ + + switch (si_code) { + case SI_USER: + case SI_TKILL: + case SI_KERNEL: + /* Sent via kill(), tkill() or tgkill(), or direct from the kernel. + * These are the only unspoofable si_code values. + */ + __get_user(tinfo->_sifields._kill._pid, &info->_sifields._kill._pid); + __get_user(tinfo->_sifields._kill._uid, &info->_sifields._kill._uid); + si_type = QEMU_SI_KILL; + break; + default: + /* Everything else is spoofable. Make best guess based on signal */ + switch (sig) { + case TARGET_SIGCHLD: + __get_user(tinfo->_sifields._sigchld._pid, + &info->_sifields._sigchld._pid); + __get_user(tinfo->_sifields._sigchld._uid, + &info->_sifields._sigchld._uid); + __get_user(tinfo->_sifields._sigchld._status, + &info->_sifields._sigchld._status); + __get_user(tinfo->_sifields._sigchld._utime, + &info->_sifields._sigchld._utime); + __get_user(tinfo->_sifields._sigchld._stime, + &info->_sifields._sigchld._stime); + si_type = QEMU_SI_CHLD; + break; + case TARGET_SIGIO: + __get_user(tinfo->_sifields._sigpoll._band, + &info->_sifields._sigpoll._band); + __get_user(tinfo->_sifields._sigpoll._fd, + &info->_sifields._sigpoll._fd); + si_type = QEMU_SI_POLL; + break; + default: + /* Assume a sigqueue()/mq_notify()/rt_sigqueueinfo() source. */ + __get_user(tinfo->_sifields._rt._pid, &info->_sifields._rt._pid); + __get_user(tinfo->_sifields._rt._uid, &info->_sifields._rt._uid); + /* XXX: potential problem if 64 bit */ + __get_user(sival_ptr, &info->_sifields._rt._sigval.sival_ptr); + tinfo->_sifields._rt._sigval.sival_ptr = sival_ptr; + + si_type = QEMU_SI_RT; + break; + } + break; + } + + tinfo->si_code = deposit32(si_code, 16, 16, si_type); +} + static void print_siginfo(const target_siginfo_t *tinfo) { /* Print a target_siginfo_t in the format desired for printing @@ -1907,10 +1994,21 @@ print_rt_sigqueueinfo(const struct syscallname *name, abi_long arg0, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5) { + void *p; + target_siginfo_t uinfo; + print_syscall_prologue(name); print_raw_param("%d", arg0, 0); print_signal(arg1, 0); - print_pointer(arg2, 1); + p = lock_user(VERIFY_READ, arg2, sizeof(target_siginfo_t), 1); + if (p) { + get_target_siginfo(&uinfo, p); + print_siginfo(&uinfo); + + unlock_user(p, arg2, 0); + } else { + print_pointer(arg2, 1); + } print_syscall_epilogue(name); } #endif @@ -1921,11 +2019,22 @@ print_rt_tgsigqueueinfo(const struct syscallname *name, abi_long arg0, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5) { + void *p; + target_siginfo_t uinfo; + print_syscall_prologue(name); print_raw_param("%d", arg0, 0); print_raw_param("%d", arg1, 0); print_signal(arg2, 0); - print_pointer(arg3, 1); + p = lock_user(VERIFY_READ, arg3, sizeof(target_siginfo_t), 1); + if (p) { + get_target_siginfo(&uinfo, p); + print_siginfo(&uinfo); + + unlock_user(p, arg3, 0); + } else { + print_pointer(arg3, 1); + } print_syscall_epilogue(name); } #endif