Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3932350pxj; Mon, 21 Jun 2021 09:38:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHT/dNNlSFVLk7fgSugq9zIbxUIEJ1vaDBn4m2zszqeWhdkq7TdXxIKQJzP3F7CzLcG+kD X-Received: by 2002:aa7:c44b:: with SMTP id n11mr5303142edr.83.1624293538729; Mon, 21 Jun 2021 09:38:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624293538; cv=none; d=google.com; s=arc-20160816; b=uSObRf3hd9oPmGZ2inCuiu2QE7ur/IpzNJ6pdyO260HPfH3q+opH7CV6TBAASWOjFK 31V0OjmEfzGltcT4UiRhHhUEwnses9epF6+L6XK59VgjGnywIW+XF/4yQJBL5YmaOSu7 mN499fLdbmbXP45rh3zbyvlc/utMThWDqwM/grXV+p+EqfMhYsyGJLixc2SoGELO4Kr0 6Y1poAtCyQzuK+mB26OKjXgTdbCIN6lra2kWWLwNSkkua8EYuOnscaIX6RFoqJCicamk z06jXCuH2qI4nOSmi+dz5KKm8PGqdvjHQcpz1P+eZ1RKL5JHI5E7OSKS31CaznzePgAe s1GA== 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=pCDy6cIZyGD64rX2DNqIqxn/FG8v+DKv5sUngV2ymHo=; b=Hlbzh1qr5pKf9edi3Nb7KugjPkYq2r7qE7RWLT4kfCdHD5B17RoB22O9diE7GEi0rG YitxV4qxKAmTIlmUjQ1TnLVEHulqMixN88VFBApuHPrM5UlRzMsdpvevZjF4JeTFZq5K ZIYF7kTdWdoA6jSQrNn5stJC8w0/4uqz5SvIPFMImGpqaFpfqDzGO4PoiYWcJG8qRFXx aQHV75CLeQsQB617X+G77EmdgDS9kVc0fE4NRGYcSRO1uxnDNMm4bJTXuCwJS/Ir72Q3 Qccf5Ekg41uBPEY5aAl576x3re5qNMW1svaOg1PL4K0WRmV7qPktfQnb1S01+c9B4js7 +PAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=E1UAgN66; 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 r9si8772558edq.55.2021.06.21.09.38.36; Mon, 21 Jun 2021 09:38:58 -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=E1UAgN66; 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 S233020AbhFUQjO (ORCPT + 99 others); Mon, 21 Jun 2021 12:39:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:56162 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232908AbhFUQex (ORCPT ); Mon, 21 Jun 2021 12:34:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 50CF86124B; Mon, 21 Jun 2021 16:27:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292845; bh=SLdZNVlc3QuvAH3Rngujdew2yvmtAj+wl+Hap5ihrjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E1UAgN66ThNMfS3ped6CN1Ps3ywZvaQPy8kW4CfT8S0zdA4Gev5lfEEUaAonLOpBt xVkGhPzKrFX2eNDtm35mP1Zy/PqJCZrbMrsfgiHRZi7+Iwe8R+Fa/1Q5EArbPf1WLp udMlMlobQEvN4z8RuXM0jC/zNtgEuxcWUwJemBEo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Lutomirski , Thomas Gleixner , Borislav Petkov , Dave Hansen , Rik van Riel Subject: [PATCH 5.10 123/146] x86/fpu: Invalidate FPU state after a failed XRSTOR from a user buffer Date: Mon, 21 Jun 2021 18:15:53 +0200 Message-Id: <20210621154919.218967475@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: Andy Lutomirski commit d8778e393afa421f1f117471144f8ce6deb6953a upstream. Both Intel and AMD consider it to be architecturally valid for XRSTOR to fail with #PF but nonetheless change the register state. The actual conditions under which this might occur are unclear [1], but it seems plausible that this might be triggered if one sibling thread unmaps a page and invalidates the shared TLB while another sibling thread is executing XRSTOR on the page in question. __fpu__restore_sig() can execute XRSTOR while the hardware registers are preserved on behalf of a different victim task (using the fpu_fpregs_owner_ctx mechanism), and, in theory, XRSTOR could fail but modify the registers. If this happens, then there is a window in which __fpu__restore_sig() could schedule out and the victim task could schedule back in without reloading its own FPU registers. This would result in part of the FPU state that __fpu__restore_sig() was attempting to load leaking into the victim task's user-visible state. Invalidate preserved FPU registers on XRSTOR failure to prevent this situation from corrupting any state. [1] Frequent readers of the errata lists might imagine "complex microarchitectural conditions". Fixes: 1d731e731c4c ("x86/fpu: Add a fastpath to __fpu__restore_sig()") Signed-off-by: Andy Lutomirski Signed-off-by: Thomas Gleixner Signed-off-by: Borislav Petkov Acked-by: Dave Hansen Acked-by: Rik van Riel Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20210608144345.758116583@linutronix.de Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/fpu/signal.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) --- a/arch/x86/kernel/fpu/signal.c +++ b/arch/x86/kernel/fpu/signal.c @@ -369,6 +369,25 @@ static int __fpu__restore_sig(void __use fpregs_unlock(); return 0; } + + /* + * The above did an FPU restore operation, restricted to + * the user portion of the registers, and failed, but the + * microcode might have modified the FPU registers + * nevertheless. + * + * If the FPU registers do not belong to current, then + * invalidate the FPU register state otherwise the task might + * preempt current and return to user space with corrupted + * FPU registers. + * + * In case current owns the FPU registers then no further + * action is required. The fixup below will handle it + * correctly. + */ + if (test_thread_flag(TIF_NEED_FPU_LOAD)) + __cpu_invalidate_fpregs_state(); + fpregs_unlock(); } else { /*