From patchwork Tue Dec 21 02:50:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 526587 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp4675014imb; Mon, 20 Dec 2021 18:54:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJwdFvt+7XYfjR+cEGEPzFPTivcRCN2gtsm8P1jLiCmOBieW+fuk53C1Zn9gai+3yT2N5MrW X-Received: by 2002:a25:311:: with SMTP id 17mr1776498ybd.483.1640055241743; Mon, 20 Dec 2021 18:54:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640055241; cv=none; d=google.com; s=arc-20160816; b=uvZrR26hZRbFd5fA7rSUi5uC6Nv3XJ7hacubB7DaDaWEI07ctj+7q4tZGAlwlinmQw /K3y35opm8wseXwMMWHpYtZl8nynhbL/wkzKHPDBnvJnqddpo+ZIstcEn+KQ1TcWT54t 1iKlKq9iP/iaVjgO4rw1wAbgQldfVXappbF+trrrrPOfD3IJtzQOVhnFswVhgdr2T+R7 L0xTqsr/xmBwCqeE6Dq69Gx34b/NB2SZrciefxdwuUR6/EpYw1KH85M2LooWUNluT6Ao QhO9TyIJ1dqQ/LQx36092IyRgCNvQQVHJK0Vsf12LbIHBOzm9zu1tXww/iS+tE+llnC7 8bNw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=HbNBQfasK4f+xfMQiEwPjjsKiwcmSRl4Jt7JCBlYZlo=; b=jbSW2CK2+L3ZGr+1mrMuE05GmIuGtb7Ibj9yH7TZ70iTSLjc/8v5bhOMQYAVebpKju CWjLjZJAwopGo0bPXxRGHDCiCWvPgCS8OlVwOkTeckmrX8qMITUQVJ9ICEZC6abMdPnY wqRhvtS25C6Q3K/CptzSE3zqxlhue/EBhkijr2P+w51GSKQ+Mb3XN31fewJ0tV66sjG6 UVo8JXDJ/FlnitK8LZcVoPRVZukXCwJTWoTr3QgwIU/a5xm1xHvIRnaEvbMcacI5mo4l ssx/yAsPLb7JE0FV0pECoyyyO3oRfdfe3QyQQTLenziMyMVlaW6LIJGESZ02/X07iEXQ SJxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=NfUfLCNI; 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=fail (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 s13si20161298ybp.359.2021.12.20.18.54.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 Dec 2021 18:54:01 -0800 (PST) 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=fail header.i=@linaro.org header.s=google header.b=NfUfLCNI; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mzVHt-00080B-8L for patch@linaro.org; Mon, 20 Dec 2021 21:54:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54222) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzVEJ-0003bU-D7 for qemu-devel@nongnu.org; Mon, 20 Dec 2021 21:50:19 -0500 Received: from [2607:f8b0:4864:20::533] (port=33724 helo=mail-pg1-x533.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mzVEH-0000AC-Jz for qemu-devel@nongnu.org; Mon, 20 Dec 2021 21:50:18 -0500 Received: by mail-pg1-x533.google.com with SMTP id f125so11082179pgc.0 for ; Mon, 20 Dec 2021 18:50:17 -0800 (PST) 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=HbNBQfasK4f+xfMQiEwPjjsKiwcmSRl4Jt7JCBlYZlo=; b=NfUfLCNIjMo8KMEKTAiv2uAEDlt0axISwbzsiOaD+OSocglWRo4Tx7kAlBR4tQfmml pvFCLm446w9QXbadzxKNpt034iCGmw+oX1New3O2pexBhh4ef9Qdylr3wtRN6alY6VXQ byyMj6mklHJp/LBIOz6J8Sw5vFb2B5PtYga/F0eyk2Rg24BPpRHr8DqMnO0x8162ovnd xv5lljWuTZ+9fZCZPq1O2Dd03SSNMICnoM4z/4RYHY2MufJ9Usf9oRJBORhXuQkWb+Y0 zp9YkyNdD3N5x8iCoXyJeOk9PQkvpxGe0UbvVRCXx8b8DKB/Ac1gS7uL0w216MIVwsYc 60/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HbNBQfasK4f+xfMQiEwPjjsKiwcmSRl4Jt7JCBlYZlo=; b=12AaVBMhuHzR7N59lDJsgCotA+ZM/ezuWPN/VjENZIfvtIJq6K49MCMWD0z6HdXd/j hFx9DOzQTt0Iyrt90YqGQ+Ihqpanciocg6l6Ufv3Khi9isbkhexb9YMU2P/9ZzTH27Iw pwNEt0UDvs/MeUsbsdGr3dntFb/UkIORWnPQLOolPT9S8V6/+fxYZRl7fnzHp1iCKuTu IHWgcN36xoo4aQEcZcs8y3cxhQalJooFxTzeBVnMoQtNH4qfLsRycRqIZxaul5ceZX7s MFs5zxA6EGkttLnwrK2uoVmcpExvvfxTTvQPIyWATWZuAXxD9IaNlR406Ej3q1PPehRG o7Ug== X-Gm-Message-State: AOAM532cWvBmcEC0hILwS6kF/qxaCVn4W2aSZFILlz4QnK5nGK3r1NzK S/GiMd7Dys1/oOCnK2TaRO+P6lZ93oCTiA== X-Received: by 2002:a63:4c45:: with SMTP id m5mr1013980pgl.105.1640055016375; Mon, 20 Dec 2021 18:50:16 -0800 (PST) Received: from localhost.localdomain ([156.19.246.20]) by smtp.gmail.com with ESMTPSA id bg23sm694025pjb.24.2021.12.20.18.50.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Dec 2021 18:50:16 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 2/7] linux-user/nios2: Fixes for signal frame setup Date: Mon, 20 Dec 2021 18:50:07 -0800 Message-Id: <20211221025012.1057923-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211221025012.1057923-1-richard.henderson@linaro.org> References: <20211221025012.1057923-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::533 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x533.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Cc: Peter Maydell , =?utf-8?q?Alex_Benn=C3=A9e?= , laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Do not confuse host and guest addresses. Lock and unlock the target_rt_sigframe structure in setup_rt_sigframe. Since rt_setup_ucontext always returns 0, drop the return value entirely. This eliminates the only write to the err variable in setup_rt_sigframe. Always copy the siginfo structure. Reviewed-by: Alex Bennée Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- linux-user/nios2/signal.c | 49 ++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/linux-user/nios2/signal.c b/linux-user/nios2/signal.c index a77e8a40f4..adbffe32e3 100644 --- a/linux-user/nios2/signal.c +++ b/linux-user/nios2/signal.c @@ -42,7 +42,7 @@ struct target_rt_sigframe { struct target_ucontext uc; }; -static int rt_setup_ucontext(struct target_ucontext *uc, CPUNios2State *env) +static void rt_setup_ucontext(struct target_ucontext *uc, CPUNios2State *env) { unsigned long *gregs = uc->tuc_mcontext.gregs; @@ -75,8 +75,6 @@ static int rt_setup_ucontext(struct target_ucontext *uc, CPUNios2State *env) __put_user(env->regs[R_GP], &gregs[25]); __put_user(env->regs[R_EA], &gregs[27]); __put_user(env->regs[R_SP], &gregs[28]); - - return 0; } static int rt_restore_ucontext(CPUNios2State *env, struct target_ucontext *uc, @@ -135,8 +133,8 @@ static int rt_restore_ucontext(CPUNios2State *env, struct target_ucontext *uc, return 0; } -static void *get_sigframe(struct target_sigaction *ka, CPUNios2State *env, - size_t frame_size) +static abi_ptr get_sigframe(struct target_sigaction *ka, CPUNios2State *env, + size_t frame_size) { unsigned long usp; @@ -144,7 +142,7 @@ static void *get_sigframe(struct target_sigaction *ka, CPUNios2State *env, usp = target_sigsp(get_sp_from_cpustate(env), ka); /* Verify, is it 32 or 64 bit aligned */ - return (void *)((usp - frame_size) & -8UL); + return (usp - frame_size) & -8; } void setup_rt_frame(int sig, struct target_sigaction *ka, @@ -153,26 +151,25 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, CPUNios2State *env) { struct target_rt_sigframe *frame; - int i, err = 0; + abi_ptr frame_addr; + int i; - frame = get_sigframe(ka, env, sizeof(*frame)); - - if (ka->sa_flags & SA_SIGINFO) { - tswap_siginfo(&frame->info, info); + frame_addr = get_sigframe(ka, env, sizeof(*frame)); + if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) { + force_sigsegv(sig); + return; } + tswap_siginfo(&frame->info, info); + /* Create the ucontext. */ __put_user(0, &frame->uc.tuc_flags); __put_user(0, &frame->uc.tuc_link); target_save_altstack(&frame->uc.tuc_stack, env); - err |= rt_setup_ucontext(&frame->uc, env); + rt_setup_ucontext(&frame->uc, env); for (i = 0; i < TARGET_NSIG_WORDS; i++) { __put_user((abi_ulong)set->sig[i], - (abi_ulong *)&frame->uc.tuc_sigmask.sig[i]); - } - - if (err) { - goto give_sigsegv; + (abi_ulong *)&frame->uc.tuc_sigmask.sig[i]); } /* Set up to return from userspace; jump to fixed address sigreturn @@ -180,19 +177,13 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, env->regs[R_RA] = (unsigned long) (0x1044); /* Set up registers for signal handler */ - env->regs[R_SP] = (unsigned long) frame; - env->regs[4] = (unsigned long) sig; - env->regs[5] = (unsigned long) &frame->info; - env->regs[6] = (unsigned long) &frame->uc; - env->regs[R_EA] = (unsigned long) ka->_sa_handler; - return; + env->regs[R_SP] = frame_addr; + env->regs[4] = sig; + env->regs[5] = frame_addr + offsetof(struct target_rt_sigframe, info); + env->regs[6] = frame_addr + offsetof(struct target_rt_sigframe, uc); + env->regs[R_EA] = ka->_sa_handler; -give_sigsegv: - if (sig == TARGET_SIGSEGV) { - ka->_sa_handler = TARGET_SIG_DFL; - } - force_sigsegv(sig); - return; + unlock_user_struct(frame, frame_addr, 1); } long do_sigreturn(CPUNios2State *env)