Development documentation

This is the in-progress lota-next branch. For the released version, see the stable documentation.

Gaming SDK

liblotagaming.so is the client library a game process links to talk to the local agent: it reads the host's attestation status, puts the process under protection, fetches a token the game server verifies with Server SDK, and lists what a protected process mapped. The header is lota_gaming.h (include/lota_gaming.h), the implementation src/sdk/lota_gaming.c, and the pkg-config module lota-gaming:

cc $(pkg-config --cflags lota-gaming) -o game game.c \
   $(pkg-config --libs lota-gaming)

The library speaks the agent's socket protocol (IPC); every call below is one request and its answer.

Connecting

lota_connect() opens a connection with the defaults and lota_connect_opts() with a struct lota_connect_opts:

struct_size

sizeof(struct lota_connect_opts). A value below LOTA_CONNECT_OPTS_SIZE_MIN is refused with LOTA_ERR_INVALID_ARG.

socket_path

The agent socket. NULL tries /run/lota/lota.sock, then $XDG_RUNTIME_DIR/lota/lota.sock, the path a container reaches, and connects to the first that exists and accepts.

timeout_ms

The connect timeout, 5000 ms when 0 or negative. It is also the request timeout until lota_set_request_timeout() changes it.

publisher_profile

The publisher the connection answers for, as the 64-character hex SHA-256 (LOTA_PUBLISHER_PROFILE_LEN) of the SubjectPublicKeyInfo of its attestation-CA anchor. It selects the AIK that signs the tokens and the verdict lota_is_attested() reports. With NULL, a host enrolled with one publisher answers for it, and a host enrolled with several refuses a token with LOTA_ERR_UNKNOWN_PROFILE. When the agent cannot answer for the named publisher, the connection fails. Publisher selection is described in IPC.

A failed connect returns NULL, and lota_connect_last_error() gives the reason. The value is kept per thread and set by every connect attempt.

#include <lota/lota_gaming.h>

struct lota_connect_opts opts = {
        .struct_size = sizeof(opts),
        .publisher_profile = publisher_hex,
};
struct lota_client *c = lota_connect_opts(&opts);

if (!c) {
        fprintf(stderr, "lota: %s\n",
                lota_strerror(lota_connect_last_error()));
        return -1;
}

lota_disconnect() closes the socket and frees the handle. lota_get_fd() returns the socket for a caller's own poll() loop.

Status

lota_get_status() fills struct lota_status:

Member

Content

flags

LOTA_FLAG_* bitmask, below.

last_attest_time

Unix time of the last attestation, 0 if none.

valid_until

Unix time the verdict lapses, 0 if none.

attest_count

Successful attestations.

fail_count

Failed attestations.

lota_is_attested() returns 1 when LOTA_FLAG_ATTESTED is set, and 0 when it is clear or the call failed. lota_flags_to_string() writes the set bits by name without the LOTA_FLAG_ prefix, separated by commas, and leaves out bits it has no name for.

A caller tests the bits it needs and ignores the others (Public API and ABI surface).

Bit

Flag

Set when

0

LOTA_FLAG_ATTESTED

The verifier of the connection's publisher holds a passing verdict on the host; with no publisher named, the host-wide verdict.

1

LOTA_FLAG_TPM_OK

The TPM opened and answered when the agent started.

2

LOTA_FLAG_IOMMU_OK

The agent's IOMMU check passed.

3

LOTA_FLAG_BPF_LOADED

The agent loaded the BPF LSM object.

4

LOTA_FLAG_SECURE_BOOT

efivarfs shows SecureBoot set to 1.

5

(no name)

The agent sees the TPM in dictionary-attack lockout. lota_gaming.h has no name for the bit and lota_flags_to_string() leaves it out.

6

LOTA_FLAG_EVENTS_LOST

The kernel left an event out of the agent's log. Refusals still hold and the token's lists are kept apart from that log. Set until the agent ends; it can arrive a second or more after the loss.

7

LOTA_FLAG_UPDATE_PENDING

A package update replaced the agent binary. The running build stays in PCR 14 and attestation keeps succeeding until the next boot.

