Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp121816ybg; Mon, 8 Jun 2020 18:13:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyD8wp1M84/tBD+BDxtJNPq4lvncxNJ5ijfvTaVV30JX5Qz05GGTC15NNvBO76BX6TJPJuV X-Received: by 2002:a50:da83:: with SMTP id q3mr1861838edj.325.1591665183918; Mon, 08 Jun 2020 18:13:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591665183; cv=none; d=google.com; s=arc-20160816; b=EIERSvoiuyGxoo8kZrJovRhxpM55RdwhM0npwVoz4bkv+iI5kQm3uc9XTrRgkhfRSJ KRMxAk+8RI5Ht3SZJFqSBMxnIe1wCLWcjGJa5Quep7jyHIH+jdUsNPegjX6C5USCng4l wzpNh/Gh5N+sigDBA3X1Tgb7g4nvqMO0cF3Q2syWjTIulH00PY0RxRveH1cAJk2st7aY gcwGyBpvpCEhLxpm7yJ/EWXEtKepR8dfmre1d1eTzWbsGEd0wgzUQi8N+GlkhYWiWiCc UsC/TZQoylszV6rdimanXEFLtqMDI4+TSlHW7bHGVFaDjDzUrPS0RP3gBVvKFLdguta3 4CMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GStXm29wXTSkllJvLFAOGa3sHk2QJKdQF95PjzZdlpU=; b=Wl6BEs8DaDfpCQk+XeYNe+Wpicz9Tlq5EX70Boggv2/90AJdj3MdzHibdI6Ki6h88u HDtqnH8IxOCnsMYrrHPfyn3hhZhjIqcLBVsn0K6MvO5V1th3Gur2H/XNjl7+zkYiqM2A 4tXWykg6ZYbujeAEi6cSedEpe3z2o8bbk0M7ACtZ9VrNn3x2E2yDhlxrEBW53H/xq48H mmG8hVuXaLQArgeQyLGL9c0sGgbhkn41X+I1l/GMlK3kzCO41eFcMVwJcyGGJJp9lWNQ 1qwt1ktX+JbUlOq3k8StOoKd44gDt13jmOh1xuifOWwNaA8SekQ/Smiw+L02GZYb1oF3 PZmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Bdr6Y18C; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m14si10844129eja.139.2020.06.08.18.12.41; Mon, 08 Jun 2020 18:13:03 -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=@kernel.org header.s=default header.b=Bdr6Y18C; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730669AbgFIBI5 (ORCPT + 99 others); Mon, 8 Jun 2020 21:08:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:50030 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727038AbgFHXGl (ORCPT ); Mon, 8 Jun 2020 19:06:41 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EBB7220814; Mon, 8 Jun 2020 23:06:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657600; bh=wYOBonMFOcw+NCR1S5pFDveiILnmyP7Jt2GUW7nzcvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Bdr6Y18CG9dJYISMtU3TvbMISNe63cBPWrptrI6KTlEw0dRNRsBxsYKBIp3jRByQY Vdd9dLL5Fg7OF0sVT3VFpVM884Tzu0KJ8kzy0r3GEIJDqMqafXDHKlSipFOltZXA15 qJp/ACPSsU1qYAknzSgamwR+fHscGA4zWaKWm1Wk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Peter Zijlstra , Miroslav Benes , Josh Poimboeuf , Sasha Levin Subject: [PATCH AUTOSEL 5.7 026/274] x86,smap: Fix smap_{save,restore}() alternatives Date: Mon, 8 Jun 2020 19:01:59 -0400 Message-Id: <20200608230607.3361041-26-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra [ Upstream commit 1ff865e343c2b59469d7e41d370a980a3f972c71 ] As reported by objtool: lib/ubsan.o: warning: objtool: .altinstr_replacement+0x0: alternative modifies stack lib/ubsan.o: warning: objtool: .altinstr_replacement+0x7: alternative modifies stack the smap_{save,restore}() alternatives violate (the newly enforced) rule on stack invariance. That is, due to there only being a single ORC table it must be valid to any alternative. These alternatives violate this with the direct result that unwinds will not be correct when it hits between the PUSH and POP instructions. Rewrite the functions to only have a conditional jump. Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Miroslav Benes Acked-by: Josh Poimboeuf Link: https://lkml.kernel.org/r/20200429101802.GI13592@hirez.programming.kicks-ass.net Signed-off-by: Sasha Levin --- arch/x86/include/asm/smap.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h index 27c47d183f4b..8b58d6975d5d 100644 --- a/arch/x86/include/asm/smap.h +++ b/arch/x86/include/asm/smap.h @@ -57,8 +57,10 @@ static __always_inline unsigned long smap_save(void) { unsigned long flags; - asm volatile (ALTERNATIVE("", "pushf; pop %0; " __ASM_CLAC, - X86_FEATURE_SMAP) + asm volatile ("# smap_save\n\t" + ALTERNATIVE("jmp 1f", "", X86_FEATURE_SMAP) + "pushf; pop %0; " __ASM_CLAC "\n\t" + "1:" : "=rm" (flags) : : "memory", "cc"); return flags; @@ -66,7 +68,10 @@ static __always_inline unsigned long smap_save(void) static __always_inline void smap_restore(unsigned long flags) { - asm volatile (ALTERNATIVE("", "push %0; popf", X86_FEATURE_SMAP) + asm volatile ("# smap_restore\n\t" + ALTERNATIVE("jmp 1f", "", X86_FEATURE_SMAP) + "push %0; popf\n\t" + "1:" : : "g" (flags) : "memory", "cc"); } -- 2.25.1