Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2737820yba; Mon, 22 Apr 2019 12:02:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqyP7mWijaA8GQAENNZ03PUE12v5In5VruP0md0g7JoVUPJ5S99Ld7EGzJ5ra6PZD+39Vh7U X-Received: by 2002:a63:d250:: with SMTP id t16mr20432911pgi.288.1555959770614; Mon, 22 Apr 2019 12:02:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555959770; cv=none; d=google.com; s=arc-20160816; b=TyZGOZ5v3lgoXDBA11+iRbzdPZzclqpBSJvDnyhBc6tVdg7fOf8hv5BgGVYTEFxL4g e6+p6NJ6VMPvdWJp3IzwaEszlflYpjvclIwsXVWjeBqthOqzOCMHE7XRJqWt/aUtt1g7 WCJCWczC/qrn5v6o9FLKHRLYt6YXyhAA01eyxsxQcEDarsGEPt3/U3OGFquKkc2PVUnT tLfxdiMev79Fgf2TxNqKy6QYCJg620Hg6IIDG/MZJJT/RV4bRpn79I5zlhi4VSm3vj/Q bDz5TKTIVqgZpBBdypCY/nXWqY5IlCqx4fkVYCTjH0bvAInRjrKM0emm3WV8kG5PDvUc qQwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=EpX7PmmGjCsoe95ecfJDQVEnFby3S4g+dchtH/l+eVw=; b=UHfrntfRAqYxAALQtp6oSYBs0+QcZ0mqw2KMU1lxqqSN1tGamyYxLsHUyG9KQWOVIO zJ3kDRrf/mGwhf/to9pdeDigikU9TmTaYUkuFuDcxseo0zNf3PfjxVDSJdvmBV+qgcer zv/GO2wIv0Dchvm+eACLwJc2WHXhgJqFV/i/xva6uG4fKrw8YLDCSs9h6AxkI0FBpvPJ bFfCqPmcbmwz+HlmRbcgEfbvUNrurqNDxkhwHtyrX/dRcZAKIVNNSUBTgaHxyiSWO8cw F7woLADwmYtu+4rSSuX6OM/BxTDG0DYvrwgrSkOnc9B/r7xJ236+bN/ou1uLHH4vKSdz +gbw== 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=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z186si12638370pgd.155.2019.04.22.12.02.35; Mon, 22 Apr 2019 12:02:50 -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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728987AbfDVTAn (ORCPT + 99 others); Mon, 22 Apr 2019 15:00:43 -0400 Received: from mga11.intel.com ([192.55.52.93]:60347 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728703AbfDVS6o (ORCPT ); Mon, 22 Apr 2019 14:58:44 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Apr 2019 11:58:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,382,1549958400"; d="scan'208";a="136417128" Received: from linksys13920.jf.intel.com (HELO rpedgeco-DESK5.jf.intel.com) ([10.54.75.11]) by orsmga008.jf.intel.com with ESMTP; 22 Apr 2019 11:58:41 -0700 From: Rick Edgecombe To: Borislav Petkov , Andy Lutomirski , Ingo Molnar Cc: linux-kernel@vger.kernel.org, x86@kernel.org, hpa@zytor.com, Thomas Gleixner , Nadav Amit , Dave Hansen , Peter Zijlstra , linux_dti@icloud.com, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, akpm@linux-foundation.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, will.deacon@arm.com, ard.biesheuvel@linaro.org, kristen@linux.intel.com, deneen.t.dock@intel.com, Nadav Amit , Rick Edgecombe Subject: [PATCH v4 04/23] x86/mm: Save DRs when loading a temporary mm Date: Mon, 22 Apr 2019 11:57:46 -0700 Message-Id: <20190422185805.1169-5-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190422185805.1169-1-rick.p.edgecombe@intel.com> References: <20190422185805.1169-1-rick.p.edgecombe@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nadav Amit Prevent user watchpoints from mistakenly firing while the temporary mm is being used. As the addresses that 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 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 d684b954f3c0..81861862038a 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(); state.prev = 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 state; } @@ -387,6 +403,13 @@ static inline void unuse_temporary_mm(temp_mm_state_t prev) { lockdep_assert_irqs_disabled(); switch_mm_irqs_off(NULL, prev.prev, 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