🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: muc.lists.freebsd.bugs
Article #897

[Bug 301480] procstat(1): cap_desc[] lacks CAP_SEEK_TELL, so distinct capability rights sets are displayed identically

#897
From: bugzilla-noreply
Date: Fri, 04 Dec 2026 03:15
156 lines
8944 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301480

            Bug ID: 301480
           Summary: procstat(1): cap_desc[] lacks CAP_SEEK_TELL, so
                    distinct capability rights sets are displayed
                    identically
           Product: Base System
           Version: 14.5-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: bin
          Assignee: bugs@FreeBSD.org
          Reporter: ing.castellanosdz@gmail.com

Created attachment 278175
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=278175&action=edit
Reproduction: fixture, libprocstat reader and outputs from 14.5-RELEASE

Description

procstat -f -C (procstat_files.c) renders a descriptor's cap_rights_t by
walking cap_desc[] and printing every entry whose rights are wholly
contained in the set (print_capability()).  cap_desc[] is maintained by
hand and has no entry for CAP_SEEK_TELL, and print_capability() does not
report bits left over after the table walk.

As a result, two descriptors whose rights differ only by CAP_SEEK_TELL
are shown with the same label.  The kernel and libprocstat report the
rights correctly; the information is lost only at the presentation layer
in procstat(1).

The observed discrepancy is confined to the presentation layer.  No
Capsicum enforcement failure was observed or is claimed in this report.
It is a representation problem that can mislead someone using
procstat -f -C to audit a sandboxed process.

Comparing the capability definitions in sys/sys/capsicum.h with
cap_desc[] on 14.5-RELEASE, CAP_SEEK_TELL has no corresponding entry.
CAP_SEEK is defined as (CAP_SEEK_TELL | 0x8), so the composite "se"
entry does not match a descriptor that holds CAP_SEEK_TELL alone.

----------------------------------------------------------------------
How to reproduce

A small fixture opens the same file read-only as fds 10-15, applies
cap_rights_limit(2), calls cap_enter(2) and pauses:

  fd 10: (no rights)
  fd 11: CAP_SEEK_TELL
  fd 12: CAP_READ
  fd 13: CAP_READ | CAP_SEEK_TELL
  fd 14: CAP_READ | CAP_FSTAT | CAP_SEEK      (control)
  fd 15: fd 14 rights | CAP_WRITE              (control)

Then, from another shell:  procstat -f -C <pid>

The fixture prints the cap_rights_t words it set (via cap_rights_get(3)
before cap_enter), and a second program reads the same descriptors
through libprocstat (procstat_getfiles(), fs_cap_rights).

----------------------------------------------------------------------
Observed (14.5-RELEASE GENERIC, releng/14.5-n274872-4099b5c82880)

Word 0 of cap_rights_t (word 1 is 0400000000000000 for every fd, in
both sources):

fd  cap_rights_get(3)  libprocstat       procstat -f -C
10  0200000000000000   0200000000000000  -
11  0200000000000004   0200000000000004  -
12  0200000000000001   0200000000000001  rd,re
13  0200000000000005   0200000000000005  rd,re
14  020000000008000d   020000000008000d  rd,se,fs,prd,re
15  020000000008000f   020000000008000f  rd,wr,se,fs,prd,pwr,re,sd

The kernel and libprocstat agree word for word, including the version
and index bits.  procstat shows fds 10/11 as "-" and fds 12/13 as
"rd,re" even though the sets differ.  The controls (14, 15) display as
expected, because CAP_SEEK has its own entry ("se").

The libxo output (procstat --libxo json -f -C) has the same loss: the
capability list is [] for fds 10 and 11 and ["rd","re"] for fds 12
and 13.

Expected: fd 11 and fd 13 should be distinguishable from fd 10 and fd 12.

Reproduced on two 14.5-RELEASE amd64 systems (one physical,
one clean VM running GENERIC with only base modules loaded), with
identical hashes of procstat_files.c, newvers.sh and the procstat binary.
By source inspection, cap_desc[] also lacks CAP_SEEK_TELL in main,
stable/15 and stable/14, and print_capability() has no residual check
there either; I have only run the reproduction on 14.5-RELEASE.

----------------------------------------------------------------------
Analysis / prior art

