Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp340417yba; Fri, 26 Apr 2019 00:36:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqzNcc8C9+CPsV1H1QWAvWFC8Qiy9hVrJZR3o6lUjiqSt8oBV/EaVkTnZYvi58inknQ4unUk X-Received: by 2002:a62:2a97:: with SMTP id q145mr46385742pfq.22.1556264187644; Fri, 26 Apr 2019 00:36:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556264187; cv=none; d=google.com; s=arc-20160816; b=adeBPPdcG5tgV+gt7aoYuQZQiPw3gucLS25FdeTvEjaOSAznyjfxS2LrkM1p6RS8mm dyVDw1BkBDUdu1X/o/UVQA9aSRV2LE4PUB1f2/ncgD2QdJMXGe5F+QRBmyqt2whfnKSO gg6cXN59LPt99P+4gypQmwRz63Gntylj5cjHEXoAIR+VGEu9/09A+04Tp0Okw/tc8qXp tnbU1f0jcqNyGQT2BO3jNhJT6cchRFj3TNLW70YDwOylq9VuOg7wdOSxciQHCkiu3PuT B0oActtvBcDbJx0hos+hNf987gZJQLDJ3780vP/U1WvlnOCR7InBL4sPKrmeL9aw84D6 szng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=lPFAvintZAuLmImKiSUYUbggO4ykcKqKJ1oG7dcZTxU=; b=mpmwcwC+w3D6RBU94W8dwF+27ccVNNrEeMfT7ykd1UDjp+flATeGZbdC7aPGzI/GdX M820v0pcjycyXRJ2Y8XO2wu5+3R1YrSh1yaBmmBzDnOFy/AsbpD1rbHM0GHUlsO0dUYd jmG5IwXnVOc40MRDJfrrY1YJ8nCpdQQ3XZc/E6HZU6fNo8/4ay6vXfiH9I5YjzMAIh4R i4b6rKFEI3JwKrQHYzLQHjzbP8Z+mgVs67VOKf2zVhgmIbTCQRWVMHXne8eF0o3yr5rm KRlJ/tspbG+J+dv3sU3/hU/llONJRlbUIebNlNjzPhIT6fLue7K2iXfOuK0vM9sop30h 9VGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d30si22917874pla.404.2019.04.26.00.36.12; Fri, 26 Apr 2019 00:36:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726786AbfDZHdk (ORCPT + 99 others); Fri, 26 Apr 2019 03:33:40 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:29121 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726088AbfDZHbs (ORCPT ); Fri, 26 Apr 2019 03:31:48 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Fri, 26 Apr 2019 00:31:44 -0700 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 8042F412A4; Fri, 26 Apr 2019 00:31:45 -0700 (PDT) From: Nadav Amit To: Peter Zijlstra , Borislav Petkov , Andy Lutomirski , Ingo Molnar CC: , , , Thomas Gleixner , Nadav Amit , Dave Hansen , , , , , , , , , , , Rick Edgecombe , Nadav Amit Subject: [PATCH v5 04/23] x86/mm: Save debug registers when loading a temporary mm Date: Thu, 25 Apr 2019 17:11:24 -0700 Message-ID: <20190426001143.4983-5-namit@vmware.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190426001143.4983-1-namit@vmware.com> References: <20190426001143.4983-1-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-002.vmware.com: namit@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Prevent user watchpoints from mistakenly firing while the temporary mm is being used. As the addresses of the temporary mm might overlap those of the user-process, this is necessary to prevent wrong signals or worse things from happening. Cc: Andy Lutomirski Acked-by: Peter Zijlstra (Intel) Signed-off-by: Nadav Amit Signed-off-by: Rick Edgecombe --- arch/x86/include/asm/mmu_context.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h index 24dc3b810970..93dff1963337 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -13,6 +13,7 @@ #include #include #include +#include extern atomic64_t last_mm_ctx_id; @@ -380,6 +381,21 @@ static inline temp_mm_state_t use_temporary_mm(struct mm_struct *mm) lockdep_assert_irqs_disabled(); temp_state.mm = this_cpu_read(cpu_tlbstate.loaded_mm); switch_mm_irqs_off(NULL, mm, current); + + /* + * If breakpoints are enabled, disable them while the temporary mm is + * used. Userspace might set up watchpoints on addresses that are used + * in the temporary mm, which would lead to wrong signals being sent or + * crashes. + * + * Note that breakpoints are not disabled selectively, which also causes + * kernel breakpoints (e.g., perf's) to be disabled. This might be + * undesirable, but still seems reasonable as the code that runs in the + * temporary mm should be short. + */ + if (hw_breakpoint_active()) + hw_breakpoint_disable(); + return temp_state; } @@ -387,6 +403,13 @@ static inline void unuse_temporary_mm(temp_mm_state_t prev_state) { lockdep_assert_irqs_disabled(); switch_mm_irqs_off(NULL, prev_state.mm, current); + + /* + * Restore the breakpoints if they were disabled before the temporary mm + * was loaded. + */ + if (hw_breakpoint_active()) + hw_breakpoint_restore(); } #endif /* _ASM_X86_MMU_CONTEXT_H */ -- 2.17.1