From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4B33C3ABC9 for ; Tue, 13 May 2025 20:57:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9831E6B00D8; Tue, 13 May 2025 16:57:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 931896B00D9; Tue, 13 May 2025 16:57:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7ADEC6B00DA; Tue, 13 May 2025 16:57:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 51F6C6B00D8 for ; Tue, 13 May 2025 16:57:34 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 481B75FB55 for ; Tue, 13 May 2025 20:57:35 +0000 (UTC) X-FDA: 83439095670.25.83FDA2C Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf22.hostedemail.com (Postfix) with ESMTP id B2374C0004 for ; Tue, 13 May 2025 20:57:33 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="SgH/4gl5"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of kees@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=kees@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1747169853; a=rsa-sha256; cv=none; b=n5lWNHzcv7PT8ApEGUnDN46l4Bv52itYuH47L54XL8OHWsQcXBiRihSh5C5hFMQF9uGIim Xq0E149rNDQuYLz9JAZHIG/3PFuDRceXU8wkrSyYunxwAug5nADSnjeGNwVdOMEc8E47g8 RfWci8YFrnXHkSFzV8yzfpKy0OnkDPA= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="SgH/4gl5"; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf22.hostedemail.com: domain of kees@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=kees@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1747169853; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=akamBwTU3WG++dvibVKWhKy32yGTG7zt7oKLcQaK63E=; b=wAShO4ijilQJyH902X6dbFKeFZ6VtcH3pjyymFFsmz5noLBh5NKuTMO2fGQEZQ2IKg0vly WJTD7HAc1bg7B2YuvP71kURDl8a0FR/bXvt3BW1ZTgKj46AORs0Jqar8m7iRRPIlfkqIcB VswtouEJIJjIX3YHPxbMC/QXii+5d+8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 4F9CC5C3E8A; Tue, 13 May 2025 20:55:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33023C4CEE4; Tue, 13 May 2025 20:57:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747169852; bh=akamBwTU3WG++dvibVKWhKy32yGTG7zt7oKLcQaK63E=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=SgH/4gl5OHphQmUDNL/pWDatdwfs97NYq4vBGIHYCV1RvttcW6YwgZrwDS/BBJqpv GxxjbhiQf2kzZX6kW5hRqhFp5CZUucN8Y26fopof8yuKNket+02GQZGZr/GyJTFaN9 9d0V1ooL84iYvFPn1PYorReXf+64c7nBbcnoqdFuJrJ2d8uNiV6C0NeA5w4Tzb81sa WREaq8S6HvKA69TRynzVoxOUYiIKAjQVsCsENZfv95ieQj8Er4/GqlTsED4dcF55VR E3f3Gw7C4JJLkhY1BQguq7h8y3xZC+QW8gjLygt7qo49KqU17uamGcq9be4XHAKck5 FFu/InBeR2S6w== Date: Tue, 13 May 2025 13:57:27 -0700 From: Kees Cook To: Mateusz Guzik , Kees Cook CC: Jann Horn , Christian Brauner , 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, oleg@redhat.com 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> <86CE201B-5632-4BB7-BCF6-7CB2C2895409@chromium.org> Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Stat-Signature: utppjr45yjp1pymsbwgkjep5aigon4fr X-Rspam-User: X-Rspamd-Queue-Id: B2374C0004 X-Rspamd-Server: rspam06 X-HE-Tag: 1747169853-280140 X-HE-Meta: U2FsdGVkX19UlnkklkBBZKp182h3+9TT/33AFV4aRI5UjUsmOYF/en31o1Vw6YI7LNKjdi61ASCFmz8rrcX3fb3KE5hx+Bv+cgyOngyv5uYM6P9abj3mVqWBTaOZQ3lQzz+5K+2hEG9VnORsO63PdAex8BSgLRLb19B5HcXSs8qwRagrDFzWGb3lBrYM+tSDyOp30RZArxa+pUqo4IxffWevQLPNYdJeyIO1dLygpgnXTLAqUjVfTWUUUn/4Zcc+Nayo3oPY2IQ2sZBQ7OT8X+khPEw/YCRZOVojoxoV5pb1TzZfrfZZXwRQyZ5k0jYYzbl7aRPzmHLGwN2UR8IksM3dVjPxuQTXDYALxHZAACzXKMVFfmshgakFNry0Wnc5gEHcheOOB3kHArh4j5jUWSW+TP1kiZiceqTf1avu5v3GrjBO0ferqWC74IcxYPtx3iJQUNZzYoporBH3al2hT4YCpM/6YO2sLy6D9hy5dlFRXsPRcGmJppcdxXnMYxr/Hmd1M1gaaxo0afuKMj4IV06qtksYLurelhWmBc55IPh8Tu9e2jJGsOxZizZhE+lxB6XyidKN3z9a1WzhzGdmJfbic9YaIRaIIUQ2h6aSX4k5aN2IdxlwkgDsmwKyiQk0vvDng6S4YNRbjgyWf1hHx3iZyqnQuYc1ZjKKNNhLUsazX2hzEv+Ffq8w886+uS5UkMILnFdMbrpesLkPCDZN5vuLGSSOU6W4bOJSQhNGX/Qz6/sG0tho4B4dMh6V4DWu0FlPLYVdnP6YN49BuAnY+m2yV232V5+Z8K8XSmFbOFYgtWZFy+kd24nkRk6rAPryn0y8hDJcXcVeKErN5PVLrE9HB1KwOKbFuVj5rKnp872PQvIyrKtL1Hl8Vv6xeVyoj5Rr9i+RlI6S5S89zpWLnAI+UfO+k2GEOYVo35X/+YemtLDQT+6URaiVh4k+jlPjjvcOAZRmSvagq3Ohnkd 3RYzp7yB n7M99EUz9GMZ9PRAnXHzpwr2r38ZqQQHKhoTCDRoAFkCmbAc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On May 13, 2025 6:05:45 AM PDT, Mateusz Guzik wrote: >On Thu, Oct 06, 2022 at 08:25:01AM -0700, Kees Cook wrote: >> 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 = heavily >> >> > threaded process trying to perform a suid exec, causing the suid p= ortion >> >> > to fail=2E This counting error appears to be unneeded, but to catc= h any >> >> > possible conditions, explicitly unshare fs_struct on exec, if it e= nds 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, c= hanges the >> >> working directory post exec it would also affect the parent=2E But a= fter >> >> 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 ex= ec is >> >> accompanied by an unshare(CLONE_FS)=2E Might still be worth trying o= fc 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/l= inux/suid/sandbox=2Ec;l=3D101?q=3DCLONE_FS&sq=3D&ss=3Dchromium >>=20 >> Oh yes=2E I think I had tried to forget this existed=2E Ugh=2E Okay, so= back to the drawing board, I guess=2E The counting will need to be fixed= =2E=2E=2E >>=20 >> It's possible we can move the counting after dethread -- it seems the e= arly count was just to avoid setting flags after the point of no return, bu= t it's not an error condition=2E=2E=2E >>=20 > >I landed here from git blame=2E > >I was looking at sanitizing shared fs vs suid handling, but the entire >ordeal is so convoluted I'm confident the best way forward is to whack >the problem to begin with=2E > >Per the above link, the notion of a shared fs struct across different >processes is depended on so merely unsharing is a no-go=2E > >However, the shared state is only a problem for suid/sgid=2E > >Here is my proposal: *deny* exec of suid/sgid binaries if fs_struct is >shared=2E This will have to be checked for after the execing proc becomes >single-threaded ofc=2E Unfortunately the above Chrome helper is setuid and uses CLONE_FS=2E But to echo what Eric asked: what problem are you trying to solve? -Kees --=20 Kees Cook