From nobody Wed Aug 19 15:40:35 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 4hQ9l64cmwz6pCw0 for ; Wed, 19 Aug 2026 15:40:50 +0000 (UTC) (envelope-from asomers@gmail.com) Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hQ9l62NnYz3xNS for ; Wed, 19 Aug 2026 15:40:50 +0000 (UTC) (envelope-from asomers@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-6a378f90555so1563187a12.3 for ; Wed, 19 Aug 2026 08:40:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1787154049; cv=none; d=google.com; s=arc-20260327; b=ZcNSTkB+eqoUj7hOWUo/+vyuLnYRft5fWhDWzH2QKNsG8fvxH8R1IQOP6dhEPAZaqu yM5pOWTzgiMXhbmHT02U+4C9Q/lljH7nD2taOoxb3kxdq2bYr/0nYiyThBJwj+Wk+90m R0Pyil/JAhyAUNkMLZh+rvWdfCfvZvr+VmCgaoicr9CpPS/oiBi1cCW5Y/Ou30gJPz/v 4MrzXeloISNicf+3AFjGFhWDLhK7FgQvNwLXrZU80JI5sHALp+lmYtR2VZjMx6vLkVh8 F6cdJcbANqiuZicmrKN4005GFGVlZtZk11ReoEqBjQPqXbENASL2koMDO9HIQ2sHNzkr 4mlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version; bh=3W9Dxv2tT8NnUyqsNDx8lWNZ8S/jOD0I62xNel8kq9o=; fh=f5/piKoaeDtCknsH0Mb7DgqKbRqhZRbQZE7ePcZwSsg=; b=fEbT5NbBDLvxaSWjNVn+UixnTTVRw26V7xvjaoHVDrEp+RpASKGoD1G3sPDXdlHIsy UFngPXAehy+mtRFkDURx86AmAKjZRpvktdp7LfRguxNJin+X0H4m+PLAJ57fK33+FV+5 5YSVsZnGtHye8mNoly9e7zCTTSMN73YQw27O7zPHmai+Wvv3rjftaKSxG8KPRFFm6n/w uoNARGo7kDEG8IMdQCvTpXhnMHGp7y+Vhmw7WaBN4QzPA95VOhxWaRiIuZX8NKlg1QWP Chsx/jTH+MWY+Z5I0iSeWboWI6Lpe3FT+47TrIxL4Gu3upe/ohh98VJyTDnSwblaE7df Tq/g==; darn=freebsd.org ARC-Authentication-Results: i=1; mx.google.com; arc=none X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787154049; x=1787758849; h=content-type:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=3W9Dxv2tT8NnUyqsNDx8lWNZ8S/jOD0I62xNel8kq9o=; b=LE2t+C6WXijgyqWIdGdFL76wMtIXpymoWNZjibDvrpKyHc+cUaIXVFZPAsCbAhxsvi lxuY7VgYwOS2+j/AklsymbLt//Em6BrJSFEnloHhJL2zX/srlO3OjwA/48iBShavnkAD fjAFLaNwwouUcuA0rVZF4SyoOlNkdKjZNeIGrpq5WgZp1oC8zvV1dc1hYjfaYDz6ndrn gjk+p4wu/rdeGeFzvNxbjnr4+5WH7kH29nh2yUTmQT1KDfddG6Gy7S1JsjwmKar4SZX2 TPBrD+twoVnmHbIMKZP1KzxGXmp85JEd3C3YUXHI2sk+DznzNfQ+oL5S0x2slimEs9Y/ W15g== X-Gm-Message-State: AOJu0YzZoJXw0zQofWh6xTXHj8xGL8Gdd6VqZfQ3q7cAupFgeDFeChlt PxxTnZo56OV0+Jbf3sofNUVOZVMl+FsBPTfS3z1wZTBuQS5OpuFYSWMthmDE8+5wv1f/5YkmO9X 1Eg/1teCp6+Qg1JiuqfncSlTXVZU6Qs8= X-Gm-Gg: AR+sD13YHiCJ41ouSsy7Oz2p/ZTXHM32XjzAEiDSQyt0UOPEnoYgXTf2EnRUFgchlo6 +BjxQGcOTMetnLjinFZlaPthF7dv0e96uOYa4AtTqizMIDPg8SP3caqzFaAFgrRKi48AOSikgMI kAFsl56jvZpcbB4l+GmE96Pw7If9MzGbS2o35NAI7AA/YOmA83gGi2KJm2MJevGBwFmiJR8mDfZ mbJFjrHCY9BO6b+ep+rWMKFK7X8sX+efC0Emidz9nO7VdmzS8W/6rrS+WI8hvIJFRQgt/aQVzoQ ByR9HuZvdvMXEO8k+QSb6nQOXRX1LWXR+/7mkJWzWV+vfW6lt7ETkmvS1Be++GRUsuzaD/CnTAK sv4eNFeNMIah75n+9rfm0AwioxJqBt1JXqYs= X-Received: by 2002:a05:6402:a0ca:b0:6a0:a644:355e with SMTP id 4fb4d7f45d1cf-6a4032d35abmr4256046a12.2.1787154048605; Wed, 19 Aug 2026 08:40:48 -0700 (PDT) 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 References: In-Reply-To: From: Alan Somers Date: Wed, 19 Aug 2026 09:40:35 -0600 X-Gm-Features: AcwNN1Wv5sl7zZmv6y_AZmCKAkR5LpxeXjxZXkovFygU0B2D-h3-lU9BfZbwoMs Message-ID: Subject: Re: chflags -RL and symlinks pointing outside the traversal: preserve behavior or add a Capsicum guardrail? To: Jitendra Bhati Cc: freebsd-hackers@freebsd.org Content-Type: multipart/alternative; boundary="00000000000039e34a0659683a2a" X-Rspamd-Queue-Id: 4hQ9l62NnYz3xNS X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US] X-Spamd-Bar: ---- --00000000000039e34a0659683a2a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Aug 19, 2026 at 8:37=E2=80=AFAM 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 thin= k > 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 erro= r. > Capsicumize -L but keep out-of-hierarchy targets working by opening a > descriptor for the resolved target's parent (loses most of the confinemen= t > 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. https://github.com/BawdyAnarchist/quBSD/blob/88621ea7693514e4342c81478cd1b8= 83d22b04a5/usr/local/libexec/qubsd/qb-ivpn#L222 > =E1=90=A7 > --00000000000039e34a0659683a2a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, Aug 19, 2026 at 8:37=E2=80=AFAM Jiten= dra Bhati <jitendrabhati2= 026@gmail.com> wrote:
Hi all,

As part of GSoC 2026 I'm c= apsicumizing chflags(1), using the new fts_openat(3) API:

https:= //github.com/freebsd/freebsd-src/pull/2375

This raises a backwar= d-compatibility question that Alan Somers and I think warrants wider input.=

In physical modes (-P, -h, and the default without -L) the traversa= l now runs inside Capsicum capability mode: chflags pre-opens a directory d= escriptor per argument, calls cap_enter(), and operates via:

chflags= at(fts_parent->fts_dirfd, fts_name, ...);

This confines chflags t= o 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 <flags> 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 reacha= ble 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 o= pen question: is "following a symlink out of the named hierarchy"= behavior worth preserving, or is it exactly the kind of thing a Capsicum-i= zed 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.
Capsicu= mize -L too, and treat out-of-hierarchy symlink targets as an error.
Cap= sicumize -L but keep out-of-hierarchy targets working by opening a descript= or for the resolved target's parent (loses most of the confinement bene= fit for -L).

I lean toward (1) for this PR and revisiting -L separat= ely, but I'd appreciate opinions on whether the stricter behavior is wo= rth the compatibility break.

Thanks,
Jitendra Bhati

I vote for #2.=C2=A0 Capsicumize the utility, and = treat out-of-hierarchy symlinks as an error.=C2=A0 I think that real users = will almost never want to follow out of hierarchy symlinks.=C2=A0 Also, eve= n if this is a POLA violation, it's extremely rare.=C2=A0 With grep, I = couldn't find any example of chflags -RL in the base system.=C2=A0 Gith= ub code search turned up a few.=C2=A0 Some were MacOS Homebrew recipes that= invoke chflags right after installing the package.=C2=A0 Those uses surely= would prefer not to follow out-of--hierarchy symlinks.=C2=A0 The most inte= resting use I found was from quBSD, a jail/bhyve manager.=C2=A0 I don't= know if that project really intends to follow out-of-hierarchy symlinks or= not, but I've notified him.

3D""==E1=90=A7
--00000000000039e34a0659683a2a--