Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3786022ybi; Mon, 29 Jul 2019 12:35:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/Ci1IIa8mersiA+4Q5e95ExCHWD9RsB3/OM0SoaoDLvyXNoyCAO7V/G0cUUi2lGQ+CCDM X-Received: by 2002:a63:8dc9:: with SMTP id z192mr50923534pgd.151.1564428931022; Mon, 29 Jul 2019 12:35:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564428931; cv=none; d=google.com; s=arc-20160816; b=M9z5okZuHondZwFtU1vguPbZStcrOu4ujjRzNW7YrJejJeWzfQO0ovs4eEHLVr61yf WiH+WgUyi3EnL5L+f+Ge/IsioPVIJ0H3LV8gQXbDy/dUT2B8b4GvPOhwmDDlvkDNigR2 0JxOrWUD0e1VfEOJVNfuUXLboXrVxjhcZc4CXCIXOYiBMNj+N6CYlvQnikKGIMcZNvmC kw806rruyaCQrqlLfgX1x0tCIfQLJmeWVauMTbvltm/+Aw7KtKXNqqmXkWqnoa2OICFS niA9snClhc/r+ZXZJJ8/M+c5Rv0BxmS+hjcER39Dmr2tGy3hUi+9iyP1qz4Y1u1ctZQH swRA== 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=/u796ak0FBwNoi2VpyahxDQ+3icNVrOQeBMUuKxfa+Y=; b=ExJj1DHF0Wx4kHjjYj/gr+8JeKItB0Ms8yK5izk4tVrVmIA6s10JHO5E6APFGGS9bN K28tdY7x4mXNBUu3m5tCFckN1hNa8fti3Dtq3QsUOt+LxFs24cNCKXMgXKT8eh6bFidn a+8AcHgdIdhHlvI7nlGI+ME8ghFm1fZ+OH/7OmhgzWDVklFeZxrxAo4PCnICHwry68vm 31qWQjOgNgtpDbxEyEyfTM0aDBqblO4dYs74m1I1UXb/gqFCLIJQmQs85Q/sIPg9RVRe i2EJAIG1vcSAW6lxiPKhPCWvQZQnqAr8snBjTZFD0xghwjUEfe62j2Gre9wNVf2b9NED z9dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=JDM7QR3X; 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 u18si24536579plq.311.2019.07.29.12.35.15; Mon, 29 Jul 2019 12:35:31 -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=JDM7QR3X; 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 S1729432AbfG2TcM (ORCPT + 99 others); Mon, 29 Jul 2019 15:32:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:45444 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730222AbfG2TcL (ORCPT ); Mon, 29 Jul 2019 15:32:11 -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 6BB60217D6; Mon, 29 Jul 2019 19:32:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428729; bh=9wT11Yaz+MY1CT0KMzqzxrxebYgBo/RtEIUH/idFx7Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JDM7QR3X0Tp2o6zsnbGBIBeBekQI1InWR0J5QxaCh+yo1mzsrLp363It0HHDvPNlh iA1NRo/+yCcJYGbq3LW9PIqfTM/YcmkziMCu8bOnuUrVAKtpT4Wm/MisDQ1WGof1VJ O/pWY35MCcUQ76NE9Mqzh20moaWsendMLRKnOf+s= 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.14 168/293] parisc: Fix kernel panic due invalid values in IAOQ0 or IAOQ1 Date: Mon, 29 Jul 2019 21:20:59 +0200 Message-Id: <20190729190837.385761772@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@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 @@ -171,6 +171,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) || @@ -232,16 +235,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, @@ -285,9 +290,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) ||