Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8128438imu; Tue, 4 Dec 2018 03:30:15 -0800 (PST) X-Google-Smtp-Source: AFSGD/XQSwrxzIIg+mkwtGgfEGtjpS/rvXW5jxBlwuxaEaU18YwW+YLw0O4RQL7RBoNZ/qNqBoz9 X-Received: by 2002:a17:902:a03:: with SMTP id 3mr19822718plo.112.1543923015380; Tue, 04 Dec 2018 03:30:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543923015; cv=none; d=google.com; s=arc-20160816; b=lxDBhgdHzmt1Bb0N5CXktJPkmInnmw7+JBx0kov9PQdBe/qgdkBA7dkQ/9ih2bkIu1 eULGM9/lBQdHTVnfBscQOswxngCWiFw4HVnuN6h8KJULALm1/mmYoekaIiDiI1XNbfPP +hwtxrIYiOCUzV7psryoDC5cr2TeW9eWsc7V8PjyqHs1HruogZFSqkYgAefANF24z5Bv 7KLiOqnArPmwQbrltCtac4GPo9ghOKNg93YXQhCPE6aEnaE8ZwCeXFVodINFO6vNZOC7 7N7e10VIvSeXaJ3VQZiLX/PJ31e2GL4Xc/n2HrcE7fX8YKi6kscBPVDAU+PnRoFhDaee Nrmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=a4cFiK64tfBYvJrWZ/rMtDB56etllpLJS/ycCbANEgc=; b=mpzGLXRTSbzkgolvk2ia68sx/jTyKmWTJH2ESrIiIekX0IPbOjFX3X2gqvCBCc9cqM 0/Jc9z6XDELzIYgp5kkU/jd0R58DiyNFvKQntR4+v1iBY9AK3TMUT0Brd/rOBFS1NcjW FW0vBhJfrkgbfKQmcCWulHA/xzfjx7p0cus/pua0+N+rNbJ5QPn/w8vjmV6qPU+0eE/w A6gllJBW6iGkarzQGTdVQu9/xIsPvP+em6rsf+MpL3iBnWgKLIHZ+lFTjZeCQ2fcxKZp P6uQdlUTbN2VA5MrbO7mnVEw+clpZz8z9jQZplshLh5fkucg2Oc1vydvGpSzg/ORDIfn L4PQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=D6LWhtPU; 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 p26si18365793pli.225.2018.12.04.03.30.00; Tue, 04 Dec 2018 03:30:15 -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; dkim=pass header.i=@kernel.org header.s=default header.b=D6LWhtPU; 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 S1727080AbeLDL3Y (ORCPT + 99 others); Tue, 4 Dec 2018 06:29:24 -0500 Received: from mail.kernel.org ([198.145.29.99]:42224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726259AbeLDK6D (ORCPT ); Tue, 4 Dec 2018 05:58:03 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (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 342FB20878; Tue, 4 Dec 2018 10:58:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1543921082; bh=4roQqHiaN6SQ3aF7ZjrYpUjkdQn/ZjwSdp3Lhdl41dY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D6LWhtPU89YVoPZ1Dg426boGt9gki8q4q04N/DtLNc+K953UaDwrgT4Xl5qK10s/H VewkdM+C6UZKR0BUo51wTO8XgRZtr8PQN9n+vnkP4WAYklSyKoEy/O36aOBJP3Tzsq SOaaW+px5reJ6a93nbuaAy8Kve2w0UIRMOsiCz8E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Max Filippov Subject: [PATCH 4.19 072/139] xtensa: fix coprocessor part of ptrace_{get,set}xregs Date: Tue, 4 Dec 2018 11:49:13 +0100 Message-Id: <20181204103653.043848392@linuxfoundation.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181204103649.950154335@linuxfoundation.org> References: <20181204103649.950154335@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Max Filippov commit 38a35a78c5e270cbe53c4fef6b0d3c2da90dd849 upstream. Layout of coprocessor registers in the elf_xtregs_t and xtregs_coprocessor_t may be different due to alignment. Thus it is not always possible to copy data between the xtregs_coprocessor_t structure and the elf_xtregs_t and get correct values for all registers. Use a table of offsets and sizes of individual coprocessor register groups to do coprocessor context copying in the ptrace_getxregs and ptrace_setxregs. This fixes incorrect coprocessor register values reading from the user process by the native gdb on an xtensa core with multiple coprocessors and registers with high alignment requirements. Cc: stable@vger.kernel.org Signed-off-by: Max Filippov Signed-off-by: Greg Kroah-Hartman --- arch/xtensa/kernel/ptrace.c | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) --- a/arch/xtensa/kernel/ptrace.c +++ b/arch/xtensa/kernel/ptrace.c @@ -127,12 +127,37 @@ static int ptrace_setregs(struct task_st } +#if XTENSA_HAVE_COPROCESSORS +#define CP_OFFSETS(cp) \ + { \ + .elf_xtregs_offset = offsetof(elf_xtregs_t, cp), \ + .ti_offset = offsetof(struct thread_info, xtregs_cp.cp), \ + .sz = sizeof(xtregs_ ## cp ## _t), \ + } + +static const struct { + size_t elf_xtregs_offset; + size_t ti_offset; + size_t sz; +} cp_offsets[] = { + CP_OFFSETS(cp0), + CP_OFFSETS(cp1), + CP_OFFSETS(cp2), + CP_OFFSETS(cp3), + CP_OFFSETS(cp4), + CP_OFFSETS(cp5), + CP_OFFSETS(cp6), + CP_OFFSETS(cp7), +}; +#endif + static int ptrace_getxregs(struct task_struct *child, void __user *uregs) { struct pt_regs *regs = task_pt_regs(child); struct thread_info *ti = task_thread_info(child); elf_xtregs_t __user *xtregs = uregs; int ret = 0; + int i __maybe_unused; if (!access_ok(VERIFY_WRITE, uregs, sizeof(elf_xtregs_t))) return -EIO; @@ -140,8 +165,13 @@ static int ptrace_getxregs(struct task_s #if XTENSA_HAVE_COPROCESSORS /* Flush all coprocessor registers to memory. */ coprocessor_flush_all(ti); - ret |= __copy_to_user(&xtregs->cp0, &ti->xtregs_cp, - sizeof(xtregs_coprocessor_t)); + + for (i = 0; i < ARRAY_SIZE(cp_offsets); ++i) + ret |= __copy_to_user((char __user *)xtregs + + cp_offsets[i].elf_xtregs_offset, + (const char *)ti + + cp_offsets[i].ti_offset, + cp_offsets[i].sz); #endif ret |= __copy_to_user(&xtregs->opt, ®s->xtregs_opt, sizeof(xtregs->opt)); @@ -157,6 +187,7 @@ static int ptrace_setxregs(struct task_s struct pt_regs *regs = task_pt_regs(child); elf_xtregs_t *xtregs = uregs; int ret = 0; + int i __maybe_unused; if (!access_ok(VERIFY_READ, uregs, sizeof(elf_xtregs_t))) return -EFAULT; @@ -166,8 +197,11 @@ static int ptrace_setxregs(struct task_s coprocessor_flush_all(ti); coprocessor_release_all(ti); - ret |= __copy_from_user(&ti->xtregs_cp, &xtregs->cp0, - sizeof(xtregs_coprocessor_t)); + for (i = 0; i < ARRAY_SIZE(cp_offsets); ++i) + ret |= __copy_from_user((char *)ti + cp_offsets[i].ti_offset, + (const char __user *)xtregs + + cp_offsets[i].elf_xtregs_offset, + cp_offsets[i].sz); #endif ret |= __copy_from_user(®s->xtregs_opt, &xtregs->opt, sizeof(xtregs->opt));