From nobody Thu Aug 20 14:41:22 2026 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hQmN43sqHz6nhMb for ; Thu, 20 Aug 2026 14:41:24 +0000 (UTC) (envelope-from markj@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hQmN4257Gz3VsW; Thu, 20 Aug 2026 14:41:24 +0000 (UTC) (envelope-from markj@freebsd.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787236884; h=from:from: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; bh=rW8Ba3chodDkAq/SfhIbhv/cl9LsaJtMqRmt+bqIcoc=; b=gMMm5XYHyiAj7WlVYxwYRGPunXNx2CeLiuQGGa9xsKN2zEdi8kf5ypr8MnXem7+XN9fkIn yH5VwYZf1A1IBfHKT+xw/tAgJZDLdmt5nHpN5zbdfVrzPfDTccFY+V4vf4evYV8f+1sjQk mSyaXW40j9FtImcZbcGCTrANKm0GLxKn5L6DP09kGmY9FWsUN4tiXK2c+3hKRc9jh5A3Ex ipfqYptU2+9GdMHpzacdSzrO5wnC7DGqV3tAuw3HHBQFdeniboA2S0OurPAE+teLXIB81X mU++hNLF6i+81pz4eRkQJueLVUPKduzfieRr7jTHSM2GY5AwU9MPH9U3lgtHaw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1787236884; a=rsa-sha256; cv=none; b=QRAMcwqLNz3/Gynzk46OF1kp1IFJdmDvXauMCUY9wm+3dWiUHA59HbbzYTDoU/5ivZ98bi NKLupJZ+7LJQTpoygV+1Cc2pKk3l8I6dsUoZfHcS7EdMKjAUPrmwrpGP6zma0HHyXvvJYg l90tEHkUgRPx2tBlfK5aJFzmjbIY5SJZknIZO8DHIXFzA/LMLUs/VrJou28ku7DQv1dMMz tJ/y9XaMyjmxhlh1HPo/LQFy/YQUIqqFQY/Vnm3pQIH9gHJd7drekmLD3uF2yznkmbpX9r w6tP3gqvp2+Hk+Vh81SgeHf6g8z3vbrPq9U0YAbN7DVtB7CrH88NG54ChwC8IQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1787236884; h=from:from: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; bh=rW8Ba3chodDkAq/SfhIbhv/cl9LsaJtMqRmt+bqIcoc=; b=d4VlFwH7/aV0+wv4Gwq59x4eWQgZh/wkCzYAkRyWfhRYH9pGT2K5hf+r9D4w4HKRYt2Lym m8qfijSuBqSKM8eepsLSumixA6xLW4V402zvjyhThPtr2O1/CaVYWEUQwr4fqUeGjUS+gA eFI9/iJWQquDehMypfqMSsVKP98CKA54xSc3DByAUTKa6VwQd1FsOzrov9l9tk4WXIwe/z WN26gjvxLFSewiCM+ugOZnUOhV9bkqevJN9MuiMX642IDRtbt4h6Dc+MNnMeTYoHdvWPyy eJ2FaxK3E5SlZwIB4zhvtLSIZYC4Hs7hgU6TNtZzSESov/IM2jTBsntH23ylGw== Received: from nuc (192-0-220-237.cpe.teksavvy.com [192.0.220.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: markj) by smtp.freebsd.org (Postfix) with ESMTPSA id 4hQmN35TZMz2BM; Thu, 20 Aug 2026 14:41:23 +0000 (UTC) (envelope-from markj@freebsd.org) Date: Thu, 20 Aug 2026 10:41:22 -0400 From: Mark Johnston To: Alan Somers Cc: Jitendra Bhati , freebsd-hackers@freebsd.org Subject: Re: chflags -RL and symlinks pointing outside the traversal: preserve behavior or add a Capsicum guardrail? Message-ID: References: List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Aug 19, 2026 at 10:46:47AM -0600, Alan Somers wrote: > On Wed, Aug 19, 2026 at 10:11 AM Mark Johnston wrote: > > > > On Wed, Aug 19, 2026 at 09:40:35AM -0600, Alan Somers wrote: > > > On Wed, Aug 19, 2026 at 8:37 AM Jitendra Bhati > > > wrote: > > > > > > > Hi all, > > > > > > > > As part of GSoC 2026 I'm capsicumizing chflags(1), using the new > > > > fts_openat(3) API: > > > > > > > > https://github.com/freebsd/freebsd-src/pull/2375 > > > > > > > > This raises a backward-compatibility question that Alan Somers and I think > > > > warrants wider input. > > > > > > > > In physical modes (-P, -h, and the default without -L) the traversal now > > > > runs inside Capsicum capability mode: chflags pre-opens a directory > > > > descriptor per argument, calls cap_enter(), and operates via: > > > > > > > > chflagsat(fts_parent->fts_dirfd, fts_name, ...); > > > > > > > > This confines chflags to the hierarchies named on the command line. > > > > > > > > The complication is -L (FTS_LOGICAL), where chflags follows symlinks. A > > > > followed symlink can point outside the traversal root, e.g.: > > > > > > > > file > > > > foo/bar/baz/link -> ../../../file > > > > > > > > Running: > > > > > > > > chflags -RL foo/bar > > > > > > > > today follows link and changes the flags on file, which lives outside > > > > foo/bar. Capability mode would block that access, because file isn't > > > > reachable from the descriptor opened for foo/bar. > > > > > > > > For now the PR preserves existing behavior: when -L is in effect it skips > > > > cap_enter() and keeps the historical path-based call: > > > > > > > > chflagsat(AT_FDCWD, p->fts_accpath, ...); > > > > > > > > So -L is not capsicumized, but nothing regresses. > > > > > > > > The open question: is "following a symlink out of the named hierarchy" > > > > behavior worth preserving, or is it exactly the kind of thing a > > > > Capsicum-ized chflags should refuse? A tree that redirects chflags at > > > > arbitrary files via a crafted symlink is arguably a threat we'd want to > > > > guard against. But it's also a long-standing, documented -L semantic, and > > > > changing it would be a POLA violation for anyone relying on it. > > > > > > > > Options: > > > > > > > > Keep -L as-is (path-based, not confined) - current PR behavior. > > > > Capsicumize -L too, and treat out-of-hierarchy symlink targets as an error. > > > > Capsicumize -L but keep out-of-hierarchy targets working by opening a > > > > descriptor for the resolved target's parent (loses most of the confinement > > > > benefit for -L). > > > > > > > > I lean toward (1) for this PR and revisiting -L separately, but I'd > > > > appreciate opinions on whether the stricter behavior is worth the > > > > compatibility break. > > > > > > > > Thanks, > > > > Jitendra Bhati > > > > > > > > > > I vote for #2. Capsicumize the utility, and treat out-of-hierarchy > > > symlinks as an error. I think that real users will almost never want to > > > follow out of hierarchy symlinks. Also, even if this is a POLA violation, > > > it's extremely rare. With grep, I couldn't find any example of chflags -RL > > > in the base system. Github code search turned up a few. Some were MacOS > > > Homebrew recipes that invoke chflags right after installing the package. > > > Those uses surely would prefer not to follow out-of--hierarchy symlinks. > > > The most interesting use I found was from quBSD, a jail/bhyve manager. I > > > don't know if that project really intends to follow out-of-hierarchy > > > symlinks or not, but I've notified him. > > > > If we go this route, I think there does need to be a chicken switch for > > any users that are legitimately impacted and want an easy workaround. > > I'm not sure what that would look like: an environment variable, sysctl, > > new command-line option? Should any such chicken switch be global, > > i.e., should it apply to all capsicumized utilities which use fts? I > > presume you are planning to extend this to work with other fts-using > > utilities which might benefit more from running in a sandbox, like grep. > > As a chicken switch, I think that an environment variable would be too > easy to set by accident (and could even be set by an attacker). A > sysctl would be annoyingly difficult to implement, because it would > need to be checked from userspace, not from kernelspace. So a > command-line option would be best. However, I couldn't find any > examples of other existing tools that have such options. In general, when capsicumizing utilities we try to avoid changing the behaviour. Here, we have no choice, and there's not much precedent for that that I'm aware of. I still think we should provide some way to work around any compatibility problems. Maybe, /rescue/chflags should not enter capability mode, and the workaround would be to use that instead. That's not a very general solution though. > As for other utilities, there isn't enough time remaining in GSoC to > adapt any others. The original motivation for this project was > net/openrsync , which could really benefit. pax could really benefit > too, since malformed archive files are a classic attack vector (unless > pax only uses fts_open in create mode, not extract mode; I haven't > checked). But we chose to convert chflags first because it would be > easiest. At a glance, it seems like pax doesn't use fts for extract mode.