From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19CEFC433B4 for ; Thu, 6 May 2021 02:40:33 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 650DF61164 for ; Thu, 6 May 2021 02:40:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 650DF61164 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4FbHqz1JcYz3c1D for ; Thu, 6 May 2021 12:40:31 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=cBU/6gwz; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::52b; helo=mail-pg1-x52b.google.com; envelope-from=jniethe5@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=cBU/6gwz; dkim-atps=neutral Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4FbHp12mdRz30BX for ; Thu, 6 May 2021 12:38:48 +1000 (AEST) Received: by mail-pg1-x52b.google.com with SMTP id d29so3698885pgd.4 for ; Wed, 05 May 2021 19:38:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hG50FrS7gX00Flt7bvZy6rZI5at8kJZgIUqs0mwHnNg=; b=cBU/6gwznBWYF2Grp26LHa2iDHDYz7+HRaANqE6YPn+hxsgvAcrZ+ZtbpB/WOIksJL u8Zx9mRWBRYZJIvWT4I6BvXaDUvbw5DgTRf+9xCRWldmG038K0+xOX/Xab4Grh4HwFby 76kkmBTxuqNxMZMIbtXxYaaBtccDbtT5LMOhMgse2H5jm04W6+MPrG6Vl2FYy1wmGEgC l9HdX+cWcVP7iiCiAa/LxVDnh5bBCQpaYMvl5axXfHM3jseB+gBvwnpjuWZy7rf2uXNT EFJ1xUVqJXui9j7KAmjDpiwaSHBTApV0FOfVtZWPoasnkyoH2TheKk9+Gf5UFmz/Nhsv 0SLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hG50FrS7gX00Flt7bvZy6rZI5at8kJZgIUqs0mwHnNg=; b=nJeJ+H84vJLxtM2WuBe4wIjS8vcNUElgEKLYZ/neySSczPohusnj1bLOPNpfCjo2Qn h9AkBLEQHAg3OHjvp2aSOJcibNyL/5gAAiuhRYAEBFAtv6BihodAVGCliwylDSlPu88X o4Mv/yRpT4kTmS20kM9rspWWILA8avpLAQFp4CAKT0EP/hN6kp6Msh/ysalFMK03ONLm HnBISG3GvlVkI1r2Y7ukSGQgrce33cEp9g8u/6qA0Oj/zb6VkyLl8wCjDfgoegSoQQsk n88ChYeHP3B7RMn29qjq29uT5zqXTNCGxyfXLohD7b338huGX+DlGFh9XZPTjHXfIETT UW7w== X-Gm-Message-State: AOAM532NTtWI5gIonWU5pn9yY1KRcrlfnyF1Ii7qttCT+aI2ozYjD0Zb g8sSZTByCrWy2bGWSQVjZUxriY+9sbo= X-Google-Smtp-Source: ABdhPJzQ1hWX6aJ+ZyiNlrR5fhcWlO3mx3Ku2YAguxLIJEtKC0qJFMUMAWCUt0a2V/sWSGVmTRGKWw== X-Received: by 2002:a62:2d6:0:b029:204:9b3b:dced with SMTP id 205-20020a6202d60000b02902049b3bdcedmr2166009pfc.36.1620268726783; Wed, 05 May 2021 19:38:46 -0700 (PDT) Received: from tee480.ozlabs.ibm.com (159-196-117-139.9fc475.syd.nbn.aussiebb.net. [159.196.117.139]) by smtp.gmail.com with ESMTPSA id k12sm454490pgh.16.2021.05.05.19.38.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 May 2021 19:38:46 -0700 (PDT) From: Jordan Niethe To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v12 3/8] powerpc/kprobes: Mark newly allocated probes as ROX Date: Thu, 6 May 2021 12:34:44 +1000 Message-Id: <20210506023449.3568630-4-jniethe5@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210506023449.3568630-1-jniethe5@gmail.com> References: <20210506023449.3568630-1-jniethe5@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ajd@linux.ibm.com, cmr@codefail.de, npiggin@gmail.com, aneesh.kumar@linux.ibm.com, naveen.n.rao@linux.ibm.com, Jordan Niethe , dja@axtens.net Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Russell Currey Add the arch specific insn page allocator for powerpc. This allocates ROX pages if STRICT_KERNEL_RWX is enabled. These pages are only written to with patch_instruction() which is able to write RO pages. Reviewed-by: Daniel Axtens Signed-off-by: Russell Currey Signed-off-by: Christophe Leroy [jpn: Reword commit message, switch to __vmalloc_node_range()] Signed-off-by: Jordan Niethe --- v9: - vmalloc_exec() no longer exists - Set the page to RW before freeing it v10: - use __vmalloc_node_range() v11: - Neaten up v12: - Switch from __vmalloc_node_range() to module_alloc() --- arch/powerpc/kernel/kprobes.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c index 01ab2163659e..73a294802f72 100644 --- a/arch/powerpc/kernel/kprobes.c +++ b/arch/powerpc/kernel/kprobes.c @@ -19,11 +19,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL; @@ -103,6 +105,21 @@ kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset) return addr; } +void *alloc_insn_page(void) +{ + void *page; + + page = module_alloc(PAGE_SIZE); + if (!page) + return NULL; + + if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) { + set_memory_ro((unsigned long)page, 1); + set_memory_x((unsigned long)page, 1); + } + return page; +} + int arch_prepare_kprobe(struct kprobe *p) { int ret = 0; -- 2.25.1