Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4183767pxb; Mon, 8 Feb 2021 09:51:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJzoRTjfzNNh1bq6vafotMxt5U6cauZ4Ak3aO8oYdARsthX2xKtlm3jFYjfawuFiZkHHT/Az X-Received: by 2002:a17:906:6bda:: with SMTP id t26mr8093279ejs.50.1612806682042; Mon, 08 Feb 2021 09:51:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612806681; cv=none; d=google.com; s=arc-20160816; b=iy6odE6CLiMeIUuy57haJ0cXt6N1eMypPF43bkXt7HqO8xVN9yfp8Fs9+CmbNZk4VW Z4f2sb0PMZrMbiV5f88J6O9vDdR/MvjfQIYPJnadhYwnDs3c96Zn11iiYwyh971yfK4D CM/Ckt04ITcB4DoDZ1Lr2tTOzKP6SqNrPLT4XNfjSTNqF4YI+Vd1Jv/zgi9e7uJ8Vq6x tMjcjmgGHlcpvDgO/pGZvKMzWrw8didfhgBwKiuL0ZBmq6i+QZ3EOOwK5/C1pc5YSYjn WWkGTXoA3R/nhmTrqxsDLP9efhCwjavNuLJDxx8vNQX8D3zIQze8viArISc8g2xEqMyE ec+g== 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=rDDim0dsThNq+5FiX4dDfhPmRstHBqFi+K8MjA+hCCg=; b=Tl00LaYnBxaLZQvbuIa802YFh2U7iS3AXU3Qv0ueojlRaK5M76P3Q+q/Ekg07VrIsj +r1g3IipMrs8kjUHsyzQcZHjxhDTXhh46U9xVRpM6eoNXVSM0shjrPDgH9w8CmVOc7pD X5SUCCmDKV63UVdFyGQ8j+VjEsS6fCQjJEKFmVRAVOBr4beJ94pgQH6u1cnvCiPFcRvf N+NCJUP/48sAeIGjFriUDUOMoZXKtcl75iaROmuf5fJJIva6SBPoN3JSKkldYf7OGcGl EL9OwEvqjFssRAh6dagm3ek2x1Ek6go7H1srYWJpTx/0TPFHro4LUlsgscQ0Sf8KF5tu tbDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wF+6gHPP; 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 g8si11371090eds.525.2021.02.08.09.50.52; Mon, 08 Feb 2021 09:51:21 -0800 (PST) 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=wF+6gHPP; 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 S234718AbhBHRr2 (ORCPT + 99 others); Mon, 8 Feb 2021 12:47:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:38206 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233833AbhBHPay (ORCPT ); Mon, 8 Feb 2021 10:30:54 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4836864F32; Mon, 8 Feb 2021 15:17:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1612797434; bh=P1RTl2tBCk28goeiL9TdQOiQWUIG305zfykMvOZ6Zb0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wF+6gHPPizRZOGwOoMf1DTib111BdSRQNO5WgYodLpiKsaANOEq4LErh92z2di0hF lzTZVJCRPEgtXQiQ0TS9yPobn7kk4nOm1i5LSe3kPPOlPirrfj9Qovd6Yll2o5B8Lg 3QdsHlHO54MTbezRQKj11cz4iUGLvsQRvnuzZrJo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lai Jiangshan , Thomas Gleixner Subject: [PATCH 5.10 109/120] x86/debug: Prevent data breakpoints on cpu_dr7 Date: Mon, 8 Feb 2021 16:01:36 +0100 Message-Id: <20210208145822.727707820@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208145818.395353822@linuxfoundation.org> References: <20210208145818.395353822@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: Lai Jiangshan commit 3943abf2dbfae9ea4d2da05c1db569a0603f76da upstream. local_db_save() is called at the start of exc_debug_kernel(), reads DR7 and disables breakpoints to prevent recursion. When running in a guest (X86_FEATURE_HYPERVISOR), local_db_save() reads the per-cpu variable cpu_dr7 to check whether a breakpoint is active or not before it accesses DR7. A data breakpoint on cpu_dr7 therefore results in infinite #DB recursion. Disallow data breakpoints on cpu_dr7 to prevent that. Fixes: 84b6a3491567a("x86/entry: Optimize local_db_save() for virt") Signed-off-by: Lai Jiangshan Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20210204152708.21308-2-jiangshanlai@gmail.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/hw_breakpoint.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/arch/x86/kernel/hw_breakpoint.c +++ b/arch/x86/kernel/hw_breakpoint.c @@ -307,6 +307,14 @@ static inline bool within_cpu_entry(unsi (unsigned long)&per_cpu(cpu_tlbstate, cpu), sizeof(struct tlb_state))) return true; + + /* + * When in guest (X86_FEATURE_HYPERVISOR), local_db_save() + * will read per-cpu cpu_dr7 before clear dr7 register. + */ + if (within_area(addr, end, (unsigned long)&per_cpu(cpu_dr7, cpu), + sizeof(cpu_dr7))) + return true; } return false;