8

LOTA_FLAG_TOKEN_ONLY

The publisher runs no verifier, or with none named, no publisher of the host does. LOTA_FLAG_ATTESTED stays clear; the game server checks a token with lota_server_verify_token().

9

LOTA_FLAG_IMAGE_FULLY_MEASURED

Every file-backed executable mapping of every protected process was measured, in a token of every one it carries. Clear when an object could not be measured or nothing is protected.

10

LOTA_FLAG_PROTECTED_TERMINATED

The agent ended a protected process for its owner or root: one of the connection's publisher, or any one when it named none. Set until the agent ends.

11

LOTA_FLAG_KERNEL_APPRAISAL

IMA is in a blocking mode and its policy has an appraise rule on BPRM_CHECK or with no func=.

12

LOTA_FLAG_IMAGE_CONTENT_HASHED

An object of a protected process had no fs-verity digest and was measured by hashing its contents while nothing could write it.

13

LOTA_FLAG_BENCH

The agent runs with --bench. Its policy is unchanged.

14

LOTA_FLAG_ENFORCE

Enforce mode with the LSM loaded.

15

LOTA_FLAG_STRICT_MMAP

A protected process maps no file executable outside the allowlist.

16

LOTA_FLAG_STRICT_EXEC

An exec of a file outside the allowlist is refused.

17

LOTA_FLAG_STRICT_MODULES

A module or firmware load outside the allowlist is refused.

18

LOTA_FLAG_BLOCK_ANON_EXEC

A protected process makes no anonymous mapping executable.

19

LOTA_FLAG_BLOCK_PTRACE

A ptrace attach on any task is refused.

20

LOTA_FLAG_AGENT_RESTARTED

An earlier agent of this boot ended without a shutdown. A token with this bit says nothing of what happened before the restart. Set until the host reboots.

21

LOTA_FLAG_REENROLLING

The publisher's certificate does not name the host's attestation key, as after a TPM clear, and the agent is enrolling again. LOTA_FLAG_ATTESTED stays clear until that completes.

Bits 14 to 19 are all clear in monitor mode. The agent and the protected processes stay guarded with all of them clear. The policy keys behind them are described in Protected processes.

Notifications

lota_subscribe() registers a callback for the LOTA_EVENT_* bits:

LOTA_EVENT_STATUS

The status flags changed.

LOTA_EVENT_ATTEST

An attestation completed, passed or failed.

LOTA_EVENT_MODE

The enforcement mode changed.

LOTA_EVENT_ALL subscribes to all three. The callback runs from lota_poll_events() and from any other call that reads a notification off the socket, on the calling thread. A subscription ends with the connection; after LOTA_ERR_NOT_CONNECTED the caller connects and subscribes again.

Protection

lota_protect_self() asks the agent to protect the calling process. The agent identifies it by the pidfd of the socket peer, so no PID is sent, and needs no trusted executable to do so. The LSM guards the process and its children from then on; the hooks and the policy keys are described in Protected processes.

lota_get_refusal() returns the last object the runtime gate refused to map into the calling process, with the CLOCK_MONOTONIC time of the refusal. The Wine hook uses it to report a failed dlopen().

Tokens

lota_get_token() asks the agent for a token over a 32-byte nonce the game server issued, and fills struct lota_token. The caller sends the result of lota_token_serialize() to the server, sized with lota_token_serialized_size(), and releases the token with lota_token_free():

struct lota_token tok;
uint8_t buf[LOTA_TOKEN_MAX_SIZE];
size_t len;

if (lota_get_token(c, server_nonce, &tok) != LOTA_OK)
        return -1;
if (lota_token_serialize(&tok, buf, sizeof(buf), &len) == LOTA_OK)
        send_to_server(buf, len);
lota_token_free(&tok);

struct lota_token holds the token as the agent sent it: valid_until, the status flags at issue time, the nonce the quote answers, sig_alg, hash_alg, pcr_mask, policy_digest, runtime_protect_digest with runtime_protect_version and stopped_ms. Four arrays are on the heap and belong to the token: protected_pids and protected_registry_digests, each of protect_pid_count entries, attest_data of attest_size bytes and signature of signature_len bytes. lota_token_free() releases them. What each field means on the wire is in Server SDK.

