Received: by 2002:ac2:5a04:0:0:0:0:0 with SMTP id q4csp1090233lfn; Wed, 23 Feb 2022 19:00:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJyC2WAdapGcUMPvbcpphm8dD+2gyoB9BRZ3PbC4uPMSiCpywD95MPPljFW2kcb6ko2pNC2i X-Received: by 2002:a17:902:ab92:b0:14d:8c80:dbff with SMTP id f18-20020a170902ab9200b0014d8c80dbffmr521993plr.89.1645671628820; Wed, 23 Feb 2022 19:00:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645671628; cv=none; d=google.com; s=arc-20160816; b=IewwvFSB4q5Dmpo/ErFVZPV9u/KMJmdwKHPNpCUNooHj5T0dWIHj/RQJ6P1ARv/deu sZxVdgwsxT5zyQX9EyvYlELQCcw8dB89VXyYktKSOU5VpQf6QwrfeipvUsWiyvsx/Sxk SvCcdwxree7d6X1Bb77zK8x8axz6Nbw5zuAnZe0kyt/F7i1vFMa9iKv5tZjVihjenns3 P23NmtsPUh4nC/X8zAMzmiQz9EJB6Dg+4hkZBzozvQs7xWMuiFDDBjah/pDriZwA63Xg gDniIBWQ1JzHUUupGV3n43Guft/tKDZ826VyxFZ678qj0d4qLy9AaBG/FFi+gNYWopVp kQfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=D2CcxrwYyRXYz06JakVhJceZ2YTU4KSBZsKMR+XmiCk=; b=HVon2/Y+penSQhhtxq7atRhLVt0u+1TbPbaroyfPaL9w0p33pgMRZDUThSlOfK7jST PJmUO8eLnoaOnq1jXxjO9cWyreBBUbnVftpzgq+jZ85kCadKbyfi3G8C8qnc9T11nLl0 sV8M1FVYKzM0ULA6PMRDThMDwX0VHkAlWAbaKfCTWvbH9eypvbaCZbtzM/WTXMsjj4d2 duvEtQrf0ipuISCZiwtPg6gqCDLLawuJBAYNVWApEUTXS11eoXwtCbmI5j1CEm8uY7c4 H7GlmKrMBNMxOHw/llEXQgIqFmpK1y/dNjIYjI2KtXK9nbmHq2jTK7hKeB+WQBXMn7PD g9Tg== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id v18si1380944pfu.27.2022.02.23.19.00.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 19:00:28 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 693A023BF1F; Wed, 23 Feb 2022 19:00:25 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230241AbiBXDAs (ORCPT + 99 others); Wed, 23 Feb 2022 22:00:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230189AbiBXDAr (ORCPT ); Wed, 23 Feb 2022 22:00:47 -0500 Received: from zeniv-ca.linux.org.uk (zeniv-ca.linux.org.uk [IPv6:2607:5300:60:148a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C5B617584A; Wed, 23 Feb 2022 19:00:14 -0800 (PST) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nN4MW-004RC0-Bt; Thu, 24 Feb 2022 03:00:12 +0000 Date: Thu, 24 Feb 2022 03:00:12 +0000 From: Al Viro To: Yun Levi Cc: Kees Cook , ebiederm@xmission.com, linux-fsdevel@vger.kernel.org, Linux Kernel Mailing List Subject: Re: [PATCH] fs/exec.c: Avoid a race in formats Message-ID: References: <20220223231752.52241-1-ppbuk5246@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 24, 2022 at 08:59:59AM +0900, Yun Levi wrote: > I think if someone wants to control their own binfmt via "ioctl" not > on time on LOAD. > For example, someone wants to control exec (notification, > allow/disallow and etc..) > and want to enable and disable own's control exec via binfmt reg / unreg > In that situation, While the module is loaded, binfmt is still live > and can be reused by > reg/unreg to enable/disable his exec' control. Er... So have your ->load_binary() start with if (I_want_it_disabled) return -ENOEXEC; and be done with that. The only caller of that thing is list_for_each_entry(fmt, &formats, lh) { if (!try_module_get(fmt->module)) continue; read_unlock(&binfmt_lock); retval = fmt->load_binary(bprm); read_lock(&binfmt_lock); put_binfmt(fmt); if (bprm->point_of_no_return || (retval != -ENOEXEC)) { read_unlock(&binfmt_lock); return retval; } } so returning -ENOEXEC is equivalent to not having it in the list. IDGI... Why bother unregistering/re-registering/etc.?