Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3932355pxj; Mon, 21 Jun 2021 09:38:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx84bHuDTUkrXav17YvOh6kDeg8JxlTqnxml5EUFt2d0sjLpQvkh3s0L3xcs9zjW8xgtn2r X-Received: by 2002:a05:6402:27c9:: with SMTP id c9mr23181742ede.371.1624293539538; Mon, 21 Jun 2021 09:38:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624293539; cv=none; d=google.com; s=arc-20160816; b=Q6yS7CQM/Y/A8mYYNMVmigC/1Y86WFWFSsG/k6e+9qrTsvlHkjlJo+WzYymPIr8C1R f0MgIDAeAsZy6HuaLz+I6rirMACWe4u6EO27iuGVbuO1PoFJwYliA3l2suPFAJFzdOmn W3K5Dk0v+ezPKHSJMZc24W8MsoKOXI6N3w460LrFgPxzJ+e9Cn48vosRRN8hw8ra6SZD 5gCmmfagJe4PPFCuvYlmBmBMo44Ms0+Rhpu7Et5r9tzBxDHWjfTUBwLZfm1USpC7fEUH k7qIUiQlXwOWxgp1/eu1/tABNocFOA909vqyn/LeMqHB6vqqWBsaNfuxBG2vPymgsVrv WEQQ== 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=fZFQVW67cngP8m3DtGtjBKyq41KSmuqqOgz7+qpQ/3ufnf7URqU3BAXr1AKGoMl2xJ D8vQRNyPzP3T+rH3kkYoQZC0CHDJ4319LUKN+ahjYyR/uKlGVPgvJgc+N9nfThy1YV7V BdWsSU89qe5xlsbhxnn6gngxsLu3YppCzxSM2gl9G6T+Ch6qwnaFb4bvnMHX0oOjip6x jg53bbE+q0T/iI5vrPdQbAt5dnxWgi0rHpQmgmj/8PnLrOCuVxp3M7xJFBRm9y+kzhu+ buaaF+YHHG4RX4T3O0IQoOepeFlwLHpoHF/v/yYFxfozGjKt0V34Rj0sP/cTaO+i/Mii LL/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XvKn3q1q; 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 ce29si10712585ejc.92.2021.06.21.09.38.36; Mon, 21 Jun 2021 09:38:59 -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=XvKn3q1q; 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 S233052AbhFUQjP (ORCPT + 99 others); Mon, 21 Jun 2021 12:39:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:54546 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232986AbhFUQe6 (ORCPT ); Mon, 21 Jun 2021 12:34:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D769661361; Mon, 21 Jun 2021 16:27:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292848; bh=d9exkhx6UjYb5GaV55vnkVuxfYJd+RqPRziOKf0SAp4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XvKn3q1qw3hjK0C/dXYjVE3WR1c4scPT7cwljm8I16CSkyOV96SeojrE0WYohR/Lc KkihTHFHh9kVZIEp8/DNAVOOT89AoTKe8RyXz6TpbLcBbXUNp+fSl/K/yxQjlPe8R5 URLnaDSADqtpN+zQCk42DvZHtdpjWzGbBqnpQTPs= 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.10 124/146] x86/fpu: Reset state for all signal restore failures Date: Mon, 21 Jun 2021 18:15:54 +0200 Message-Id: <20210621154919.282112764@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154911.244649123@linuxfoundation.org> References: <20210621154911.244649123@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;