LOTA_TOKEN_MAX_SIZE is in lota_token.h, which lota_gaming.h does not include. The wire format and what the server checks are in Server SDK; how the agent builds a token and how often it issues one are in Tokens.

lota_get_boot_evidence() returns the values of the PCRs a token quotes and the PCR 7 events behind them, for a server with no verifier. It matches the token only while those PCRs hold the same values, so the caller fetches it together with the token.

Registry

lota_get_registry() returns what the last token round found in one protected process the caller owns, of its own instance: the code objects it mapped executable and the processes that reached it. The caller releases the result with lota_registry_free(). round is the measurement round the list comes from, pid the process asked for, and objects and actors hold count and actor_count entries. registry_digest covers the flags, the objects and the actors; round and pid are outside it. With LOTA_REGISTRY_MEASURED set it is the token's protected_registry_digests entry for the PID, and the server recomputes it with lota_server_registry_digest() before it trusts the list. How the agent builds the list is in Protected processes.

struct lota_registry flags:

LOTA_REGISTRY_MEASURED

registry_digest is the token's entry for the process.

LOTA_REGISTRY_HISTORY_LOST

An executable mapping went unrecorded, so an object may be missing.

LOTA_REGISTRY_ACTORS_LOST

An actor went unrecorded, so a process that reached in may be missing.

LOTA_REGISTRY_FROM_EXEC

The image was executed under protection and the list starts at its exec. Without it the list starts when protection did.

LOTA_REGISTRY_TRUNCATED

The process had more executable mappings than one measurement holds; those past the limit are unmeasured.

struct lota_registry_object describes one object: size, dev, ino, the soname (at most LOTA_REGISTRY_SONAME_MAX bytes) and path (LOTA_REGISTRY_PATH_MAX), a digest of digest_len bytes (0, 32 or 64), how it was taken in road:

LOTA_REGISTRY_ROAD_NONE

No digest.

LOTA_REGISTRY_ROAD_VERITY

The fs-verity measurement.

LOTA_REGISTRY_ROAD_CONTENT

The contents hashed while the process ran.

and its flags:

LOTA_REGISTRY_OBJECT_UNMAPPED

Mapped since protection began and gone when measured: no path, no digest, the soname is the file's name.

LOTA_REGISTRY_OBJECT_WRITABLE

When it was mapped executable, something held it open for write or mapped it shared writable, or it was a memfd or shm segment with no write seal.

LOTA_REGISTRY_OBJECT_MEMORY

Backed by memory only (memfd, shm, tmpfs, hugetlbfs).

struct lota_registry_actor describes one process that reached a process of the instance: tgid, uid, comm, its start time in clock ticks (start_ticks), the device and inode of its executable, the process it reached (owner_tgid, owner_comm), how many times (count) and how (kind):

LOTA_REGISTRY_ACTOR_CONNECT

Connected to a stream or seqpacket unix socket of the instance.

LOTA_REGISTRY_ACTOR_SEND

Sent a datagram to one.

LOTA_REGISTRY_ACTOR_PTRACE_READ

A read-mode ptrace access from inside the instance.

LOTA_REGISTRY_ACTOR_PTRACE_ATTACH

ptrace, process_vm_* or /proc/<pid>/mem access from inside the instance.

LOTA_REGISTRY_ACTOR_SIGNAL

A signal from inside the instance.

LOTA_REGISTRY_ACTOR_ANON_EXEC

The process made its own anonymous memory executable; owner_tgid is its own tgid.

Errors

Calls return LOTA_OK (0) or a negative enum lota_error. lota_strerror() describes a code.

Value

Code

Meaning

-1

LOTA_ERR_NOT_CONNECTED

The connection is gone; connect again.

-2

LOTA_ERR_CONNECTION_FAILED

No agent answered, or it hung up.

-3

LOTA_ERR_TIMEOUT

No answer within the timeout.

-4

LOTA_ERR_PROTOCOL

A malformed answer.

-5

LOTA_ERR_NOT_ATTESTED