- Bug 263165 / D34874, commit 869199d9922c ("libsysdecode: Fix decoding
  of Capsicum rights", 2022) fixed the same class of problem in
  libsysdecode: rights not covered by the name table are now reported
  as unknown rights instead of being silently dropped.  procstat has
  its own table and did not get an equivalent check.
- cap_desc[] in procstat is kept in sync by hand: CAP_FCHROOT was added
  to it in b165e9e3ea4e (present in main and stable/15, not in
  stable/14), which shows the table depends on
  manual updates when new rights appear.

----------------------------------------------------------------------
Possible fixes

R0 (minimal): add a CAP_SEEK_TELL entry to cap_desc[] in
    procstat_files.c, e.g. { CAP_SEEK_TELL, "st" } ("st" is not used
    in cap_desc[] on releng/14.5, main, stable/15 or stable/14; the final
    abbreviation is the maintainers' choice), and document it in
    procstat(1).  Because CAP_SEEK includes CAP_SEEK_TELL and
    print_capability() prints every contained entry, descriptors with
    CAP_SEEK would also start showing "st"; this is a visible change in
    existing output and should be covered by tests.  With "st" placed
    just before "se", the fixture would show:
      fd 11: st
      fd 13: rd,st,re
      fd 14: rd,st,se,fs,prd,re
    and the same distinction should appear in the libxo output.

R1 (robust): following the approach of D34874, in
    print_capability() copy the set, clear the rights of every entry
    that is contained in the original set, and if anything is left,
    print a marker for unrepresented rights.  Containment should be
    tested against the original set, not the copy, because entries
    overlap (e.g. CAP_SEEK contains CAP_SEEK_TELL).  Using the Capsicum
    API rather than raw bit operations keeps the index and version bits
    correct.  width_capability() must be changed the same way so the
    column width stays consistent.  A right missing from the table would
    then be reported as unrepresented instead of being silently dropped
    (R1 does not by itself make two different residuals distinguishable).

R2 (structured output): with libxo output (procstat --libxo), also
    emit the raw rights words as hex strings (to avoid precision loss in
    JSON consumers that use IEEE 754 numbers), so tools do not depend
    on the abbreviation table.  This probably needs its own discussion.

R0 fixes the current gap; R1 makes any future gap visible when new
rights are added.  None of the fixes has been tested yet.  The fixture,
the libprocstat reader and their output are attached.  I can prepare
R0 and R1 as separate patches if that direction is acceptable.

-- 
You are receiving this mail because:
You are the assignee for the bug.

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID: <bug-301480-227@https.bugs.freebsd.org/bugzilla/>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.szaf.org!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mo.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.szaf.org!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: bugzilla-noreply@freebsd.org
Newsgroups: muc.lists.freebsd.bugs
Subject: [Bug 301480] procstat(1): cap_desc[] lacks CAP_SEEK_TELL, so
 distinct capability rights sets are displayed identically
Date: Fri, 04 Dec 2026 03:15:22 +0000
Organization: Newsgate at muc.de e.V.
Approved: news-admin@muc.de
Distribution: world
Message-ID: <bug-301480-227@https.bugs.freebsd.org/bugzilla/>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
	logging-data="98119"; mail-complaints-to="news-admin@muc.de"
X-Original-To: bugs@mlmmj.nyi.freebsd.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1796354123;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding;
	bh=/HIYu10T51ZQg0Y7QXsjolx65kgKXCT5X5pRvfp+g54=;
	b=ulY0yXnMAYwMS9HopaLtKg8kbjp9UIrEVSeEhHQrkulKnr4ywFXs5rANoJd42FS021WSLD
	KdJRvkciTDG5V5RrEaw8Ouw/LyP8cOKoHXkMUGufW5mchLGQ4iakZs1Q9dNiE5y6wsszPL
	ssgQPTNkVJyjxFTx7a88lA1quzPCHm6LPGYEp/XyF1SBO+T/zlySc/K2GGULKnwOn3xEYK
	sZAEqGfi2ZENo3dr25H6U2zn89DCeWpoh2Pmly3tjifYVZBdpJK56phe2J4r4/u1T/hEHq
	6C2vtnEKpreNBT5egSlb0C/M+Pxz5cobt5FoAuxXoOt34LDisVrDbSGT7yH7+w==
X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f
Auto-Submitted: auto-generated
Precedence: list
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes