Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4778854yba; Tue, 30 Apr 2019 04:21:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqzGbeHLDZ6UwcTC7daUUmbf26rDR9vqDh5IXfJ99qrBKVj+ZyIkiqI+WkTzdg0hWAlubRzu X-Received: by 2002:a63:1301:: with SMTP id i1mr19867925pgl.226.1556623285300; Tue, 30 Apr 2019 04:21:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556623285; cv=none; d=google.com; s=arc-20160816; b=OyAU11DN9ordnf9aYoEXeSgzgpthEzUIBqJGkYu00O6rsJojSZsk/w0YeKixgm8RbG 201kqnSqRmN6WDEn7cX9VicVdCmiZSDEvgtbsSYwvaYoSQI1S2j14gPyFrGPZmHq7HBp 4E75AGcJR1A3XcWMEtsQFUo3o6ZzBIV9rXaAao2dK7/uvErvkW1flI8dYXkvvVUt7K/O ddEHdP6taDF3ntkawSZCFFzD+YOJd2eYlX8TcdYxTqjOOD8xTbPeAFOdRhKViBHzRSb6 WMbQibxM2ynuhqnEp0LUqw8BytqIIDGogsTQaBxXcYdGnR0ou9amRfaLnZexYPYj39KP mZWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:dkim-signature:dkim-filter; bh=iVUAx2Bubh49DKX266pi1uDMbz1jQDL6ubH1m7QOUEw=; b=RWnhTLO2GNAjdVuvl8A7Ini+zPWiyyZijqMxaMwfLpBKkd4S8K5tSmeRTNduB4jrjM +fX1rQZlrz2mfh0qyfJNasTEhnbqbikUAvOqmGsvdCbHoHacmmXeIQvCxxwIOlo8xas0 5OvZ54UUFaLgnmn/j8bHiwLcUs5nwGLPovbARgi4V8e7gQbqPoh6SStO92nTj60pXk4B ie4Uh5awPu4JIIK/f9Khbkx9EE4Hma8VstRYcWEE7L6KxjEU6NnyjF7kwIoiiWbsqEdU 4s3MozklpwT6W6GIsANojNzNfj9fJuWumRSdJYV/sguWN7NoYy5znVqsbfHbBFQ4GpHa cG2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zytor.com header.s=2019041745 header.b=m2XXsiHU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y29si36085007pgk.120.2019.04.30.04.21.09; Tue, 30 Apr 2019 04:21:25 -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; dkim=pass header.i=@zytor.com header.s=2019041745 header.b=m2XXsiHU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727570AbfD3LSV (ORCPT + 99 others); Tue, 30 Apr 2019 07:18:21 -0400 Received: from terminus.zytor.com ([198.137.202.136]:50349 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726648AbfD3LSU (ORCPT ); Tue, 30 Apr 2019 07:18:20 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x3UBI0nW1346868 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 30 Apr 2019 04:18:00 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 terminus.zytor.com x3UBI0nW1346868 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2019041745; t=1556623080; bh=iVUAx2Bubh49DKX266pi1uDMbz1jQDL6ubH1m7QOUEw=; h=Date:From:Cc:Reply-To:In-Reply-To:References:To:Subject:From; b=m2XXsiHUbHw6knN55s4hDiFeIZJ6BrfbG2WZMC3mu12ZhHOCTHSmB32ini4U3oz5q Xw62FKUg/QVtqweDahTQd7ooQiD8os+WafrI9qBkc/Sz4UaDPHySTmmMm2Xrke/AOY 1ozK5gIguYsLjOOgSH8lgiNTeosmI4w0SbIvoBagclu3yOcrB+f8k+iyaWc7ZAw5N2 wR8qGU10QVoxHagNXW+jyMl1dg9JP2ypz1khtJdEXREv0rItVL5h3fABXTmF2ee32H sh61t44YfhzCBjTISo/w6JTeRnRHl4lXqG4ZgFF5LmzXd6dJV/6PQXlYDIM5tt8/jq /vf+/o1USJi6A== Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x3UBHxDq1346863; Tue, 30 Apr 2019 04:17:59 -0700 Date: Tue, 30 Apr 2019 04:17:59 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Nadav Amit Message-ID: Cc: namit@vmware.com, linux-kernel@vger.kernel.org, rick.p.edgecombe@intel.com, peterz@infradead.org, bp@alien8.de, luto@kernel.org, riel@surriel.com, acme@kernel.org, lkp@intel.com, mingo@kernel.org, dave.hansen@linux.intel.com, hpa@zytor.com, torvalds@linux-foundation.org, tglx@linutronix.de Reply-To: bp@alien8.de, peterz@infradead.org, luto@kernel.org, linux-kernel@vger.kernel.org, namit@vmware.com, rick.p.edgecombe@intel.com, hpa@zytor.com, tglx@linutronix.de, torvalds@linux-foundation.org, riel@surriel.com, mingo@kernel.org, dave.hansen@linux.intel.com, lkp@intel.com, acme@kernel.org In-Reply-To: <20190426232303.28381-6-nadav.amit@gmail.com> References: <20190426232303.28381-6-nadav.amit@gmail.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/mm] uprobes: Initialize uprobes earlier Git-Commit-ID: aad42dd44db086c79ca3f470ad563d2ac4ac218d X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-3.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: aad42dd44db086c79ca3f470ad563d2ac4ac218d Gitweb: https://git.kernel.org/tip/aad42dd44db086c79ca3f470ad563d2ac4ac218d Author: Nadav Amit AuthorDate: Fri, 26 Apr 2019 16:22:44 -0700 Committer: Ingo Molnar CommitDate: Tue, 30 Apr 2019 12:37:51 +0200 uprobes: Initialize uprobes earlier In order to have a separate address space for text poking, we need to duplicate init_mm early during start_kernel(). This, however, introduces a problem since uprobes functions are called from dup_mmap(), but uprobes is still not initialized in this early stage. Since uprobes initialization is necassary for fork, and since all the dependant initialization has been done when fork is initialized (percpu and vmalloc), move uprobes initialization to fork_init(). It does not seem uprobes introduces any security problem for the poking_mm. Crash and burn if uprobes initialization fails, similarly to other early initializations. Change the init_probes() name to probes_init() to match other early initialization functions name convention. Reported-by: kernel test robot Signed-off-by: Nadav Amit Signed-off-by: Peter Zijlstra (Intel) Cc: Andy Lutomirski Cc: Arnaldo Carvalho de Melo Cc: Borislav Petkov Cc: Dave Hansen Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Rick Edgecombe Cc: Rik van Riel Cc: Thomas Gleixner Cc: akpm@linux-foundation.org Cc: ard.biesheuvel@linaro.org Cc: deneen.t.dock@intel.com Cc: kernel-hardening@lists.openwall.com Cc: kristen@linux.intel.com Cc: linux_dti@icloud.com Cc: will.deacon@arm.com Link: https://lkml.kernel.org/r/20190426232303.28381-6-nadav.amit@gmail.com Signed-off-by: Ingo Molnar --- include/linux/uprobes.h | 5 +++++ kernel/events/uprobes.c | 8 +++----- kernel/fork.c | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h index 103a48a48872..12bf0b68ed92 100644 --- a/include/linux/uprobes.h +++ b/include/linux/uprobes.h @@ -115,6 +115,7 @@ struct uprobes_state { struct xol_area *xol_area; }; +extern void __init uprobes_init(void); extern int set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr); extern int set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr); extern bool is_swbp_insn(uprobe_opcode_t *insn); @@ -154,6 +155,10 @@ extern void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr, struct uprobes_state { }; +static inline void uprobes_init(void) +{ +} + #define uprobe_get_trap_addr(regs) instruction_pointer(regs) static inline int diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index c5cde87329c7..e6a0d6be87e3 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -2294,16 +2294,14 @@ static struct notifier_block uprobe_exception_nb = { .priority = INT_MAX-1, /* notified after kprobes, kgdb */ }; -static int __init init_uprobes(void) +void __init uprobes_init(void) { int i; for (i = 0; i < UPROBES_HASH_SZ; i++) mutex_init(&uprobes_mmap_mutex[i]); - if (percpu_init_rwsem(&dup_mmap_sem)) - return -ENOMEM; + BUG_ON(percpu_init_rwsem(&dup_mmap_sem)); - return register_die_notifier(&uprobe_exception_nb); + BUG_ON(register_die_notifier(&uprobe_exception_nb)); } -__initcall(init_uprobes); diff --git a/kernel/fork.c b/kernel/fork.c index 9dcd18aa210b..44fba5e5e916 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -815,6 +815,7 @@ void __init fork_init(void) #endif lockdep_init_task(&init_task); + uprobes_init(); } int __weak arch_dup_task_struct(struct task_struct *dst,