Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1124860rwb; Thu, 6 Oct 2022 08:44:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM66X+8qhapUvGBU06UwkEo4BIxOgjsFmquODy8IeKpYERrhn91c0YnKqHSLm6pF/LZK4DYp X-Received: by 2002:a05:6402:2743:b0:459:1914:493d with SMTP id z3-20020a056402274300b004591914493dmr350924edd.361.1665071062850; Thu, 06 Oct 2022 08:44:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665071062; cv=none; d=google.com; s=arc-20160816; b=00GZtOKF0KN6fhzjhv6ZHBL0+Q6i71XmLSH9Rhm20xfhcNMV5nYvcl56sNjBVBGnuS iKAQEEyfKWffuGqIhCqQFwQ1ZyxDyugjpAmYuSpGu0pDEa+TyWUrsRghoVJ50csIjcxA 4hxip/aECaTvq8TX2dDC8RDUWQKX6Z3mhVgjjYIoNdGFQUk/wZ3kZrN8eXQST2/BmV32 RIKGjcqBoUdcPJPxPYhVwoMNSEaybbG/5JUqyEpOLNXNa2T4/EUz2WQD3B8uyjraVoYZ tZpATS9h+Zm70hnEV6oAur2rLg7regfI/6PFHzAsJ/Bh7JTIL5I6YsgnCcKFmIGegy+z 0+nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:references:in-reply-to:user-agent:subject:cc:to:from :date:dkim-signature; bh=OtDkks39cgYVeSHQm8gd1cyY+JEJiwboAG4vuizNOOQ=; b=kUxepFQQ8CZb03u1TUL7+yKkrv36Uyv0/Mqz8qPoLIxg74WM74NX1rAjIMRTFhBBgW EELwjMnjQfpsv7UXQORcpegkfF5b7JGpPzK9SVfEVf2U24OjoUJ1sm/sFq3yLTJf3x58 FuhCD1+T+uSWNsH/xUQCF5aoJARWi6LgW4zyYp4ZG1tG7ipC2cE71avawwLbi1tue0AW DDREdvcJPokgrePIzL5SEgmEYH+3CaNsy9CXn1Bfl/8ycPWR5lqhAqW2/036J8l8CH4P WATgHcJK7/Q/H+L+2xaWFXOmu9X694BU+tHPKFmWgbafbPTPe5AFfBO/EcuZaA2Uk6aS 2Hpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bwYKBKdR; 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=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j22-20020a50ed16000000b0045895e80ebfsi14180882eds.53.2022.10.06.08.43.54; Thu, 06 Oct 2022 08:44:22 -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=@chromium.org header.s=google header.b=bwYKBKdR; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231693AbiJFPZN (ORCPT + 99 others); Thu, 6 Oct 2022 11:25:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231730AbiJFPZI (ORCPT ); Thu, 6 Oct 2022 11:25:08 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C1018E0D8 for ; Thu, 6 Oct 2022 08:25:06 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id 204so2327366pfx.10 for ; Thu, 06 Oct 2022 08:25:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:to:from:date:from:to:cc:subject :date; bh=OtDkks39cgYVeSHQm8gd1cyY+JEJiwboAG4vuizNOOQ=; b=bwYKBKdRbKMXUGR+1Ba8s3APih/vqE4MzepUDPFpZZHmlwMDQPXFSRTr6JI2afx1mB 5cCbkbKmfA/SsPQewwxLX0n1fuUOpqCqwDg8icP+4MjefbAGmbzfdCmtuHboewFG1cgf 2Xuw32nN44/m5B/9jthRwgcr/98+HiByIIItU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:references :in-reply-to:user-agent:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date; bh=OtDkks39cgYVeSHQm8gd1cyY+JEJiwboAG4vuizNOOQ=; b=WJgPceMmYj1VgGucfCqRhekO0bNEBkyWrOaDZ/9VQVuqLGuDBahGV1/wnZLJO4hLom pTDCOO/lxl/LBIaCYOYCgrGDFIRtd2nC2UHBsEElAq+hFTLFxJjDTu0yO5hY8yZADuw1 CANjMgT9rUSWTweMUC25X51YAMbkAXka7+RjpUxzOPMo7ZIq0hu8m9iuflcYpIZVzoCo NtsTeL8GWFi1Q7rQD0o8neTEoPThQ6UziOGc/kuQu54RmnpSXLH+nMVvZz9taTjw2T+q dMXhXxLv9xtUhheoo1RRDVJP0JxrtwauC0rZlgh5v4SMOCfbQ9XIp9S5+K8OXtY7Riju BUXg== X-Gm-Message-State: ACrzQf2R/23ZW6GaXjMKbwKYhfmfBexpbN11VyL2LuMNybFyOhBFhEQ7 RXrK0KqXBjmn4GjbcviTg2yfrQ== X-Received: by 2002:a05:6a00:22c9:b0:561:8635:7b35 with SMTP id f9-20020a056a0022c900b0056186357b35mr334380pfj.3.1665069905412; Thu, 06 Oct 2022 08:25:05 -0700 (PDT) Received: from [127.0.0.1] (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 73-20020a63054c000000b0042fe1914e26sm2006066pgf.37.2022.10.06.08.25.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 Oct 2022 08:25:04 -0700 (PDT) Date: Thu, 06 Oct 2022 08:25:01 -0700 From: Kees Cook To: Jann Horn , Christian Brauner CC: 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 Subject: Re: [PATCH 1/2] fs/exec: Explicitly unshare fs_struct on exec User-Agent: K-9 Mail for Android In-Reply-To: References: <20221006082735.1321612-1-keescook@chromium.org> <20221006082735.1321612-2-keescook@chromium.org> <20221006090506.paqjf537cox7lqrq@wittgenstein> Message-ID: <86CE201B-5632-4BB7-BCF6-7CB2C2895409@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 October 6, 2022 7:13:37 AM PDT, 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 hea= vily >> > threaded process trying to perform a suid exec, causing the suid port= ion >> > to fail=2E This counting error appears to be unneeded, but to catch a= ny >> > 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=2E So if the child e=2Eg=2E, chan= ges the >> working directory post exec it would also affect the parent=2E But afte= r >> this change here this would no longer be true=2E So a child changing a >> workding directoro would not affect the parent anymore=2E IOW, an exec = is >> accompanied by an unshare(CLONE_FS)=2E 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=2E > >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=2Echromium=2Eorg/chromium/chromium/src/+/main:sandbox/linu= x/suid/sandbox=2Ec;l=3D101?q=3DCLONE_FS&sq=3D&ss=3Dchromium Oh yes=2E I think I had tried to forget this existed=2E Ugh=2E Okay, so ba= ck to the drawing board, I guess=2E The counting will need to be fixed=2E= =2E=2E It's possible we can move the counting after dethread -- it seems the earl= y count was just to avoid setting flags after the point of no return, but i= t's not an error condition=2E=2E=2E --=20 Kees Cook