Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp808739rwi; Fri, 14 Oct 2022 08:51:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4lc2RqdjO5G4uQgqhWM78jbu6ViFrgZUE4aByvrjKepoZ1xOZ3TwLo6dHBbMXA9DOnmVd7 X-Received: by 2002:a17:906:fe46:b0:73d:939a:ec99 with SMTP id wz6-20020a170906fe4600b0073d939aec99mr4111387ejb.169.1665762664871; Fri, 14 Oct 2022 08:51:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665762664; cv=none; d=google.com; s=arc-20160816; b=hXyPaCatYX3tnvWnEu6dBNnhg/K2HzddCYF0ogIJLzXaXCN/xt2uA1wRFcr+KUM/MM imjCSiKjPE83LRszAwsPRBCrQyAh8qNS6MSkVcZ9P7X2jS0NXMaGdrHhe1wv/ftVYEUb NdpQ19NL2BByr+luEBaeUkNZQ72JiLJJ0fiihQarBVgn9NLyrZzbZHJ06ED9Glmd817g HJlYiO65RmlRqRl1cdEEKA0WtlIQt/mH46CXhraWJBodTr1MqB4OUAool9ueJi5oLoGc t3xBm3+Qo5Irkj+8y2YUn4HJ9LNVaLCQVcMYuVcYyGDXXoXW/fk0Sswy1jq5oVp/uxmH JZIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Ytj3+kIoMyv4FX1lyc9tQ8OGwlhuPVWv2RqpKd5YyDU=; b=vckCo8HP3nzEd/8585wbZOY+Dhuu8G+i835VC0TNBabvkhBrPMhe7FIzwEZLOpTkdT Bw9c2h1dQL0agJrTlqfKfTlOZUz9jdAokAS//j5I8VSE1w9UX73Fya6OPXsI0El60084 H0lIv7OkRBTnRzeBIGf5F+NKSBrBwhqJXUg/j0JBJq2FXtGtfHcgGjK977Uu+djLiPg+ rfiBRu0IQuD+zg+ZqDNglPL8BWXHhuA/Kd/eXF0JmosWpwOUTAy7URQK3waP65Ec3BfY AJmvqo5NLbqjQSNj/aBPQX5c2Q592XpjDT4d4RNpl28AEbvcivcuDAYvg/6pXQfUE0BS /ROQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=JR0xr0fI; 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 b15-20020a056402084f00b00458c9c8a637si3040316edz.328.2022.10.14.08.50.37; Fri, 14 Oct 2022 08:51:04 -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=JR0xr0fI; 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 S230439AbiJNPgG (ORCPT + 99 others); Fri, 14 Oct 2022 11:36:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229818AbiJNPgF (ORCPT ); Fri, 14 Oct 2022 11:36:05 -0400 Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 462AC2A711 for ; Fri, 14 Oct 2022 08:36:03 -0700 (PDT) Received: by mail-il1-x133.google.com with SMTP id y17so2693331ilq.8 for ; Fri, 14 Oct 2022 08:36:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Ytj3+kIoMyv4FX1lyc9tQ8OGwlhuPVWv2RqpKd5YyDU=; b=JR0xr0fIsskJTzO427SqrUgqb1DWjVVtwkmODGGjkSZJ4FMfX2ZsXK6Mm2spguP5Fi nyMmB82X0MA3h2JOCrtW3gl25dxsj4jiveXGKR6Z8STGPeeVjmS2VTjycP+RBn0tVhJl RTnAEkh5Qc5sIHtelNV80ZV0a1sV1g2AGrc8jU/2ZL2m19qrw9p6cxMlxHCX1YxptKvv NWg2UfEw3P0qeI86qPSMdLeiUDU5LTngBxTc3KHC3yReE92Ufkh4RP9JTPdhqddOZWDg 6zCkai4UfclKgR3ffQ4VMj7CkN9eR7ciGLAV2JgtjXPGADfXQqzzW05FazqVHzwOwv/N dRvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding: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=Ytj3+kIoMyv4FX1lyc9tQ8OGwlhuPVWv2RqpKd5YyDU=; b=k+0nc0GmQDkmfqgApUYFT2eRxOrI6r56VX+FjID+cAA/4ySRUFQMbVMZBfinwPW9zH cCY6HR7bW6nAhAZ7ISVIuRH25XUZuydOz8lURp/sYAJ8uKCFVRDXXtPcbtEnlAQQMonG pJQwrrq5NQJqt+ZCCAG8y80H1G34sFc0xArq0voLk6NyzUJgSGN+0mFwwNV5r+36nzSV 8QuqVvTo7T5GWeuWoDzxDpIFInmoAumB9aFidvABvKpgh9GJdWUt/HVoXLSrYEMZLfA3 w9R6vKmSeOVfDcNkV2uLcAaU4WLKsWye6hg/qPr2Bav/A/69tWFaSTyyR5zqn/335KqU Ffhg== X-Gm-Message-State: ACrzQf2q05Kw9RUP7sUgBlrCnkcFCOCSG6SIHc+ubz5uOsBLlPI3DR9U W/1TYEbN2jFBzRIpQ6yeLC2N61oYll4H4SGRLS2zAw== X-Received: by 2002:a05:6e02:1c27:b0:2fc:6aa7:edda with SMTP id m7-20020a056e021c2700b002fc6aa7eddamr2701536ilh.177.1665761762432; Fri, 14 Oct 2022 08:36:02 -0700 (PDT) MIME-Version: 1.0 References: <20221006082735.1321612-1-keescook@chromium.org> <20221006082735.1321612-2-keescook@chromium.org> <20221006090506.paqjf537cox7lqrq@wittgenstein> <2032f766-1704-486b-8f24-a670c0b3cb32@app.fastmail.com> In-Reply-To: <2032f766-1704-486b-8f24-a670c0b3cb32@app.fastmail.com> From: Jann Horn Date: Fri, 14 Oct 2022 17:35:26 +0200 Message-ID: Subject: Re: [PATCH 1/2] fs/exec: Explicitly unshare fs_struct on exec To: Andy Lutomirski Cc: Christian Brauner , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=ham 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 Fri, Oct 14, 2022 at 5:18 AM Andy Lutomirski wrote: > 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 he= avily > >> > threaded process trying to perform a suid exec, causing the suid por= tion > >> > to fail. This counting error appears to be unneeded, but to catch an= y > >> > possible conditions, explicitly unshare fs_struct on exec, if it end= s up > >> > >> Isn't this a potential uapi break? Afaict, before this change a call t= o > >> 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 t= he > >> 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 i= s > >> accompanied by an unshare(CLONE_FS). Might still be worth trying ofc b= ut > >> 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=3D101?q=3DCLONE_FS&sq=3D&ss=3Dchromium > > Wait, this is absolutely nucking futs. On a very quick inspection, the s= harable things like this are fs, files, sighand, and io. files and sigha= nd get unshared, which makes sense. fs supposedly checks for extra refs an= d prevents gaining privilege. io is... ignored! At least it's not immedia= tely 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? I agree that this is pretty wild. The single user I'm aware of is Chrome, and as far as I know, they use it for establishing their sandbox on systems where unprivileged user namespaces are disabled - see . They also have seccomp-based sandboxing, but IIRC there are some small holes that mean it's still useful for them to be able to set up namespaces, like how sendmsg() on a unix domain socket can specify a file path as the destination address. (By the way, I think maybe Chrome wouldn't need this wacky trick with the shared fs_struct if the "NO_NEW_PRIVS permits chroot()" thing had ever landed that you (https://lore.kernel.org/lkml/0e2f0f54e19bff53a3739ecfddb4ffa9a6dbde4d.1327= 858005.git.luto@amacapital.net/) and Micka=C3=ABl Sala=C3=BCn proposed in the past... or alternatively, if t= here was a way to properly filter all the syscalls that Chrome has to permit for renderers.) (But also, to be clear, I don't speak for Chrome, this is just my understanding of how their stuff works.)