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.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 CCF3CC433B4 for ; Wed, 21 Apr 2021 06:52:14 +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 D775D6140F for ; Wed, 21 Apr 2021 06:52:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D775D6140F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au 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 4FQB7J1c2rz302p for ; Wed, 21 Apr 2021 16:52:12 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ellerman.id.au header.i=@ellerman.id.au header.a=rsa-sha256 header.s=201909 header.b=FNoseHrP; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ellerman.id.au (client-ip=2401:3900:2:1::2; helo=ozlabs.org; envelope-from=mpe@ellerman.id.au; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ellerman.id.au header.i=@ellerman.id.au header.a=rsa-sha256 header.s=201909 header.b=FNoseHrP; dkim-atps=neutral Received: from ozlabs.org (ozlabs.org [IPv6:2401:3900:2:1::2]) (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 4FQB6p6lRDz2y07 for ; Wed, 21 Apr 2021 16:51:45 +1000 (AEST) Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4FQB6Z68ZCz9tB1; Wed, 21 Apr 2021 16:51:34 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ellerman.id.au; s=201909; t=1618987895; bh=uA2hTlCrBexgLM/6u4kMgngO8YfJd4Ykb4JUjZKiLOQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=FNoseHrPAQSKXddjnrEL6cDE1s6S+Hm+CLVb/4BpaSgN06mxeuRX4eVceHmHRJDEy kN5ll+6/FQybDyVJsoXOcwlX+sE5+sBAo+fqpCtu0uh1VGYIGr/6Z87V7/CHw70Snq awTqhBwLZf6HdQW6zwD2oWDdhOWmaIMxcmJ7/jePr3K09sD5eGE5hH18sN2uJ+ldoF NPu/KiFp43rMYxbZl3TUlllzypUx+xyC8gvSOTMEU14nCgxQPn0p28/IPWM1VmkG+e 1BOfu7ME02YDWopEfXTNz0CiywhWVrqmbBGvoGQEwtsTpreXXAw5yqkoyiOpFcCvrH Ed0tkXl240gjg== From: Michael Ellerman To: Jordan Niethe Subject: Re: [PATCH v10 05/10] powerpc/bpf: Write protect JIT code In-Reply-To: References: <20210330045132.722243-1-jniethe5@gmail.com> <20210330045132.722243-6-jniethe5@gmail.com> <87wntnwqw9.fsf@mpe.ellerman.id.au> Date: Wed, 21 Apr 2021 16:51:30 +1000 Message-ID: <87wnswb05p.fsf@mpe.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain 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, Nicholas Piggin , naveen.n.rao@linux.ibm.com, linuxppc-dev , Daniel Axtens Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Jordan Niethe writes: > On Wed, Mar 31, 2021 at 9:37 PM Michael Ellerman wrote: >> >> Jordan Niethe writes: >> >> > Once CONFIG_STRICT_MODULE_RWX is enabled there will be no need to >> > override bpf_jit_free() because it is now possible to set images >> > read-only. So use the default implementation. >> > >> > Also add the necessary call to bpf_jit_binary_lock_ro() which will >> > remove write protection and add exec protection to the JIT image after >> > it has finished being written. >> > >> > Signed-off-by: Jordan Niethe >> > --- >> > v10: New to series >> > --- >> > arch/powerpc/net/bpf_jit_comp.c | 5 ++++- >> > arch/powerpc/net/bpf_jit_comp64.c | 4 ++++ >> > 2 files changed, 8 insertions(+), 1 deletion(-) >> > >> > diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c >> > index e809cb5a1631..8015e4a7d2d4 100644 >> > --- a/arch/powerpc/net/bpf_jit_comp.c >> > +++ b/arch/powerpc/net/bpf_jit_comp.c >> > @@ -659,12 +659,15 @@ void bpf_jit_compile(struct bpf_prog *fp) >> > bpf_jit_dump(flen, proglen, pass, code_base); >> > >> > bpf_flush_icache(code_base, code_base + (proglen/4)); >> > - >> > #ifdef CONFIG_PPC64 >> > /* Function descriptor nastiness: Address + TOC */ >> > ((u64 *)image)[0] = (u64)code_base; >> > ((u64 *)image)[1] = local_paca->kernel_toc; >> > #endif >> > + if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) { >> > + set_memory_ro((unsigned long)image, alloclen >> PAGE_SHIFT); >> > + set_memory_x((unsigned long)image, alloclen >> PAGE_SHIFT); >> > + } >> >> You don't need to check the ifdef in a caller, there are stubs that >> compile to nothing when CONFIG_ARCH_HAS_SET_MEMORY=n. > As Christophe pointed out we could have !CONFIG_STRICT_MODULE_RWX and > CONFIG_ARCH_HAS_SET_MEMORY which would then be wrong here. > Probably we could make CONFIG_ARCH_HAS_SET_MEMORY depend on > CONFIG_STRICT_MODULE_RWX? I thought it already did depend on it :) That seems a reasonable dependency to me. cheers