Received: by 2002:a05:6520:1682:b0:147:d1a0:b502 with SMTP id ck2csp5595265lkb; Mon, 11 Oct 2021 09:37:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypWv5NaVWOhxiCXlkoyRCMeASEXsrw0h1GyCyGH+2lrOfY9Lg72ZURwVqIt78BE/pXVSe5 X-Received: by 2002:a17:90a:9b13:: with SMTP id f19mr51565pjp.16.1633970250122; Mon, 11 Oct 2021 09:37:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633970250; cv=none; d=google.com; s=arc-20160816; b=IfYuHLP3+SQxYS1MAlHKr9ntLslgC7CmSdUEWGUZ4W1EjdNcPkXPN8IkO1WetllfKz 9B1OSEh9J0fHpBuTwoQYQPUkVgzQLAj/iv/cqkIPY4ZQYXjMK16MpBSdEOCTH3k6ZjP4 lpK49kMTf1PD6hZM2/pY8XwJgc6u1usVSbNV57esfWNHUKmGDvV+/wFAPEAcG7atYoYM YBMU/3Ib/6HifoBI9SjX6d2OAm7fYu4yqmxNcKfRTIjHc/+G1WzmNeFK6Pz4fYd1jEUH ofoL7xamJBU3oTvZDDXkJpM9PUxz8/AssG40b7NO0hkr/3iD/uM/JRXMQN5kuUY9qeYM 3yBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=liCf90VSNxgCaO2keDK0X4HzroO9SCjrVULWW9ozXhQ=; b=nL9ALocX/xl3aElocpFk+3x2yS78H39MvAGjPlHl9DwNVa05C4BkH0lNzSuAj9mtyo dX0oRJcJ2WW/cFNsG5DcCBOxkUXuR3Epl2Y8PpFRms39XiPvhuo2hwlRsQl1YIJKj3Xo J0q/6SD20A3LqK4gA2xZq28fxN/vcKrc1vfu12aMJaiezcy2XkYvamXtRHSbfKi3E3tv uv/KXNb/3wXtIekzEFo+yBCKihd8aU2oGP6N13kC0j9UVu0+SjkB/vcIy5Pe7aHQw8Jg 8p+NSickCWpaTSvqLvGB1GBPAteCfkUhZHlByVhJALtihd3Bas7uXAuqW/D7PViyJH0t carw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1yjp0fe7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w25si13332062pgk.256.2021.10.11.09.37.17; Mon, 11 Oct 2021 09:37:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1yjp0fe7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242239AbhJKOPt (ORCPT + 99 others); Mon, 11 Oct 2021 10:15:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:33822 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243886AbhJKON1 (ORCPT ); Mon, 11 Oct 2021 10:13:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D835F6128A; Mon, 11 Oct 2021 14:04:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633961059; bh=99AyWAF8IJk2ARIKBNNnAEB7qLtTvX0BfrcYa2p3i/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1yjp0fe7EkEIlfHBU0nf4wso4qrY3RKXqE6K3iISh162lnrB3Ym/I9kEs5EAO/4Hj B12S9+vHwzymRfxVr51ZlR9YHdEBX+1UwzR4MGhAIOfp8codEZBYOXJoElKZrYzbfc 6Njnpmcfo0M8eLaNOlflnaRYnrMHWBIZvoZZFaIY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ser Olmy , Borislav Petkov Subject: [PATCH 5.14 147/151] x86/fpu: Restore the masking out of reserved MXCSR bits Date: Mon, 11 Oct 2021 15:46:59 +0200 Message-Id: <20211011134522.575320425@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011134517.833565002@linuxfoundation.org> References: <20211011134517.833565002@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Borislav Petkov commit d298b03506d3e161f7492c440babb0bfae35e650 upstream. Ser Olmy reported a boot failure: init[1] bad frame in sigreturn frame:(ptrval) ip:b7c9fbe6 sp:bf933310 orax:ffffffff \ in libc-2.33.so[b7bed000+156000] Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b CPU: 0 PID: 1 Comm: init Tainted: G W 5.14.9 #1 Hardware name: Hewlett-Packard HP PC/HP Board, BIOS JD.00.06 12/06/2001 Call Trace: dump_stack_lvl dump_stack panic do_exit.cold do_group_exit get_signal arch_do_signal_or_restart ? force_sig_info_to_task ? force_sig exit_to_user_mode_prepare syscall_exit_to_user_mode do_int80_syscall_32 entry_INT80_32 on an old 32-bit Intel CPU: vendor_id : GenuineIntel cpu family : 6 model : 6 model name : Celeron (Mendocino) stepping : 5 microcode : 0x3 Ser bisected the problem to the commit in Fixes. tglx suggested reverting the rejection of invalid MXCSR values which this commit introduced and replacing it with what the old code did - simply masking them out to zero. Further debugging confirmed his suggestion: fpu->state.fxsave.mxcsr: 0xb7be13b4, mxcsr_feature_mask: 0xffbf WARNING: CPU: 0 PID: 1 at arch/x86/kernel/fpu/signal.c:384 __fpu_restore_sig+0x51f/0x540 so restore the original behavior only for 32-bit kernels where you have ancient machines with buggy hardware. For 32-bit programs on 64-bit kernels, user space which supplies wrong MXCSR values is considered malicious so fail the sigframe restoration there. Fixes: 6f9866a166cd ("x86/fpu/signal: Let xrstor handle the features to init") Reported-by: Ser Olmy Signed-off-by: Borislav Petkov Tested-by: Ser Olmy Cc: Link: https://lkml.kernel.org/r/YVtA67jImg3KlBTw@zn.tnic Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/fpu/signal.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) --- a/arch/x86/kernel/fpu/signal.c +++ b/arch/x86/kernel/fpu/signal.c @@ -379,9 +379,14 @@ static int __fpu_restore_sig(void __user sizeof(fpu->state.fxsave))) return -EFAULT; - /* Reject invalid MXCSR values. */ - if (fpu->state.fxsave.mxcsr & ~mxcsr_feature_mask) - return -EINVAL; + if (IS_ENABLED(CONFIG_X86_64)) { + /* Reject invalid MXCSR values. */ + if (fpu->state.fxsave.mxcsr & ~mxcsr_feature_mask) + return -EINVAL; + } else { + /* Mask invalid bits out for historical reasons (broken hardware). */ + fpu->state.fxsave.mxcsr &= ~mxcsr_feature_mask; + } /* Enforce XFEATURE_MASK_FPSSE when XSAVE is enabled */ if (use_xsave())