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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 03D59C64EC4 for ; Wed, 8 Mar 2023 12:38:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vy+B5cEaAD1hzWI7vwQ7rQtqCP0PfxBNnBcjl1NnlFQ=; b=mE0Xn5hHJ7sfwX pcqHY/mlVit/Ch/OvK6z31iRIe8ZjcIqWGGFlnex4Iw7T2u/4+5Q7eR/DRbf5laDoSMFhfaSGzRe+ hF/DY9Dk63W8FATXSbT8mi2Auv0JFtexainOCprBCZ82aAuYhH0Q1fqLclh7Yo/m+QP2Smv52EIGO u1iW3OCro7j1+1ZvGExSH2PAhiXfOkCWdjn2FcN670zNAtDSAtHCl6IrpiR+Df9i2nNCdUtU4YbAW byyjD3D95Zqhy+anYvAOhZPNN9wHWts2Buign++uw9cFLvgFlhSgkCwyef3t1m6ZanIy+m27lprbf c6J7f217bvIVn2IbxBZg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZt2e-004si4-Qd; Wed, 08 Mar 2023 12:37:12 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pZt2a-004sgb-Ly for linux-arm-kernel@lists.infradead.org; Wed, 08 Mar 2023 12:37:10 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 39E8EB81C27; Wed, 8 Mar 2023 12:37:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5E71C433D2; Wed, 8 Mar 2023 12:37:02 +0000 (UTC) Date: Wed, 8 Mar 2023 12:36:59 +0000 From: Catalin Marinas To: Alexey Izbyshev Cc: Joey Gouly , Andrew Morton , Lennart Poettering , Zbigniew =?utf-8?Q?J=C4=99drzejewski-Szmek?= , Alexander Viro , Kees Cook , Szabolcs Nagy , Mark Brown , Jeremy Linton , Topi Miettinen , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-abi-devel@lists.sourceforge.net, nd@arm.com, shuah@kernel.org Subject: Re: [PATCH v2 1/2] mm: Implement memory-deny-write-execute as a prctl Message-ID: References: <20230119160344.54358-2-joey.gouly@arm.com> <8408d8901e9d7ee6b78db4c6cba04b78@ispras.ru> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <8408d8901e9d7ee6b78db4c6cba04b78@ispras.ru> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230308_043708_879899_AE0F2383 X-CRM114-Status: GOOD ( 19.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Mar 07, 2023 at 04:01:56PM +0300, Alexey Izbyshev wrote: > On 2023-01-19 19:03, Joey Gouly wrote: > > diff --git a/mm/mmap.c b/mm/mmap.c > > index 87d929316d57..99a4d9e2b0d8 100644 > > --- a/mm/mmap.c > > +++ b/mm/mmap.c > > @@ -2665,6 +2665,16 @@ unsigned long mmap_region(struct file *file, > > unsigned long addr, > > vma_set_anonymous(vma); > > } > > > > + if (map_deny_write_exec(vma, vma->vm_flags)) { > > + error = -EACCES; > > + if (file) > > + goto close_and_free_vma; > > + else if (vma->vm_file) > > + goto unmap_and_free_vma; > > + else > > + goto free_vma; > > + } > > + > > Why is the cleanup dispatch logic duplicated here, instead of simply doing > "goto close_and_free_vma" (where basically the same dispatch is done)? Yes, though that's only possible after commit cc8d1b097de7 ("mmap: clean up mmap_region() unrolling") in 6.3-rc1. It's worth adding a separate patch to simplify this before final 6.3. > > diff --git a/mm/mprotect.c b/mm/mprotect.c > > index 908df12caa26..bc0587df042f 100644 > > --- a/mm/mprotect.c > > +++ b/mm/mprotect.c > > @@ -762,6 +762,11 @@ static int do_mprotect_pkey(unsigned long start, > > size_t len, > > break; > > } > > > > + if (map_deny_write_exec(vma, newflags)) { > > + error = -EACCES; > > + goto out; > > + } > > + > > Why does this check use "goto out", thereby skipping post-loop cleanup, > instead of "break" like all other checks? This looks like a bug to me. Ah, good point, thanks. I think that's a left-over from my early attempt at this series. The loop was changed in 5.19 with commit 4a18419f71cd ("mm/mprotect: use mmu_gather") but the patch not updated. So yeah, it needs fixing. Joey, could you please send fixes for both issues above? Thanks. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel