Contents · Forum Home · StreamSec Tools 4.1.5.363 documentation

stFileJail.Posix

POSIX half of the stFileJail verification backend. The Windows half is
  stFileJail.Windows; both declare the same descendant contract and stFileJail
  selects one in its implementation uses clause.

  THE WHOLE UNIT IS WRAPPED IN A POSIX CONDITIONAL so it compiles to a legal
  empty unit elsewhere and can sit unconditionally in every StrSecIV package
  contains clause - the arrangement StreamSec.Mobile.AsyncTLSListener.Posix
  already uses.

  HOW THE CHECK WORKS, AND WHY IT IS NOT THE WINDOWS CHECK. Containment here is
  STRUCTURAL, not textual. The validated relative path is walked one segment at
  a time with openat(dirfd,segment,O_NOFOLLOW), starting from the pinned root
  descriptor. No name is ever re-resolved, nothing is concatenated and handed
  back to the kernel, and no symbolic link is ever traversed - so there is no
  containment STRING COMPARISON in this backend at all, and nothing for a fold,
  a case rule or a prefix test to get wrong. '..' cannot appear by the core's
  contract and is rejected here anyway.

  THE DELIBERATE DIVERGENCE FROM THE WINDOWS BACKEND. Windows follows reparse
  points and then asks the kernel what it actually opened, so a junction that
  stays inside the root is permitted there. Here ANY symbolic link on the path
  is jvLinkEscape - including one whose target is inside the root.

  That is a DEFAULT, not a platform limitation, and the distinction matters
  because an earlier draft of this comment claimed the latter. Containment for
  a link target IS provable here: resolve the segment without O_NOFOLLOW, then
  run the same upward (st_dev,st_ino) walk BeneathRoot already performs. What
  is missing is the leaf case, where the target's parent is not one of the
  descriptors the walk is holding - and on Linux 5.6+ openat2 with
  RESOLVE_IN_ROOT does the whole job in the kernel. Refusing is the safe
  default and is what ships; an opt-in follow mode is a known, deliberate gap
  rather than an impossibility.

  The ROOT itself is still resolved WITH links followed, exactly once, at mint
  time - which is what makes a symlinked document root (/tmp and /var on macOS,
  and most admin-convenience docroots) work rather than refuse everything.

  WHAT THIS BACKEND CAN DO THAT WINDOWS CANNOT. It hands back the final
  segment's PARENT DIRECTORY DESCRIPTOR. unlinkat / renameat / fdopendir take a
  directory descriptor plus a leaf name, so a later mutation never re-resolves a
  path and the residual delete-by-name race the Windows backend has to admit to
  does not exist here.

  WHY THE FINAL OPEN CARRIES O_NONBLOCK. A FIFO planted in a document root
  would otherwise block the opening thread inside open() until somebody writes
  to it - a reactor thread lost for good, from a file the peer merely asked for.
  The flag makes that open return instead, the fstat that follows refuses
  anything that is not a regular file or a directory, and O_NONBLOCK is cleared
  again once the object has proved to be a regular file, so the stream handed to
  the caller behaves normally.

Feature notes: File jail (filesystem confinement) notes

Classes, interfaces and records

classtPosixJailVerifier

inherits from tJailVerifier

function OpenRoot(const aRoot: string; out aHandle: tJailHandle; out aVerdict: tJailVerdict): Boolean; override; function OpenAt(const aRoot: tJailHandle; const aRelative: string; aAccess: tJailAccessSet; aOptions: tJailOptions; aCaseMode: tCaseMode; aShareMode: tJailShareMode; out aHandle: tJailHandle; out aVerdict: tJailVerdict): Boolean; override; function NewStream(var aHandle: tJailHandle; aAccess: tJailAccessSet; out aStream: TStream; out aVerdict: tJailVerdict): Boolean; override; procedure Close(var aHandle: tJailHandle); override;