Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10431442ybi; Wed, 24 Jul 2019 23:05:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqzRy1IjnY2GhKr6q7TWFpJf31WSrRY0PBN6jxgIbwm/v0w3P24DvxxVkaV8eWC9tTSH9RLB X-Received: by 2002:a17:902:2aab:: with SMTP id j40mr38239243plb.76.1564034758830; Wed, 24 Jul 2019 23:05:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564034758; cv=none; d=google.com; s=arc-20160816; b=jO3017c4FpkrD31lbsD+55XP8mjOivYKNuGt8zdFtq3Nb6Ovd1qaTvcDwgjYq6+IB2 IFDPGxKWrkPsISgTiHxJ40/By/3kzw+zwnuZySwIAj/IJonWl3h9HCnNNgDFZ15vDo7A jrsTjNsUOUmMLK/XGtrcohBuQU3MU7UUOMc8ljl9gkyXgP98gxti5SDhyrHUwSn0mc/+ jAuUmIUCWSccxPKAUWzqkIKfbp0Jyl11QDYxBRaXAHENutS+afwGw3s1K/3Zl2v0Z09k aubzOxILhnFn16VJIAKCszu26p7enNiRyQ3DTbuCZqaqQ8OW7Av+mUSgRTQ8NNT3F8BQ 9rIw== 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=Wlh1VwTzCMbwbzKq2g9O0f9RMhQJnW0bAoBhvtZH8iU=; b=1CZXq+yF/vAHSGaDPHkk0zrKNgr0bO6RsEgEOVBxJho9blynU4Db0zlghzQ2jjnq/6 m/4/2sQvukziNeShh33aBZzxXqdx1wR1ZwUn9iWOIAFl822lH0NWdxWz+vzhIiaUBDJR V8lHt4JuXMDU6cKOna2IbKIEBinorBE9sSy0RsqKYUnuzJkD3bs+ttByGsHwk4uPxPJQ Rcm/KU7C3hBPVamsdK988W8mDmlkjhiU8fROlkB8n7RcK0/qZXLxwima3xK8ktSth+R1 t3py+wbHdwo9nC2qZa6H+rcFKnmGWN3qKert59Aq2+xLm4iC5oSzAoDTlbwFTAxfbNhY eNfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=g9JwG2N+; 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 o21si14663271pll.169.2019.07.24.23.05.44; Wed, 24 Jul 2019 23:05: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=g9JwG2N+; 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 S2391462AbfGYFqj (ORCPT + 99 others); Thu, 25 Jul 2019 01:46:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:34278 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391443AbfGYFqc (ORCPT ); Thu, 25 Jul 2019 01:46:32 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 D94CE20657; Thu, 25 Jul 2019 05:46:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564033592; bh=jzbZqHBVRXZiqnxEGm7vZE5GcK2Hnq/boLbxtVC6yGo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g9JwG2N+aCbwmp2/hpa2K5qokQvTc9TE7WWk4jsW65SxwiYnmEZX6d3pHsS+D3P1Y wpRewUGH0bVLdLvyFggjjCOjOkpJYIenMaaVKGrHWQahcZDHu8TQJGjLLA5ufumpah owz7sFC3i5n1qZBRDoLQIwhvOQXfy988vmeQ9iEI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jeroen Roovers , Rolf Eike Beer , Helge Deller Subject: [PATCH 4.19 254/271] parisc: Fix kernel panic due invalid values in IAOQ0 or IAOQ1 Date: Wed, 24 Jul 2019 21:22:03 +0200 Message-Id: <20190724191716.967977296@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191655.268628197@linuxfoundation.org> References: <20190724191655.268628197@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Helge Deller commit 10835c854685393a921b68f529bf740fa7c9984d upstream. On parisc the privilege level of a process is stored in the lowest two bits of the instruction pointers (IAOQ0 and IAOQ1). On Linux we use privilege level 0 for the kernel and privilege level 3 for user-space. So userspace should not be allowed to modify IAOQ0 or IAOQ1 of a ptraced process to change it's privilege level to e.g. 0 to try to gain kernel privileges. This patch prevents such modifications by always setting the two lowest bits to one (which relates to privilege level 3 for user-space) if IAOQ0 or IAOQ1 are modified via ptrace calls in the native and compat ptrace paths. Link: https://bugs.gentoo.org/481768 Reported-by: Jeroen Roovers Cc: Tested-by: Rolf Eike Beer Signed-off-by: Helge Deller Signed-off-by: Greg Kroah-Hartman --- arch/parisc/kernel/ptrace.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) --- a/arch/parisc/kernel/ptrace.c +++ b/arch/parisc/kernel/ptrace.c @@ -167,6 +167,9 @@ long arch_ptrace(struct task_struct *chi if ((addr & (sizeof(unsigned long)-1)) || addr >= sizeof(struct pt_regs)) break; + if (addr == PT_IAOQ0 || addr == PT_IAOQ1) { + data |= 3; /* ensure userspace privilege */ + } if ((addr >= PT_GR1 && addr <= PT_GR31) || addr == PT_IAOQ0 || addr == PT_IAOQ1 || (addr >= PT_FR0 && addr <= PT_FR31 + 4) || @@ -228,16 +231,18 @@ long arch_ptrace(struct task_struct *chi static compat_ulong_t translate_usr_offset(compat_ulong_t offset) { - if (offset < 0) - return sizeof(struct pt_regs); - else if (offset <= 32*4) /* gr[0..31] */ - return offset * 2 + 4; - else if (offset <= 32*4+32*8) /* gr[0..31] + fr[0..31] */ - return offset + 32*4; - else if (offset < sizeof(struct pt_regs)/2 + 32*4) - return offset * 2 + 4 - 32*8; + compat_ulong_t pos; + + if (offset < 32*4) /* gr[0..31] */ + pos = offset * 2 + 4; + else if (offset < 32*4+32*8) /* fr[0] ... fr[31] */ + pos = (offset - 32*4) + PT_FR0; + else if (offset < sizeof(struct pt_regs)/2 + 32*4) /* sr[0] ... ipsw */ + pos = (offset - 32*4 - 32*8) * 2 + PT_SR0 + 4; else - return sizeof(struct pt_regs); + pos = sizeof(struct pt_regs); + + return pos; } long compat_arch_ptrace(struct task_struct *child, compat_long_t request, @@ -281,9 +286,12 @@ long compat_arch_ptrace(struct task_stru addr = translate_usr_offset(addr); if (addr >= sizeof(struct pt_regs)) break; + if (addr == PT_IAOQ0+4 || addr == PT_IAOQ1+4) { + data |= 3; /* ensure userspace privilege */ + } if (addr >= PT_FR0 && addr <= PT_FR31 + 4) { /* Special case, fp regs are 64 bits anyway */ - *(__u64 *) ((char *) task_regs(child) + addr) = data; + *(__u32 *) ((char *) task_regs(child) + addr) = data; ret = 0; } else if ((addr >= PT_GR1+4 && addr <= PT_GR31+4) ||