Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3920088pxj; Mon, 21 Jun 2021 09:23:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybAF5zIo1B19uwGOcjWhZpoqvXlHq6WepZFscGzDEw4M5LyzLa4zLf6jLzVbgXNewHDm/w X-Received: by 2002:a17:906:375b:: with SMTP id e27mr20737171ejc.437.1624292589764; Mon, 21 Jun 2021 09:23:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624292589; cv=none; d=google.com; s=arc-20160816; b=MwiEvCMHiCKBIfBBg9Vw00dkFqS36lsraOzxFUhEynKqjLX0t2BV2rb4ftUCm2wCk3 xjBtFsAbzPxiwvCbgMbVzQNbNQQiJjFl2tXE+SEcIuEVdd8jgLsUjwBrlGy6nbRs+ljW i213aQbnaVA50VzTgKvM6yo74eqqxQwWHz5SEKi3qFiMCohX0kpBSL/t3o+4Rged8dFP 5PuJB9pfVqTgnJxpUs2NfrS00k+YWAmuQEgFTQe+e9YdFXusKXBMiUYH72MWyw1jyO6Z JlE9gT8k9bnjLDlh7740RziAW1fjMzuGzDXXX+Hai0FA5IZKMRGIjksrLE0svIBK+nc7 99wg== 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=1IBQMTq80q7bPcArCUH/RJIgUPACT9dnBw/DDT7sp6s=; b=wUcJ8w1tVqgwdLc2EFXDTpYS1mmttMgZQkRs2/81ogS4PF1D7tfB46dFOITsWU+mFd UVbiNv2OqucqPkQUPPvVDrTclBXjwMOr0isFIetQZdepds7G49CeKmS5mt7niiZ72V9A QJbboavTH9XGcxDAsySzewwSQobP+bTOFdU7D+EU7rfoJnwVX8/CmPdqqDh+SMFDZUos PWf4Dyc/6Ei2cgRLGXX0K8qJnGSaegV+9IcsBOUWX9NJ3DFcsNilbj8nWjXJ7QsOPYCK aBgKya5idsRolFuHUlvx+uX87jU+W5g48+CJ6zXkjD8mTrPODkgfBlhcHLMwzMYVK47y Rozw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mW7OFvNc; 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 j10si17780112edw.560.2021.06.21.09.22.47; Mon, 21 Jun 2021 09:23:09 -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=mW7OFvNc; 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 S231557AbhFUQXV (ORCPT + 99 others); Mon, 21 Jun 2021 12:23:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:41976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231840AbhFUQV7 (ORCPT ); Mon, 21 Jun 2021 12:21:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 17B566137D; Mon, 21 Jun 2021 16:19:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292379; bh=LLnmG8brgOHwQ+R3d71IMf6uE3aacgY7WIo8T8fv9JM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mW7OFvNck4yk/sz76c/yAwL0948Qats/rgdYIizdCEG7xefR33boTUC+fJVZE5qsd KvZTKYbK3cwmUGPk6VXxpHMR+3qRYDHe533vNm/0kkNJiYKMIROLL8vT1zGBydlB6q il5i0UeAHIB2nUjC2SU5dlS5e6YCxmVeoEMLvMHI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Gleixner , Borislav Petkov Subject: [PATCH 5.4 68/90] x86/fpu: Reset state for all signal restore failures Date: Mon, 21 Jun 2021 18:15:43 +0200 Message-Id: <20210621154906.462940408@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154904.159672728@linuxfoundation.org> References: <20210621154904.159672728@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: Thomas Gleixner commit efa165504943f2128d50f63de0c02faf6dcceb0d upstream. If access_ok() or fpregs_soft_set() fails in __fpu__restore_sig() then the function just returns but does not clear the FPU state as it does for all other fatal failures. Clear the FPU state for these failures as well. Fixes: 72a671ced66d ("x86, fpu: Unify signal handling code paths for x86 and x86_64 kernels") Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/87mtryyhhz.ffs@nanos.tec.linutronix.de Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/fpu/signal.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) --- a/arch/x86/kernel/fpu/signal.c +++ b/arch/x86/kernel/fpu/signal.c @@ -289,13 +289,17 @@ static int __fpu__restore_sig(void __use return 0; } - if (!access_ok(buf, size)) - return -EACCES; + if (!access_ok(buf, size)) { + ret = -EACCES; + goto out; + } - if (!static_cpu_has(X86_FEATURE_FPU)) - return fpregs_soft_set(current, NULL, - 0, sizeof(struct user_i387_ia32_struct), - NULL, buf) != 0; + if (!static_cpu_has(X86_FEATURE_FPU)) { + ret = fpregs_soft_set(current, NULL, 0, + sizeof(struct user_i387_ia32_struct), + NULL, buf); + goto out; + } if (use_xsave()) { struct _fpx_sw_bytes fx_sw_user; @@ -333,7 +337,7 @@ static int __fpu__restore_sig(void __use if (ia32_fxstate) { ret = __copy_from_user(&env, buf, sizeof(env)); if (ret) - goto err_out; + goto out; envp = &env; } else { /* @@ -369,7 +373,7 @@ static int __fpu__restore_sig(void __use ret = validate_xstate_header(&fpu->state.xsave.header); } if (ret) - goto err_out; + goto out; sanitize_restored_xstate(&fpu->state, envp, xfeatures, fx_only); @@ -382,7 +386,7 @@ static int __fpu__restore_sig(void __use ret = __copy_from_user(&fpu->state.fxsave, buf_fx, state_size); if (ret) { ret = -EFAULT; - goto err_out; + goto out; } sanitize_restored_xstate(&fpu->state, envp, xfeatures, fx_only); @@ -397,7 +401,7 @@ static int __fpu__restore_sig(void __use } else { ret = __copy_from_user(&fpu->state.fsave, buf_fx, state_size); if (ret) - goto err_out; + goto out; fpregs_lock(); ret = copy_kernel_to_fregs_err(&fpu->state.fsave); @@ -408,7 +412,7 @@ static int __fpu__restore_sig(void __use fpregs_deactivate(fpu); fpregs_unlock(); -err_out: +out: if (ret) fpu__clear(fpu); return ret;