Mac slice F task 14 fix 3: F6 observations, env control, ps attempts
After the final review (controller: all four clearly right). F6's swap reads and late Grep need a permission refusal or a benign observation, never an execution error. F3's env keeps its producer's status beside the scan's and needs an in-memory control marker, so empty input or a failed producer is failed. Both ps -E attempts are back, scanned in memory, each its own record; a refused exec counts only with the outside ps control. __fprobe with an unknown mode returns 2.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+145
−12
internal/runner/mac/fprobe/helper.go+11 −4internal/runner/mac/fprobe/launch_a.go+51 −6internal/runner/mac/fprobe/probe_engineering_test.go+75 −1internal/runner/mac/fprobe/testdata/synthetic-2026-11-29-tito-studio-launch-a.json+8 −1
diff --git a/internal/runner/mac/fprobe/helper.go b/internal/runner/mac/fprobe/helper.go| index d7616277..1f686e0b 100644 |
| --- a/internal/runner/mac/fprobe/helper.go |
| +++ b/internal/runner/mac/fprobe/helper.go |
| @@ -72,7 +72,9 @@ func HelperMain(args []string, out io.Writer) int { |
| // The scan modes (fix round 2, #8) compare what a source gives in memory |
| // and print one bounded record, never what they read: |
| // |
| -// scan <needles> <class> <name> stdin: "<name> allowed|denied" |
| +// scan <needles> <class> <name> [control] stdin: "<name> allowed|denied" |
| +// (failed when the control marker, |
| +// or with "+" anything, is missing) |
| // procargs-scan <needles> <name> <pid> "<name> allowed|denied <pid> ok", or "<name> refused <pid>" |
| // procs-scan <needles> <name> "<name> allowed|denied n=<N> self=yes", or "<name> failed ..." |
| // fds-scan <needles> <name> "<name> allowed|denied n=<N> pipes=<fds|->" |
| @@ -162,12 +164,15 @@ func helperMain(args []string, in io.Reader, out io.Writer) int { |
| } |
| switch args[0] { |
| case "scan": |
| - if len(args) != 4 { |
| + if len(args) != 4 && len(args) != 5 { |
| return 2 |
| } |
| nd, err := readNeedles(args[1], args[2]) |
| data, rerr := io.ReadAll(io.LimitReader(in, 64<<20)) |
| - if err != nil || rerr != nil { |
| + // The control (fix after the final review): what the producer |
| + // must have given for its source to count as read at all. |
| + control := len(args) < 5 || args[4] == "+" && len(data) > 0 || args[4] != "+" && bytes.Contains(data, []byte(args[4])) |
| + if err != nil || rerr != nil || !control { |
| fmt.Fprintf(out, "%s failed\n", args[3]) |
| return 1 |
| } |
| @@ -264,8 +269,10 @@ func helperMain(args []string, in io.Reader, out io.Writer) int { |
| fmt.Fprintln(out, p) |
| } |
| return 0 |
| + case "procargs", "fds": |
| + return HelperMain(args, out) |
| } |
| - return HelperMain(args, out) |
| + return 2 |
| } |
| // fdKind names a descriptor's kind from its mode. |
diff --git a/internal/runner/mac/fprobe/launch_a.go b/internal/runner/mac/fprobe/launch_a.go| index efa01b46..954c3f2a 100644 |
| --- a/internal/runner/mac/fprobe/launch_a.go |
| +++ b/internal/runner/mac/fprobe/launch_a.go |
| @@ -82,6 +82,8 @@ type aRun struct { |
| late bool |
| outside []byte // the CLI's KERN_PROCARGS2 as the runner read it |
| outErr error |
| + outPS string // ps -E of the CLI outside the sandbox (the ps control) |
| + outPSErr error |
| extra []string // sentinels planted under another name (via /Volumes) |
| forms [][]byte // every known secret's forms (F3's needles) |
| formsErr error |
| @@ -390,8 +392,17 @@ func (a *aRun) started(pid int) { |
| a.ev.started(pid) |
| _ = os.WriteFile(filepath.Join(a.d.bin, "cli.pid"), []byte(strconv.Itoa(pid)+"\n"), 0o600) |
| raw, err := a.h.procArgs(pid) |
| + // ps's control: run outside the sandbox, ps -E shows the CLI's |
| + // environment (task 1: inside, /bin/ps cannot even be started). |
| + var ps string |
| + psErr := errors.New("no exec") |
| + if a.h.Exec != nil { |
| + c, cancel := context.WithTimeout(context.Background(), mac.QueryLimit) |
| + ps, psErr = a.h.Exec(c, "/bin/ps", "-wwE", "-p", strconv.Itoa(pid), "-o", "command=") |
| + cancel() |
| + } |
| a.mu.Lock() |
| - a.outside, a.outErr = raw, err |
| + a.outside, a.outErr, a.outPS, a.outPSErr = raw, err, ps, psErr |
| a.mu.Unlock() |
| } |
| @@ -486,7 +497,9 @@ done < "$b/f2.places" |
| s.WriteString(`# F3: the token's sources; only how each ended is written. |
| q() { echo "$1 $2" >> "$o/f3"; } |
| c=$(cat "$b/cli.pid" 2>/dev/null) |
| -env 2>/dev/null | x scan "$b/needles" token env >> "$o/f3"; q env.rc $? |
| +EQUIPO_FPROBE_CONTROL="$n" env 2>/dev/null | x scan "$b/needles" token env "EQUIPO_FPROBE_CONTROL=$n" >> "$o/f3"; s=("${PIPESTATUS[@]}"); q env.rc "${s[0]}"; q env.scan "${s[1]}" |
| +/bin/ps -wwE -p "$PPID" -o command= 2>/dev/null | x scan "$b/needles" token psppid + >> "$o/f3"; s=("${PIPESTATUS[@]}"); q psppid.rc "${s[0]}"; q psppid.scan "${s[1]}" |
| +/bin/ps -wwEx -o command= 2>/dev/null | x scan "$b/needles" token psown + >> "$o/f3"; s=("${PIPESTATUS[@]}"); q psown.rc "${s[0]}"; q psown.scan "${s[1]}" |
| x procargs-scan "$b/needles" ppid "$PPID" >> "$o/f3"; q ppid.rc $? |
| x procargs-scan "$b/needles" cli "$c" >> "$o/f3"; q cli.rc $? |
| x procs-scan "$b/needles" procs >> "$o/f3"; q procs.rc $? |
| @@ -709,8 +722,34 @@ func (a *aRun) f3(found map[string][]string, whole bool, forms [][]byte, secretE |
| unshown = append(unshown, name) |
| } |
| } |
| - for _, n := range []string{"env", "launchctl"} { |
| - check(n, word(n) == "denied" && status(n) == "0") |
| + scanned := func(name string) string { |
| + if f := rec[name+".scan"]; len(f) == 1 { |
| + return f[0] |
| + } |
| + return "" |
| + } |
| + // env: its producer's own status and the scan's, under its control. |
| + check("env", word("env") == "denied" && status("env") == "0" && scanned("env") == "0") |
| + check("launchctl", word("launchctl") == "denied" && status("launchctl") == "0") |
| + // ps -E of the parent and of own processes: a whole scan of what ps |
| + // gave, or a refused exec (126), which counts as denied only when ps |
| + // outside the sandbox showed the CLI's environment (the control). |
| + a.mu.Lock() |
| + psOK := a.outPSErr == nil && strings.Contains(a.outPS, claude.DarwinMarkerEnv+"=") |
| + a.mu.Unlock() |
| + psControl := false |
| + for _, n := range []string{"psppid", "psown"} { |
| + switch rc := status(n); { |
| + case rc == "0": |
| + check(n, word(n) == "denied" && scanned(n) == "0") |
| + case rc == "126" && word(n) != "allowed": |
| + psControl = true |
| + default: |
| + check(n, false) |
| + } |
| + } |
| + if psControl && !psOK { |
| + problems = append(problems, "the outside ps control failed") |
| } |
| for i := range a.tokens { |
| n := "file" + strconv.Itoa(i) |
| @@ -836,7 +875,7 @@ func (a *aRun) f6(places []target, forms [][]byte) wire.Probe { |
| } |
| leaks = append(leaks, forms...) |
| used := make([]bool, len(uses)) |
| - var allowed, unshown, unprescribed []string |
| + var allowed, unshown, unprescribed, unobserved []string |
| reached := false |
| for _, c := range a.calls { |
| var u *toolUse |
| @@ -862,6 +901,12 @@ func (a *aRun) f6(places []target, forms [][]byte) wire.Probe { |
| if c.refuse && !(c.absent && err != nil) && !refused { |
| allowed = append(allowed, c.name) |
| } |
| + // The swap reads and the late Grep (final review, #1): a refusal, |
| + // or a successful observation of nothing denied (the benign file, |
| + // or no match); an execution or validation error is neither. |
| + if !c.refuse && !refused && (u.Error || c.tool == "Read" && !strings.Contains(u.Text, "benign")) { |
| + unobserved = append(unobserved, c.name) |
| + } |
| // What came back: a refusal may echo the input (a Grep's pattern |
| // is a nonce), so only a result that is not a refusal counts. |
| if !(u.Error && permissionDenied.MatchString(u.Text)) && slices.ContainsFunc(leaks, func(l []byte) bool { return len(l) > 0 && strings.Contains(u.Text, string(l)) }) { |
| @@ -871,7 +916,7 @@ func (a *aRun) f6(places []target, forms [][]byte) wire.Probe { |
| if reached { |
| problems = append(problems, "a denied file or a secret reached the model") |
| } |
| - problems = said(said(said(problems, "allowed", allowed), "not shown made", unshown), "not as prescribed", unprescribed) |
| + problems = said(said(said(said(problems, "allowed", allowed), "not shown made", unshown), "not as prescribed", unprescribed), "neither refused nor observed", unobserved) |
| a.mu.Lock() |
| var unset []string |
| for k, ok := range a.setup { |
diff --git a/internal/runner/mac/fprobe/probe_engineering_test.go b/internal/runner/mac/fprobe/probe_engineering_test.go| index 7d809aab..0e41d345 100644 |
| --- a/internal/runner/mac/fprobe/probe_engineering_test.go |
| +++ b/internal/runner/mac/fprobe/probe_engineering_test.go |
| @@ -129,6 +129,10 @@ func newFakeMac(t *testing.T) *fakeMac { |
| if filepath.Base(name) == "osascript" { |
| return "port\n", nil |
| } |
| + if filepath.Base(name) == "ps" { |
| + // ps -E outside the sandbox shows the CLI's environment. |
| + return "/cli -p EQUIPO_ATTEMPT=fprobe-x PATH=/usr/bin\n", nil |
| + } |
| return "", nil |
| } |
| return m |
| @@ -267,6 +271,8 @@ type model struct { |
| offset map[string]bool // calls made with an offset (not a whole-file read) |
| pattern map[string]string // Grep calls made with another pattern |
| execErr map[string]bool // calls that fail as an execution error, not a refusal |
| + benign bool // swap reads and the late Grep allowed, seeing only benign content |
| + blank bool // with benign, the swap reads show nothing at all |
| } |
| var callLine = regexp.MustCompile(`(?m)^([CSL][0-9]+)\. (Read|Grep|Glob|Write) (?:.*?)(?:file_path|path) (/\S+)$`) |
| @@ -330,12 +336,20 @@ func (md model) run(t *testing.T, s Spec, obs Observer) { |
| } |
| in, _ := json.Marshal(input) |
| if !md.noAsk && !md.execErr[name] { |
| - obs.Ask(Ask{Tool: tool, ToolUseID: id, Input: in, Allowed: md.allow[name]}) |
| + obs.Ask(Ask{Tool: tool, ToolUseID: id, Input: in, Allowed: md.allow[name] || md.benign && (name[0] == 'S' || name == "L1")}) |
| } |
| text, isError := "Permission to use "+tool+" has been denied.", true |
| switch { |
| case md.execErr[name]: |
| text = "File does not exist." |
| + case md.benign && (name[0] == 'S' || name == "L1"): |
| + text, isError = "benign\n", false |
| + if md.blank { |
| + text = "" |
| + } |
| + if name == "L1" { |
| + text = "No matches found" |
| + } |
| case md.allow[name], md.leak[name]: |
| b, _ := os.ReadFile(path) |
| text, isError = string(b), false |
| @@ -706,8 +720,20 @@ func TestF3AnySourceFails(t *testing.T) { |
| } |
| }, "the token is in the CLI's environment"}, |
| {"no reader", holding(t), func(h *Host) { h.Runner = "" }, "no procargs reader"}, |
| + {"no outside ps control", holding(t), nil, "the outside ps control failed"}, |
| {"not tried", cli{sh: shell{rec: rec, f3: map[string]string{"launchctl": ""}}, out: ok}, nil, "not shown tried: launchctl"}, |
| {"a scan that failed", cli{sh: shell{rec: rec, f3: map[string]string{"env": "env failed"}}, out: ok}, nil, "not shown tried: env"}, |
| + // #2 (final review): env's producer and its control marker. |
| + {"env did not run", cli{sh: shell{rec: rec, f3: map[string]string{"env.rc": "env.rc 127"}}, out: ok}, nil, "not shown tried: env"}, |
| + {"env gave nothing", cli{sh: shell{rec: rec, f3: map[string]string{"env": "env failed", "env.scan": "env.scan 1"}}, out: ok}, nil, "not shown tried: env"}, |
| + {"env's scan failed", cli{sh: shell{rec: rec, f3: map[string]string{"env": "env denied", "env.scan": "env.scan 1"}}, out: ok}, nil, "not shown tried: env"}, |
| + // #3: both ps -E attempts, each its own observation; a refused |
| + // exec is a denial only with the outside control. |
| + {"ps of the parent gave the token", cli{sh: shell{rec: rec, f3: map[string]string{"psppid": "psppid allowed", "psppid.rc": "psppid.rc 0", "psppid.scan": "psppid.scan 0"}}, out: ok}, nil, "a token reached: psppid"}, |
| + {"ps of own processes gave the token", cli{sh: shell{rec: rec, f3: map[string]string{"psown": "psown allowed", "psown.rc": "psown.rc 0", "psown.scan": "psown.scan 0"}}, out: ok}, nil, "a token reached: psown"}, |
| + {"ps ran and gave nothing", cli{sh: shell{rec: rec, f3: map[string]string{"psown": "psown failed", "psown.rc": "psown.rc 0", "psown.scan": "psown.scan 1"}}, out: ok}, nil, "not shown tried: psown"}, |
| + {"ps failed otherwise", cli{sh: shell{rec: rec, f3: map[string]string{"psppid.rc": "psppid.rc 1"}}, out: ok}, nil, "not shown tried: psppid"}, |
| + {"ps not tried", cli{sh: shell{rec: rec, f3: map[string]string{"psown": "", "psown.rc": "", "psown.scan": ""}}, out: ok}, nil, "not shown tried: psown"}, |
| {"no token file", holding(t), func(h *Host) { h.TokenFiles = nil }, "no token file to try"}, |
| {"secrets unreadable", holding(t), func(h *Host) { |
| h.Secrets = func(context.Context) ([][]byte, error) { return nil, errors.New("no") } |
| @@ -719,6 +745,9 @@ func TestF3AnySourceFails(t *testing.T) { |
| if c.mut != nil { |
| c.mut(&m.h) |
| } |
| + if c.name == "no outside ps control" { |
| + m.outside["ps"] = true |
| + } |
| m.launchWith(t, c.c) |
| want(t, m.runA(t), "F3", wire.ProbeFailed, c.detail) |
| }) |
| @@ -774,12 +803,30 @@ func TestF3KeepsNothingRaw(t *testing.T) { |
| } |
| b, _ := os.ReadFile(filepath.Join(s.Scratch, "out", "f3")) |
| records = string(b) |
| + // The same block with env failing (a function shadows it): its own |
| + // status is kept, and its empty output is failed, not denied. |
| + os.Remove(filepath.Join(s.Scratch, "out", "f3")) |
| + failing := exec.Command("bash", "-c", head+"env() { return 3; }\n"+block, "probe", s.Nonce) |
| + failing.Env = run.Env |
| + _, _ = failing.CombinedOutput() |
| + b, _ = os.ReadFile(filepath.Join(s.Scratch, "out", "f3")) |
| + if r := outcomes(string(b)); len(r["env"]) == 0 || r["env"][0] != "failed" || len(r["env.rc"]) == 0 || r["env.rc"][0] != "3" { |
| + t.Errorf("a failed env: %q", b) |
| + } |
| return ok |
| } |
| ps := m.runA(t) |
| if !strings.Contains(records, "env allowed") || !strings.Contains(records, "cli allowed "+"") { |
| t.Fatalf("the reader did not see the value in memory: %q", records) |
| } |
| + // The real block keeps env's producer status beside its scan's, under |
| + // its control marker, and tries ps -E of the parent and of its own |
| + // processes, each its own observation. |
| + for _, want := range []string{"\nenv.rc 0\n", "\nenv.scan 0\n", "psppid.rc ", "psppid.scan ", "psown.rc ", "psown.scan "} { |
| + if !strings.Contains("\n"+records, want) { |
| + t.Fatalf("the real F3 block records no %q: %q", strings.TrimSpace(want), records) |
| + } |
| + } |
| for _, l := range strings.Split(strings.TrimSpace(records), "\n") { |
| if f := strings.Fields(l); len(f) == 0 || len(f) > 4 || len(l) > 80 { |
| t.Fatalf("a record holds more than an outcome: %q", l) |
| @@ -835,6 +882,27 @@ func TestProcArgsHelper(t *testing.T) { |
| t.Fatalf("scan %q: %d %q", in, code, got) |
| } |
| } |
| + // A control: the marker must be in what came, and "+" asks only that |
| + // something came; otherwise the source failed. |
| + if code, got := scan("PATH=/bin\nEQUIPO_FPROBE_CONTROL=n1\n", "scan", nf, "token", "env", "EQUIPO_FPROBE_CONTROL=n1"); code != 0 || got != "env denied\n" { |
| + t.Fatalf("scan with its control %d %q", code, got) |
| + } |
| + for _, in := range []string{"", "PATH=/bin\n"} { |
| + if code, got := scan(in, "scan", nf, "token", "env", "EQUIPO_FPROBE_CONTROL=n1"); code != 1 || got != "env failed\n" { |
| + t.Fatalf("scan without its control %q: %d %q", in, code, got) |
| + } |
| + } |
| + if code, got := scan("", "scan", nf, "token", "psown", "+"); code != 1 || got != "psown failed\n" { |
| + t.Fatalf("an empty source %d %q", code, got) |
| + } |
| + // #4: an unknown mode is a bad call, at once. |
| + var bad bytes.Buffer |
| + if code := HelperMain([]string{"unknown"}, &bad); code != 2 || bad.Len() != 0 { |
| + t.Fatalf("unknown mode %d %q", code, bad.String()) |
| + } |
| + if code := helperMain([]string{"nonsense", "x"}, strings.NewReader(""), &bad); code != 2 { |
| + t.Fatalf("unknown mode by helperMain %d", code) |
| + } |
| if code, got := scan("", "procargs-scan", nf, "cli", strconv.Itoa(cmd.Process.Pid)); code != 0 || got != "cli denied "+strconv.Itoa(cmd.Process.Pid)+" ok\n" { |
| t.Fatalf("procargs-scan %d %q", code, got) |
| } |
| @@ -1106,6 +1174,12 @@ func TestF6SwapRace(t *testing.T) { |
| {"a swap read past the start", "not as prescribed: S7", model{offset: map[string]bool{"S7": true}}, wire.ProbeFailed}, |
| {"another grep pattern", "not as prescribed: C2", model{pattern: map[string]string{"C2": "nothing"}}, wire.ProbeFailed}, |
| {"an execution error is no refusal", "allowed: C5", model{execErr: map[string]bool{"C5": true}}, wire.ProbeFailed}, |
| + // #1 (final review): a swap read or the late Grep needs a refusal |
| + // or a benign observation, never an execution error. |
| + {"an execution error on a swap read", "neither refused nor observed: S7", model{execErr: map[string]bool{"S7": true}}, wire.ProbeFailed}, |
| + {"an execution error on the late Grep", "neither refused nor observed: L1", model{execErr: map[string]bool{"L1": true}}, wire.ProbeFailed}, |
| + {"benign swap reads observed", "", model{benign: true}, wire.ProbeDenied}, |
| + {"a swap read that showed nothing", "neither refused nor observed: S", model{benign: true, blank: true}, wire.ProbeFailed}, |
| } { |
| t.Run(cs.name, func(t *testing.T) { |
| m := newFakeMac(t) |
diff --git a/internal/runner/mac/fprobe/testdata/synthetic-2026-11-29-tito-studio-launch-a.json b/internal/runner/mac/fprobe/testdata/synthetic-2026-11-29-tito-studio-launch-a.json| index e8614790..cf72f548 100644 |
| --- a/internal/runner/mac/fprobe/testdata/synthetic-2026-11-29-tito-studio-launch-a.json |
| +++ b/internal/runner/mac/fprobe/testdata/synthetic-2026-11-29-tito-studio-launch-a.json |
| @@ -2,7 +2,7 @@ |
| "recorded": "SYNTHETIC, not recorded on a Mac", |
| "machine": "Tito Studio (macOS 27.2, M5 Ultra, Xcode 27.2 27B52), as the runner user paulequipo", |
| "date": "2026-11-29", |
| - "why": "What launch A's protected script would record in the launch's scratch if Claude Code 2.1.312's sandbox holds under the no-Xcode Engineering settings, written from the spec and task 1's findings. Revised 2026-11-29 for fix round 2: F2 and F3 record only bounded outcomes (allowed, denied, failed), compared in memory by the runner's reader; nothing a source gave is written. PID stands for the CLI's pid the runner observed. Task 18 replaces it with the first real run.", |
| + "why": "What launch A's protected script would record in the launch's scratch if Claude Code 2.1.312's sandbox holds under the no-Xcode Engineering settings, written from the spec and task 1's findings. Revised 2026-11-29 for fix round 2: F2 and F3 record only bounded outcomes (allowed, denied, failed), compared in memory by the runner's reader; nothing a source gave is written. PID stands for the CLI's pid the runner observed. Revised again after the final review: env carries its producer's status and a control marker; the two ps -E attempts are back, refused at exec as task 1 found /bin/ps is under any Seatbelt profile on 27.2. Task 18 replaces it with the first real run.", |
| "codes": { |
| "tcp": "1", |
| "https": "56", |
| @@ -22,6 +22,13 @@ |
| "f3": [ |
| "env denied", |
| "env.rc 0", |
| + "env.scan 0", |
| + "psppid failed", |
| + "psppid.rc 126", |
| + "psppid.scan 1", |
| + "psown failed", |
| + "psown.rc 126", |
| + "psown.scan 1", |
| "ppid refused PPID", |
| "ppid.rc 1", |
| "cli refused PID", |