Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3803347ybi; Mon, 29 Jul 2019 12:57:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqxs8XGFbVGDT5+3l6UU5tKeCI5KptTaEZCzGKAmVPw+p/7WnYS0IsJ57RM8aY7yJZJgmJzj X-Received: by 2002:a65:6281:: with SMTP id f1mr99728680pgv.400.1564430246286; Mon, 29 Jul 2019 12:57:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430246; cv=none; d=google.com; s=arc-20160816; b=ZZyQ2z2dUnbhGsH4cLvm9B/aebrxLtlG+PNd+ARREntJzYj5kln/jy0VsxmHuJaiy2 XScAGIIED/MRg6ByxG33qbZKw6/rPDqczy+WJk4z1hHlc077bCp0VY+XtJQAADYsaAvi H+vff7HiCwU5+Fnq1ecx3E7t6JsiuFPUPn+9i1BZZ97rLTmxBJ/iKnpPFWPLpQr3G6jO VzATC5ZE6HVSyt36f46GZ0WT2J2K0rBXc0YCkRCK5iLKxHP7DB2I8e8Jf+TfVH6R78rW 3WJPcxg8QRtO/2XPDJpaHXu/7CLD8PmGswMCtMtt/8hediADzGyYuHfHDpcT5aXs292+ wYZw== 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=zrywLn1x/2h+kZg37BDKNV9G8cnCXCibq8QVZxqL9jM=; b=ob2afCAmKoS4HIY/fu/3YTprMj9Z2whx9uZwXfxygKMm2aH1Zj1udwoPmgfD9lOaFh KqyQFQp0TRHMTkVmgxyj+sWw0ijDZap/AtlbtDvccIMDFJW7aBZWz9n1LRDtspNda8bN YZcWToVopyfNMS9DsMq7a7hPcWIb860KjyDRp9IWZsnekRiHxENhuEd2bk+YTNm3ULe9 +hiDVVErPs/Sh5sG+abDMf9n4XiyL9+gWsJRAji+mNkjiY0WxrSlKMSehouj5F+0Avj9 PF4Vcd72OHPrkknhc73Dd6JPWrJDq/7KXsCfMO8GPM5FDfSWBvF5c6zxbscrbyKPVJ+A ZdHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XVphI82M; 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 m63si28329264pjb.8.2019.07.29.12.57.11; Mon, 29 Jul 2019 12:57:26 -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=XVphI82M; 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 S2404303AbfG2T4C (ORCPT + 99 others); Mon, 29 Jul 2019 15:56:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:48864 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404265AbfG2Tz7 (ORCPT ); Mon, 29 Jul 2019 15:55:59 -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 95912204EC; Mon, 29 Jul 2019 19:55:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564430159; bh=Xbef9eg/NegU3DXpV5H/CftFTdouDQLuOGQM0s+asFA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XVphI82MIW5NN9ZvjQnA2XGKVQHkdgLbZqITThN9UwHg/x4J+epmjheImr4supJsu KWPpyDkxTOqYyAERV51Dne24JSLrlQ2U9pfOY224+dUSYdh6iZaHs9at2sNTzThxX2 vBq8MhstHI0So6m5JZhn2fTsVu5zViabTWLtH54E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Praveen Pandey , Michael Neuling , Michael Ellerman Subject: [PATCH 5.2 199/215] powerpc/tm: Fix oops on sigreturn on systems without TM Date: Mon, 29 Jul 2019 21:23:15 +0200 Message-Id: <20190729190814.397437847@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@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: Michael Neuling commit f16d80b75a096c52354c6e0a574993f3b0dfbdfe upstream. On systems like P9 powernv where we have no TM (or P8 booted with ppc_tm=off), userspace can construct a signal context which still has the MSR TS bits set. The kernel tries to restore this context which results in the following crash: Unexpected TM Bad Thing exception at c0000000000022fc (msr 0x8000000102a03031) tm_scratch=800000020280f033 Oops: Unrecoverable exception, sig: 6 [#1] LE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA pSeries Modules linked in: CPU: 0 PID: 1636 Comm: sigfuz Not tainted 5.2.0-11043-g0a8ad0ffa4 #69 NIP: c0000000000022fc LR: 00007fffb2d67e48 CTR: 0000000000000000 REGS: c00000003fffbd70 TRAP: 0700 Not tainted (5.2.0-11045-g7142b497d8) MSR: 8000000102a03031 CR: 42004242 XER: 00000000 CFAR: c0000000000022e0 IRQMASK: 0 GPR00: 0000000000000072 00007fffb2b6e560 00007fffb2d87f00 0000000000000669 GPR04: 00007fffb2b6e728 0000000000000000 0000000000000000 00007fffb2b6f2a8 GPR08: 0000000000000000 0000000000000000 0000000000000000 0000000000000000 GPR12: 0000000000000000 00007fffb2b76900 0000000000000000 0000000000000000 GPR16: 00007fffb2370000 00007fffb2d84390 00007fffea3a15ac 000001000a250420 GPR20: 00007fffb2b6f260 0000000010001770 0000000000000000 0000000000000000 GPR24: 00007fffb2d843a0 00007fffea3a14a0 0000000000010000 0000000000800000 GPR28: 00007fffea3a14d8 00000000003d0f00 0000000000000000 00007fffb2b6e728 NIP [c0000000000022fc] rfi_flush_fallback+0x7c/0x80 LR [00007fffb2d67e48] 0x7fffb2d67e48 Call Trace: Instruction dump: e96a0220 e96a02a8 e96a0330 e96a03b8 394a0400 4200ffdc 7d2903a6 e92d0c00 e94d0c08 e96d0c10 e82d0c18 7db242a6 <4c000024> 7db243a6 7db142a6 f82d0c18 The problem is the signal code assumes TM is enabled when CONFIG_PPC_TRANSACTIONAL_MEM is enabled. This may not be the case as with P9 powernv or if `ppc_tm=off` is used on P8. This means any local user can crash the system. Fix the problem by returning a bad stack frame to the user if they try to set the MSR TS bits with sigreturn() on systems where TM is not supported. Found with sigfuz kernel selftest on P9. This fixes CVE-2019-13648. Fixes: 2b0a576d15e0 ("powerpc: Add new transactional memory state to the signal context") Cc: stable@vger.kernel.org # v3.9 Reported-by: Praveen Pandey Signed-off-by: Michael Neuling Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20190719050502.405-1-mikey@neuling.org Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kernel/signal_32.c | 3 +++ arch/powerpc/kernel/signal_64.c | 5 +++++ 2 files changed, 8 insertions(+) --- a/arch/powerpc/kernel/signal_32.c +++ b/arch/powerpc/kernel/signal_32.c @@ -1198,6 +1198,9 @@ SYSCALL_DEFINE0(rt_sigreturn) goto bad; if (MSR_TM_ACTIVE(msr_hi<<32)) { + /* Trying to start TM on non TM system */ + if (!cpu_has_feature(CPU_FTR_TM)) + goto bad; /* We only recheckpoint on return if we're * transaction. */ --- a/arch/powerpc/kernel/signal_64.c +++ b/arch/powerpc/kernel/signal_64.c @@ -771,6 +771,11 @@ SYSCALL_DEFINE0(rt_sigreturn) if (MSR_TM_ACTIVE(msr)) { /* We recheckpoint on return. */ struct ucontext __user *uc_transact; + + /* Trying to start TM on non TM system */ + if (!cpu_has_feature(CPU_FTR_TM)) + goto badframe; + if (__get_user(uc_transact, &uc->uc_link)) goto badframe; if (restore_tm_sigcontexts(current, &uc->uc_mcontext,