Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2273126imm; Mon, 28 May 2018 05:10:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqJeaAtLgzw9FO58/VWE2wVIRv3nn62KKchk4ulGrHNJLq77i7UK46pzWy9n1CUSnQKC3eI X-Received: by 2002:a63:7a03:: with SMTP id v3-v6mr10128165pgc.285.1527509458394; Mon, 28 May 2018 05:10:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527509458; cv=none; d=google.com; s=arc-20160816; b=q51+cFYY/Fnn3PW5XWXRDVSPWSjNpqU+O3t0tM/Cxsi6TCB8HoimTNtICw6WpUK+2t 7mg8pJ7qpo+YT+qY5WXVoo48vOG58sQ9Iqh4m1nmbMCWItczbPIbRX9LOUGwJKL07thu CSpmTBHg9ZlQH8BZSxqPHNAfFZtzRqu4SM9YKjdQwK0oCUAohsDEJarILf0NNRoc7DvB SDtkJS9hgaJcUyV3lQvE2jTTVCqnvL8Pm+fFoV4AeWzOX6y8Il/Srutbdd5rPFeODwaz AfkoDwKO+tzkcvyjLSa5LSNBBCaPGvdGi83bxno0ij8FpYVtHJiudE6oR2F0VyQL5KI3 HLkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=0M2pa0zHGT1vJ2K5ilpnRGDOVRl1FXfYk7HatR7jVsI=; b=EsvUUN6ANwcBvvqhuikqBCa4gwF2lGBpaloDQOnXVCzD/ckiilSrReYbd6LU3rSzuv tj6tRakC0VXTf/VqrYxareSf9o5ul9WjU6RVJDMHGHD4npjz9tA/Q/fcqqxBej8znWOi tL3tzh4DNt8RdKDs9q/KjDFmHatSXMI0lP2DWnYdS/l4orjLG4yHAUBs86DaWN60JRDT lbgAJ7jzpu88Wt5ZL6SUVxw0Lo3YPlbkSJQouDWfN8V2NqBz0vBXo3uZHmUoNEyVAQpm IngtCcIKo+BiSVtMzl2/l3xV6ICb21NQkqrxszIH0g3OjJewmIFo96vV/nDwgAv1G77L bnug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xHhY0ZJB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k185-v6si29683259pfc.361.2018.05.28.05.10.43; Mon, 28 May 2018 05:10:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xHhY0ZJB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1165025AbeE1LEl (ORCPT + 99 others); Mon, 28 May 2018 07:04:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:51556 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1164993AbeE1LE1 (ORCPT ); Mon, 28 May 2018 07:04:27 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5EAAF2087E; Mon, 28 May 2018 11:04:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527505466; bh=zPJ5We2s1tTVTnUx6DuGrawXm/zWI8FOqgcj00xqjzE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xHhY0ZJB1gpFqOSvnRy7Rh5XLPqv8Mdo+g9FlWEwEYuyAn8otHKpL5SrO4Ob5Dz5u H1/+qtyJiKHNlqeekVyaNFzd1rMnQhpZEHw3AEGTpXYwXqlWaVb7FGP9hA8FgxEg4H TmKTFzfF9/6wmYQHYNkIBnbxvnv8D/1iaLltoeYc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, James Hogan , "Maciej W. Rozycki" , Ralf Baechle , linux-mips@linux-mips.org Subject: [PATCH 4.16 005/272] MIPS: ptrace: Expose FIR register through FP regset Date: Mon, 28 May 2018 12:00:38 +0200 Message-Id: <20180528100240.636170749@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100240.256525891@linuxfoundation.org> References: <20180528100240.256525891@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Maciej W. Rozycki commit 71e909c0cdad28a1df1fa14442929e68615dee45 upstream. Correct commit 7aeb753b5353 ("MIPS: Implement task_user_regset_view.") and expose the FIR register using the unused 4 bytes at the end of the NT_PRFPREG regset. Without that register included clients cannot use the PTRACE_GETREGSET request to retrieve the complete FPU register set and have to resort to one of the older interfaces, either PTRACE_PEEKUSR or PTRACE_GETFPREGS, to retrieve the missing piece of data. Also the register is irreversibly missing from core dumps. This register is architecturally hardwired and read-only so the write path does not matter. Ignore data supplied on writes then. Fixes: 7aeb753b5353 ("MIPS: Implement task_user_regset_view.") Signed-off-by: James Hogan Signed-off-by: Maciej W. Rozycki Cc: Ralf Baechle Cc: linux-mips@linux-mips.org Cc: # 3.13+ Patchwork: https://patchwork.linux-mips.org/patch/19273/ Signed-off-by: James Hogan Signed-off-by: Greg Kroah-Hartman --- arch/mips/kernel/ptrace.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) --- a/arch/mips/kernel/ptrace.c +++ b/arch/mips/kernel/ptrace.c @@ -463,7 +463,7 @@ static int fpr_get_msa(struct task_struc /* * Copy the floating-point context to the supplied NT_PRFPREG buffer. * Choose the appropriate helper for general registers, and then copy - * the FCSR register separately. + * the FCSR and FIR registers separately. */ static int fpr_get(struct task_struct *target, const struct user_regset *regset, @@ -471,6 +471,7 @@ static int fpr_get(struct task_struct *t void *kbuf, void __user *ubuf) { const int fcr31_pos = NUM_FPU_REGS * sizeof(elf_fpreg_t); + const int fir_pos = fcr31_pos + sizeof(u32); int err; if (sizeof(target->thread.fpu.fpr[0]) == sizeof(elf_fpreg_t)) @@ -483,6 +484,12 @@ static int fpr_get(struct task_struct *t err = user_regset_copyout(&pos, &count, &kbuf, &ubuf, &target->thread.fpu.fcr31, fcr31_pos, fcr31_pos + sizeof(u32)); + if (err) + return err; + + err = user_regset_copyout(&pos, &count, &kbuf, &ubuf, + &boot_cpu_data.fpu_id, + fir_pos, fir_pos + sizeof(u32)); return err; } @@ -531,7 +538,8 @@ static int fpr_set_msa(struct task_struc /* * Copy the supplied NT_PRFPREG buffer to the floating-point context. * Choose the appropriate helper for general registers, and then copy - * the FCSR register separately. + * the FCSR register separately. Ignore the incoming FIR register + * contents though, as the register is read-only. * * We optimize for the case where `count % sizeof(elf_fpreg_t) == 0', * which is supposed to have been guaranteed by the kernel before @@ -545,6 +553,7 @@ static int fpr_set(struct task_struct *t const void *kbuf, const void __user *ubuf) { const int fcr31_pos = NUM_FPU_REGS * sizeof(elf_fpreg_t); + const int fir_pos = fcr31_pos + sizeof(u32); u32 fcr31; int err; @@ -572,6 +581,11 @@ static int fpr_set(struct task_struct *t ptrace_setfcr31(target, fcr31); } + if (count > 0) + err = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf, + fir_pos, + fir_pos + sizeof(u32)); + return err; }