Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1999611lqg; Mon, 4 Mar 2024 09:43:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUYtJS33qnsz9Oim8TOjbzVLixfMorPR+CNcBsuosyUv/i3vpUO7GsN9tYSuzxKIGx9wEzI8n7cYHAkenCE6zhNhpTMpB/zfFUdJjfiag== X-Google-Smtp-Source: AGHT+IHM/JxYREXDUb4dtr+2OleTNvUAIFm/ssq4dCeWE4S9FxtY/AuwfTlz6X/qhiQbTFJl5WlM X-Received: by 2002:a05:6512:34c4:b0:513:4bf6:9710 with SMTP id w4-20020a05651234c400b005134bf69710mr1133300lfr.26.1709574233095; Mon, 04 Mar 2024 09:43:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709574233; cv=pass; d=google.com; s=arc-20160816; b=jG9FYLJ7NVgorDwWQpzelkfD/VJtcU9pZmenN15yuaMZWcYABC5IbjxZxwnTOZqbrj k6JJ0avsJtrIhDIXG3IG7pRaXQgTZElGFellskLnyOKzueQIyjarlNuyqWl/1bRvQP7/ 7Vs5CVszJZTjC348tlh6jqVXMJ8bfrTdcjTYWVYITRfUfSsYIrCQZmrm7sIJD9LqszUZ nh0tVOHrq/H8O7C6zBsnO9stLFQwuxkNLsw3lVsIDpnOvh6qMBkOzxRDbrTGGTBkMOhn 6VvIn5+3moxRfE6448qmVDgzuT7+rHaD4b6/k9rJkRWvzqEMYSMl7U5D+2cHDUPo6f1u JKkw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=avRWHU8M4QiZaJ1VUjT1h71GgCHpu89KSWnmXCLWs8U=; fh=ZNQh3oeHUv4xU+iduHJPkfCjnD0oU9jL3TM5AwgQSQg=; b=TVZqw7SdOBkMK9h2yEWYpGGHKZv+Y/m/886SbG3POeWEoKOaG5M/frRI80a+MR5xic FHLGKR5rYZEYZFahIUsn9yRzLURpz3a3bufnZvy3nHHDLHMnwczjcp2yAKdr5y9DyKdV UMz+mFQrSr5JIhEiwdEoEVj7zJ5f/GdOBeZYvnFb9hYGHoxHmVWfPrU1dZQwVdOW9sT5 Zkb4kIqfdFQziF4BdDAyTFjv86ED2z0CHKeKd+g4kcne4Cbdm+H7I/NR/u92FTEDNaKf ri8D61/FcQkNL+y4P0OqgCId6Gls+3mJ6Y8sVwlVNdLaQgHATJHclrxDU0IXl5ryGHnQ suGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=mr5lOpib; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-91018-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91018-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u23-20020a50d517000000b005664cf05f01si4241602edi.558.2024.03.04.09.43.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 09:43:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-91018-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=mr5lOpib; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-91018-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91018-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9781D1F22CDB for ; Mon, 4 Mar 2024 17:43:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E559B612F7; Mon, 4 Mar 2024 17:43:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mr5lOpib" Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74F944653A for ; Mon, 4 Mar 2024 17:43:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709574226; cv=none; b=daSJ8QYDGMI7TXoaG0NlW+zHCZv+iLH7/8qDljvgrKv1XHs3QXXgxy/XUeB0emEW/hXhpe/kSG1lkhzQ9dXOg4IocKmmQeVpFKicdR1GLffG+71UiqmVXBc6IfFYjHGD436/VfULZO99CxIYRk4rQuzz2JOe+qbO14mKgjgh0Hs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709574226; c=relaxed/simple; bh=csBhKfknigH6z0pQN2wfmequHHA18feIPmtOVrb7rUA=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=gfbjAszOjeJB8MwRH+bkQ6TGndOLXccOMAnrGEHZbzLXJyeU8qGPiznEI+IAFiCXHbbEDEPf8oB8+fAbHKVdaygaQiqq7h2VaWhn1GUGanUbufULl/ibC1lLp8zFB8RbhM3E4bUo190VodPPC6jOeBV0sfEqjdGtZ5bHRmCklGA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=mr5lOpib; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-412d84ffbfaso1995e9.0 for ; Mon, 04 Mar 2024 09:43:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709574223; x=1710179023; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=avRWHU8M4QiZaJ1VUjT1h71GgCHpu89KSWnmXCLWs8U=; b=mr5lOpibv3RMTfIytOlWQuuL+PqHQcNpLkx/pJ2pW4zo/Xmcnq2Z7ybD9Z47vT2UpR ibcDZ1v3frWv5n/y0u+wz/pTHofFduYbJODhV9nOJggXT4KwkHctZnxj25S7cWgZ1VRj UglN4zSPgsn4PDyIwUwml3i+87iVHpwh/4grafiB5m0/A8ADwUHG8YD7J4FsPDX/ks4+ RmjjYSOKs5V6UWocqPQsyDfS10+mARU4Y3biw06IoNEy4cmHa2FPliWBbPugjcemISb+ 3yNEeswu9C3LyR0msqYKZYGDYrG7qsOG/wq7fuXhZ/RJIY60f7LVZ/2lq2MZfjc0dEHe oPCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709574223; x=1710179023; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=avRWHU8M4QiZaJ1VUjT1h71GgCHpu89KSWnmXCLWs8U=; b=j2Mw5zPn/RsSDEFrGC9lKU8fp/VtehuqvsWTRqmjTG7AWNBxae13oj1nGnMMEoXhey m7WGnery4Zneq9tVGwujaIe6oPvW2PQNi2g5/45djYSLMI9oP+8pAF60sOOmAGq+lhjx U7kxO6HGLZrxMGJ1gmGY0GXMxLlVvLt+E0EDzXUtsrzkibrU53c+k9LQU27x8l3IFgLt iDPjnkRlw/QZupk1EV9c5m8NSi6RDDnCShkUBBiMfV/dY48y/PtellFjPyndz1vc92IS QCehLjxbHIeU/RFUzPEVJcm1crNJBd++SbOCqIDffSFMqitD0e8UulUwv4FHWVyda1rR XacQ== X-Forwarded-Encrypted: i=1; AJvYcCVd75aAcNn5bmvHJWU8WV1E7JmuzG+11qnFS88rVfrPTgYleMO7AbwoQEJHnih7AYEePdKgH8t4hbCz8olqnumQ3ncMQcda0+M6IzDc X-Gm-Message-State: AOJu0YyI/7SVDEMrgYIg2/szLtae26GSTofSuW/bPxkxvOOz2lEOCTkB CleA1pzMYHJNVXQ4cgLm4d2JoHgvHCDihDQD5Zs0RoM+ztqK3rKKu+8dOxbRaA== X-Received: by 2002:a05:600c:3b20:b0:412:e4fc:b10 with SMTP id m32-20020a05600c3b2000b00412e4fc0b10mr175366wms.3.1709574222713; Mon, 04 Mar 2024 09:43:42 -0800 (PST) Received: from localhost ([2a00:79e0:9d:4:ad6c:c121:3812:b9b6]) by smtp.gmail.com with ESMTPSA id q13-20020a5d61cd000000b0033e11ff6284sm12119927wrv.12.2024.03.04.09.43.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 09:43:42 -0800 (PST) From: Jann Horn To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org Subject: [PATCH] x86/debug: Forbid tracing arch_uninstall_hw_breakpoint() Date: Mon, 4 Mar 2024 18:43:36 +0100 Message-ID: <20240304174336.68929-1-jannh@google.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit I tried using perf_event_open() to set hardware breakpoints on every allowed address between the kernel's _text and _etext. (For reasons.) arch_uninstall_hw_breakpoint() was the only function where this immediately blew up, with DB0 set to the address of the instruction for `dr7 = this_cpu_read(cpu_dr7)`, where the directly preceding instruction does `*slot = NULL;`. I think the issue there is that we clear the breakpoint tracking state before actually disarming the breakpoint. Signed-off-by: Jann Horn --- arch/x86/kernel/hw_breakpoint.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/hw_breakpoint.c b/arch/x86/kernel/hw_breakpoint.c index b01644c949b2..f46a460dbd31 100644 --- a/arch/x86/kernel/hw_breakpoint.c +++ b/arch/x86/kernel/hw_breakpoint.c @@ -140,8 +140,11 @@ int arch_install_hw_breakpoint(struct perf_event *bp) * * Atomic: we hold the counter->ctx->lock and we only handle variables * and registers local to this cpu. + * + * noinstr avoids getting hit with a breakpoint when the debug register is + * still active but we've already removed ourselves from bp_per_reg. */ -void arch_uninstall_hw_breakpoint(struct perf_event *bp) +void noinstr arch_uninstall_hw_breakpoint(struct perf_event *bp) { struct arch_hw_breakpoint *info = counter_arch_bp(bp); unsigned long dr7; -- 2.39.2