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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFD95C83F11 for ; Sun, 27 Aug 2023 13:12:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229892AbjH0NLj (ORCPT ); Sun, 27 Aug 2023 09:11:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229893AbjH0NLF (ORCPT ); Sun, 27 Aug 2023 09:11:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BD17188 for ; Sun, 27 Aug 2023 06:10:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 29E1D611EB for ; Sun, 27 Aug 2023 13:10:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DC54C433C7; Sun, 27 Aug 2023 13:10:52 +0000 (UTC) Date: Sun, 27 Aug 2023 16:10:51 +0300 From: Catalin Marinas To: Florent Revest Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, anshuman.khandual@arm.com, joey.gouly@arm.com, mhocko@suse.com, keescook@chromium.org, david@redhat.com, peterx@redhat.com, izbyshev@ispras.ru, broonie@kernel.org, szabolcs.nagy@arm.com, kpsingh@kernel.org, gthelen@google.com, toiwoton@gmail.com Subject: Re: [PATCH v3 4/5] mm: Add a NO_INHERIT flag to the PR_SET_MDWE prctl Message-ID: References: <20230704153630.1591122-1-revest@chromium.org> <20230704153630.1591122-5-revest@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230704153630.1591122-5-revest@chromium.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 04, 2023 at 05:36:28PM +0200, Florent Revest wrote: > static inline int prctl_set_mdwe(unsigned long bits, unsigned long arg3, > unsigned long arg4, unsigned long arg5) > { > + unsigned long current_bits; > + > if (arg3 || arg4 || arg5) > return -EINVAL; > > - if (bits & ~(PR_MDWE_REFUSE_EXEC_GAIN)) > + if (bits & ~(PR_MDWE_REFUSE_EXEC_GAIN | PR_MDWE_NO_INHERIT)) > + return -EINVAL; > + > + /* NO_INHERIT only makes sense with REFUSE_EXEC_GAIN */ > + if (bits & PR_MDWE_NO_INHERIT && !(bits & PR_MDWE_REFUSE_EXEC_GAIN)) > return -EINVAL; > > + current_bits = get_current_mdwe(); > + if (current_bits && current_bits != bits) > + return -EPERM; /* Cannot unset the flags */ > + > + if (bits & PR_MDWE_NO_INHERIT) > + set_bit(MMF_HAS_MDWE_NO_INHERIT, ¤t->mm->flags); > if (bits & PR_MDWE_REFUSE_EXEC_GAIN) > set_bit(MMF_HAS_MDWE, ¤t->mm->flags); > - else if (test_bit(MMF_HAS_MDWE, ¤t->mm->flags)) > - return -EPERM; /* Cannot unset the flag */ > > return 0; > } This works for me, it's easier to read. I don't expect a use-case where the app starts with MDWE no-inherit, forks some new processes and wants to turn inherit on for further forking. > @@ -2384,9 +2406,7 @@ static inline int prctl_get_mdwe(unsigned long arg2, unsigned long arg3, > { > if (arg2 || arg3 || arg4 || arg5) > return -EINVAL; > - > - return test_bit(MMF_HAS_MDWE, ¤t->mm->flags) ? > - PR_MDWE_REFUSE_EXEC_GAIN : 0; > + return (int)get_current_mdwe(); Nitpick: the type conversion should be handled by the compiler as prctl_get_mdwe() returns an int already. Reviewed-by: Catalin Marinas