Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4637458imm; Mon, 14 May 2018 10:20:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZogsLg53K3AWkYJX4g1TansqfXXKqXvtFW5SETKGswNV2rNS14ITYf/VmVEwhtJ40/j7l2z X-Received: by 2002:a62:4353:: with SMTP id q80-v6mr11453652pfa.228.1526318420869; Mon, 14 May 2018 10:20:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526318420; cv=none; d=google.com; s=arc-20160816; b=UPiMVsSz3Tzrh9f98qInbjKT7X2ec7EUgRPqgAARQUn0CIzmw6ZGB1QEWGAoJghZno 7UjlcN3CZOS3ldpiu7s42MPdRybyesMx4CnU+8H1hYB3ezUjcK1Iu69F06yc7SrtFXKU VOsoNeVPLth0XQHgd4UX0+j4Z7bCMWaWIh5mTLydJzSAgYWevPBkynJtJgtwoJUU4zAq ws2PDNDni9MMEi9hRtlOPFb1WXh0lQfyyO9LuXL78Y7QUdidsPZTWYFjebWpV6G7i3xd 8cvNOmyS3cGU68smuAc2t/pbp2Qd28gANwQyho5mEP41z0HoKhdPdXzbR2ElqJJXr3Wj S0lQ== 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:message-id :subject:cc:to:from:date:arc-authentication-results; bh=MHKYFVdyrITEYUPvVfoMXiCuqgLxfOF8P2Qf8wEiUlg=; b=VUAvKz8k6xFBGYEM3EVpyTmc9WwPkTifmd+rOz+RiBdvv5e3i5NZqZEVCRNiUIGsDe 6dmx/ZDI0gYsK2HwaPjAL50CySKb+4PmJEwLvvR0fPAxKUSupwLswl8W9E2FLPe5+PSf aVEGE1ZfhRKGKnx6YT/4CcXoLAZqqf0yaFsxlph1L+M+bci1TETop2aOTU1ONA9Fq3rc ESSfNA54GEab4urKSKRwaUvUdg+ehkrIUA+1soFKZArwDdK5txm6+mKpsSqomfwpMQeW /SjWX7F3BpG5a/OKsAYPrGx+T8Siqr7pVhef9hPNDvBweRRlfoKxJ7fju+YKJtcpnfWp Y0dw== 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 g3-v6si7567154pgf.498.2018.05.14.10.20.06; Mon, 14 May 2018 10:20:20 -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; 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 S1754523AbeENPt5 (ORCPT + 99 others); Mon, 14 May 2018 11:49:57 -0400 Received: from 9pmail.ess.barracuda.com ([64.235.154.211]:39779 "EHLO 9pmail.ess.barracuda.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752039AbeENPtz (ORCPT ); Mon, 14 May 2018 11:49:55 -0400 Received: from mipsdag02.mipstec.com (mail2.mips.com [12.201.5.32]) by mx1401.ess.rzc.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=NO); Mon, 14 May 2018 15:49:51 +0000 Received: from [10.20.78.96] (10.20.78.96) by mipsdag02.mipstec.com (10.20.40.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1415.2; Mon, 14 May 2018 08:50:19 -0700 Date: Mon, 14 May 2018 16:49:43 +0100 From: "Maciej W. Rozycki" To: James Hogan CC: Ralf Baechle , , , Subject: [PATCH] MIPS: Fix ptrace(2) PTRACE_PEEKUSR and PTRACE_POKEUSR accesses to o32 FGRs Message-ID: User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-Originating-IP: [10.20.78.96] X-ClientProxiedBy: mipsdag02.mipstec.com (10.20.40.47) To mipsdag02.mipstec.com (10.20.40.47) X-BESS-ID: 1526312991-321457-24569-35339-1 X-BESS-VER: 2018.6-r1805102334 X-BESS-Apparent-Source-IP: 12.201.5.32 X-BESS-Outbound-Spam-Score: 0.01 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.192979 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.00 BSF_BESS_OUTBOUND META: BESS Outbound 0.01 BSF_SC0_SA_TO_FROM_DOMAIN_MATCH META: Sender Domain Matches Recipient Domain X-BESS-Outbound-Spam-Status: SCORE=0.01 using account:ESS59374 scores of KILL_LEVEL=7.0 tests=BSF_BESS_OUTBOUND, BSF_SC0_SA_TO_FROM_DOMAIN_MATCH X-BESS-BRTS-Status: 1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Check the TIF_32BIT_FPREGS task setting of the tracee rather than the tracer in determining the layout of floating-point general registers in the floating-point context, correcting access to odd-numbered registers for o32 tracees where the setting disagrees between the two processes. Cc: stable@vger.kernel.org # 3.14+ Fixes: 597ce1723e0f ("MIPS: Support for 64-bit FP with O32 binaries") Signed-off-by: Maciej W. Rozycki --- Hi, These are not the usual requests used by GDB to access the floating-point context, which is likely why it went unnoticed so long. They are only used as a fallback in the case where PTRACE_GETFPREGS and PTRACE_SETFPREGS requests are not supported, i.e. with ancient kernels. However to verify an unrelated GDB bug fix I have tweaked GDB to always use PTRACE_PEEKUSR and PTRACE_POKEUSR, and then discovered this issue in native GDB regression testing, as it showed regressions from corrupt FGR contents across numerous tests compared to the usual results. This fix removed those regressions then. Not being typically used does not mean we ought to keep the interface broken. Therefore please apply. Maciej --- arch/mips/kernel/ptrace.c | 4 ++-- arch/mips/kernel/ptrace32.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) linux-mips-ptrace-test-thread-flag.diff Index: linux/arch/mips/kernel/ptrace.c =================================================================== --- linux.orig/arch/mips/kernel/ptrace.c 2018-05-12 22:52:19.000000000 +0100 +++ linux/arch/mips/kernel/ptrace.c 2018-05-12 22:56:07.893993000 +0100 @@ -1059,7 +1059,7 @@ long arch_ptrace(struct task_struct *chi fregs = get_fpu_regs(child); #ifdef CONFIG_32BIT - if (test_thread_flag(TIF_32BIT_FPREGS)) { + if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) { /* * The odd registers are actually the high * order bits of the values stored in the even @@ -1154,7 +1154,7 @@ long arch_ptrace(struct task_struct *chi init_fp_ctx(child); #ifdef CONFIG_32BIT - if (test_thread_flag(TIF_32BIT_FPREGS)) { + if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) { /* * The odd registers are actually the high * order bits of the values stored in the even Index: linux-mipsswbrd038/arch/mips/kernel/ptrace32.c =================================================================== --- linux-mipsswbrd038.orig/arch/mips/kernel/ptrace32.c 2018-05-12 22:52:19.000000000 +0100 +++ linux-mipsswbrd038/arch/mips/kernel/ptrace32.c 2018-05-12 22:55:20.906637000 +0100 @@ -99,7 +99,7 @@ long compat_arch_ptrace(struct task_stru break; } fregs = get_fpu_regs(child); - if (test_thread_flag(TIF_32BIT_FPREGS)) { + if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) { /* * The odd registers are actually the high * order bits of the values stored in the even @@ -212,7 +212,7 @@ long compat_arch_ptrace(struct task_stru sizeof(child->thread.fpu)); child->thread.fpu.fcr31 = 0; } - if (test_thread_flag(TIF_32BIT_FPREGS)) { + if (test_tsk_thread_flag(child, TIF_32BIT_FPREGS)) { /* * The odd registers are actually the high * order bits of the values stored in the even