No valid attestation exists for a token.

-6

LOTA_ERR_INVALID_ARG

A bad argument or option, or a refusal without a code of its own.

-7

LOTA_ERR_BUFFER_TOO_SMALL

The caller's buffer cannot hold the result.

-8

LOTA_ERR_AGENT_ERROR

The agent failed the request.

-9

LOTA_ERR_NO_MEMORY

An allocation failed.

-10

LOTA_ERR_RATE_LIMITED

The caller exceeded a rate limit of the agent.

-11

LOTA_ERR_ACCESS_DENIED

The agent refused the caller for this request.

-12

LOTA_ERR_UNKNOWN_PROFILE

No profile for the named publisher, or none named on a host enrolled with several.

-13

LOTA_ERR_CONSENT_REQUIRED

Nobody on the host agreed to answer to that publisher.

-14

LOTA_ERR_UNMEASURABLE_SELF

The caller's own executable has no measurable identity, so no token is issued; the agent's log names the object.

-15

LOTA_ERR_NO_TPM

The agent holds no TPM.

-16

LOTA_ERR_NO_ENFORCEMENT

The agent applied no policy and loaded no LSM, so a call that changes enforcement is refused.

-17

LOTA_ERR_NO_KEY_SLOT

The agent's attestation-key handle range is full.

-18

LOTA_ERR_TPM_LOCKED

The TPM is in dictionary-attack lockout.

-19

LOTA_ERR_NOT_PROTECTED

The last token round did not measure the process.

-20

LOTA_ERR_TOO_MANY_PROCESSES

The caller's instance holds more protected processes than one token lists.

Functions

struct lota_client *lota_connect(void)

Connect to the local LOTA agent.

Return

a handle to release with lota_disconnect(), NULL on failure (lota_connect_last_error() says why).

struct lota_client *lota_connect_opts(const struct lota_connect_opts *opts)

lota_connect() with custom options.

Parameters

const struct lota_connect_opts *opts

socket path, timeout and publisher; NULL for the defaults.

Return

as for lota_connect().

int lota_connect_last_error(void)

Why the last connect on this thread failed.

Set by every connect attempt on the calling thread, LOTA_OK included. Meaningless after anything else.

Return

LOTA_OK if it connected, LOTA_ERR_INVALID_ARG for bad options or publisher or a refusal not named here, LOTA_ERR_NO_MEMORY, LOTA_ERR_CONNECTION_FAILED for no agent or one that hung up unanswered, LOTA_ERR_TIMEOUT for no answer in time, LOTA_ERR_PROTOCOL for a malformed answer, LOTA_ERR_UNKNOWN_PROFILE for a publisher this machine has no profile for, LOTA_ERR_CONSENT_REQUIRED for one nobody here agreed to answer to, LOTA_ERR_NO_KEY_SLOT for no attestation-key slot left.

void lota_disconnect(struct lota_client *client)

Close the connection and free the handle.

Parameters

struct lota_client *client

may be NULL.

int lota_get_fd(struct lota_client *client)

Get the underlying socket file descriptor.

Parameters

struct lota_client *client

connection from lota_connect().

Return

the descriptor, -1 without a client.

int lota_set_request_timeout(struct lota_client *client, int timeout_ms)

Set the deadline for a request's answer.

Parameters

struct lota_client *client

connection from lota_connect().

int timeout_ms

milliseconds a request may wait for its answer, above 0.

The connect timeout bounds reaching the local socket. An answer can take longer: a status call may first measure a large protected process, and one shared deadline reports a busy agent as a missing one. Does not affect a request already in flight.

Return

LOTA_OK, LOTA_ERR_INVALID_ARG for no client or timeout_ms <= 0.

int lota_ping(struct lota_client *client, uint64_t *uptime_sec)

Check that the agent is responsive.

Parameters

struct lota_client *client

connection from lota_connect().

uint64_t *uptime_sec

receives the agent's uptime; may be NULL.

Return

LOTA_OK, or a negative LOTA_ERR_*.

int lota_protect_self(struct lota_client *client)

Register the calling process as protected.

Parameters

