From nobody Fri Mar 29 09:34:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581596609333179.04351523274374; Thu, 13 Feb 2020 04:23:29 -0800 (PST) Received: from localhost ([::1]:51342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2DWi-0000g2-1j for importer@patchew.org; Thu, 13 Feb 2020 07:23:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39161) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2DUf-0006Xr-61 for qemu-devel@nongnu.org; Thu, 13 Feb 2020 07:21:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2DUe-0003N9-7p for qemu-devel@nongnu.org; Thu, 13 Feb 2020 07:21:21 -0500 Received: from mout.kundenserver.de ([212.227.126.131]:59659) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j2DUd-0003Mp-Vr for qemu-devel@nongnu.org; Thu, 13 Feb 2020 07:21:20 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MAORn-1jDRcq3OOJ-00Btl7; Thu, 13 Feb 2020 13:21:12 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 1/5] linux-user: add missing TARGET_SIGRTMIN for hppa Date: Thu, 13 Feb 2020 13:21:04 +0100 Message-Id: <20200213122108.965455-2-laurent@vivier.eu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200213122108.965455-1-laurent@vivier.eu> References: <20200213122108.965455-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:YfOIAiU/LjNkBiZ3cPPuh1vObMf3Wv0zYFURKZ1NvR0fNa2PHdP KLvXX5BAbFbyazvl0/iJV4RtkQKrK1lpXH/xC9CG8pGZWujIM3vv+hytl12fPM8GAxQ3c1t 7q7V0uQZyefn29axRzNPNAmaMqeroVG8nf7tqsfI8zA0wW9E+4j7e5jfW4sXQKGQttawt5p Qn9cEbc9NSNtK+Y+scHGQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:xOwFN2M/zUI=:69c3wmChX0RFLQr2vRj/4e ZiNM8n01Cp0ykPrX7XCR/9tTRDl02LqxyLDCWztExqNARjvym6sKB4WL6qFYrw8dB2tTKddL3 hsptHf05VmiQ3UCJ0k9nC3hudLKYVrfbdEwUDNEjQgSZP42t/BD6QTXUcLAi4HKwU7Tr81Vk3 GWymoVJGn8JiWJJ077/1jHZJq1wZxAApobQVDQR6Vwz0KxlGcOOIIEdy3ZIDMtxFl6vXI1BHY FKJibgDAxsGr4W6K5RvdoRTsEqLcqJ4Q8D1xtxYySZ7zI5MszyGzDGXhGQF/KKRHxKQBXj1KD tka2bhYbLYgTQXg0ALw9QQHUULBqihWr/VTZ0+7f0WMbl9zY8yUHD7yeAXUkEwvGbu2HiYhnn w87SF3KL0tnO/QoTMGUVdoDNubtwUCZQhIe2luVfgCjDoO3z/sVts/esGDZGTLMgqP+hw5kXQ 1VZzJxuPB/MuY5FGz4H+KpV8tse8cueAndwrXZFgtyrgK7aV9vfHq/ycjzQWEQ4scrb1JJhnx T0/5FtYTly/BXs29vSZnfkZLDj+3A1XGMYVx2pZIq4Yqdok0SMMfb1b4JeLJLmCn+vZPX7Yh4 gOuyg+qm07XcConQapmuP4ynCwc8QfiX/KBmbMYWP4zyMjAbz+nr+47MHh4HuxYIoFsMB/nNW tLuOqp6FwushmShKTZtn1H3bCNkf6K2rGsjmvDHAtjnVLrqy3/F1klNEv9K3VtyZwRH3KRKPG mBJW0vuezaUUaSlesqAZdjGU1RArNxL603CwAO/eEGa9VZBDWSOe8oie8BMB2a/I1Xh9BMmAk sr7kEo1fy0tIM1blS/o9kGPMjdRcOSTQhMm3tuQptqDBb0pYLQykGIRYkMlpEFXD4NxWlVV X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.131 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Taylor Simpson , Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This signal is defined for all other targets and we will need it later Signed-off-by: Laurent Vivier [pm: that this was actually an ABI change in the hppa kernel (at kernel version 3.17, kernel commit 1f25df2eff5b25f52c139d). Before that SIGRTMIN was 37... All our other HPPA TARGET_SIG* values are for the updated ABI following that commit, so using 32 for SIGRTMIN is the right thing for us.] Reviewed-by: Peter Maydell Tested-by: Taylor Simpson Message-Id: <20200212125658.644558-2-laurent@vivier.eu> Signed-off-by: Laurent Vivier --- linux-user/hppa/target_signal.h | 1 + 1 file changed, 1 insertion(+) diff --git a/linux-user/hppa/target_signal.h b/linux-user/hppa/target_signa= l.h index ba159ff8d006..c2a0102ed73d 100644 --- a/linux-user/hppa/target_signal.h +++ b/linux-user/hppa/target_signal.h @@ -34,6 +34,7 @@ #define TARGET_SIGURG 29 #define TARGET_SIGXFSZ 30 #define TARGET_SIGSYS 31 +#define TARGET_SIGRTMIN 32 =20 #define TARGET_SIG_BLOCK 0 #define TARGET_SIG_UNBLOCK 1 --=20 2.24.1 From nobody Fri Mar 29 09:34:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581596730734556.6586376665034; Thu, 13 Feb 2020 04:25:30 -0800 (PST) Received: from localhost ([::1]:51364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2DYf-000325-H3 for importer@patchew.org; Thu, 13 Feb 2020 07:25:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39219) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2DUo-0006hL-Hm for qemu-devel@nongnu.org; Thu, 13 Feb 2020 07:21:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2DUm-0003T5-Un for qemu-devel@nongnu.org; Thu, 13 Feb 2020 07:21:30 -0500 Received: from mout.kundenserver.de ([212.227.126.133]:46313) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j2DUm-0003Se-I0 for qemu-devel@nongnu.org; Thu, 13 Feb 2020 07:21:28 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1M1HmE-1j4xJS1bdC-002rCW; Thu, 13 Feb 2020 13:21:12 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 2/5] linux-user: cleanup signal.c Date: Thu, 13 Feb 2020 13:21:05 +0100 Message-Id: <20200213122108.965455-3-laurent@vivier.eu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200213122108.965455-1-laurent@vivier.eu> References: <20200213122108.965455-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:SEIsdpIS5khGsUrVlRokoMCc+1TMm3BusnO+gHBgm0QURWBEV6y LG7ABpQVJA9fdsxk4wxY9gvSFjmHmv+/PvICcPBtfQZzWSiIWD7nhHeqdwt120N6T7MnCKi OBbBUC4086isw2K4SItuP/erZrwvDEuhVQfRjzD/qGfWknDn4Mw3fManHM+YUkZcbbKXClM PUttQZV8Van+8AhEPogng== X-UI-Out-Filterresults: notjunk:1;V03:K0:N9WlkuKcuc8=:fMziHU3JDerD1IVs+dYVEI pPY/DTdpMptWks6pjC+ddc+bEadxt7ZujCG06qlVW+V8Kc0ID0SbWJQGprq5mFerUmxo6uQ27 JQ8c0SdHG1Fr2Pld41VXMkUpbQnXaGpRggRLT9kQJDCYHgpW1mhFkugYiUncbGU/bklz/uiHt iPXZRdn9H0+/t3wnlYXdceLeRwaKxY9gpXOac6eL9ql3snkmQvQSV0nbbf2+sKzqyrUz5ltDb vVYKOr+XRg4HnYFr5ye9qVNX6df78z4RM4B2hAD1Lwahff/dOb7V4EHg6Fl31M43BnhzRr6PB 38ipZSSUYPoYpyIXzfFw8mruIxRoC8PXe3snrzeq5YUuKx63DKWFg3EEYr6MKFlJto9eqGTCY 4Dmp2faFKrF4oWyOLkziR9Eqyf10KoUYt5yKzGjRgST0s8IvYIPwt5ic1XWI0c2V6lBWGcUlq XJ2AaQtOclrIrLsiDkPyQWm3BXOlL+NEwY6Qx/VdJhP9lc0chGq/CA5dv0wVreYK1EKvor04X r+L9mVx+fhaOLKxWAKfDuBRA74DwQl60jfQfgV+vo1qlzkdCaYs0WpNjEE+2AyybumT8XDqlQ QmAkGE1pPQqp4atq6McR9SrS0toAhzNaWqd6fW1tUrMpRpSQBUCS+NDp8fXOKNJH1zikFJZl8 5Pl0GgfXgpj4LsjQf75ZCkpvHcPKRhO6Aa6/maP50CTXv7lvy+npDERMg9WgwmjbjKnybSgjJ WKvSe6neT2M1GOUYDK5zg58picuHfFpZErlUMWJY678SxO0NEwTYE/mfr65JuPXMrDFcwF+iS m4CqrspD6YDOuowlVzZrFmJZJwe3ZKs+hlVqtiigmUvM/Op6g/HvTeBkQqCYvfbGOiKkza2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.133 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Taylor Simpson , Riku Voipio , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" No functional changes. Prepare the field for future fixes. Remove memset(.., 0, ...) that is useless on a static array Signed-off-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Peter Maydell Tested-by: Taylor Simpson Message-Id: <20200212125658.644558-3-laurent@vivier.eu> --- linux-user/signal.c | 48 ++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 5ca6d62b15d3..246315571c09 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -66,12 +66,6 @@ static uint8_t host_to_target_signal_table[_NSIG] =3D { [SIGPWR] =3D TARGET_SIGPWR, [SIGSYS] =3D TARGET_SIGSYS, /* next signals stay the same */ - /* Nasty hack: Reverse SIGRTMIN and SIGRTMAX to avoid overlap with - host libpthread signals. This assumes no one actually uses SIGRTMA= X :-/ - To fix this properly we need to do manual signal delivery multiplex= ed - over a single host signal. */ - [__SIGRTMIN] =3D __SIGRTMAX, - [__SIGRTMAX] =3D __SIGRTMIN, }; static uint8_t target_to_host_signal_table[_NSIG]; =20 @@ -480,31 +474,45 @@ static int core_dump_signal(int sig) } } =20 +static void signal_table_init(void) +{ + int host_sig, target_sig; + + /* + * Nasty hack: Reverse SIGRTMIN and SIGRTMAX to avoid overlap with + * host libpthread signals. This assumes no one actually uses SIGRTMA= X :-/ + * To fix this properly we need to do manual signal delivery multiplex= ed + * over a single host signal. + */ + host_to_target_signal_table[__SIGRTMIN] =3D __SIGRTMAX; + host_to_target_signal_table[__SIGRTMAX] =3D __SIGRTMIN; + + /* generate signal conversion tables */ + for (host_sig =3D 1; host_sig < _NSIG; host_sig++) { + if (host_to_target_signal_table[host_sig] =3D=3D 0) { + host_to_target_signal_table[host_sig] =3D host_sig; + } + } + for (host_sig =3D 1; host_sig < _NSIG; host_sig++) { + target_sig =3D host_to_target_signal_table[host_sig]; + target_to_host_signal_table[target_sig] =3D host_sig; + } +} + void signal_init(void) { TaskState *ts =3D (TaskState *)thread_cpu->opaque; struct sigaction act; struct sigaction oact; - int i, j; + int i; int host_sig; =20 - /* generate signal conversion tables */ - for(i =3D 1; i < _NSIG; i++) { - if (host_to_target_signal_table[i] =3D=3D 0) - host_to_target_signal_table[i] =3D i; - } - for(i =3D 1; i < _NSIG; i++) { - j =3D host_to_target_signal_table[i]; - target_to_host_signal_table[j] =3D i; - } + /* initialize signal conversion tables */ + signal_table_init(); =20 /* Set the signal mask from the host mask. */ sigprocmask(0, 0, &ts->signal_mask); =20 - /* set all host signal handlers. ALL signals are blocked during - the handlers to serialize them. */ - memset(sigact_table, 0, sizeof(sigact_table)); - sigfillset(&act.sa_mask); act.sa_flags =3D SA_SIGINFO; act.sa_sigaction =3D host_signal_handler; --=20 2.24.1 From nobody Fri Mar 29 09:34:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581596542243333.83623882897314; Thu, 13 Feb 2020 04:22:22 -0800 (PST) Received: from localhost ([::1]:51328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2DVc-0007QN-C3 for importer@patchew.org; Thu, 13 Feb 2020 07:22:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39158) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2DUf-0006Xq-1A for qemu-devel@nongnu.org; Thu, 13 Feb 2020 07:21:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2DUd-0003Mv-RR for qemu-devel@nongnu.org; Thu, 13 Feb 2020 07:21:20 -0500 Received: from mout.kundenserver.de ([212.227.126.131]:55905) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j2DUd-0003Mf-I5 for qemu-devel@nongnu.org; Thu, 13 Feb 2020 07:21:19 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mgvj3-1jgkIn3t3V-00hQst; Thu, 13 Feb 2020 13:21:13 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 3/5] linux-user: fix TARGET_NSIG and _NSIG uses Date: Thu, 13 Feb 2020 13:21:06 +0100 Message-Id: <20200213122108.965455-4-laurent@vivier.eu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200213122108.965455-1-laurent@vivier.eu> References: <20200213122108.965455-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:ImjfzA8yN07Xrsgut7wGvlm4lfTs1AoZTmdxsWJtcVvDfms5WBS zbCOtzwdYhSiLxZstVw6muo9CkgMU/swgrejmzIHaJd/Uy0DcsRr1TiVeKQSTeKzbLsi7UY t0c5lK6TcLccw4Sx1CMnRICi5H3AjufS2VGGDXEJDgkIZ+F8B8BXVvw8K1R4nkb9jxg0nCx IwBr0w/foXiZPFY1FBsmg== X-UI-Out-Filterresults: notjunk:1;V03:K0:BarVK4u5Zn0=:jxBsOQQDxQGl0vmuRNX3MV wXR2zmW1kPxw/lpGBj/YZ0gxP/Rq6yLEDfjkBXrvhpQYMpUqmfA1S5RIu9EYCjBZerNsjATyi g+8NM/em/hsoQrAeiMFLSjHoxRiBovkEujndJqXpJyJuzy1DdQ7Kf5JctDZQuZAEH6NsgfGVt QsInJz6zXCO1z70mhThBPyGg8dDWbkHj+AhDeeNtTgNmDwGHYe4pOP5/YDNFeX5PErdIXAubt g0A8OM3YLkqnC9SuNk9nA+SHdm7ltT5OAucMvJzfoixC0oCg09h8YbrCRkhwbns0ZGt1bS9PL JgykOrXym73+/9JTqfZBYKneMP6ZYTNGiNBcFJkDTRnVuUgrVR2DpXP5SFPtImQ+6hgiF9g+8 oJF4TN6Huz2W7abCBlb/QNRfGQY/6Pf1oE0XjkDczPrE7unYZsuZMt0PitmNRlV0GAuLGL8L9 jFKmDERUyMa4MJ7BVs3oPbbmXvxtBZCjiNh55Nf8rF78qYsyXMNWq4dUVEt7gktbkmjDAc5GQ pg1loNQuLDYS/fybrn+bBTvRtvd/0o37pxMdK1FaEhLJOlg1Q/THghBSsAjwmj/KeWUf4SMTo ixz2vJqckozSmWub5Ml75uIgX0x46LHcHx0oY8CzCvNfUeHCVL/Ky6+eK1smie8BFJaBwCJgU vzxOwQ9+hVq5r2VhpFoYDs/R/RGlMg+I8eavTxjwBsa6fNvjjMOXx+Y22lrr17iLoVlDxYaOb 5byd0KuDsu767HoCD1QhVgUAVeKsm5lsBej3H7ia2kJiHILN3JhL4wKFTwhZTLSwwOMRwU1Zr h9IUZoeooZHr9rv8I8Fh6bDYXiXqhoxkXFQfTUGTXji1lVSfzAzX1W9wRHy0b34nPyjOJJ0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.131 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Taylor Simpson , Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Valid signal numbers are between 1 (SIGHUP) and SIGRTMAX. System includes define _NSIG to SIGRTMAX + 1, but QEMU (like kernel) defines TARGET_NSIG to TARGET_SIGRTMAX. Fix all the checks involving the signal range. Signed-off-by: Laurent Vivier Reviewed-by: Peter Maydell Tested-by: Taylor Simpson Message-Id: <20200212125658.644558-4-laurent@vivier.eu> --- linux-user/signal.c | 52 ++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 246315571c09..c1e664f97a7c 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -30,6 +30,15 @@ static struct target_sigaction sigact_table[TARGET_NSIG]; static void host_signal_handler(int host_signum, siginfo_t *info, void *puc); =20 + +/* + * System includes define _NSIG as SIGRTMAX + 1, + * but qemu (like the kernel) defines TARGET_NSIG as TARGET_SIGRTMAX + * and the first signal is SIGHUP defined as 1 + * Signal number 0 is reserved for use as kill(pid, 0), to test whether + * a process exists without sending it a signal. + */ +QEMU_BUILD_BUG_ON(__SIGRTMAX + 1 !=3D _NSIG); static uint8_t host_to_target_signal_table[_NSIG] =3D { [SIGHUP] =3D TARGET_SIGHUP, [SIGINT] =3D TARGET_SIGINT, @@ -67,19 +76,24 @@ static uint8_t host_to_target_signal_table[_NSIG] =3D { [SIGSYS] =3D TARGET_SIGSYS, /* next signals stay the same */ }; -static uint8_t target_to_host_signal_table[_NSIG]; =20 +static uint8_t target_to_host_signal_table[TARGET_NSIG + 1]; + +/* valid sig is between 1 and _NSIG - 1 */ int host_to_target_signal(int sig) { - if (sig < 0 || sig >=3D _NSIG) + if (sig < 1 || sig >=3D _NSIG) { return sig; + } return host_to_target_signal_table[sig]; } =20 +/* valid sig is between 1 and TARGET_NSIG */ int target_to_host_signal(int sig) { - if (sig < 0 || sig >=3D _NSIG) + if (sig < 1 || sig > TARGET_NSIG) { return sig; + } return target_to_host_signal_table[sig]; } =20 @@ -100,11 +114,15 @@ static inline int target_sigismember(const target_sig= set_t *set, int signum) void host_to_target_sigset_internal(target_sigset_t *d, const sigset_t *s) { - int i; + int host_sig, target_sig; target_sigemptyset(d); - for (i =3D 1; i <=3D TARGET_NSIG; i++) { - if (sigismember(s, i)) { - target_sigaddset(d, host_to_target_signal(i)); + for (host_sig =3D 1; host_sig < _NSIG; host_sig++) { + target_sig =3D host_to_target_signal(host_sig); + if (target_sig < 1 || target_sig > TARGET_NSIG) { + continue; + } + if (sigismember(s, host_sig)) { + target_sigaddset(d, target_sig); } } } @@ -122,11 +140,15 @@ void host_to_target_sigset(target_sigset_t *d, const = sigset_t *s) void target_to_host_sigset_internal(sigset_t *d, const target_sigset_t *s) { - int i; + int host_sig, target_sig; sigemptyset(d); - for (i =3D 1; i <=3D TARGET_NSIG; i++) { - if (target_sigismember(s, i)) { - sigaddset(d, target_to_host_signal(i)); + for (target_sig =3D 1; target_sig <=3D TARGET_NSIG; target_sig++) { + host_sig =3D target_to_host_signal(target_sig); + if (host_sig < 1 || host_sig >=3D _NSIG) { + continue; + } + if (target_sigismember(s, target_sig)) { + sigaddset(d, host_sig); } } } @@ -492,10 +514,10 @@ static void signal_table_init(void) if (host_to_target_signal_table[host_sig] =3D=3D 0) { host_to_target_signal_table[host_sig] =3D host_sig; } - } - for (host_sig =3D 1; host_sig < _NSIG; host_sig++) { target_sig =3D host_to_target_signal_table[host_sig]; - target_to_host_signal_table[target_sig] =3D host_sig; + if (target_sig <=3D TARGET_NSIG) { + target_to_host_signal_table[target_sig] =3D host_sig; + } } } =20 @@ -518,7 +540,7 @@ void signal_init(void) act.sa_sigaction =3D host_signal_handler; for(i =3D 1; i <=3D TARGET_NSIG; i++) { #ifdef TARGET_GPROF - if (i =3D=3D SIGPROF) { + if (i =3D=3D TARGET_SIGPROF) { continue; } #endif --=20 2.24.1 From nobody Fri Mar 29 09:34:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581596661979980.4744728293194; Thu, 13 Feb 2020 04:24:21 -0800 (PST) Received: from localhost ([::1]:51354 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2DXY-00021N-E2 for importer@patchew.org; Thu, 13 Feb 2020 07:24:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39207) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2DUm-0006fc-UR for qemu-devel@nongnu.org; Thu, 13 Feb 2020 07:21:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2DUl-0003S9-9H for qemu-devel@nongnu.org; Thu, 13 Feb 2020 07:21:28 -0500 Received: from mout.kundenserver.de ([212.227.126.134]:49887) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j2DUl-0003Qs-03 for qemu-devel@nongnu.org; Thu, 13 Feb 2020 07:21:27 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MQ5nE-1ip4Lx1rV2-00M450; Thu, 13 Feb 2020 13:21:13 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 4/5] linux-user: fix use of SIGRTMIN Date: Thu, 13 Feb 2020 13:21:07 +0100 Message-Id: <20200213122108.965455-5-laurent@vivier.eu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200213122108.965455-1-laurent@vivier.eu> References: <20200213122108.965455-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:MleeMIE0cAxKS0cEfFJvt48rVMBIGdRfm5bSToK1ySZ8kt1ZrX6 d330DfzWiYOFYbZDh6WkLKq5+ffkq45cl3zmcm3I2f7auDk8kfsZmHQR/s0HL+q4CssYrZ2 SbWRBkIgL2BgfyQfJC2hVJucVk8x2N1MnGgOE/bkmEClRJTCd3eNwAbaYyACmrR87p3s691 1mBUdqJquZOaohya2o33A== X-UI-Out-Filterresults: notjunk:1;V03:K0:5Ic2Biv6Ui4=:p9ns19Vsp3jKY/I1OkYLBf 8vZnag5+r2LBljhPaP9KirU4sgBzLz+80IQ60G/iWaoWtHQ0fZaJ9xyUACEmuTVcp7g5L4/gc qSusjP7y6cGdCuYvrWtZdESoupaP0ePdevx4uV/Ky85La8CxbgjN6PQ2S8NRN8gX3bSbOFG0O vh5YlZmCE4TDE7XQE5HEKivBEstxqvLVrXzvhx0RTm7C8s2kbWJRrAVT5eXSiIZ7x/jsQmr3a n0R9pTBIDVKxDk7u3PGgxYDZDlLofvBUtI47WMJ0KSTKKcTK75ectW2IFU6Am3iael4Vg1bSE 7ygJvc30IGe7dhgZWClX0C48r7csLSCmV6MYeLEnJCxj4vIS1gVowyNFmIJbwS08a26qZ8RCj 3Y3ihfBnV+Qb7el+OSifIhzcQsYeFyWrWYftoqpJ/MdMm2Gr5wuLrKl9blEOp1fUYyVE+ADYh 4vaVeqe7Rmy05rwVlqSjpA5utxV50Zb4LuJoWS028aZ8OwwmkpGCN9LJFgnPuHFsvV5iAqv5O uhjI2B62s+t1j87DRLZlAOd6Qv+1mcnVCb2stNT996tjRuolucieTPZ3P8uF9LxV6WBzXCskN cCizM2YE7ftN6bOL4keGQzEKavvdd5lBKedB6iBYmRnTwThB7498qgC+md3HwLZtUFSjT8g9d 8BPl+88xqCkzGjoZ4sAl/AuJB57cgrUVkCapNr5xYRGiBvBsNfnK/3XLtc+f/3+peKVdgCzl2 ycZfkpsjDH7FzsbL2tUBz5bdF2QV+Rye9aZJls43V9u/FxtKu/mC+FKMMYHF8ixyALgia95po 6TKXZlTJArUYFUEn4mFhpSnJkhdwYsSQh+EZW5HpdiQu7+LzvKJ/qW2pe9IPGHjTNSqqLWB X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.134 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Taylor Simson , Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Some RT signals can be in use by glibc, it's why SIGRTMIN (34) is generally greater than __SIGRTMIN (32). So SIGRTMIN cannot be mapped to TARGET_SIGRTMIN. Instead of swapping only SIGRTMIN and SIGRTMAX, map all the range [TARGET_SIGRTMIN ... TARGET_SIGRTMAX - X] to [__SIGRTMIN + X ... SIGRTMAX ] (SIGRTMIN is __SIGRTMIN + X). Signed-off-by: Laurent Vivier Reviewed-by: Taylor Simson Tested-by: Taylor Simpson Reviewed-by: Peter Maydell Message-Id: <20200212125658.644558-5-laurent@vivier.eu> --- linux-user/signal.c | 50 ++++++++++++++++++++++++++++++++++++----- linux-user/trace-events | 3 +++ 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index c1e664f97a7c..046159dd0c5b 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -498,18 +498,30 @@ static int core_dump_signal(int sig) =20 static void signal_table_init(void) { - int host_sig, target_sig; + int host_sig, target_sig, count; =20 /* - * Nasty hack: Reverse SIGRTMIN and SIGRTMAX to avoid overlap with - * host libpthread signals. This assumes no one actually uses SIGRTMA= X :-/ + * Signals are supported starting from TARGET_SIGRTMIN and going up + * until we run out of host realtime signals. + * glibc at least uses only the lower 2 rt signals and probably + * nobody's using the upper ones. + * it's why SIGRTMIN (34) is generally greater than __SIGRTMIN (32) * To fix this properly we need to do manual signal delivery multiplex= ed * over a single host signal. + * Attempts for configure "missing" signals via sigaction will be + * silently ignored. */ - host_to_target_signal_table[__SIGRTMIN] =3D __SIGRTMAX; - host_to_target_signal_table[__SIGRTMAX] =3D __SIGRTMIN; + for (host_sig =3D SIGRTMIN; host_sig <=3D SIGRTMAX; host_sig++) { + target_sig =3D host_sig - SIGRTMIN + TARGET_SIGRTMIN; + if (target_sig <=3D TARGET_NSIG) { + host_to_target_signal_table[host_sig] =3D target_sig; + } + } =20 /* generate signal conversion tables */ + for (target_sig =3D 1; target_sig <=3D TARGET_NSIG; target_sig++) { + target_to_host_signal_table[target_sig] =3D _NSIG; /* poison */ + } for (host_sig =3D 1; host_sig < _NSIG; host_sig++) { if (host_to_target_signal_table[host_sig] =3D=3D 0) { host_to_target_signal_table[host_sig] =3D host_sig; @@ -519,6 +531,15 @@ static void signal_table_init(void) target_to_host_signal_table[target_sig] =3D host_sig; } } + + if (trace_event_get_state_backends(TRACE_SIGNAL_TABLE_INIT)) { + for (target_sig =3D 1, count =3D 0; target_sig <=3D TARGET_NSIG; t= arget_sig++) { + if (target_to_host_signal_table[target_sig] =3D=3D _NSIG) { + count++; + } + } + trace_signal_table_init(count); + } } =20 void signal_init(void) @@ -817,6 +838,8 @@ int do_sigaction(int sig, const struct target_sigaction= *act, int host_sig; int ret =3D 0; =20 + trace_signal_do_sigaction_guest(sig, TARGET_NSIG); + if (sig < 1 || sig > TARGET_NSIG || sig =3D=3D TARGET_SIGKILL || sig = =3D=3D TARGET_SIGSTOP) { return -TARGET_EINVAL; } @@ -847,6 +870,23 @@ int do_sigaction(int sig, const struct target_sigactio= n *act, =20 /* we update the host linux signal state */ host_sig =3D target_to_host_signal(sig); + trace_signal_do_sigaction_host(host_sig, TARGET_NSIG); + if (host_sig > SIGRTMAX) { + /* we don't have enough host signals to map all target signals= */ + qemu_log_mask(LOG_UNIMP, "Unsupported target signal #%d, ignor= ed\n", + sig); + /* + * we don't return an error here because some programs try to + * register an handler for all possible rt signals even if they + * don't need it. + * An error here can abort them whereas there can be no problem + * to not have the signal available later. + * This is the case for golang, + * See https://github.com/golang/go/issues/33746 + * So we silently ignore the error. + */ + return 0; + } if (host_sig !=3D SIGSEGV && host_sig !=3D SIGBUS) { sigfillset(&act1.sa_mask); act1.sa_flags =3D SA_SIGINFO; diff --git a/linux-user/trace-events b/linux-user/trace-events index f6de1b8befc0..0296133daeb6 100644 --- a/linux-user/trace-events +++ b/linux-user/trace-events @@ -1,6 +1,9 @@ # See docs/devel/tracing.txt for syntax documentation. =20 # signal.c +signal_table_init(int i) "number of unavailable signals: %d" +signal_do_sigaction_guest(int sig, int max) "target signal %d (MAX %d)" +signal_do_sigaction_host(int sig, int max) "host signal %d (MAX %d)" # */signal.c user_setup_frame(void *env, uint64_t frame_addr) "env=3D%p frame_addr=3D0x= %"PRIx64 user_setup_rt_frame(void *env, uint64_t frame_addr) "env=3D%p frame_addr= =3D0x%"PRIx64 --=20 2.24.1 From nobody Fri Mar 29 09:34:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581596611040122.9631281714768; Thu, 13 Feb 2020 04:23:31 -0800 (PST) Received: from localhost ([::1]:51344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2DWj-0000jd-RS for importer@patchew.org; Thu, 13 Feb 2020 07:23:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39198) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2DUm-0006e5-09 for qemu-devel@nongnu.org; Thu, 13 Feb 2020 07:21:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2DUk-0003RQ-OO for qemu-devel@nongnu.org; Thu, 13 Feb 2020 07:21:27 -0500 Received: from mout.kundenserver.de ([212.227.126.134]:33905) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j2DUk-0003Pr-FJ for qemu-devel@nongnu.org; Thu, 13 Feb 2020 07:21:26 -0500 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MmDAW-1jkJjd48RM-00iDZO; Thu, 13 Feb 2020 13:21:14 +0100 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL 5/5] linux-user: implement TARGET_SO_PEERSEC Date: Thu, 13 Feb 2020 13:21:08 +0100 Message-Id: <20200213122108.965455-6-laurent@vivier.eu> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200213122108.965455-1-laurent@vivier.eu> References: <20200213122108.965455-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:pXdY38UTIdcbZNZR88eBsXzg58bbI5HYUMzcwVSUd7ASq4azCuG 7wK2FkvwqbCTlVA9qTPcECDpFoCm0aJoCbWlClrGq8sHilrsnESxZhN19va4WrS0bNVK9Yc Vpu7fqpqH24Lrbc2q79+ryU1XGo01pcd0whueVtTmxCpypu9gC4gUb9SDXQI5jaa7xcmRRr bZT8xaLjAsPeoLiGgOC3A== X-UI-Out-Filterresults: notjunk:1;V03:K0:iJgSuFHQbf4=:DMRKxnf85KIDcqlFlFkITr QA1q4lwoHgzvyGfBUi223bRs4815vC61J9qJLRz/1i7ZXozixt0RkGBOzO8lX/OaRHZB7ZJAk YXugjmH1f5o5bheLdxlGwHeqnbVXVRO2Tge3tA+UqSrdzJkpwqFrj3nZuDKutaps0OOXawcE/ 4hUZQO2kfh+coH10nQJZMMPZajIfBF02mJWpJQ8eVd56fcvhkoCf2RTHiSpZA7o6ZsZIPw83T r++h228FCAzLVrDDSDe/1Ttg6Hpxgqm/sEmqJWgDlFVIz0dEbT5BO/rIT2ZEpZM/j7Tx9Rkyd ZZzpfd9DdataEjFFh62WOkfri8GKmqeECvGvBPWvTnQ+ZNws1u1k5O77khJYRkK8+EMkWB5m3 4pXqnqhdIXiqUUvjYijKKCbFbZGn4yOHVc7vMSp1/JjH7la+ZvXzPe0lijC3QKvSfJP6SrtO0 5A+H4yy9KyjNV58T+vdU/kJcMVVKA6JXObSXhz08hx83ujDGuFLC3cNvdOU0mloOc+GO9KOQG Vs3PeCrjfX63pBXDrluWfBWrT82qW21NWDjfl45zT8hovKkraK7uRNRO2lrtB4zlGB4Rv9RaG IPWhdYqbNUsrXZ1tpexwbGgAC3eDpncCEB9pB5Taa+yvKVCY63x6Rtgp/LFvyXKf2tkd77g6p ncto1TkSpHp6/g+C4R5rzAEf4viwnZ19urwA8iOBMUpiV7AftkEYDAXRS8QYZV7XGRv9h140E AahogyMdl+Qv+i+55TQqvW/z0kV7pStvElnRho4HR/XGsSvi0QK+mFWxlkSFGoh+GzvsCI7/G JDTyG829HYGDU3XsWqeSUYYdSuH+NKQARdIBmByYXGZhXB5KDjjy955yV/nZGe/x5RfGJr5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.134 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Laurent Vivier , =?UTF-8?q?Matthias=20L=C3=BCscher?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" "The purpose of this option is to allow an application to obtain the security credentials of a Unix stream socket peer. It is analogous to SO_PEERCRED (which provides authentication using standard Unix credentials of pid, uid and gid), and extends this concept to other security models." -- https://lwn.net/Articles/62370/ Until now it was passed to the kernel with an "int" argument and fails when it was supported by the host because the parameter is like a filename: it is always a \0-terminated string with no embedded \0 characters, but is not guaranteed to be ASCII or UTF-8. I've tested the option with the following program: /* * cc -o getpeercon getpeercon.c */ #include #include #include #include #include int main(void) { int fd; struct sockaddr_in server, addr; int ret; socklen_t len; char buf[256]; fd =3D socket(PF_INET, SOCK_STREAM, 0); if (fd =3D=3D -1) { perror("socket"); return 1; } server.sin_family =3D AF_INET; inet_aton("127.0.0.1", &server.sin_addr); server.sin_port =3D htons(40390); connect(fd, (struct sockaddr*)&server, sizeof(server)); len =3D sizeof(buf); ret =3D getsockopt(fd, SOL_SOCKET, SO_PEERSEC, buf, &len); if (ret =3D=3D -1) { perror("getsockopt"); return 1; } printf("%d %s\n", len, buf); return 0; } On host: $ ./getpeercon 33 system_u:object_r:unlabeled_t:s0 With qemu-aarch64/bionic without the patch: $ ./getpeercon getsockopt: Numerical result out of range With the patch: $ ./getpeercon 33 system_u:object_r:unlabeled_t:s0 Bug: https://bugs.launchpad.net/qemu/+bug/1823790 Reported-by: Matthias L=C3=BCscher Tested-by: Matthias L=C3=BCscher Signed-off-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20200204211901.1731821-1-laurent@vivier.eu> --- linux-user/syscall.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index d60142f0691c..c930577686da 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2344,6 +2344,28 @@ static abi_long do_getsockopt(int sockfd, int level,= int optname, } break; } + case TARGET_SO_PEERSEC: { + char *name; + + if (get_user_u32(len, optlen)) { + return -TARGET_EFAULT; + } + if (len < 0) { + return -TARGET_EINVAL; + } + name =3D lock_user(VERIFY_WRITE, optval_addr, len, 0); + if (!name) { + return -TARGET_EFAULT; + } + lv =3D len; + ret =3D get_errno(getsockopt(sockfd, level, SO_PEERSEC, + name, &lv)); + if (put_user_u32(lv, optlen)) { + ret =3D -TARGET_EFAULT; + } + unlock_user(name, optval_addr, lv); + break; + } case TARGET_SO_LINGER: { struct linger lg; --=20 2.24.1