From nobody Wed Aug 19 19:22:16 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 4hQGfq6zdFz6pWYY for ; Wed, 19 Aug 2026 19:22:27 +0000 (UTC) (envelope-from vadimnuclight@gmail.com) Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) (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 4hQGfq4jWmz3YCl for ; Wed, 19 Aug 2026 19:22:27 +0000 (UTC) (envelope-from vadimnuclight@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4994c49f588so2344705e9.0 for ; Wed, 19 Aug 2026 12:22:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787167340; x=1787772140; darn=freebsd.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=SConwwIj7k8I1dZWtqb9g2nMIG4ItfzxyxDhwYw0EPo=; b=c2eJwSzCayGAGJo8TbYFBYzZ4kPqIQV2leDP1JSmtMrdC4aEpyn6X3I/WV1JCeCBVS qOQSGt1X09i3nmluNEfckEUV2MhDAULZJFSBMeieCUQag4+zVnTHDBkGQCCAzHJr4ROo r9r1y0rfdHCMBDz/qjQBuBz6RfXweMEa71H0Pnqsnaq8qpFWNaosl4GMlfL4LXGSzg1G chKSVF8W8VpSOSkkqmcdEEyWyaOyJthFpg+h5hge14qs9Uhh1I8k75UorjgRjdxghmh9 7wj4q746NcuSTtLAwmpmG/do5i06Li4/pG1UIXLfIWYfouA5LjPCy/gbXF73xNos27CV zHkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787167340; x=1787772140; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=SConwwIj7k8I1dZWtqb9g2nMIG4ItfzxyxDhwYw0EPo=; b=Lco0zBu4sErvaiulVhMc1SXuE0ScyjC+hMe+64oWJnv9EYA1UuZ3eRuZG15f6LhlU9 QokhZkd+FV6dJg+K+YRYryXc9pVRP7n4HcG7fVZW80fjUwUUDTKiUmftT+EFNAmNcNVK ndNgWwbh/ycCEHNva/sbru1fOWWVoXh1hERoX1ZHv/N0Nk7etfKYFkYb0fus5EPQWk3w Wr9XDyGwHghPPpj05GxPMqvEjnpkaabE93NaPb+k4WZC9hYoiEwAGz22awEW6AUs0B4+ MrGBgFlu+6+DwXdH9K7LXPgjalfnnm4pg3wD0ZUqGLx5UO5NwvN32FG/eDwwEw9ZJ4n8 ZvbA== X-Forwarded-Encrypted: i=1; AHgh+RpxW60rIgAPiIKiAMYHQJrKwCd/iKKToY1p9hTyXHly+Q6Imw/q2RxVRZ/8h5tenUIE39unVl/WPWIsr5lFu1M=@freebsd.org X-Gm-Message-State: AOJu0YxR4UgPFWa05fbBQu+MzOO2+qFhdLGCTX8UxliQZH5fHfTx93eS rnifdxhItLnYtNnlu+uwvWSeL+k6pMnH6FqoYS+g3NcKLmONEKpWALfy X-Gm-Gg: AR+sD120Bae2gDaU41oNHX5C228gHFQPTaPpb2dZNntiC7hZvD3VLu1jtBShk6Ykxyn fBTzAZUSC5sK+zzVZucvl7NrTRwI2nJG5h2V8/QmMBGLe2qJ+Uejq/94l+hzsYth8ZfTcTNSXYm tgCjabb2zLpX8IP9FwRrMuWxrLzt2ga1ZPUKTGBPRd3vt8v2N7hXTBKDZWcIdBCugTHHWjZk6b8 rlDs2VUueupyxcCeJ7rmASeCrQ8Aa3HZElqi/GiCt7Vrfp7HOdadGc7Qv4BxOo1rgR0wE37zRbn YtCBILw6jKNmg05ffBVvZfzpyi63GkJXH3fdqL6oqiTUTpPZ6094ecmCHUeUqokPBwQ80ku/yoE uF3XMnAZ5OMo0s7doeu2Y6hBqIkQQb+SZQ7pye2fA/UH/sCf1B8CnbPT+AOfmmBQy2SKn/eKnos qHZvSSAxiRY6Rp2p56xw9BWQecHiePxQ2f5jLJ6GnRLDbCYT6IlhcNJaaF+NMQ9jsLkiueUdNNi aztEC2Sh2TXPD1jfv7xaJkLhC85rJc= X-Received: by 2002:a05:600c:810a:b0:499:59fd:dbfc with SMTP id 5b1f17b1804b1-499b06a58ffmr22326165e9.1.1787167339473; Wed, 19 Aug 2026 12:22:19 -0700 (PDT) Received: from nuclight.lan (broadband-77-37-180-76.ip.moscow.rt.ru. [77.37.180.76]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-499aa17e241sm73088275e9.12.2026.08.19.12.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Aug 2026 12:22:19 -0700 (PDT) Date: Wed, 19 Aug 2026 22:22:16 +0300 From: Vadim Goncharov To: Alan Somers Cc: Mark Johnston , 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: <20260819222216.6ef37684@nuclight.lan> In-Reply-To: References: X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; amd64-portbld-freebsd13.5) 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-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 4hQGfq4jWmz3YCl 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:2a00:1450::/32, country:US] X-Spamd-Bar: ---- On Wed, 19 Aug 2026 10:46:47 -0600 Alan Somers wrote: > On Wed, Aug 19, 2026 at 10:11=E2=80=AFAM Mark Johnston wrote: > > > > On Wed, Aug 19, 2026 at 09:40:35AM -0600, Alan Somers wrote: =20 > > > On Wed, Aug 19, 2026 at 8:37=E2=80=AFAM Jitendra Bhati > > > wrote: > > > =20 > > > > 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 direc= tory > > > > 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 symlink= s. 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 outsi= de > > > > 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 hierarc= hy" > > > > 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 wan= t to > > > > guard against. But it's also a long-standing, documented -L semanti= c, > > > > 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 > > > > =20 > > > > > > 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 examp= le > > > of chflags -RL in the base system. Github code search turned up a fe= w. > > > 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. =20 > > > > 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= . =20 >=20 > 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. >=20 > 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. I've scrolled via login.conf(5) to see what can be (ab)used for this instea= d, and my eye fall on "priority" - as user can't increase it's own priority le= vel (decrease niceness), only decrease, this somewhat shields from environment variables changes by attacker. It's probably not better to implement than sysctl except absence of TOCTOU window when sysctl changes on the fly. Some arbitrary inherited process flags should exist here as a best solution, don't know if extended attributes in filesystem can provide this. --=20 WBR, @nuclight