struct lota_client *client

connection from lota_connect().

The agent protects the process that opened the connection, by its pidfd from SO_PEERPIDFD, under its PID in the agent's PID namespace; no PID crosses the socket. No trusted executable is needed: opting in to stricter enforcement is not a privilege escalation. A second call from the same task leaves the runtime PID set alone and, unless rate limited, returns LOTA_OK.

The LSM hooks guard the process and what it creates from then on, from its first instruction. As the event budget and ring buffer allow, task_kill records a signal at it unless it comes from the process itself, the agent, a BPF admin or the kernel, or is a permitted probe. Under strict_mmap a protected task maps only files with an allowed fs-verity digest or a trusted_libs inode.

Return

LOTA_OK, LOTA_ERR_ACCESS_DENIED if the process exited, runs in a PID namespace outside the agent's or a tracer already holds it, LOTA_ERR_RATE_LIMITED if the caller's UID exceeded the rate window, or another negative LOTA_ERR_*.

int lota_get_status(struct lota_client *client, struct lota_status *status)

Get the current attestation status.

Parameters

struct lota_client *client

connection from lota_connect().

struct lota_status *status

receives the status.

Return

LOTA_OK, or a negative LOTA_ERR_*.

int lota_is_attested(struct lota_client *client)

Check LOTA_FLAG_ATTESTED through lota_get_status().

Parameters

struct lota_client *client

connection from lota_connect().

Return

1 if attested, 0 otherwise or on error.

int lota_get_token(struct lota_client *client, const uint8_t *nonce, struct lota_token *token)

Get an attestation token for server verification.

Parameters

struct lota_client *client

connection from lota_connect().

const uint8_t *nonce

32-byte challenge from the server; what stops the server accepting a replayed token. NULL for none.

struct lota_token *token

receives the token; release it with lota_token_free().

Return

LOTA_OK, LOTA_ERR_NOT_ATTESTED if no valid attestation exists, LOTA_ERR_UNKNOWN_PROFILE if the connection named no publisher on a host that answers for several, LOTA_ERR_TOO_MANY_PROCESSES past the token's process limit, or another negative LOTA_ERR_*.

void lota_token_free(struct lota_token *token)

Free the buffers lota_get_token() allocated.

Parameters

struct lota_token *token

may be NULL, zeroed or already freed.

size_t lota_token_serialized_size(const struct lota_token *token)

Calculate the serialized size of a token.

Parameters

const struct lota_token *token

token from lota_get_token().

Return

bytes needed, 0 if the token is invalid.

int lota_token_serialize(const struct lota_token *token, uint8_t *buf, size_t buflen, size_t *written)

Serialize a token to its wire format.

Parameters

const struct lota_token *token

token from lota_get_token().

uint8_t *buf

receives the wire bytes.

size_t buflen

size of buf.

size_t *written

receives the bytes written; may be NULL.

The server verifies the result with lota_server_verify_token().

Return

LOTA_OK, LOTA_ERR_BUFFER_TOO_SMALL if buf is too small, LOTA_ERR_INVALID_ARG for an invalid token.

int lota_get_boot_evidence(struct lota_client *client, uint8_t *buf, size_t buflen, size_t *written)

Fetch the evidence behind a token's boot PCRs.

Parameters

struct lota_client *client

connection from lota_connect().

uint8_t *buf

LOTA_BOOT_EVIDENCE_MAX_SIZE (lota_token.h) holds any.

size_t buflen

size of buf.

size_t *written

receives the bytes written; may be NULL.

The values of the PCRs a token quotes and the PCR 7 events behind them, in the wire format of lota_token.h, for a server that runs no verifier: lota_server_verify_boot_evidence() checks them against the token. Fetch it next to its token: it matches only while the quoted PCRs hold the same values.

Return

LOTA_OK, LOTA_ERR_BUFFER_TOO_SMALL, LOTA_ERR_NO_TPM, LOTA_ERR_RATE_LIMITED (the per-user limit of lota_get_token()), or another negative LOTA_ERR_*.

int lota_get_refusal(struct lota_client *client, char *object, size_t len, uint64_t *at_ns)

