Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1094658pxm; Wed, 23 Feb 2022 18:00:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJyvGYbBYooTmkNJ8U6ImMtMR+oYW9uy1LwWfLXB/gaYFB/wdwzKXVzi0rdWOpve2i2xCt0N X-Received: by 2002:a17:902:aa05:b0:14f:18b7:f0b4 with SMTP id be5-20020a170902aa0500b0014f18b7f0b4mr315828plb.171.1645668049240; Wed, 23 Feb 2022 18:00:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645668049; cv=none; d=google.com; s=arc-20160816; b=G9dAHj0tBBzEldN6YEO//4M+/CI89dl1DnL6iQJhzs5+pvQGLtRziKL1wvH0NXUTOp TI+ncVxfG9Syf8TiRzvuOeVKOlrrR4Gs68zSl1pJtc2JRKH7jF7pmXt6Ye8+Puh/ew5P FceRHv5C6zUphBaHlFq1Prm0CjAXHpMYRDU777BGGZHUJOMAGwLF3xYh8W6ZAlJj9MaG GrGirZmHY7J0V7zBYx91EXgC2GmbUS52zUDl0rZH2HhKPxR3HkwZN4Yey2tFBIF1Zxo9 SMVL1sTtvx3JdECVz99Q6/Envjl1eN38zfCJ1UG3jIirsJGJjtSiG2RmoeO/DWH8rVUN UmUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:mime-version:user-agent:message-id :in-reply-to:date:references:cc:to:from; bh=dpye1vXTRTTrkrCs/NPrv04d2VQdXwZvzjzC3iHTUc4=; b=aeqTyNraNGmSUwfpgzcYAj5I1u8ztbCiMz7aLL40Q3gYtb762MLbfUfFwoVf6jIkeJ yf7mOqhtD1xVZFJIOKMhftj9TIP4J4/RmvPkr0m5xB1EfgJjYskMnzPXd9+8+4UiCRMt 7KSD4OTXiEoQrwWQAEDlOIRfG2wblfehCm3f64ZChgn0naEgvmPzMafUUPIpgnd3U9D5 U2a+fZAjSeWxwjJx3ZD67NSR4GCCFa5wc2R1Ti0vcOCjaGM83lStg7N4XplPcFJCjjja G8iHJ2UsAqmnjp/omdwghsXUzJR6z9FDOl2wpHVmISFh6pfQkDKplpVLADv0pnvxiDjh hwEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id bc2si1130765plb.349.2022.02.23.18.00.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 18:00:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1D945246374; Wed, 23 Feb 2022 17:29:15 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229878AbiBXAnH (ORCPT + 99 others); Wed, 23 Feb 2022 19:43:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbiBXAnF (ORCPT ); Wed, 23 Feb 2022 19:43:05 -0500 Received: from out01.mta.xmission.com (out01.mta.xmission.com [166.70.13.231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA67D24F1D; Wed, 23 Feb 2022 16:42:31 -0800 (PST) Received: from in02.mta.xmission.com ([166.70.13.52]:45334) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nN2D6-00GEzI-QL; Wed, 23 Feb 2022 17:42:23 -0700 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:51728 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nN2D4-003rP5-OE; Wed, 23 Feb 2022 17:42:20 -0700 From: "Eric W. Biederman" To: Yun Levi Cc: Al Viro , Kees Cook , linux-fsdevel@vger.kernel.org, Linux Kernel Mailing List References: <20220223231752.52241-1-ppbuk5246@gmail.com> Date: Wed, 23 Feb 2022 18:41:53 -0600 In-Reply-To: (Yun Levi's message of "Thu, 24 Feb 2022 09:10:43 +0900") Message-ID: <878ru1umcu.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1nN2D4-003rP5-OE;;;mid=<878ru1umcu.fsf@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.174.4;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX19E7m5cfdNbK2Kadeox25wwXYPVTo6knKU= X-SA-Exim-Connect-IP: 68.227.174.4 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Spam-Level: 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-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Yun Levi X-Spam-Relay-Country: X-Spam-Timing: total 1335 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 10 (0.7%), b_tie_ro: 8 (0.6%), parse: 0.80 (0.1%), extract_message_metadata: 12 (0.9%), get_uri_detail_list: 1.57 (0.1%), tests_pri_-1000: 10 (0.7%), tests_pri_-950: 1.25 (0.1%), tests_pri_-900: 1.03 (0.1%), tests_pri_-90: 57 (4.2%), check_bayes: 55 (4.1%), b_tokenize: 7 (0.5%), b_tok_get_all: 7 (0.6%), b_comp_prob: 2.3 (0.2%), b_tok_touch_all: 35 (2.6%), b_finish: 0.95 (0.1%), tests_pri_0: 1232 (92.3%), check_dkim_signature: 0.51 (0.0%), check_dkim_adsp: 2.8 (0.2%), poll_dns_idle: 0.55 (0.0%), tests_pri_10: 2.3 (0.2%), tests_pri_500: 8 (0.6%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH] fs/exec.c: Avoid a race in formats X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Yun Levi writes: > On Thu, Feb 24, 2022 at 8:59 AM Yun Levi wrote: >> >> On Thu, Feb 24, 2022 at 8:24 AM Al Viro wrote: >> > >> > On Thu, Feb 24, 2022 at 08:17:52AM +0900, Levi Yun wrote: >> > > Suppose a module registers its own binfmt (custom) and formats is like: >> > > >> > > +---------+ +----------+ +---------+ >> > > | custom | -> | format1 | -> | format2 | >> > > +---------+ +----------+ +---------+ >> > > >> > > and try to call unregister_binfmt with custom NOT in __exit stage. >> > >> > Explain, please. Why would anyone do that? And how would such >> > module decide when it's safe to e.g. dismantle data structures >> > used by methods of that binfmt, etc.? >> > Could you give more detailed example? >> >> 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. >> >> module can decide it's safe to unload by tracing the stack and >> confirming whether some tasks in the custom binfmt's function after it >> unregisters its own binfmt. >> >> > Because it looks like papering over an inherently unsafe use of binfmt interfaces.. >> >> I think the above example it's quite a trick and stupid. it's quite >> unsafe to use as you mention. >> But, misuse allows that situation to happen without any warning. >> As a robustness, I just try to avoid above situation But, >> I think it's better to restrict unregister binfmt unregister only when >> there is no module usage. > > And not only stupid exmaple, > if someone loadable custom binfmt register in __init and __exit via > register and unregister_binfmt, > I think that situation could happen. Mostly of what has been happening with binary formats lately is code removal. So I humbly suggest the best defense against misuse by modules is to simply remove "EXPORT_SYMBOL(__register_binfmt)". Eric