Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9941349ybi; Wed, 24 Jul 2019 12:43:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqwj8PJCpWQiwd+J10ZSUXXyYD1J+HhNgKMLCmOYTye95uA2/FHIgK1ApVTe1cmkvcrmb9Vm X-Received: by 2002:a62:2582:: with SMTP id l124mr12807148pfl.43.1563997439439; Wed, 24 Jul 2019 12:43:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563997439; cv=none; d=google.com; s=arc-20160816; b=LhqaI0pne4SGezcgyGyf+0VSYWu5tvgnjWawo+ulsjqcYjWB63XsZLzHPL22m4echF 36pyubUmDeU45mMLoRLViPQl+ewrbIfYKNDVE8e2NHwRqd9hH0cDOx0l173WLiJIaMsK USNoCMnjyCF2BIqkQS+/+X+emNnG1bpdX1nFLhcyC7nwFw36D2hig5yKjjt/2a7o4gnN kFybBOr+aEzCjwnsipb7A6uykb2lEcfWK7Qs14eq230vqYeDkNqCNzr4Llw1DKlxZpFU RbURa0rDB+ZHaDZuY5QBHV8z6NJmvbsMzeMvenkQB1KRb/zZSdVaHciRZOyGB/+PS7Oj a1iQ== 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=LyfQL3umZtWDYzGuMawigbNFuIZzXlCF/cKUog4zAjhjkeUZqKGO1ZMH2cvPklDGhA 5dA/r6Td4Qej+ZUa4TngrGgrr/G4I6wrsSWm/us762Ws3v6sG93T42FHiEQNjdnOV5Im w9QIdnTDp4oYjwasMUta7YO16RjDBXHf7VwYfVFOepeijO0dCSwtYop8h4uiWBo3UgcM lZv/pW4rpdsQrwrwsO82tQNDx7fRinW9PXZY7TWUF9HsSXZR32USc8AqugAJydurVmaL qPLtRJWS9f72b/bRaHOv8FPEPfr4VNMWBgEgNVydgLukhmdkxGRKgAadzyCDh3q33tNB xAdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MfMTWbwg; 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 u15si17019540pfh.213.2019.07.24.12.43.44; Wed, 24 Jul 2019 12:43:59 -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=MfMTWbwg; 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 S2390357AbfGXTmY (ORCPT + 99 others); Wed, 24 Jul 2019 15:42:24 -0400 Received: from mail.kernel.org ([198.145.29.99]:44024 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389769AbfGXTmX (ORCPT ); Wed, 24 Jul 2019 15:42:23 -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 79DE2214AF; Wed, 24 Jul 2019 19:42:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563997342; bh=jzbZqHBVRXZiqnxEGm7vZE5GcK2Hnq/boLbxtVC6yGo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MfMTWbwgLUGYgkX27mcRhMO1cyTL/9BBsiWpJdVhh+Rqd135MnYFXS0FRKcRLt/61 18aQ+yZp4PqJvON6JWBaVmChKhoWxz5lGRTp1FhA8+L+7oE26wpvQJyO59/D7tK6zG bqqd15dV8QX4H+YOjleXGWfye/btGj4BuHNTcYMQ= 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 5.2 386/413] parisc: Fix kernel panic due invalid values in IAOQ0 or IAOQ1 Date: Wed, 24 Jul 2019 21:21:17 +0200 Message-Id: <20190724191802.601580770@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191735.096702571@linuxfoundation.org> References: <20190724191735.096702571@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) ||