interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / src / osh / host / osh_caps.h

76 lines · 3880 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * osh_caps.h -- capability enforcement for the Linux host adapter (aien-architecture#158, ABI section 9).
19 *
20 * Authority: omega's own host capability root (src/runtime/rx_caproot.{h,c}), no new authority. The root runs in a
21 * separate process and is the only writer of the capability table; the osh process holds a read-only view. This file
22 * is HOST code: it parses a launch policy, asks the root to mint, and answers the effect hook. The shell core (.osc)
23 * never sees it, and no shell syntax, variable, environment entry, command name or argv[0] reaches it.
24 *
25 * Policy file (parsed here, by the host only):
26 * principal <u32> once, before any grant
27 * allow spawn|read|write|chdir <absolute path prefix>
28 * '#' starts a comment. One minted capability per grant: subject = principal, resource = the grant's number (1..N,
29 * assigned here, never a hash), rights EFFECT (spawn) / READ (read, chdir) / WRITE (write). The session itself holds a
30 * principal capability (resource 0, READ); revoking it revokes every effect at once. No policy: every effect is denied.
31 *
32 * WHAT THIS DOES NOT DO. It gates what osh itself does: the spawn of a program it resolved, the opens it performs
33 * for redirections, and cd. A child that was allowed to start runs with the full authority of the Linux user (any file
34 * that user may open, any program, the network). A prefix allowlist is not a sandbox and no containment is claimed:
35 * nothing here uses seccomp, Landlock or namespaces. The check and the syscall are two steps (a path swapped in between
36 * is not prevented). The root is the Linux development root (rx_caproot.h); on AIENOS the kernel authority is the root.
37 */
38#ifndef OSH_CAPS_H
39#define OSH_CAPS_H
40#include <stddef.h>
41
42#include "osh_host.h"
43#include "rx_caproot.h"
44
45#define OSH_CAPS_MAX_GRANTS 200
46
47typedef struct {
48 int op; /* OSH_OP_* */
49 char *prefix; /* canonical absolute prefix */
50 uint64_t resource; /* grant number */
51 RxCapRef ref;
52} OshGrant;
53
54typedef struct OshCaps {
55 RxCapRoot root; /* read-only view: the only thing the effect check touches */
56 RxCapAdmin admin; /* host/embedder only; wiped by osh_caps_seal() */
57 int started, sealed;
58 uint32_t principal;
59 RxCapRef principal_ref;
60 OshGrant grants[OSH_CAPS_MAX_GRANTS];
61 int ngrants;
62} OshCaps;
63
64/* Start the root. 0 ok, else a negative RX_CAP_ERR_*. */
65int osh_caps_start(OshCaps *c);
66/* Parse the policy text and have the root mint one capability per grant. 0 ok; else -1 and a message in err. */
67int osh_caps_load(OshCaps *c, const char *text, char *err, size_t errsz);
68/* Bind the session: effect hook + principal binding (domain 2, full 64-bit generation). */
69void osh_caps_attach(OshCaps *c, OshSession *s);
70/* The hook installed by osh_caps_attach (exposed for tests). */
71int osh_caps_effect(void *ctx, const OshBinding *b, int op, const char *path);
72/* Drop the admin handle: wipe the token, close the control socket. After this nothing in this process can mint or
73 * revoke; the root exits and the table is frozen. The osh program seals before running the first command. */
74void osh_caps_seal(OshCaps *c);
75void osh_caps_stop(OshCaps *c);
76#endif