Received: by 10.223.185.116 with SMTP id b49csp6399196wrg; Wed, 28 Feb 2018 08:46:30 -0800 (PST) X-Google-Smtp-Source: AH8x224xTXbvhj9kaL66apE8fxHyt+HE3zOC4hq5shx5nQroL4zGM179JwQUcCstwHccA1uPYMue X-Received: by 2002:a17:902:48:: with SMTP id 66-v6mr18092855pla.288.1519836390379; Wed, 28 Feb 2018 08:46:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519836390; cv=none; d=google.com; s=arc-20160816; b=jjZDwGljUmzYru8QnJeVuuoqkQdRSTbuac+xqAW96kSgumgz34BSIepRsqH+akK+YX xYBdDzNmJiCcua79TGm0PTjf3QmPrrdV1R/ahmdTiEOdnaOeerACCOxwmbOGE+IF5W7N 19XMKsjzRCcI3icRrXdYgj0bgwZrVQYE5UOa7tYMns12FK0+nBJhtRwVVuo0zDCT8GZ9 oWE+3JOz4fsmXoHerDRxfzFTIHh0MnclUw7nYGb02b+FsgNl2L9QtwYJrNDedotSR8iO WRkHExS8b1PAgUOBl7MXY4cblGQnfsEOP3mPhmq3JAbkPwRzF36LyLGdlX2HK9AYU0QY xisA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=Pa6evtyhutOpFEj6eZw70PMj+p4oU3rr+7yu5k8IbdQ=; b=ZlrXIw6Y1SGVyUwp8DwIyN5KaGZKPjAn/THtJUz8nTijkIPxSltI1aOYxvNRAk8l8l SzvNYuaKBxKRx7PXGvkxeG5k7IvW0cb8gKdZJnByk504KNqy9hDyYbuPh7HlyvBROKKS u3NCofvCmGe+ca/uSxO6ZChyWk/r/GOyKDpq5LFNAHhamQez1wL4xLx4D4ldy9gXszsV 8JJh6S+ZRC/XZj4AzAVgyenD+TlvKP9ymSjQpqh+Zi689MDkG0PnG9ZpN/QMgUmX3Mpo 6ZC5ZvDcNRng/34xWXosIUJs3cQwDcNLF8I5pW0lnO3S1Pfb97H70GYEBJQ7dQ8K9/FV g9gg== ARC-Authentication-Results: i=1; mx.google.com; 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 64si1229050pgi.67.2018.02.28.08.46.15; Wed, 28 Feb 2018 08:46:30 -0800 (PST) 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; 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 S932409AbeB1QpP (ORCPT + 99 others); Wed, 28 Feb 2018 11:45:15 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34665 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932236AbeB1QAd (ORCPT ); Wed, 28 Feb 2018 11:00:33 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1er3Yt-0006Xg-GE; Wed, 28 Feb 2018 15:22:31 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Yg-0008Vz-2F; Wed, 28 Feb 2018 15:22:18 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, linux-mips@linux-mips.org, "Paul Burton" , "Ralf Baechle" Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 094/254] MIPS: prevent FP context set via ptrace being discarded In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.55-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Paul Burton commit ac9ad83bc318635ed7496e9dff30beaa522eaec7 upstream. If a ptracee has not used the FPU and the ptracer sets its FP context using PTRACE_POKEUSR, PTRACE_SETFPREGS or PTRACE_SETREGSET then that context will be discarded upon either the ptracee using the FPU or a further write to the context via ptrace. Prevent this loss by recording that the task has "used" math once its FP context has been written to. The context initialisation code that was present for the PTRACE_POKEUSR case is reused for the other 2 cases to provide consistent behaviour for the different ptrace requests. Signed-off-by: Paul Burton Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/9166/ Signed-off-by: Ralf Baechle Signed-off-by: Ben Hutchings --- arch/mips/kernel/ptrace.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) --- a/arch/mips/kernel/ptrace.c +++ b/arch/mips/kernel/ptrace.c @@ -47,6 +47,26 @@ #define CREATE_TRACE_POINTS #include +static void init_fp_ctx(struct task_struct *target) +{ + /* If FP has been used then the target already has context */ + if (tsk_used_math(target)) + return; + + /* Begin with data registers set to all 1s... */ + memset(&target->thread.fpu.fpr, ~0, sizeof(target->thread.fpu.fpr)); + + /* ...and FCSR zeroed */ + target->thread.fpu.fcr31 = 0; + + /* + * Record that the target has "used" math, such that the context + * just initialised, and any modifications made by the caller, + * aren't discarded. + */ + set_stopped_child_used_math(target); +} + /* * Called by kernel/ptrace.c when detaching.. * @@ -143,6 +163,7 @@ int ptrace_setfpregs(struct task_struct if (!access_ok(VERIFY_READ, data, 33 * 8)) return -EIO; + init_fp_ctx(child); fregs = get_fpu_regs(child); for (i = 0; i < 32; i++) { @@ -440,6 +461,8 @@ static int fpr_set(struct task_struct *t /* XXX fcr31 */ + init_fp_ctx(target); + if (sizeof(target->thread.fpu.fpr[i]) == sizeof(elf_fpreg_t)) return user_regset_copyin(&pos, &count, &kbuf, &ubuf, &target->thread.fpu, @@ -678,12 +701,7 @@ long arch_ptrace(struct task_struct *chi case FPR_BASE ... FPR_BASE + 31: { union fpureg *fregs = get_fpu_regs(child); - if (!tsk_used_math(child)) { - /* FP not yet used */ - memset(&child->thread.fpu, ~0, - sizeof(child->thread.fpu)); - child->thread.fpu.fcr31 = 0; - } + init_fp_ctx(child); #ifdef CONFIG_32BIT if (test_thread_flag(TIF_32BIT_FPREGS)) { /*