Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5833767imu; Tue, 13 Nov 2018 12:27:58 -0800 (PST) X-Google-Smtp-Source: AJdET5crGhC+X6zKkn/c7GkohcRvGQGMbDyYFPvpUb954Zj+Q+xlpTqm55iqoXBrjXoPXyN5mPxz X-Received: by 2002:a63:111c:: with SMTP id g28mr5981759pgl.85.1542140877988; Tue, 13 Nov 2018 12:27:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542140877; cv=none; d=google.com; s=arc-20160816; b=gpgPOEH5FgUN9Qt1fg8c4WcQq0lcBlfHkAZ4aJSFXBL/Er7T+6xvikFem8OzNy0nXi 7a0FDqivRN7MQtvf15yKDBfe3oezmaLi9JdZMdSjFyMGlXIL6jUNLU+I70uEJd6BTS94 iFCuNUlpkL9gw1ltZMSiZpJNOSknxdv7msICoL1uRE9ZywrkdmcLbpSbSWd+1PaPT2/8 HhsOwtbrXjW5gHEy4SVuET5kK/q8rKIgt3aedK9TJuvcH23sMw38KR+BS3UefxI4Yk8f 8VresgyylHS8ubwLExMoeqDC5nJ2hf2d9kjJJHgoMFXTg/+cZ9FU/fJPbj7Kok2JV60k meMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=jhdWsEOLCu5aGlsFR44KKd0rOZS0MbLfdcmPu2ZrTr8=; b=I9+Zh8YrxsORjLJj5rno7kf3ZGBcCnyqVl9n9Aqfef8674rPYs46RQnDfZpKjhhOfJ agaVn99pkWVgLkuylEmIAMIvqwhlWL0S06ubO5DpDPNV+5PD1PGCGtHwlf8qasc5BDqI u1r/pSTfFUXpm28bC12/ZSWzNPRa7aMxrxKd05PjsEvxNY4VbsZ+lfD770nAtQajl03T a44SbITXhzZ+sHGDh4czqZmwMLEsU6ouCwHuG/NZJ3SbvWdLxmi80FkjamWUXFjpO0dP GPg+pUlSZaWU3lNvO71xvCq9Jtric0ynIlTSKxWOFg8dozu5fHgIyMPvamkVXGUoGw8l TnUg== 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=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 59-v6si23309504pla.195.2018.11.13.12.27.43; Tue, 13 Nov 2018 12:27:57 -0800 (PST) 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=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728041AbeKNGZ0 (ORCPT + 99 others); Wed, 14 Nov 2018 01:25:26 -0500 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:45045 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725835AbeKNGZ0 (ORCPT ); Wed, 14 Nov 2018 01:25:26 -0500 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Tue, 13 Nov 2018 12:25:16 -0800 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 7068AB1A4D; Tue, 13 Nov 2018 15:25:38 -0500 (EST) From: Nadav Amit To: Ingo Molnar CC: , , "H. Peter Anvin" , Thomas Gleixner , Borislav Petkov , Dave Hansen , Peter Zijlstra , , , , Nadav Amit Subject: [PATCH v5 00/10] x86/alternative: text_poke() fixes Date: Tue, 13 Nov 2018 05:07:20 -0800 Message-ID: <20181113130730.44844-1-namit@vmware.com> X-Mailer: git-send-email 2.17.1 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 This patch-set addresses some issues that might affect the security and the correctness of code patching. The main issue that the patches deal with is the fact that the fixmap PTEs that are used for patching are available for access from other cores and might be exploited. They are not even flushed from the TLB in remote cores, so the risk is even higher. This set addresses this issue by introducing a temporary mm that is only used during patching. To do so, we need to avoid using text_poke() before the poking-mm is initialized and instead use text_poke_early(). During v3 of this set, Andy & Thomas suggested that early patching of modules can be improved by simply writing to the memory. This actually raises a security concern: there should not be any W+X mappings at any given moment, and modules loading breaks this protection for no good reason. So this patch also addresses this issue, while (presumably) improving patching speed by making module memory initially RW(+NX) and before execution changing it into RO(+X). In addition the patch addresses various issues that are related to code patching, and do some cleanup. I removed in this version some tested-by and reviewed-by tags due to some extensive changes of some patches. v4->v5: - Fix Xen breakage [Damian Tometzki] - BUG_ON() when poking_mm initialization fails [PeterZ] - Better comments on "x86/mm: temporary mm struct" - Cleaner removal of the custom poker v3->v4: - Setting modules as RO when loading [Andy, tglx] - Adding text_poke_kgdb() to keep the text_mutex assertion [tglx] - Simpler logic to decide when to use early-poking [peterZ] - More cleanup v2->v3: - Remove the fallback path in text_poke() [peterZ] - poking_init() was broken due to the local variable poking_addr - Preallocate tables for the temporary-mm to avoid sleep-in-atomic - Prevent KASAN from yelling at text_poke() v1->v2: - Partial revert of 9222f606506c added to 1/6 [masami] - Added Masami's reviewed-by tag RFC->v1: - Added handling of error in get_locked_pte() - Remove lockdep assertion, clarify text_mutex use instead [masami] - Comment fix [peterz] - Removed remainders of text_poke return value [masami] - Use __weak for poking_init instead of macros [masami] - Simplify error handling in poking_init [masami] Andy Lutomirski (1): x86/mm: temporary mm struct Nadav Amit (9): Fix "x86/alternatives: Lockdep-enforce text_mutex in text_poke*()" x86/jump_label: Use text_poke_early() during early init fork: provide a function for copying init_mm x86/alternative: initializing temporary mm for patching x86/alternative: use temporary mm for text poking x86/kgdb: avoid redundant comparison of code x86: avoid W^X being broken during modules loading x86/jump-label: remove support for custom poker x86/alternative: remove the return value of text_poke_*() Andy Lutomirski (1): x86/mm: temporary mm struct Nadav Amit (9): Fix "x86/alternatives: Lockdep-enforce text_mutex in text_poke*()" x86/jump_label: Use text_poke_early() during early init fork: provide a function for copying init_mm x86/alternative: initializing temporary mm for patching x86/alternative: use temporary mm for text poking x86/kgdb: avoid redundant comparison of patched code x86: avoid W^X being broken during modules loading x86/jump-label: remove support for custom poker x86/alternative: remove the return value of text_poke_*() arch/x86/include/asm/fixmap.h | 2 - arch/x86/include/asm/mmu_context.h | 32 +++++ arch/x86/include/asm/pgtable.h | 3 + arch/x86/include/asm/text-patching.h | 9 +- arch/x86/kernel/alternative.c | 208 +++++++++++++++++++++------ arch/x86/kernel/jump_label.c | 19 ++- arch/x86/kernel/kgdb.c | 19 +-- arch/x86/kernel/module.c | 2 +- arch/x86/mm/init_64.c | 35 +++++ arch/x86/xen/mmu_pv.c | 2 - include/linux/filter.h | 6 + include/linux/sched/task.h | 1 + init/main.c | 3 + kernel/fork.c | 24 +++- kernel/module.c | 10 ++ 15 files changed, 292 insertions(+), 83 deletions(-) -- 2.17.1