Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1078446rwb; Thu, 6 Oct 2022 08:12:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4+DLpdNeoNLDn27R1hz8XOGHg5ZEWPFQqd8pLNhw77PWPKEaMKqbyX0Mxxduk8mQEWNECr X-Received: by 2002:a05:6402:e01:b0:442:dd7e:f49d with SMTP id h1-20020a0564020e0100b00442dd7ef49dmr199926edh.355.1665069143682; Thu, 06 Oct 2022 08:12:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665069143; cv=none; d=google.com; s=arc-20160816; b=L2H47F4p5A+JekiKe36P2/GRhT1ChmifilqxUBtMAb3yJyJhMGoFplpEZUmpXmKL/B 9jM209ml7C/t2hfOSHzGUufAfapZSl5xzJLmNZk//cpMLQ0CmEpb6VnlKfOH2RRsml95 oeEyDKDdlaFGq5zQs0Yrf3wHfVp9dXZWT/iGyFyTk40faHDkL+39M/3ayefUp33SY7av dt1n5BA8ndwIqBL8c6mkeY1cCYh/ET0Cuol7BJZ1xK9eB0DHy3p2CXGy0GArgqGGEY3S mZ5WFwo88JWMcH4v9jbSaVlaVTI+4rakk7VWlklMXVuP8RFN5fPPIYf+uZVJ3e9bihXK 3u5Q== 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=uPoSw2DcS8I2PL1GAxLCIjBZkmIbahmymE7q5ESqNH4=; b=rZ1ZKP1HhsR7ZucP9/StmGfWncz8XXNlJW/IQrgvC3O8gYOJFqXPcdfeRBVL1lIye8 d+fg94hcjdnKchCUJQ5uSJOa00P+rTAzjEZB+EcJ1RmhmGcrMpm57DErg8mhhG8aBmet Lmo3h0s4dFxm23MbaeD+6vEUcdG/KbjAn0hRQi0OnJGaaXltwKqt4T9scY4U7CisCh62 oCoj22FFP5TkR2cVpAlq4INQi13X6Z5Tt/mSlrfVAh1sxyglgcsiggoo5alP36JA/WH2 wbxBHXlf1CcQmuFV+dhd+yIOFoXRrCm2OVIu0bOe7U5/IbB/KyqpdMQXvgKJAT1Lf0ZZ Akkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=J9UmphxO; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ds21-20020a170907725500b0078a10544d24si13144510ejc.793.2022.10.06.08.11.46; Thu, 06 Oct 2022 08:12:23 -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=@google.com header.s=20210112 header.b=J9UmphxO; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231926AbiJFOR1 (ORCPT + 99 others); Thu, 6 Oct 2022 10:17:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231915AbiJFOQr (ORCPT ); Thu, 6 Oct 2022 10:16:47 -0400 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47C39AE214 for ; Thu, 6 Oct 2022 07:14:15 -0700 (PDT) Received: by mail-io1-xd31.google.com with SMTP id d196so1339064iof.11 for ; Thu, 06 Oct 2022 07:14:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=uPoSw2DcS8I2PL1GAxLCIjBZkmIbahmymE7q5ESqNH4=; b=J9UmphxOwRlKuKwKJGEStMq2njru+PiIwGVLUfPBPq5L+NiQWR0X0ph0BMc2W5nbt8 4fY0afnp5OGHoR48WDeXsZwHxoMN5k4f3cAvRzRwXhvGYbcMUIpKQGeu62j2J2SnGy+J Xj/w4pUH+FdGPKiKioCFBigar50r6VlCGptHXogYu0vEHZthEC9POAERgLfXsIlNUJAT 4LL5lhcH/9QJf5wjtvXr093IFQ5FVgHnW9DKsbH5n9oFVp8IFEYJH/pVve/xHlsOIZTb JrrThpZZTRv6pIFAUlojtCkCpeK6hrRAxbyXE8fkyWQe0FnS13WwHzjaGBDQmYXcBSxS r/Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=uPoSw2DcS8I2PL1GAxLCIjBZkmIbahmymE7q5ESqNH4=; b=dY31nzR1trVBQmLMP/P+67271UUxdFCtIx459YuVB3+84FqbuDT1qeyTjesIST/FrK PDQ7nREJKObZGowzrn2G9p7wOJK5WEhGICniKccnJcc1P56xu/IPRz2NplRHNh/cBIS6 VVTVtfaxBeD/rNWyHsLuSf/QBQ9GIc58t2uPYBJi0W6vwJFSS9ztJr3XNqw06kWMmYpD uJuZDd42/ZqD0GeuT8kOcKrAQuuxCvF+a8cFAF6x5C/DZNbTtNpleYoBU09a4gDYHjTo MSFHo/EysYnRMy8akK8QLYAkbjYy3tcOCcmRgfvoGDrogw5O35c+HlP71rJ/O++sHeLL IHdA== X-Gm-Message-State: ACrzQf1rtwHrUbuIET5kqYKXg/2sXV6NKZp4Ehjw9lZnz+wF6Ybpoiaf Ybj2y8rHiTgk3QeQmkkeP756YzKPjmDW/tzjGLqVww== X-Received: by 2002:a6b:5d07:0:b0:6bb:7253:a439 with SMTP id r7-20020a6b5d07000000b006bb7253a439mr37286iob.2.1665065653849; Thu, 06 Oct 2022 07:14:13 -0700 (PDT) MIME-Version: 1.0 References: <20221006082735.1321612-1-keescook@chromium.org> <20221006082735.1321612-2-keescook@chromium.org> <20221006090506.paqjf537cox7lqrq@wittgenstein> In-Reply-To: <20221006090506.paqjf537cox7lqrq@wittgenstein> From: Jann Horn Date: Thu, 6 Oct 2022 16:13:37 +0200 Message-ID: Subject: Re: [PATCH 1/2] fs/exec: Explicitly unshare fs_struct on exec To: Christian Brauner Cc: Kees Cook , Eric Biederman , Jorge Merlino , Alexander Viro , Thomas Gleixner , Andy Lutomirski , 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@vger.kernel.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-hardening@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 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