The last file the gate refused this process to map.

Parameters

struct lota_client *client

connection from lota_connect().

char *object

receives the file's path as this process sees it, or only its name for a memory file (memfd, shared memory, /dev/zero) or when the gate could not give the path; "" when there was none.

size_t len

size of object; 256 holds any.

uint64_t *at_ns

receives the CLOCK_MONOTONIC time of the refusal, 0 when there was none; may be NULL.

The gate keeps the last refusal of a process that was protected when it refused it, a dependency the loader pulled in as much as the object the process asked for, and the agent answers with the refusal of the process that opened client: one given its PID later has none.

Return

LOTA_OK, LOTA_ERR_BUFFER_TOO_SMALL when object cannot hold the name, or another negative LOTA_ERR_*.

type lota_status_callback_fn

Status change callback.

Parameters

status

current status snapshot.

events

LOTA_EVENT_* that changed.

user_data

pointer given to lota_subscribe().

int lota_subscribe(struct lota_client *client, uint32_t event_mask, lota_status_callback_fn callback, void *user_data)

Subscribe to status change notifications.

Parameters

struct lota_client *client

connection from lota_connect().

uint32_t event_mask

LOTA_EVENT_* bitmask.

lota_status_callback_fn callback

receives each notification.

void *user_data

passed to callback.

callback runs from lota_poll_events() and from other SDK calls that read a notification. event_mask is narrowed to the events the agent publishes to titles, so LOTA_EVENT_ALL subscribes to the three above.

A subscription lasts as long as the connection: resubscribe after LOTA_ERR_NOT_CONNECTED.

Return

LOTA_OK, or a negative LOTA_ERR_*.

int lota_unsubscribe(struct lota_client *client)

Stop notifications on this connection.

Parameters

struct lota_client *client

connection from lota_connect().

Return

LOTA_OK, or a negative LOTA_ERR_*.

int lota_poll_events(struct lota_client *client, int timeout_ms)

Dispatch pending notifications to the callback.

Parameters

struct lota_client *client

connection from lota_connect().

int timeout_ms

maximum wait; 0 does not block, -1 blocks indefinitely.

Return

notifications dispatched, or a negative LOTA_ERR_*.

int lota_get_registry(struct lota_client *client, uint32_t pid, struct lota_registry **out)

Fetch what the last token round found in a process.

Parameters

struct lota_client *client

connection from lota_connect().

uint32_t pid

a protected process the caller owns, of the caller's own instance.

struct lota_registry **out

receives a registry to release with lota_registry_free().

Objects the agent could not measure are listed too. The LOTA_REGISTRY_* flags say what the list may miss. The token binds the list: with LOTA_REGISTRY_MEASURED set, registry_digest is the token's protected_registry_digests entry for pid, and lota_server_registry_digest() over the objects and actors reproduces it. A relying party checks both before trusting the list.

Return

LOTA_OK, LOTA_ERR_NOT_PROTECTED for a process the last round did not measure, LOTA_ERR_ACCESS_DENIED for one of another owner or instance, or another negative LOTA_ERR_*.

void lota_registry_free(struct lota_registry *reg)

Release a registry from lota_get_registry().

Parameters

struct lota_registry *reg

may be NULL.

const char *lota_strerror(int error)

Describe a LOTA_ERR_* code.

Parameters

int error

LOTA_ERR_* code.

Return

a static string.

const char *lota_sdk_version(void)

Name the LOTA release this library was compiled from.

The same one lota_server_sdk_version() reports. Treat it as opaque: match it, do not parse it. Binary compatibility is the soname and the ABI version of the pkg-config module.

Runs inside the calling process, which on a player's machine is memory an attacker controls, so a relying party must never decide trust from it.

Return

a static string.

int lota_flags_to_string(uint32_t flags, char *buf, size_t buflen)

Write flags as "ATTESTED,TPM_OK,BPF_LOADED".

Parameters

uint32_t flags

LOTA_FLAG_* bitmask.

char *buf

receives the string.

size_t buflen

size of buf.

Return

bytes written without the terminator, or a negative LOTA_ERR_*.