Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3940805pxj; Mon, 21 Jun 2021 09:50:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxU2R6OozzkykVRKmeog8lu7tf6++8UUg2YtNhDr1ltSIcQ7K16RtT6kgnorw1X/FQswm4m X-Received: by 2002:a92:d9c1:: with SMTP id n1mr18204537ilq.70.1624294205801; Mon, 21 Jun 2021 09:50:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624294205; cv=none; d=google.com; s=arc-20160816; b=lGq8OSoH0xz79kjeYFEVC9ncmJzkULWonWZm7+qFeLooRmwctBrd4bkeHcXQ8Hs8YZ NtxndRniH4fnL43rWneHa9GTXwKfBfgb67ytOXxNsukV41YL3vhTGB8ZD6RM0JBYOZ1W EmzXEmxEBQ9khLDLWg0r4AouZFhBz6NIXlOnY4PRH+CcZvYbI46obOfvVIA/kiX2zJ2J gvw2mf/0VcStuO8Z33cf7VW8Mh4HLAjmrrYW4yqYDwNYpOOBjQ5I2SmcCbIG9pXoh+7f klTcK79Ld1P2YQMkzfoSRnmuR+56obThhFmbC4HPZO+xK+3ajAXmYDHYzhX8lwldI68b rOUQ== 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=cQvGezhpc+f8PWb8LQfe0kRuwCRIZgIYDt7FcdRRST0=; b=dnEt913QYNI0QIOeSCrtXPsgXpOut3DHcolxbMqcfdbnqs3T2R0zMgqcB/nwZhNrN5 DtA4jvmgHIgpyHgU8M19nIr+l+ES2eUUcQTOC9R4ja37SUK5ZK5AqgP/XEWb8omNFl0v +m/oNyz0mL086Wz7Ysq9LoL7qYPFiS9YfHq862TJB53W6Or62hZgWivmGfHLxxqvQwYW TXYuP9/JVMxW9UfoUr7CAnWJgete9uwGhwtdhjFN1Vg92o6v0oxGF/vFC8IJ+Gw8Ih7P ZgIrKujuqBHEjZ7Q/APp8E7UKvULD8rrr+wD35eGVDc6wZ4TS+hmy7Sfh3tR7c9lhyig GPMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Dy8Crybf; 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 q44si368127jav.16.2021.06.21.09.49.53; Mon, 21 Jun 2021 09:50:05 -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=Dy8Crybf; 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 S232629AbhFUQvc (ORCPT + 99 others); Mon, 21 Jun 2021 12:51:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:37430 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231298AbhFUQry (ORCPT ); Mon, 21 Jun 2021 12:47:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 46AB46124B; Mon, 21 Jun 2021 16:33:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624293227; bh=d9exkhx6UjYb5GaV55vnkVuxfYJd+RqPRziOKf0SAp4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Dy8CrybfRyoBVp1uu4bCsRGCiuAg7vsRt5pFp8cGTT1CYn722zlp3pylq1UB+aflp b9ajUC6f+cPj/UhzqFMZdo3rt5G+6reio4NxNYV+PjPpH6LR4XpZqYbBGqQKw7ott8 we/zZw2A7H9fu76FucRbEpFPDa0HzusXj4Dux6zs= 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.12 146/178] x86/fpu: Reset state for all signal restore failures Date: Mon, 21 Jun 2021 18:16:00 +0200 Message-Id: <20210621154927.742598994@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154921.212599475@linuxfoundation.org> References: <20210621154921.212599475@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 @@ -307,13 +307,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; @@ -396,7 +400,7 @@ static int __fpu__restore_sig(void __use */ ret = __copy_from_user(&env, buf, sizeof(env)); if (ret) - goto err_out; + goto out; envp = &env; } @@ -426,7 +430,7 @@ static int __fpu__restore_sig(void __use ret = copy_user_to_xstate(&fpu->state.xsave, buf_fx); if (ret) - goto err_out; + goto out; sanitize_restored_user_xstate(&fpu->state, envp, user_xfeatures, fx_only); @@ -446,7 +450,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_user_xstate(&fpu->state, envp, user_xfeatures, @@ -464,7 +468,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); @@ -475,7 +479,7 @@ static int __fpu__restore_sig(void __use fpregs_deactivate(fpu); fpregs_unlock(); -err_out: +out: if (ret) fpu__clear_user_states(fpu); return ret;