From patchwork Mon Oct 17 14:54:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 3546 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1494618wrs; Mon, 17 Oct 2022 07:59:24 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6CJn1v7qpt715RyuiF6udewwz0WDvDvTxhQpbF3V7126XykQkUEz77s8y8Dg1gRlyEdL66 X-Received: by 2002:aa7:8dd5:0:b0:565:d35c:4a5d with SMTP id j21-20020aa78dd5000000b00565d35c4a5dmr13140470pfr.7.1666018764061; Mon, 17 Oct 2022 07:59:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666018764; cv=none; d=google.com; s=arc-20160816; b=SObefzwMz+pMfuoLbNh7+OcVV3B8WnNgsz5V8agfoFxto61Enyjg3eeyqaQCjXZ+4q 50Yg53gagzISb3uzM7PP4DmzoKbAVzi1ozk4BtPXEDCx2LsPInJEtmusNc0yb1HcQCPE cixUIChYqdAxcMX5et0zR0UxMpXBJ1MiACvKwoKYGAuMEhPH5y+H5QVIhlfsUevOycHA 8vMAzB5PU64QkPNwGjvbPV/MU2k0WlLcDpJwn7BXNfjYGHFKOx58QQqVcbwTOKxVOkb/ ZV4nzWD6DOOkzV0IosU+Aku3PMfmeG3fM95uMu8tqmXgzMqCfzRdJmZMvVhyfGtR8D1r 3Ujg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=OTvjpn0KgxNDsUjGGkGy4CVh9hhBuLzsShC+ZJJI72s=; b=w7qRUjmWjpNAKV3bykBkiwaY21zN3Q1IfMDQv69nnozKj2k3oG3j9vGtxh5XwSE0/G ymY1YGH9zzbEwKLB9HA4fqAvGuGPusul09dCgB+LJfkXYYRl6eoSexmeNf2tgcQ7VLuB Vze0TW1Z+zGsow8Klusq0sU7JgCTQYtI6cN9q8+OKvX/91GhfuMM49xn4RLLKEeKNoZH 3/k5T4XlrsRxY3G4PyifyJPxyBFpWJrpKtSfzMYwTVFPQIQ2orm2iNLde8APtHBhlULw adjP4C0F4nVB2jlFOdc73QAZuyiBOh2PWwn9BIBEOAxGgE2IYosefdyfYb6mnNQBkt7t XSXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZuUbGX3e; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Dt+G7S7e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b8-20020a17090a550800b0020b020b98a1si11770098pji.36.2022.10.17.07.59.10; Mon, 17 Oct 2022 07:59:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=ZuUbGX3e; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=Dt+G7S7e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231299AbiJQO64 (ORCPT + 99 others); Mon, 17 Oct 2022 10:58:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231481AbiJQO5c (ORCPT ); Mon, 17 Oct 2022 10:57:32 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E5B568885; Mon, 17 Oct 2022 07:55:06 -0700 (PDT) Date: Mon, 17 Oct 2022 14:54:27 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1666018469; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OTvjpn0KgxNDsUjGGkGy4CVh9hhBuLzsShC+ZJJI72s=; b=ZuUbGX3ey9eh0jBsFcA2kdL30QHF9+gx2ErowuXokFcOl55hCFV2jiq5nIeH/Eex+qIU+z 82UvcM/XGrI4oy8viPD8cuwyJW/wPSLGZRz5MMEg0CIZkQOgObWsKdCX8ZZg4tmEjxllY8 Hpv2VJ2WZj4pzHSVY5P+lBhPBponHHhQMUK+01SODfyYuEHGqezH2vmPh1bkTAI27c1OQ5 +t5S1iZFDWEkUnCer0VQd2mcwtGU+4vj+Upr1L5j2eLy/60FmEri507fWmhZOGI1WutY29 7S06+AtZakNC8KUisQ24cc2IUTioJRErY6Zo1/1kDQpd65L9WAALtehtrs+B1Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1666018469; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OTvjpn0KgxNDsUjGGkGy4CVh9hhBuLzsShC+ZJJI72s=; b=Dt+G7S7eDmQAVkBZBs/EHpf9iUowfCZrLbdlc392Rw5FYqOMd/+wh1yh22GDeTkY7fXkWw mqARFQmuWUOCrzBw== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/core] x86/modules: Set VM_FLUSH_RESET_PERMS in module_alloc() Cc: Thomas Gleixner , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220915111143.406703869@infradead.org> References: <20220915111143.406703869@infradead.org> MIME-Version: 1.0 Message-ID: <166601846783.401.2287915526289128493.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746947291264744995?= X-GMAIL-MSGID: =?utf-8?q?1746947291264744995?= The following commit has been merged into the x86/core branch of tip: Commit-ID: 4c4eb3ecc91f4fee6d6bf7cfbc1e21f2e38d19ff Gitweb: https://git.kernel.org/tip/4c4eb3ecc91f4fee6d6bf7cfbc1e21f2e38d19ff Author: Thomas Gleixner AuthorDate: Thu, 15 Sep 2022 13:10:44 +02:00 Committer: Peter Zijlstra CommitterDate: Mon, 17 Oct 2022 16:40:57 +02:00 x86/modules: Set VM_FLUSH_RESET_PERMS in module_alloc() Instead of resetting permissions all over the place when freeing module memory tell the vmalloc code to do so. Avoids the exercise for the next upcoming user. Signed-off-by: Thomas Gleixner Signed-off-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/r/20220915111143.406703869@infradead.org --- arch/x86/kernel/ftrace.c | 2 -- arch/x86/kernel/kprobes/core.c | 1 - arch/x86/kernel/module.c | 9 +++++---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index bd16500..00eac45 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -413,8 +413,6 @@ create_trampoline(struct ftrace_ops *ops, unsigned int *tramp_size) /* ALLOC_TRAMP flags lets us know we created it */ ops->flags |= FTRACE_OPS_FL_ALLOC_TRAMP; - set_vm_flush_reset_perms(trampoline); - if (likely(system_state != SYSTEM_BOOTING)) set_memory_ro((unsigned long)trampoline, npages); set_memory_x((unsigned long)trampoline, npages); diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index eb8bc82..01b8d95 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -414,7 +414,6 @@ void *alloc_insn_page(void) if (!page) return NULL; - set_vm_flush_reset_perms(page); /* * First make the page read-only, and only then make it executable to * prevent it from being W+X in between. diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index c032edc..43f0112 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -74,10 +74,11 @@ void *module_alloc(unsigned long size) return NULL; p = __vmalloc_node_range(size, MODULE_ALIGN, - MODULES_VADDR + get_module_load_offset(), - MODULES_END, gfp_mask, - PAGE_KERNEL, VM_DEFER_KMEMLEAK, NUMA_NO_NODE, - __builtin_return_address(0)); + MODULES_VADDR + get_module_load_offset(), + MODULES_END, gfp_mask, PAGE_KERNEL, + VM_FLUSH_RESET_PERMS | VM_DEFER_KMEMLEAK, + NUMA_NO_NODE, __builtin_return_address(0)); + if (p && (kasan_alloc_module_shadow(p, size, gfp_mask) < 0)) { vfree(p); return NULL;