Received: by 2002:ac2:5a04:0:0:0:0:0 with SMTP id q4csp1071983lfn; Wed, 23 Feb 2022 18:15:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJxJSQl8nQE+oDeS8szLB5bzXYT91M4CzyZbx+UF12SxiUNn50dQBWFmQVs9DquTknSuRIN4 X-Received: by 2002:a17:90a:8b14:b0:1b9:3472:23fe with SMTP id y20-20020a17090a8b1400b001b9347223femr511146pjn.39.1645668958935; Wed, 23 Feb 2022 18:15:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645668958; cv=none; d=google.com; s=arc-20160816; b=mYMsRSsGTtG32bfJzMw4dVfAdnRZ60Wi3B7IX8XLaj6VKdOWj4jdCIZ5rKlHZDCI97 vnX4osIDdKJL9mV8HFo6WeFL1VUmf/nRcsgUkngVNmDP+cIeMaHPunuHgBXBeY2PUHMu baX85NzFZkVy5nmkte3dqDIxG/Z1/owOt90SY7Tz0Yba/EmlwrnO33pZeVeCzlYN5BYd 9by557of1nz4Fw3E57rJwd9SVh3CzG+ZzmwdSacUwexP6BtRGRExlBEA3x4MzyIAcGE/ ggJoZNAtXkiJevaJ9gufUEIVZ89e0o97MV3yZJMqtPPvAbiWW2FaC54bL6fgM+4+ktSh JcCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=gDzVZls32Tn+CgZQqLjQPwA2ePA8pNdpM8QzmA533pc=; b=qdVNlgr9jZ4txhSIyGVqSmgqOL1K9dHibtbRmUTkSaX3QoDyrh6RMu9qVd9PSOrads g+UjstcE7DuckRwh1GUhkNrdW8fFS0FosYapQR8hAsZUvy7Q74oOG+ntmErP1YmaK+Ag ffjXTCc18decWusVeAzEdwPmGYRANB/C93bN3IZmWqJ77zZAima7WBqnIIFufles3JsU sjS7fN6nyqNzfgLnzWdjrcmdibV3PqEnCBtqNK6Wr8s/iCxHSrzlt39OJ5IAuVXSuHHK BAB2RsFHicVcPEJsBodchFNOiHXc1uxzE+0WcBteBWHVlL8mSh+IZT9h6P3+U7aX194U uU6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OQw7yyey; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id f5si1381944plg.566.2022.02.23.18.15.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 18:15:58 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OQw7yyey; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 76DC1434BF; Wed, 23 Feb 2022 18:01:35 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229910AbiBXCB4 (ORCPT + 99 others); Wed, 23 Feb 2022 21:01:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229901AbiBXCBz (ORCPT ); Wed, 23 Feb 2022 21:01:55 -0500 Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D31D915B3EF; Wed, 23 Feb 2022 18:01:26 -0800 (PST) Received: by mail-yb1-xb33.google.com with SMTP id b35so913201ybi.13; Wed, 23 Feb 2022 18:01:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=gDzVZls32Tn+CgZQqLjQPwA2ePA8pNdpM8QzmA533pc=; b=OQw7yyeyEfFjC3dZHjfMUxfYBAU6NRghHcNxQF46CLKtKLTCRbMhhIOy/86n2j985E 0Vmj9b1akLS6fQiSBG5w/PNqCfUgNLZuvwpZcDO65I+hCX7QbLCusXXBrrErXdl4uqUA h2GGW+pwPYI2ZnE/6se/UMP+7x4QsMf040AkEqX1ftBaJHRMN7yJ7VqGzTZ4SQWkUylL 6VCJ5jMq3ANhXUTxzd7HHKyKp5vZs/WIibePxYqzWgwrjVvib+nKCq5gMjuwlfJgh1Tx VTDst8A4foBg6aCtgMiMJc8yBoXtifMA2RumB//CZdWVFYSm/w2MTrF1xCxz/SG8yauR yAMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=gDzVZls32Tn+CgZQqLjQPwA2ePA8pNdpM8QzmA533pc=; b=wNPqZabYgXD/XJ4yIhSHEiuOZXw3ry0mKdiDVeLZlA4U32hYbaN/6XjNN51T7TrnGf 2uM3tvw0F7+LZ00xdgFnLKIYuyatcJmaCcLVig7wXWVKhG/1B1c7ermGE0UtmTq6xhJ5 lyhl/FMOaUs5BVdRtn+emwG6GFd9wreoH4U88yPzE8n+2CdVPe8T5Lpd1/rt1A2c3q+M o9jGj6uqJ1szJISGhoRNy6lOlhxw0eA9exCrMdv5K9xxZHB0OiSLBfZwDg8OOhJs+HF1 btURGBikcTP6rVPjkWzF6mupEGRk9vnreWVjYBI91ZWFo/3n4F1kaRxZ7vSwZ0H/J28t lCQQ== X-Gm-Message-State: AOAM531NA4+65DHJqUt6DRFfIVBT9FI5suU+1Bxzj64XlusMlvbD/7o/ JpFSuW3wLAbkcQr5RDCJZpTQqBHhDKZh6J47B8mcSkAM5xlRPw== X-Received: by 2002:a25:241:0:b0:61e:fb6e:8f33 with SMTP id 62-20020a250241000000b0061efb6e8f33mr278196ybc.413.1645663892466; Wed, 23 Feb 2022 16:51:32 -0800 (PST) MIME-Version: 1.0 References: <20220223231752.52241-1-ppbuk5246@gmail.com> <878ru1umcu.fsf@email.froward.int.ebiederm.org> In-Reply-To: <878ru1umcu.fsf@email.froward.int.ebiederm.org> From: Yun Levi Date: Thu, 24 Feb 2022 09:51:21 +0900 Message-ID: Subject: Re: [PATCH] fs/exec.c: Avoid a race in formats To: "Eric W. Biederman" Cc: Al Viro , Kees Cook , linux-fsdevel@vger.kernel.org, Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, 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 > 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)". It could be a solution. but that means the kernel doesn't allow dynamic binfmt using modules too. I think the best safe way to remove registered binfmt is ... unregister binfmt list first ---- (1) synchronize_rcu_task(); // tasklist stack-check... unload module. But for this, there shouldn't happen in the above situation of (1). If unregister_binfmt has this problem.. I think there is no way to unload safely for dynamic registered binfmt via module. On Thu, Feb 24, 2022 at 9:42 AM Eric W. Biederman wrote: > > 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