From patchwork Wed Aug 23 05:16:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 716077 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp622491wrp; Tue, 22 Aug 2023 22:18:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFZgeD/qqxqhhAwsTSQW5491ThEH72ibWAB4CNiDCWkjsuo+ClkeZCpLya+JnvslV2L9v+u X-Received: by 2002:a05:622a:178f:b0:403:ef0a:ac69 with SMTP id s15-20020a05622a178f00b00403ef0aac69mr14875834qtk.62.1692767917690; Tue, 22 Aug 2023 22:18:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692767917; cv=none; d=google.com; s=arc-20160816; b=JQ24iSAJ6Uhkj6TOkDV6W1dpBXUKLUwIuVkSFbVX3gpALAVQ5wFKcBBT1YZgNp1kco LtAmWvGnSGEtjtHZshQfS9M6JVxROignU84t0SqFBkpzeBFp77zc86AJLk7bCknwG3fA 3YGD2UL1tYeIBUH5pNXblX42Jk3Oj2OC7WmS/CSrxfAiSYvP1AMdXZ1amYHI/M9Dxrpc 4Iwyqr51rxV0kl+20xsXuawyunHAivvJpUDUKcOWfVh87lonfsd/Y45HCL3V+RMcNcrU NEzqume7p818g8ufP/rjod6r2cC0VXt2oFt4JQaPMj/aiWjTtqW1nEbU7j1zqvEZJLqv 9c0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TV1TciBhkf4DHVRrzToQTqKckAEQKZ4+I2kgg1P7TXM=; fh=uta8CuNdWwEUIsmWLQQIuZWY0GOyjYTd4DbN32nR8cE=; b=CUuFp0qGGG4N3lNS0bj1ANnBSYwqD7sIY+YqFg+bDVZ+/o41r3KtPY+DfdFqxYvUnG MYpmPRkjlRC7yR8Ps2r3ap9prO9pIHtKJNCEuEo3ElujeU9SO28aw9qSF7mglGk2BnX9 yG8YMg11/toXBnRkPyI1C01zApFR/ZqwT964h8rKy/n3N9m+0R15QQaF83/VZ+vBjWZT qjNfb30rZGe8R0elympSBdOqViqRHuLIdA64bmqilzRF9L9mwYSu9gEr9xifehKxCApF ZX6L+74fbEnD42RN5pmUgY2MhlR1jMGEjmSCCTwWYjWXi6VmNcb8vYm3idk7sZTsxKV2 5ytA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RxAJjeNL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id b16-20020ac87fd0000000b0040325117d5csi2139751qtk.405.2023.08.22.22.18.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 22:18:37 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RxAJjeNL; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYgEJ-0004xW-D6; Wed, 23 Aug 2023 01:16:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYgEG-0004wS-Ie for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:28 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYgEE-0000t9-0z for qemu-devel@nongnu.org; Wed, 23 Aug 2023 01:16:28 -0400 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1bc0d39b52cso34956655ad.2 for ; Tue, 22 Aug 2023 22:16:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692767784; x=1693372584; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TV1TciBhkf4DHVRrzToQTqKckAEQKZ4+I2kgg1P7TXM=; b=RxAJjeNLloBT6VR1NWFt/G/gTCHKVA7TdGYmAHhP7lrZj8DU9Zyfdl0OYlhi7B2Zaf BLSWDgnrQTj5PJDWjz4nKwHLFlXwEV9k4OTUUunW4xWJOChf796NNzOOOOIK8bSsvN2O od36PHx0+vVx/72QNxWr7jk0UvBOn3jK3nXRfKzI1JGExjT+Mg1D9FXRuZGFsueqhETD sKMOX1kY4+nDABnLPNYRjw77qa6f1+gok170wSeYKBkNUsWQDlXjpwweELgW3LdyB3PW dCY1KPaG3ytiD3c17tDjpJ9xeHMHIxXR/vY+U4cJZDCWk9FaB4jiBoneexf0z/2LYBlp nrxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692767784; x=1693372584; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TV1TciBhkf4DHVRrzToQTqKckAEQKZ4+I2kgg1P7TXM=; b=k2Q+UVktQIMReu0f6R4IhpKerBOZs4OJ+WTysM1VuS7Fsvt/JNw4yCyXbq3gROLKAB Sjet91H16J3VkYfwFceBRlTSIZ2VbXurc7H6RzN6ENRE0MeC/0V0kJd/Zm4qmSt8400x ebkTshsJ0ICMvE6xgwat5PYODHUEs3F3q/bANS51PWiFkdYuyws6iz/b2cz0Fpuf0o4y AWab5VTTAt62QGMGaw1V5PoKB8zq7eme+ED8QR1x7ozzZFERjzBy5AGefUbajKFPSgED obuw8jTBY7WhBrxM7qH+RdzOAQRdMVDTji7qyx7Qst7U9TcWL0VpZhoJKFxAnMrGcKQd MItg== X-Gm-Message-State: AOJu0Yw4st8gcMSpK95wQWot9Ztkcg5M5pSQGLnyC5iLlPthQZS3fhsq gMeRDZg93Eos74OHLhLZAqiX/6IVw4WW9IM9uys= X-Received: by 2002:a17:903:4cd:b0:1bf:4185:ed1c with SMTP id jm13-20020a17090304cd00b001bf4185ed1cmr8172600plb.43.1692767784368; Tue, 22 Aug 2023 22:16:24 -0700 (PDT) Received: from stoup.. ([2602:47:d483:7301:4e3c:f4a4:b92a:b5ab]) by smtp.gmail.com with ESMTPSA id 5-20020a170902c24500b001bf044dc1a6sm9969402plg.39.2023.08.22.22.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 22:16:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: deller@gmx.de Subject: [PATCH v4 06/10] linux-user: Map unsupported signals to an out-of-bounds value Date: Tue, 22 Aug 2023 22:16:11 -0700 Message-Id: <20230823051615.1297706-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823051615.1297706-1-richard.henderson@linaro.org> References: <20230823051615.1297706-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Do not return a valid signal number in one domain when given an invalid signal number in the other domain. Signed-off-by: Richard Henderson --- linux-user/signal.c | 72 ++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 73f40699ad..9d16e3c8c5 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -45,9 +45,8 @@ abi_ulong default_sigreturn; abi_ulong default_rt_sigreturn; /* - * 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 + * System includes define _NSIG as SIGRTMAX + 1, but qemu (like the kernel) + * defines TARGET_NSIG as TARGET_SIGRTMAX and the first signal is 1. * Signal number 0 is reserved for use as kill(pid, 0), to test whether * a process exists without sending it a signal. */ @@ -58,7 +57,6 @@ static uint8_t host_to_target_signal_table[_NSIG] = { #define MAKE_SIG_ENTRY(sig) [sig] = TARGET_##sig, MAKE_SIGNAL_LIST #undef MAKE_SIG_ENTRY - /* next signals stay the same */ }; static uint8_t target_to_host_signal_table[TARGET_NSIG + 1]; @@ -66,18 +64,24 @@ 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 < 1 || sig >= _NSIG) { + if (sig < 1) { return sig; } + if (sig >= _NSIG) { + return TARGET_NSIG + 1; + } return host_to_target_signal_table[sig]; } /* valid sig is between 1 and TARGET_NSIG */ int target_to_host_signal(int sig) { - if (sig < 1 || sig > TARGET_NSIG) { + if (sig < 1) { return sig; } + if (sig > TARGET_NSIG) { + return _NSIG; + } return target_to_host_signal_table[sig]; } @@ -508,48 +512,48 @@ static int core_dump_signal(int sig) static void signal_table_init(void) { - int host_sig, target_sig, count; + int hsig, tsig, count; /* * 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 multiplexed - * over a single host signal. + * until we run out of host realtime signals. Glibc uses the lower 2 + * RT signals and (hopefully) nobody uses the upper ones. + * This is why SIGRTMIN (34) is generally greater than __SIGRTMIN (32). + * To fix this properly we would need to do manual signal delivery + * multiplexed over a single host signal. * Attempts for configure "missing" signals via sigaction will be * silently ignored. */ - for (host_sig = SIGRTMIN; host_sig <= SIGRTMAX; host_sig++) { - target_sig = host_sig - SIGRTMIN + TARGET_SIGRTMIN; - if (target_sig <= TARGET_NSIG) { - host_to_target_signal_table[host_sig] = target_sig; + for (hsig = SIGRTMIN; hsig <= SIGRTMAX; hsig++) { + tsig = hsig - SIGRTMIN + TARGET_SIGRTMIN; + if (tsig <= TARGET_NSIG) { + host_to_target_signal_table[hsig] = tsig; } } - /* generate signal conversion tables */ - for (target_sig = 1; target_sig <= TARGET_NSIG; target_sig++) { - target_to_host_signal_table[target_sig] = _NSIG; /* poison */ - } - for (host_sig = 1; host_sig < _NSIG; host_sig++) { - if (host_to_target_signal_table[host_sig] == 0) { - host_to_target_signal_table[host_sig] = host_sig; - } - target_sig = host_to_target_signal_table[host_sig]; - if (target_sig <= TARGET_NSIG) { - target_to_host_signal_table[target_sig] = host_sig; + /* Invert the mapping that has already been assigned. */ + for (hsig = 1; hsig < _NSIG; hsig++) { + tsig = host_to_target_signal_table[hsig]; + if (tsig) { + assert(target_to_host_signal_table[tsig] == 0); + target_to_host_signal_table[tsig] = hsig; } } - if (trace_event_get_state_backends(TRACE_SIGNAL_TABLE_INIT)) { - for (target_sig = 1, count = 0; target_sig <= TARGET_NSIG; target_sig++) { - if (target_to_host_signal_table[target_sig] == _NSIG) { - count++; - } + /* Map everything else out-of-bounds. */ + for (hsig = 1; hsig < _NSIG; hsig++) { + if (host_to_target_signal_table[hsig] == 0) { + host_to_target_signal_table[hsig] = TARGET_NSIG + 1; } - trace_signal_table_init(count); } + for (count = 0, tsig = 1; tsig <= TARGET_NSIG; tsig++) { + if (target_to_host_signal_table[tsig] == 0) { + target_to_host_signal_table[tsig] = _NSIG; + count++; + } + } + + trace_signal_table_init(count); } void signal_init(void)