Message ID | 20230918072955.2507221-10-rppt@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2491347vqi; Mon, 18 Sep 2023 00:49:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/TkJT+mjHW3N2Z/YohXclPwnQftyot3YCN4TVGaS/JOBzQWrB3Hi285CYVj7ViS4A3PQ/ X-Received: by 2002:a05:6a20:9699:b0:148:4c5:9714 with SMTP id hp25-20020a056a20969900b0014804c59714mr7052975pzc.13.1695023348864; Mon, 18 Sep 2023 00:49:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695023348; cv=none; d=google.com; s=arc-20160816; b=PrmsukZozurKlu1H9fvxQJm+azagBSg9dSyJBgy3LwjwpPkuP7BT4JeN0dKXkFVYiT lUScB/s/pXqVBCW1Jy4YwnJKBr4CgH0nFgFFMV4BEdqg4v8X5VCquk1j/skRUyBrP9Rz 1Io7ZiKxyATkCn+P3kwwsNX2o/jNBGm6FhH8BH4PSnNbU6Tf78+HJvguw+6xY+G2CBgw pSnSI8SorJRGV8Aqdh/hVDGmmIeIR/AjNcHSgPs0mo95sgdKD8V639xkrbnHj7J11ray 5oyufY+btehf58/50B9U6BG85OMTtn1jWfMl5zZjjBiZgOE4ViPrXRraeVwCZvYuSOaC 3mww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EJSx7dTPSl55UPeMrpomdQNp6HYHj5K4Qaz1intYvHs=; fh=mYytDhFxh0BOqNSa1Iv610hxG4sclAxBmwUIWE9B5gw=; b=cgimPfSVoQ8qshahlN4W0muIOlUIBi8C/xWb2v67HxI8EBMlUbnavP/60Zq+LiE3Xn KveO/bwqT/fG3vD+5oDmpywg3tNrzEB7jqwl4Fx5WmQYVwFQb0jYI8rs/xnTzeffBo7G FINaOEfZ8JGJS6tmVWZdLKWkVtQx2V0szCA2PZDsNN7apgHfKVgQjd6FZjFeBPE/mdGq XTBpqIvJW/Vh7qtLdiilpJMabmupd3M7KSdew+jyD5tTDb+RXPpbVvynawc2upC1TL29 O1tYx6OhTDicfMQrxsKEY9NlBrN6hgjCHIoxnO7sJFHGPn+vLeyNVLrcsHbFHwXetvw+ 6y+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d2NNM60P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id u17-20020a17090341d100b001b8af930e3dsi8075202ple.487.2023.09.18.00.49.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 00:49:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d2NNM60P; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id C008A80BC3ED; Mon, 18 Sep 2023 00:33:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238569AbjIRHc3 (ORCPT <rfc822;kernel.ruili@gmail.com> + 27 others); Mon, 18 Sep 2023 03:32:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240385AbjIRHb4 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 18 Sep 2023 03:31:56 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03D8118C; Mon, 18 Sep 2023 00:31:42 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5155AC433B7; Mon, 18 Sep 2023 07:31:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695022302; bh=35ZlmvV7rKqwzQaOmbBijH380/EeVtPirZbGWiToTW8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d2NNM60PB58jmuhS2dGN8NLbq1KB4ygYvRR0t6DZZJS7qBVZpROHao20O2uQV3bli 0QvXp0s5+eLFeJhc/w10Fn3KC9lksq3uhoYzEZC5CWp+6gjai+j/d0a89/bBUhyjJy FfXXBFOSn88hPGWgJbSxUtSr8ULAUympoyAWJKP5uJmt4lykdt9r5kJb2u9np9CG9l pAU2vChu/4/QGlbV5wO6V/EhzFjCpLIlsY1oLhcdgzQ+bitYphtILzsTup5ZLrX357 OmssgGZ5JmBAamSicGtU177ClYYdO2+YHkslBuFOroSFhEYDOcBWDp8NAr0VRv3fiX mkBw/0g11HpDQ== From: Mike Rapoport <rppt@kernel.org> To: linux-kernel@vger.kernel.org Cc: Andrew Morton <akpm@linux-foundation.org>, =?utf-8?b?QmrDtnJuIFTDtnBl?= =?utf-8?b?bA==?= <bjorn@kernel.org>, Catalin Marinas <catalin.marinas@arm.com>, Christophe Leroy <christophe.leroy@csgroup.eu>, "David S. Miller" <davem@davemloft.net>, Dinh Nguyen <dinguyen@kernel.org>, Heiko Carstens <hca@linux.ibm.com>, Helge Deller <deller@gmx.de>, Huacai Chen <chenhuacai@kernel.org>, Kent Overstreet <kent.overstreet@linux.dev>, Luis Chamberlain <mcgrof@kernel.org>, Mark Rutland <mark.rutland@arm.com>, Michael Ellerman <mpe@ellerman.id.au>, Mike Rapoport <rppt@kernel.org>, Nadav Amit <nadav.amit@gmail.com>, "Naveen N. Rao" <naveen.n.rao@linux.ibm.com>, Palmer Dabbelt <palmer@dabbelt.com>, Puranjay Mohan <puranjay12@gmail.com>, Rick Edgecombe <rick.p.edgecombe@intel.com>, Russell King <linux@armlinux.org.uk>, Song Liu <song@kernel.org>, Steven Rostedt <rostedt@goodmis.org>, Thomas Bogendoerfer <tsbogend@alpha.franken.de>, Thomas Gleixner <tglx@linutronix.de>, Will Deacon <will@kernel.org>, bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, linux-parisc@vger.kernel.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, loongarch@lists.linux.dev, netdev@vger.kernel.org, sparclinux@vger.kernel.org, x86@kernel.org Subject: [PATCH v3 09/13] powerpc: extend execmem_params for kprobes allocations Date: Mon, 18 Sep 2023 10:29:51 +0300 Message-Id: <20230918072955.2507221-10-rppt@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230918072955.2507221-1-rppt@kernel.org> References: <20230918072955.2507221-1-rppt@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 18 Sep 2023 00:33:16 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777360803448765803 X-GMAIL-MSGID: 1777360803448765803 |
Series |
mm: jit/text allocator
|
|
Commit Message
Mike Rapoport
Sept. 18, 2023, 7:29 a.m. UTC
From: "Mike Rapoport (IBM)" <rppt@kernel.org> powerpc overrides kprobes::alloc_insn_page() to remove writable permissions when STRICT_MODULE_RWX is on. Add definition of EXECMEM_KRPOBES to execmem_params to allow using the generic kprobes::alloc_insn_page() with the desired permissions. As powerpc uses breakpoint instructions to inject kprobes, it does not need to constrain kprobe allocations to the modules area and can use the entire vmalloc address space. Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org> --- arch/powerpc/kernel/kprobes.c | 14 -------------- arch/powerpc/kernel/module.c | 11 +++++++++++ 2 files changed, 11 insertions(+), 14 deletions(-)
Comments
On Mon, Sep 18, 2023 at 12:31 AM Mike Rapoport <rppt@kernel.org> wrote: > [...] > @@ -135,5 +138,13 @@ struct execmem_params __init *execmem_arch_params(void) > > range->pgprot = prot; > > + execmem_params.ranges[EXECMEM_KPROBES].start = VMALLOC_START; > + execmem_params.ranges[EXECMEM_KPROBES].start = VMALLOC_END; .end = VMALLOC_END. Thanks, Song > + > + if (strict_module_rwx_enabled()) > + execmem_params.ranges[EXECMEM_KPROBES].pgprot = PAGE_KERNEL_ROX; > + else > + execmem_params.ranges[EXECMEM_KPROBES].pgprot = PAGE_KERNEL_EXEC; > + > return &execmem_params; > } > -- > 2.39.2 > >
Hi Mike, Le 18/09/2023 à 09:29, Mike Rapoport a écrit : > From: "Mike Rapoport (IBM)" <rppt@kernel.org> > > powerpc overrides kprobes::alloc_insn_page() to remove writable > permissions when STRICT_MODULE_RWX is on. > > Add definition of EXECMEM_KRPOBES to execmem_params to allow using the > generic kprobes::alloc_insn_page() with the desired permissions. > > As powerpc uses breakpoint instructions to inject kprobes, it does not > need to constrain kprobe allocations to the modules area and can use the > entire vmalloc address space. I don't understand what you mean here. Does it mean kprobe allocation doesn't need to be executable ? I don't think so based on the pgprot you set. On powerpc book3s/32, vmalloc space is not executable. Only modules space is executable. X/NX cannot be set on a per page basis, it can only be set on a 256 Mbytes segment basis. See commit c49643319715 ("powerpc/32s: Only leave NX unset on segments used for modules") and 6ca055322da8 ("powerpc/32s: Use dedicated segment for modules with STRICT_KERNEL_RWX") and 7bee31ad8e2f ("powerpc/32s: Fix is_module_segment() when MODULES_VADDR is defined"). So if your intention is still to have an executable kprobes, then you can't use vmalloc address space. Christophe > > Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org> > --- > arch/powerpc/kernel/kprobes.c | 14 -------------- > arch/powerpc/kernel/module.c | 11 +++++++++++ > 2 files changed, 11 insertions(+), 14 deletions(-) > > diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c > index 62228c7072a2..14c5ddec3056 100644 > --- a/arch/powerpc/kernel/kprobes.c > +++ b/arch/powerpc/kernel/kprobes.c > @@ -126,20 +126,6 @@ kprobe_opcode_t *arch_adjust_kprobe_addr(unsigned long addr, unsigned long offse > return (kprobe_opcode_t *)(addr + offset); > } > > -void *alloc_insn_page(void) > -{ > - void *page; > - > - page = execmem_text_alloc(EXECMEM_KPROBES, PAGE_SIZE); > - if (!page) > - return NULL; > - > - if (strict_module_rwx_enabled()) > - set_memory_rox((unsigned long)page, 1); > - > - return page; > -} > - > int arch_prepare_kprobe(struct kprobe *p) > { > int ret = 0; > diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c > index 824d9541a310..bf2c62aef628 100644 > --- a/arch/powerpc/kernel/module.c > +++ b/arch/powerpc/kernel/module.c > @@ -95,6 +95,9 @@ static struct execmem_params execmem_params __ro_after_init = { > [EXECMEM_DEFAULT] = { > .alignment = 1, > }, > + [EXECMEM_KPROBES] = { > + .alignment = 1, > + }, > [EXECMEM_MODULE_DATA] = { > .alignment = 1, > }, > @@ -135,5 +138,13 @@ struct execmem_params __init *execmem_arch_params(void) > > range->pgprot = prot; > > + execmem_params.ranges[EXECMEM_KPROBES].start = VMALLOC_START; > + execmem_params.ranges[EXECMEM_KPROBES].start = VMALLOC_END; > + > + if (strict_module_rwx_enabled()) > + execmem_params.ranges[EXECMEM_KPROBES].pgprot = PAGE_KERNEL_ROX; > + else > + execmem_params.ranges[EXECMEM_KPROBES].pgprot = PAGE_KERNEL_EXEC; > + > return &execmem_params; > }
On Thu, Sep 21, 2023 at 03:30:46PM -0700, Song Liu wrote: > On Mon, Sep 18, 2023 at 12:31 AM Mike Rapoport <rppt@kernel.org> wrote: > > > [...] > > @@ -135,5 +138,13 @@ struct execmem_params __init *execmem_arch_params(void) > > > > range->pgprot = prot; > > > > + execmem_params.ranges[EXECMEM_KPROBES].start = VMALLOC_START; > > + execmem_params.ranges[EXECMEM_KPROBES].start = VMALLOC_END; > > .end = VMALLOC_END. Thanks, this should have been execmem_params.ranges[EXECMEM_KPROBES].start = range->start; execmem_params.ranges[EXECMEM_KPROBES].end = range->end; where range points to the same range as EXECMEM_MODULE_TEXT. > Thanks, > Song > > > + > > + if (strict_module_rwx_enabled()) > > + execmem_params.ranges[EXECMEM_KPROBES].pgprot = PAGE_KERNEL_ROX; > > + else > > + execmem_params.ranges[EXECMEM_KPROBES].pgprot = PAGE_KERNEL_EXEC; > > + > > return &execmem_params; > > } > > -- > > 2.39.2 > > > >
Hi Christophe, On Fri, Sep 22, 2023 at 10:32:46AM +0000, Christophe Leroy wrote: > Hi Mike, > > Le 18/09/2023 à 09:29, Mike Rapoport a écrit : > > From: "Mike Rapoport (IBM)" <rppt@kernel.org> > > > > powerpc overrides kprobes::alloc_insn_page() to remove writable > > permissions when STRICT_MODULE_RWX is on. > > > > Add definition of EXECMEM_KRPOBES to execmem_params to allow using the > > generic kprobes::alloc_insn_page() with the desired permissions. > > > > As powerpc uses breakpoint instructions to inject kprobes, it does not > > need to constrain kprobe allocations to the modules area and can use the > > entire vmalloc address space. > > I don't understand what you mean here. Does it mean kprobe allocation > doesn't need to be executable ? I don't think so based on the pgprot you > set. > > On powerpc book3s/32, vmalloc space is not executable. Only modules > space is executable. X/NX cannot be set on a per page basis, it can only > be set on a 256 Mbytes segment basis. > > See commit c49643319715 ("powerpc/32s: Only leave NX unset on segments > used for modules") and 6ca055322da8 ("powerpc/32s: Use dedicated segment > for modules with STRICT_KERNEL_RWX") and 7bee31ad8e2f ("powerpc/32s: Fix > is_module_segment() when MODULES_VADDR is defined"). > > So if your intention is still to have an executable kprobes, then you > can't use vmalloc address space. Right, and I've fixed the KPROBES range to uses the same range as MODULES. The commit message is stale and I need to update it. > Christophe > > > > > Signed-off-by: Mike Rapoport (IBM) <rppt@kernel.org> > > --- > > arch/powerpc/kernel/kprobes.c | 14 -------------- > > arch/powerpc/kernel/module.c | 11 +++++++++++ > > 2 files changed, 11 insertions(+), 14 deletions(-) > > > > diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c > > index 62228c7072a2..14c5ddec3056 100644 > > --- a/arch/powerpc/kernel/kprobes.c > > +++ b/arch/powerpc/kernel/kprobes.c > > @@ -126,20 +126,6 @@ kprobe_opcode_t *arch_adjust_kprobe_addr(unsigned long addr, unsigned long offse > > return (kprobe_opcode_t *)(addr + offset); > > } > > > > -void *alloc_insn_page(void) > > -{ > > - void *page; > > - > > - page = execmem_text_alloc(EXECMEM_KPROBES, PAGE_SIZE); > > - if (!page) > > - return NULL; > > - > > - if (strict_module_rwx_enabled()) > > - set_memory_rox((unsigned long)page, 1); > > - > > - return page; > > -} > > - > > int arch_prepare_kprobe(struct kprobe *p) > > { > > int ret = 0; > > diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c > > index 824d9541a310..bf2c62aef628 100644 > > --- a/arch/powerpc/kernel/module.c > > +++ b/arch/powerpc/kernel/module.c > > @@ -95,6 +95,9 @@ static struct execmem_params execmem_params __ro_after_init = { > > [EXECMEM_DEFAULT] = { > > .alignment = 1, > > }, > > + [EXECMEM_KPROBES] = { > > + .alignment = 1, > > + }, > > [EXECMEM_MODULE_DATA] = { > > .alignment = 1, > > }, > > @@ -135,5 +138,13 @@ struct execmem_params __init *execmem_arch_params(void) > > > > range->pgprot = prot; > > > > + execmem_params.ranges[EXECMEM_KPROBES].start = VMALLOC_START; > > + execmem_params.ranges[EXECMEM_KPROBES].start = VMALLOC_END; > > + > > + if (strict_module_rwx_enabled()) > > + execmem_params.ranges[EXECMEM_KPROBES].pgprot = PAGE_KERNEL_ROX; > > + else > > + execmem_params.ranges[EXECMEM_KPROBES].pgprot = PAGE_KERNEL_EXEC; > > + > > return &execmem_params; > > }
diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c index 62228c7072a2..14c5ddec3056 100644 --- a/arch/powerpc/kernel/kprobes.c +++ b/arch/powerpc/kernel/kprobes.c @@ -126,20 +126,6 @@ kprobe_opcode_t *arch_adjust_kprobe_addr(unsigned long addr, unsigned long offse return (kprobe_opcode_t *)(addr + offset); } -void *alloc_insn_page(void) -{ - void *page; - - page = execmem_text_alloc(EXECMEM_KPROBES, PAGE_SIZE); - if (!page) - return NULL; - - if (strict_module_rwx_enabled()) - set_memory_rox((unsigned long)page, 1); - - return page; -} - int arch_prepare_kprobe(struct kprobe *p) { int ret = 0; diff --git a/arch/powerpc/kernel/module.c b/arch/powerpc/kernel/module.c index 824d9541a310..bf2c62aef628 100644 --- a/arch/powerpc/kernel/module.c +++ b/arch/powerpc/kernel/module.c @@ -95,6 +95,9 @@ static struct execmem_params execmem_params __ro_after_init = { [EXECMEM_DEFAULT] = { .alignment = 1, }, + [EXECMEM_KPROBES] = { + .alignment = 1, + }, [EXECMEM_MODULE_DATA] = { .alignment = 1, }, @@ -135,5 +138,13 @@ struct execmem_params __init *execmem_arch_params(void) range->pgprot = prot; + execmem_params.ranges[EXECMEM_KPROBES].start = VMALLOC_START; + execmem_params.ranges[EXECMEM_KPROBES].start = VMALLOC_END; + + if (strict_module_rwx_enabled()) + execmem_params.ranges[EXECMEM_KPROBES].pgprot = PAGE_KERNEL_ROX; + else + execmem_params.ranges[EXECMEM_KPROBES].pgprot = PAGE_KERNEL_EXEC; + return &execmem_params; }