From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9775C48BDF for ; Sun, 20 Jun 2021 21:31:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 969D061164 for ; Sun, 20 Jun 2021 21:31:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230222AbhFTVcv (ORCPT ); Sun, 20 Jun 2021 17:32:51 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:57830 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230051AbhFTVcv (ORCPT ); Sun, 20 Jun 2021 17:32:51 -0400 Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 222641FD29; Sun, 20 Jun 2021 21:30:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1624224637; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jr3EKkDtgn8FizBBDVJKegsYoeH9jissvBbAKGoDq+8=; b=gSAmezX+CA9jlMqe+4UmOmWobkOa54tZqltCq/MslwgMLDn69QASbjgqLG3OdHfvC8gxs5 e9/c3GAeGpilTx3EEWP+75NRZOxlsIgeD540C6M8nJPLZp3bcjPflnURe7/zwK9pdcwmlA laaA1YQ3HaBhqcqT1Y4cbGCh7bMA0kc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1624224637; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jr3EKkDtgn8FizBBDVJKegsYoeH9jissvBbAKGoDq+8=; b=dLVsKyeB21FpEOtAyaYBvbY1mZLtc/yYTPibx1udlGA7tw86YHWqR1Ta3yd3yH2jye5LFP 9FUbe27lu9o1gIBQ== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 09DB2118DD; Sun, 20 Jun 2021 21:30:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1624224637; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jr3EKkDtgn8FizBBDVJKegsYoeH9jissvBbAKGoDq+8=; b=gSAmezX+CA9jlMqe+4UmOmWobkOa54tZqltCq/MslwgMLDn69QASbjgqLG3OdHfvC8gxs5 e9/c3GAeGpilTx3EEWP+75NRZOxlsIgeD540C6M8nJPLZp3bcjPflnURe7/zwK9pdcwmlA laaA1YQ3HaBhqcqT1Y4cbGCh7bMA0kc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1624224637; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jr3EKkDtgn8FizBBDVJKegsYoeH9jissvBbAKGoDq+8=; b=dLVsKyeB21FpEOtAyaYBvbY1mZLtc/yYTPibx1udlGA7tw86YHWqR1Ta3yd3yH2jye5LFP 9FUbe27lu9o1gIBQ== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id GH+jAn2zz2CHTwAALh3uQQ (envelope-from ); Sun, 20 Jun 2021 21:30:37 +0000 Date: Sun, 20 Jun 2021 23:30:23 +0200 From: Borislav Petkov To: Thomas Gleixner Cc: LKML , Andy Lutomirski , Dave Hansen , Fenghua Yu , Tony Luck , Yu-cheng Yu , Sebastian Andrzej Siewior , Peter Zijlstra , Kan Liang Subject: Re: [patch V3 11/66] x86/fpu: Sanitize xstateregs_set() Message-ID: References: <20210618141823.161158090@linutronix.de> <20210618143445.667573756@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210618143445.667573756@linutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 18, 2021 at 04:18:34PM +0200, Thomas Gleixner wrote: > xstateregs_set() operates on a stopped task and tries to copy the provided > buffer into the task's fpu.state.xsave buffer. > > Any error while copying or invalid state detected after copying results in > wiping the target task's FPU state completely including supervisor states. > > That's just wrong. The caller supplied invalid data or has a problem with > unmapped memory, so there is absolutely no justification to corrupt the > target state. > > Fix this with the following modifications: > > 1) If data has to be copied from userspace, allocate a buffer and copy from > user first. > > 2) Use copy_kernel_to_xstate() unconditionally so that header checking > works correctly. > > 3) Return on error without corrupting the target state. > > This prevents corrupting states and lets the caller deal with the problem > it caused in the first place. > > Signed-off-by: Thomas Gleixner > --- > arch/x86/include/asm/fpu/xstate.h | 4 --- > arch/x86/kernel/fpu/regset.c | 44 +++++++++++++++----------------------- > arch/x86/kernel/fpu/xstate.c | 14 ++++++------ > 3 files changed, 26 insertions(+), 36 deletions(-) Reviewed-by: Borislav Petkov Nice! -- Regards/Gruss, Boris. SUSE Software Solutions Germany GmbH, GF: Felix Imendörffer, HRB 36809, AG Nürnberg