Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp34700rwi; Thu, 13 Oct 2022 20:53:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6wa5cpDwiFfAuFue5tLfU+30DduCW2dcxVZvpbqYhJ20pPiUsfV7zwTvI7sE8sYlKY4sc0 X-Received: by 2002:a17:90b:350d:b0:20d:5438:f594 with SMTP id ls13-20020a17090b350d00b0020d5438f594mr15155291pjb.216.1665719622352; Thu, 13 Oct 2022 20:53:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665719622; cv=none; d=google.com; s=arc-20160816; b=JY/7InCulz08Uv8ZQChjWkkH3HkRAMUSYQNkNDaFixfjbd57C+HAdrqLieqqduUmhm Uh2lsQKg8nPphBCDWSoRU1hl8kWfNfh/NAG6gpOgVxa0KrO5XgloJSfsl4Mca9k8KNaW vmTJ3OzfAnqTEeFVJngaeVYv+H1s+iHe/Cg6L48dhegQcAAyKzven51u9YW1P3zURa/T HizXyQu+x5U+zghW0/+9X15OFxncE542dU1e/8W9+d1d/M+ebJfbtRy9YjitPYku7wnT fYG0CqK7UmMn30oYWlyIlBw6CeoyvYTIaRDyR3iiC+3KFvj6z64W5hXK+Pss1zAVS861 R1Ow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:feedback-id:dkim-signature; bh=KvxDJx5zOu00qbNqJPi5qC/MLlKEgI3Wyos+eU+li2Y=; b=V9qMC7yP+R1f8RpXcFrKJJx82nkfpslN4YdnqmXn2Sl7l8zQeD2cOD/UXf+c+BlxFP KHm94thlaLgtXKJuoAK73rq4X/+9uBwBxUI13aiqHOArlO4jgahICdeahyQl/iBfrIG/ mYkL1x1k+RERz8JvaFyizZcnZl7LyVGRsHM3ZxLgQEtBm1q2cDtBYyTQWLyqY0H/614F /d403uGBk/Q9z25ufBnlWzSd9bUnLTYXnw/YHUcJ8IQ6WQC9gSaGQP7YwZzvtfednQGs JqHnW+fCrnYgQFSKKO2dV2N9BZ//j9P6vy5nIb9T3cBW/vLaZrbLYDIn5u6qhIao2yEG ZUTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TCqLtjMU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mh8-20020a17090b4ac800b00200435da17asi8765301pjb.128.2022.10.13.20.53.30; Thu, 13 Oct 2022 20:53:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TCqLtjMU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229533AbiJNDTB (ORCPT + 99 others); Thu, 13 Oct 2022 23:19:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229769AbiJNDSc (ORCPT ); Thu, 13 Oct 2022 23:18:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 020BF1119CB; Thu, 13 Oct 2022 20:18:30 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 60263619D6; Fri, 14 Oct 2022 03:18:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE094C43470; Fri, 14 Oct 2022 03:18:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665717509; bh=XdPGgMOKnebM+bZev/ZKP6wiusPUf6c3wma5ZTnpm0o=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=TCqLtjMUhY3E6hf1ob6xgOd/SwpJweBv3tU3uwDefMm4A/ahGMxIC1fYKYYfBlwsp c4OzGNUkyZI/EWcYPFYJKey7rW0cEUkZE+LOkpGV19buQ6rtAwI/hLX5iw1NyHEOWp FqFekRHYzRsrNlju7lbJW+OBW4KWCrNhryyrvGL4FXB9xq9XMqweABSa7E89pobMDj dhbr4pgnLECh4yJxmSvj30PN6CSkv/1SL630AvtuHSSPF+716FXaWyEJPJV5YfWvUX AcpoA4Go3xPK5zpt0aNt/TWRQOKwqnAINiTRleYiI5qW8pa8hRcvsqQddsl387N9qW FvzX+DBznhG0Q== Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 7304527C0054; Thu, 13 Oct 2022 23:18:27 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute2.internal (MEProxy); Thu, 13 Oct 2022 23:18:27 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeekuddgieelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvfevufgtsehttdertderredtnecuhfhrohhmpedftehn ugihucfnuhhtohhmihhrshhkihdfuceolhhuthhosehkvghrnhgvlhdrohhrgheqnecugg ftrfgrthhtvghrnhepgeejhfehkeejleffheetkefhtdduuedtieehheekgfekudeggfff udejuddufeeknecuffhomhgrihhnpegthhhrohhmihhumhdrohhrghenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrnhguhidomhgvshhmthhp rghuthhhphgvrhhsohhnrghlihhthidqudduiedukeehieefvddqvdeifeduieeitdekqd hluhhtoheppehkvghrnhgvlhdrohhrgheslhhinhhugidrlhhuthhordhush X-ME-Proxy: Feedback-ID: ieff94742:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 878A331A03F7; Thu, 13 Oct 2022 23:18:25 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-1047-g9e4af4ada4-fm-20221005.001-g9e4af4ad Mime-Version: 1.0 Message-Id: <2032f766-1704-486b-8f24-a670c0b3cb32@app.fastmail.com> In-Reply-To: References: <20221006082735.1321612-1-keescook@chromium.org> <20221006082735.1321612-2-keescook@chromium.org> <20221006090506.paqjf537cox7lqrq@wittgenstein> Date: Thu, 13 Oct 2022 20:18:04 -0700 From: "Andy Lutomirski" To: "Jann Horn" , "Christian Brauner" Cc: "Kees Cook" , "Eric W. Biederman" , "Jorge Merlino" , "Al Viro" , "Thomas Gleixner" , "Sebastian Andrzej Siewior" , "Andrew Morton" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, "John Johansen" , "Paul Moore" , "James Morris" , "Serge E. Hallyn" , "Stephen Smalley" , "Eric Paris" , "Richard Haines" , "Casey Schaufler" , "Xin Long" , "David S. Miller" , "Todd Kjos" , "Ondrej Mosnacek" , "Prashanth Prahlad" , "Micah Morton" , "Fenghua Yu" , "Andrei Vagin" , "Linux Kernel Mailing List" , apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH 1/2] fs/exec: Explicitly unshare fs_struct on exec Content-Type: text/plain X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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, Oct 6, 2022, at 7:13 AM, Jann Horn wrote: > On Thu, Oct 6, 2022 at 11:05 AM Christian Brauner wrote: >> On Thu, Oct 06, 2022 at 01:27:34AM -0700, Kees Cook wrote: >> > The check_unsafe_exec() counting of n_fs would not add up under a heavily >> > threaded process trying to perform a suid exec, causing the suid portion >> > to fail. This counting error appears to be unneeded, but to catch any >> > possible conditions, explicitly unshare fs_struct on exec, if it ends up >> >> Isn't this a potential uapi break? Afaict, before this change a call to >> clone{3}(CLONE_FS) followed by an exec in the child would have the >> parent and child share fs information. So if the child e.g., changes the >> working directory post exec it would also affect the parent. But after >> this change here this would no longer be true. So a child changing a >> workding directoro would not affect the parent anymore. IOW, an exec is >> accompanied by an unshare(CLONE_FS). Might still be worth trying ofc but >> it seems like a non-trivial uapi change but there might be few users >> that do clone{3}(CLONE_FS) followed by an exec. > > I believe the following code in Chromium explicitly relies on this > behavior, but I'm not sure whether this code is in active use anymore: > > https://source.chromium.org/chromium/chromium/src/+/main:sandbox/linux/suid/sandbox.c;l=101?q=CLONE_FS&sq=&ss=chromium Wait, this is absolutely nucking futs. On a very quick inspection, the sharable things like this are fs, files, sighand, and io. files and sighand get unshared, which makes sense. fs supposedly checks for extra refs and prevents gaining privilege. io is... ignored! At least it's not immediately obvious that io is a problem. But seriously, this makes no sense at all. It should not be possible to exec a program and then, without ptrace, change its cwd out from under it. Do we really need to preserve this behavior? --Andy