1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright © 2025 Microsoft Corporation 4 * Copyright © 2026 Cloudflare, Inc. 5 */ 6 7 #undef TRACE_SYSTEM 8 #define TRACE_SYSTEM landlock 9 10 #if !defined(_TRACE_LANDLOCK_H) || defined(TRACE_HEADER_MULTI_READ) 11 #define _TRACE_LANDLOCK_H 12 13 #include <linux/in.h> 14 #include <linux/in6.h> 15 #include <linux/landlock.h> 16 #include <linux/socket.h> 17 #include <linux/string.h> 18 #include <linux/string_helpers.h> 19 #include <linux/tracepoint.h> 20 #include <linux/trace_seq.h> 21 #include <net/af_unix.h> 22 23 enum landlock_request_type; 24 struct dentry; 25 struct landlock_blockers; 26 struct landlock_domain; 27 struct landlock_hierarchy; 28 struct landlock_rule; 29 struct landlock_ruleset; 30 struct path; 31 struct sock; 32 struct task_struct; 33 34 static_assert(sizeof(access_mask_t) <= sizeof(u64)); 35 36 TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_FS_CHANGE_TOPOLOGY); 37 TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_FS_ACCESS); 38 TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_NET_ACCESS); 39 TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_NAMESPACE); 40 TRACE_DEFINE_ENUM(LANDLOCK_REQUEST_CAPABILITY); 41 42 #ifdef CREATE_TRACE_POINTS 43 44 /* About 6 KiB, leaving about 2 KiB for sibling helpers and fixed fields. */ 45 #define TRACE_UNTRUSTED_STR_OUTPUT_SIZE \ 46 (TRACE_SEQ_BUFFER_SIZE - TRACE_SEQ_BUFFER_SIZE / 4) 47 48 /* 49 * A raw UTF-8 ellipsis (…) marks truncation and cannot collide with escaped 50 * input: ESCAPE_NAP renders every non-ASCII input byte in octal. 51 */ 52 #define TRACE_TRUNCATION_MARKER "\xe2\x80\xa6" 53 54 /* 55 * Escapes @len bytes of an untrusted string into the trace sequence @p so it 56 * cannot inject field separators or control characters into the ftrace text 57 * output, and can be unambiguously recovered. Called from the TP_printk() of 58 * the tracepoints that expose paths and process names. @len is passed by the 59 * caller (rather than derived with strlen()) so a name that is not 60 * NUL-terminated or carries embedded NUL bytes (an abstract socket name) is 61 * escaped in full instead of being truncated at the first NUL. 62 * 63 * Strings that exceed the output limit retain the largest complete escaped 64 * prefix followed by the truncation marker. 65 * 66 * Return: a pointer into @p's buffer, or NULL if @src is NULL or the fixed 67 * output reservation is unavailable. 68 */ 69 static inline const char * 70 __trace_print_untrusted_str(struct trace_seq *p, const char *src, size_t len) 71 { 72 const unsigned int escape_flags = ESCAPE_SPACE | ESCAPE_SPECIAL | 73 ESCAPE_NAP | ESCAPE_APPEND | 74 ESCAPE_OCTAL; 75 const size_t marker_len = sizeof(TRACE_TRUNCATION_MARKER) - 1; 76 size_t buf_size, prefix_len, prefix_size; 77 int escaped_size; 78 char *buf; 79 const char *ret; 80 81 buf_size = seq_buf_get_buf(&p->seq, &buf); 82 if (!src || buf_size < TRACE_UNTRUSTED_STR_OUTPUT_SIZE) 83 return NULL; 84 85 ret = trace_seq_buffer_ptr(p); 86 escaped_size = string_escape_mem(src, len, buf, 87 TRACE_UNTRUSTED_STR_OUTPUT_SIZE, 88 escape_flags, " ='\"\\"); 89 if (likely(escaped_size < TRACE_UNTRUSTED_STR_OUTPUT_SIZE)) { 90 seq_buf_commit(&p->seq, escaped_size); 91 trace_seq_putc(p, 0); 92 return ret; 93 } 94 95 prefix_len = 0; 96 prefix_size = 0; 97 while (prefix_len < len) { 98 const char *const src_char = src + prefix_len; 99 int char_size; 100 101 char_size = string_escape_mem(src_char, 1, NULL, 0, 102 escape_flags, " ='\"\\"); 103 if (char_size > TRACE_UNTRUSTED_STR_OUTPUT_SIZE - marker_len - 104 1 - prefix_size) 105 break; 106 prefix_size += char_size; 107 prefix_len++; 108 } 109 110 escaped_size = string_escape_mem(src, prefix_len, buf, prefix_size, 111 escape_flags, " ='\"\\"); 112 if (WARN_ON_ONCE(escaped_size != prefix_size)) 113 return NULL; 114 memcpy(buf + prefix_size, TRACE_TRUNCATION_MARKER, marker_len); 115 seq_buf_commit(&p->seq, prefix_size + marker_len); 116 trace_seq_putc(p, 0); 117 return ret; 118 } 119 120 /* 121 * Fills the dense per-domain-layer array layers (one access mask per layer, 122 * indexed by level - 1) from rule's sparse layer stack, keeping only the 123 * requested rights (access_request). Layers with no matching rule entry get 124 * a zero mask. Shared by the check_rule_inode and check_rule_net_port events. 125 * 126 * rule->layers is sorted by ascending level, with levels in the domain's 127 * [1, num_layers] range (see landlock_merge_ruleset()), so every entry maps 128 * to a slot. A leftover entry would be a malformed rule; the zero-filled 129 * slots keep the output and the array bounds safe regardless. 130 */ 131 static inline void 132 __trace_landlock_fill_layers(access_mask_t *const layers, 133 const size_t num_layers, 134 const struct landlock_rule *const rule, 135 const access_mask_t access_request) 136 { 137 size_t i = 0; 138 139 for (size_t level = 1; level <= num_layers; level++) { 140 access_mask_t grants = 0; 141 142 if (i < rule->num_layers && level == rule->layers[i].level) { 143 grants = rule->layers[i].access & access_request; 144 i++; 145 } 146 layers[level - 1] = grants; 147 } 148 149 /* A leftover entry means an out-of-range or unsorted rule level. */ 150 WARN_ON_ONCE(i < rule->num_layers); 151 } 152 153 /* 154 * Renders the dense per-domain-layer access array as symbolic flag names for 155 * the grants field: layers wrapped in "{}", flags within a layer joined by 156 * "|", layers separated by ",", an empty layer rendered as nothing. 157 * Open-codes the flag walk because trace_print_flags_seq() NUL-terminates per 158 * call and so cannot be chained into a single field. The shared names table 159 * covers every access right, so masked bits are always named. Returns the 160 * trace_seq position like __print_flags(). 161 */ 162 static inline const char *__trace_landlock_print_layers( 163 struct trace_seq *p, const access_mask_t *const layers, 164 const size_t num_layers, const struct trace_print_flags *const names, 165 const size_t names_size) 166 { 167 const char *const ret = trace_seq_buffer_ptr(p); 168 169 trace_seq_putc(p, '{'); 170 for (size_t i = 0; i < num_layers; i++) { 171 access_mask_t mask = layers[i]; 172 bool first = true; 173 174 if (i) 175 trace_seq_putc(p, ','); 176 for (size_t j = 0; mask && j < names_size; j++) { 177 if ((mask & names[j].mask) != names[j].mask) 178 continue; 179 if (!first) 180 trace_seq_putc(p, '|'); 181 trace_seq_puts(p, names[j].name); 182 mask &= ~names[j].mask; 183 first = false; 184 } 185 } 186 trace_seq_putc(p, '}'); 187 trace_seq_putc(p, 0); 188 return ret; 189 } 190 191 #endif /* CREATE_TRACE_POINTS */ 192 193 /* clang-format off */ 194 195 /* Maps a shared _LANDLOCK_*_NAMES entry to a __print_flags() pair. */ 196 #define _LANDLOCK_NAME_ENTRY(mask, name) { mask, name } 197 198 #define _LANDLOCK_FS_BLOCKER_TYPE_NAMES \ 199 { LANDLOCK_REQUEST_FS_CHANGE_TOPOLOGY, "change_topology" } 200 201 /** 202 * DOC: Landlock trace events 203 * 204 * These guarantees and constraints hold for every Landlock tracepoint. 205 * A new tracepoint must uphold them, and an eBPF consumer can rely on 206 * them. 207 * 208 * Decision context 209 * ~~~~~~~~~~~~~~~~ 210 * 211 * A denial event identifies the domain whose policy denied the request, the 212 * Landlock operation and policy object that were checked, and the blocker or 213 * domain relationship responsible for the denial. When tracing starts with 214 * sandbox construction, ruleset and domain events provide the policy history 215 * needed to interpret these identifiers. The denying domain is the subject 216 * that enforced the policy, not necessarily current. Generic tracepoints can 217 * provide additional operational context. 218 * 219 * Lifecycle consistency 220 * ~~~~~~~~~~~~~~~~~~~~~~ 221 * 222 * Lifecycle emission is balanced: a creation event always has a matching 223 * deallocation event and vice versa. A consumer that observes an object's 224 * complete lifetime can model it from this pair; one that attaches late or 225 * loses exported records must reconcile incomplete state. A creation event 226 * fires while the object is still private to the calling thread 227 * (landlock_create_ruleset fires before the ruleset's file descriptor is 228 * installed, so it cannot race a concurrent :manpage:`close(2)`); if fd 229 * installation later fails and the ruleset is freed, free_ruleset still 230 * fires, keeping the pair balanced. The domain pair (create_domain and 231 * free_domain) is balanced the same way: create_domain fires when the 232 * domain is created (under the ruleset lock, before thread-sync), and 233 * free_domain fires when it is freed. A rare thread-sync failure aborts 234 * the just-created domain, which then emits both events (its creation, then 235 * an immediate free). Denial events fire only for denials that actually 236 * happen. 237 * 238 * Pointer access 239 * ~~~~~~~~~~~~~~ 240 * 241 * All pointer arguments in TP_PROTO are guaranteed non-NULL by the 242 * caller, but pointers reached through them may still be NULL (e.g., 243 * hierarchy->parent at a root domain) and must be checked. eBPF programs 244 * read these pointers via BTF for richer introspection than the 245 * TP_STRUCT__entry fields, which serve TP_printk display only. 246 * 247 * Mutable object pointers are passed while the caller holds the object's 248 * lock, so TP_fast_assign and a BTF reader see the exact object the event 249 * reports, a snapshot no concurrent writer can change: add_rule holds the 250 * modified ruleset's lock, and create_domain holds the ruleset lock across 251 * the emission (before the thread-sync wait) so the inspected ruleset is 252 * the one merged into the domain. Objects immutable at the emission site 253 * (a domain after creation, a hierarchy at its last reference) need no 254 * lock. A few values that no held lock protects are a best-effort 255 * lockless snapshot instead: a task's comm, and the deny_access_net struct 256 * sock (whose network hook holds no socket lock), matching how the sched 257 * and signal trace events sample comm. 258 * 259 * Field encoding 260 * ~~~~~~~~~~~~~~ 261 * 262 * Fields that mirror the Landlock UAPI preserve their widths and endianness 263 * (e.g. network ports are u64 in host endianness, like 264 * landlock_net_port_attr.port). Per-event details, such as where a value 265 * is byte-swapped, live in the field's own kdoc. 266 * 267 * Rule-check fields 268 * ~~~~~~~~~~~~~~~~~ 269 * 270 * The check_rule events fire during an access check, once per matching 271 * rule, before the final allow-or-deny verdict. They share domain (the 272 * enforcing domain being evaluated), access_request (the access mask being 273 * checked), and rule (the matching rule, with per-layer access masks). 274 * 275 * Denial fields 276 * ~~~~~~~~~~~~~ 277 * 278 * Every denial event shares three fields. domain is the ID of the 279 * innermost domain that blocked the access. same_exec tells whether the 280 * current task is the same executable that entered that domain. logged is 281 * the complete audit-submission selection for this denial: the domain's 282 * log_status and per-execution flag, per-object or per-member quiet rules, 283 * and request-specific no-audit options. This excludes global audit state 284 * and audit-side filters. A stateless ftrace filter can select the denials 285 * the domain submits to audit with logged==1, without reconstructing those 286 * inputs. Denial events order their shared fields as domain, same_exec, 287 * and logged. Access and permission denial events follow these with the 288 * blockers verdict input, type-specific fields, and any variable-length field. 289 * 290 * Relational referents 291 * ~~~~~~~~~~~~~~~~~~~~~ 292 * 293 * A scope or ptrace verdict compares two domains, so the other party's 294 * domain is part of the decision context. It is exposed as a scalar 295 * domain ID (0 when that party is unsandboxed): target_domain (signal), 296 * peer_domain (abstract unix socket), tracee_domain (ptrace). With both 297 * IDs in the stream, a consumer that tracked domain creation can relate 298 * the two parties without kernel-internal state. The ID is a scalar 299 * snapshot, not a live domain pointer that could dangle: an optional 300 * relational referent is a scalar (0 sentinel), not a nullable pointer. 301 * Nonzero IDs are unique within one boot. For ptrace, same_exec instead 302 * describes the tracer, even for 303 * PTRACE_TRACEME, and may differ from the current task. 304 * 305 * Blocker fields 306 * ~~~~~~~~~~~~~~ 307 * 308 * Blocker arguments identify the request type and carry its final missing 309 * access subset when applicable. The type determines how to interpret the 310 * access value. 311 */ 312 313 /* 314 * Prints a per-layer access mask array (the dynamic array @array) as symbolic 315 * flag names using the shared @flag_names list (a _LANDLOCK_*_NAMES macro). 316 * Stays outside CREATE_TRACE_POINTS: TP_printk is expanded in the print-output 317 * pass where that macro is undefined. 318 */ 319 #define __print_landlock_layers(array, flag_names...) \ 320 ({ \ 321 static const struct trace_print_flags __layer_names[] = { \ 322 flag_names \ 323 }; \ 324 __trace_landlock_print_layers( \ 325 p, __get_dynamic_array(array), \ 326 __get_dynamic_array_len(array) / \ 327 sizeof(access_mask_t), \ 328 __layer_names, ARRAY_SIZE(__layer_names)); \ 329 }) 330 331 /** 332 * landlock_create_ruleset - New ruleset created 333 * 334 * @ruleset: Newly created ruleset (never NULL); not yet shared via an fd, 335 * so no lock is needed. 336 * 337 * Emitted by sys_landlock_create_ruleset() while the new ruleset is still 338 * private to the calling thread, before its file descriptor is installed, 339 * so it cannot race a concurrent :manpage:`close(2)`. Balanced by a 340 * matching landlock_free_ruleset event. 341 */ 342 TRACE_EVENT(landlock_create_ruleset, 343 344 TP_PROTO(const struct landlock_ruleset *ruleset), 345 346 TP_ARGS(ruleset), 347 348 TP_STRUCT__entry( 349 __field( u64, ruleset_id ) 350 __field( u64, ruleset_version ) 351 __field( access_mask_t, handled_fs ) 352 __field( access_mask_t, handled_net ) 353 __field( access_mask_t, scoped ) 354 __field( access_mask_t, handled_permissions ) 355 ), 356 357 TP_fast_assign( 358 __entry->ruleset_id = ruleset->id; 359 __entry->ruleset_version = ruleset->version; 360 __entry->handled_fs = ruleset->layer.handled.fs; 361 __entry->handled_net = ruleset->layer.handled.net; 362 __entry->scoped = ruleset->layer.handled.scope; 363 __entry->handled_permissions = 364 ruleset->layer.handled.permissions; 365 ), 366 367 TP_printk("ruleset=%llx.%llu handled_fs=%s handled_net=%s scoped=%s handled_permissions=%s", 368 __entry->ruleset_id, __entry->ruleset_version, 369 __print_flags(__entry->handled_fs, "|", _LANDLOCK_ACCESS_FS_NAMES), 370 __print_flags(__entry->handled_net, "|", _LANDLOCK_ACCESS_NET_NAMES), 371 __print_flags(__entry->scoped, "|", _LANDLOCK_SCOPE_NAMES), 372 __print_flags(__entry->handled_permissions, "|", 373 _LANDLOCK_PERMISSION_NAMES)) 374 ); 375 376 /** 377 * landlock_free_ruleset - Ruleset freed 378 * 379 * @ruleset: Ruleset being freed (never NULL); at its last reference, so no 380 * lock is needed. 381 * 382 * Emitted when a ruleset's last reference is dropped (typically when 383 * the creating process closes the ruleset file descriptor). Fires even 384 * when file-descriptor installation failed after creation, keeping the 385 * create/free pair balanced. 386 */ 387 TRACE_EVENT(landlock_free_ruleset, 388 389 TP_PROTO(const struct landlock_ruleset *ruleset), 390 391 TP_ARGS(ruleset), 392 393 TP_STRUCT__entry( 394 __field( u64, ruleset_id ) 395 __field( u64, ruleset_version ) 396 ), 397 398 TP_fast_assign( 399 __entry->ruleset_id = ruleset->id; 400 __entry->ruleset_version = ruleset->version; 401 ), 402 403 TP_printk("ruleset=%llx.%llu", 404 __entry->ruleset_id, __entry->ruleset_version) 405 ); 406 407 /** 408 * landlock_add_rule_path_beneath - Path-beneath rule added to a ruleset 409 * 410 * @ruleset: Source ruleset (never NULL). 411 * @flags: Complete validated landlock_add_rule_flags value supplied by this 412 * successful call, not the rule's accumulated quiet state. 413 * @access_rights: Canonical per-call access mask passed to 414 * landlock_insert_rule() after normalization, not the raw 415 * sys_landlock_add_rule() argument or accumulated rule. 416 * @path: Filesystem path for the rule (never NULL). 417 * @pathname: Resolved absolute path string (never NULL; error placeholder 418 * on resolution failure). 419 * 420 * Emitted by sys_landlock_add_rule() under the modified ruleset's lock, so 421 * the reported ruleset is a stable snapshot that no concurrent writer can 422 * change. 423 */ 424 TRACE_EVENT(landlock_add_rule_path_beneath, 425 426 TP_PROTO(const struct landlock_ruleset *ruleset, u32 flags, 427 u64 access_rights, const struct path *path, 428 const char *pathname), 429 430 TP_ARGS(ruleset, flags, access_rights, path, pathname), 431 432 TP_STRUCT__entry( 433 __field( u64, ruleset_id ) 434 __field( u64, ruleset_version ) 435 __field( access_mask_t, access_rights ) 436 __field( dev_t, dev ) 437 __field( ino_t, ino ) 438 __string( pathname, pathname ) 439 ), 440 441 TP_fast_assign( 442 lockdep_assert_held(&ruleset->lock); 443 __entry->ruleset_id = ruleset->id; 444 __entry->ruleset_version = ruleset->version; 445 __entry->access_rights = access_rights; 446 __entry->dev = path->dentry->d_sb->s_dev; 447 /* 448 * The inode number may not be the user-visible one, 449 * but it will be the same used by audit. 450 */ 451 __entry->ino = d_backing_inode(path->dentry)->i_ino; 452 __assign_str(pathname); 453 ), 454 455 TP_printk("ruleset=%llx.%llu access_rights=%s dev=%u:%u ino=%lu path=%s", 456 __entry->ruleset_id, __entry->ruleset_version, 457 __print_flags(__entry->access_rights, "|", _LANDLOCK_ACCESS_FS_NAMES), 458 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, 459 __trace_print_untrusted_str(p, __get_str(pathname), 460 __get_dynamic_array_len(pathname) - 1)) 461 ); 462 463 /** 464 * landlock_add_rule_net_port - Network-port rule added to a ruleset 465 * 466 * @ruleset: Source ruleset (never NULL). 467 * @flags: Complete validated landlock_add_rule_flags value supplied by this 468 * successful call, not the rule's accumulated quiet state. 469 * @access_rights: Canonical per-call access mask passed to 470 * landlock_insert_rule() after normalization, not the raw 471 * sys_landlock_add_rule() argument or accumulated rule. 472 * @port: Network port in host endianness, forwarded directly from 473 * &landlock_net_port_attr.port. 474 * 475 * Emitted by sys_landlock_add_rule() under the modified ruleset's lock, so 476 * the reported ruleset is a stable snapshot that no concurrent writer can 477 * change. 478 */ 479 TRACE_EVENT(landlock_add_rule_net_port, 480 481 TP_PROTO(const struct landlock_ruleset *ruleset, u32 flags, 482 u64 access_rights, u64 port), 483 484 TP_ARGS(ruleset, flags, access_rights, port), 485 486 TP_STRUCT__entry( 487 __field( u64, ruleset_id ) 488 __field( u64, ruleset_version ) 489 __field( access_mask_t, access_rights ) 490 __field( u64, port ) 491 ), 492 493 TP_fast_assign( 494 lockdep_assert_held(&ruleset->lock); 495 __entry->ruleset_id = ruleset->id; 496 __entry->ruleset_version = ruleset->version; 497 __entry->access_rights = access_rights; 498 __entry->port = port; 499 ), 500 501 TP_printk("ruleset=%llx.%llu access_rights=%s port=%llu", 502 __entry->ruleset_id, __entry->ruleset_version, 503 __print_flags(__entry->access_rights, "|", _LANDLOCK_ACCESS_NET_NAMES), 504 __entry->port) 505 ); 506 507 /** 508 * landlock_add_rule_namespace - Namespace rule added to a ruleset 509 * 510 * @ruleset: Source ruleset (never NULL). 511 * @flags: Complete validated landlock_add_rule_flags value supplied by this 512 * successful call, not the rule's accumulated quiet state. 513 * @permissions: Validated permission mask from the rule attribute. 514 * @allowed_namespace_types: Effective known namespace types allowed by this 515 * call, using CLONE_NEW* values. 516 * @quiet_namespace_types: Effective known namespace types quieted by this 517 * call, using CLONE_NEW* values. 518 * 519 * Emitted by sys_landlock_add_rule() under the modified ruleset's lock, so 520 * the reported ruleset is a stable snapshot that no concurrent writer can 521 * change. 522 */ 523 TRACE_EVENT(landlock_add_rule_namespace, 524 525 TP_PROTO(const struct landlock_ruleset *ruleset, u32 flags, 526 u64 permissions, u64 allowed_namespace_types, 527 u64 quiet_namespace_types), 528 529 TP_ARGS(ruleset, flags, permissions, allowed_namespace_types, 530 quiet_namespace_types), 531 532 TP_STRUCT__entry( 533 __field( u64, ruleset_id ) 534 __field( u64, ruleset_version ) 535 __field( access_mask_t, permissions ) 536 __field( u64, allowed_namespace_types ) 537 __field( u64, quiet_namespace_types ) 538 ), 539 540 TP_fast_assign( 541 lockdep_assert_held(&ruleset->lock); 542 __entry->ruleset_id = ruleset->id; 543 __entry->ruleset_version = ruleset->version; 544 __entry->permissions = permissions; 545 __entry->allowed_namespace_types = allowed_namespace_types; 546 __entry->quiet_namespace_types = quiet_namespace_types; 547 ), 548 549 TP_printk("ruleset=%llx.%llu permissions=%s allowed_namespace_types=0x%llx quiet_namespace_types=0x%llx", 550 __entry->ruleset_id, __entry->ruleset_version, 551 __print_flags(__entry->permissions, "|", 552 _LANDLOCK_PERMISSION_NAMES), 553 __entry->allowed_namespace_types, 554 __entry->quiet_namespace_types) 555 ); 556 557 /** 558 * landlock_add_rule_capability - Capability rule added to a ruleset 559 * 560 * @ruleset: Source ruleset (never NULL). 561 * @flags: Complete validated landlock_add_rule_flags value supplied by this 562 * successful call, not the rule's accumulated quiet state. 563 * @permissions: Validated permission mask from the rule attribute. 564 * @allowed_capabilities: Effective known capabilities allowed by this call. 565 * @quiet_capabilities: Effective known capabilities quieted by this call. 566 * 567 * Emitted by sys_landlock_add_rule() under the modified ruleset's lock, so 568 * the reported ruleset is a stable snapshot that no concurrent writer can 569 * change. 570 */ 571 TRACE_EVENT(landlock_add_rule_capability, 572 573 TP_PROTO(const struct landlock_ruleset *ruleset, u32 flags, 574 u64 permissions, u64 allowed_capabilities, 575 u64 quiet_capabilities), 576 577 TP_ARGS(ruleset, flags, permissions, allowed_capabilities, 578 quiet_capabilities), 579 580 TP_STRUCT__entry( 581 __field( u64, ruleset_id ) 582 __field( u64, ruleset_version ) 583 __field( access_mask_t, permissions ) 584 __field( u64, allowed_capabilities ) 585 __field( u64, quiet_capabilities ) 586 ), 587 588 TP_fast_assign( 589 lockdep_assert_held(&ruleset->lock); 590 __entry->ruleset_id = ruleset->id; 591 __entry->ruleset_version = ruleset->version; 592 __entry->permissions = permissions; 593 __entry->allowed_capabilities = allowed_capabilities; 594 __entry->quiet_capabilities = quiet_capabilities; 595 ), 596 597 TP_printk("ruleset=%llx.%llu permissions=%s allowed_capabilities=0x%llx quiet_capabilities=0x%llx", 598 __entry->ruleset_id, __entry->ruleset_version, 599 __print_flags(__entry->permissions, "|", 600 _LANDLOCK_PERMISSION_NAMES), 601 __entry->allowed_capabilities, __entry->quiet_capabilities) 602 ); 603 604 /** 605 * landlock_create_domain - New domain created 606 * 607 * @domain: Newly created domain (never NULL, immutable after creation). 608 * @domain->hierarchy->id is its unique ID, shared with the 609 * landlock_enforce_domain and landlock_free_domain events; 610 * @domain->hierarchy->details holds the requesting process. 611 * @ruleset: Source ruleset frozen into the domain (never NULL). The 612 * ruleset lock is held across the emission, so a BPF program 613 * reading it via BTF sees the exact merged ruleset; 614 * @ruleset->id / @ruleset->version identify it. 615 * 616 * Emitted by sys_landlock_restrict_self() once, in the requesting 617 * thread's context, right after the merge and before thread-sync. The 618 * flags-only path (ruleset_fd == -1) creates no domain and does not 619 * emit this event. Paired with the per-thread landlock_enforce_domain 620 * (join on @domain->hierarchy->id) and balanced by a matching 621 * landlock_free_domain event. 622 */ 623 TRACE_EVENT(landlock_create_domain, 624 625 TP_PROTO(const struct landlock_domain *domain, 626 const struct landlock_ruleset *ruleset), 627 628 TP_ARGS(domain, ruleset), 629 630 TP_STRUCT__entry( 631 __field( u64, domain_id ) 632 __field( u64, parent_id ) 633 __field( u64, ruleset_id ) 634 __field( u64, ruleset_version ) 635 ), 636 637 TP_fast_assign( 638 lockdep_assert_held(&ruleset->lock); 639 __entry->domain_id = domain->hierarchy->id; 640 __entry->parent_id = domain->hierarchy->parent ? 641 domain->hierarchy->parent->id : 0; 642 __entry->ruleset_id = ruleset->id; 643 __entry->ruleset_version = ruleset->version; 644 ), 645 646 TP_printk("domain=%llx parent=%llx ruleset=%llx.%llu", 647 __entry->domain_id, __entry->parent_id, 648 __entry->ruleset_id, __entry->ruleset_version) 649 ); 650 651 /** 652 * landlock_enforce_domain - Domain enforced on a thread 653 * 654 * @domain: Domain now enforced on the current thread (never NULL, 655 * immutable; read locklessly). Correlate to 656 * landlock_create_domain via @domain->hierarchy->id for the 657 * source ruleset and requesting thread, or read 658 * @domain->hierarchy->details for the requesting process. 659 * @complete: Set on the single event that concludes the operation, after 660 * all its other enforcements; filter on it for one event per 661 * operation. 662 * @process_wide: The enforcement covers every eligible (non-exiting) 663 * thread of the process: set when the caller used 664 * %LANDLOCK_RESTRICT_SELF_TSYNC or the process is 665 * single-threaded. A lone thread whose group still 666 * holds a zombie leader is not counted single-threaded, 667 * so process_wide == 0 never proves the opposite. 668 * @no_new_privs: The enforcing thread's no_new_privs state at 669 * enforcement time: 1 if set (by a prior 670 * :manpage:`prctl(2)` %PR_SET_NO_NEW_PRIVS or by 671 * %LANDLOCK_RESTRICT_SELF_NO_NEW_PRIVS), 0 if the domain 672 * was enforced with %CAP_SYS_ADMIN instead. 673 * 674 * Emitted for each thread sys_landlock_restrict_self() enforces the 675 * domain on, in that thread's own context, right after its 676 * commit_creds(), so it fires only once the thread is irreversibly 677 * enforcing the domain (aborted operations emit none). Not 678 * balanced; every enforcement falls between the domain's 679 * landlock_create_domain and landlock_free_domain events. 680 * 681 * @complete == 1 && @process_wide == 1 means the whole process is 682 * sandboxed by @domain, durably (Landlock domains are monotonic and 683 * inherited on :manpage:`clone(2)`). 684 */ 685 TRACE_EVENT(landlock_enforce_domain, 686 687 TP_PROTO(const struct landlock_domain *domain, bool complete, 688 bool process_wide, bool no_new_privs), 689 690 TP_ARGS(domain, complete, process_wide, no_new_privs), 691 692 TP_STRUCT__entry( 693 __field( u64, domain_id ) 694 __field( bool, complete ) 695 __field( bool, process_wide ) 696 __field( bool, no_new_privs ) 697 ), 698 699 TP_fast_assign( 700 __entry->domain_id = domain->hierarchy->id; 701 __entry->complete = complete; 702 __entry->process_wide = process_wide; 703 __entry->no_new_privs = no_new_privs; 704 ), 705 706 TP_printk("domain=%llx complete=%d process_wide=%d no_new_privs=%d", 707 __entry->domain_id, __entry->complete, __entry->process_wide, 708 __entry->no_new_privs) 709 ); 710 711 /** 712 * landlock_free_domain - Domain freed 713 * 714 * @hierarchy: Hierarchy node being freed (never NULL). 715 * 716 * Emitted when the hierarchy node's last reference is dropped: its 717 * refcount reaches zero after all child domains have released their 718 * parent reference. A committed domain is 719 * freed from a kworker via landlock_put_domain_deferred() (the credential 720 * free path runs in RCU context, where sleeping is forbidden), so the 721 * current task is not the sandboxed task that triggered the free. Balanced 722 * by a matching landlock_create_domain event. 723 */ 724 TRACE_EVENT(landlock_free_domain, 725 726 TP_PROTO(const struct landlock_hierarchy *hierarchy), 727 728 TP_ARGS(hierarchy), 729 730 TP_STRUCT__entry( 731 __field( u64, domain_id ) 732 __field( u64, denials ) 733 ), 734 735 TP_fast_assign( 736 __entry->domain_id = hierarchy->id; 737 __entry->denials = atomic64_read(&hierarchy->num_denials); 738 ), 739 740 TP_printk("domain=%llx denials=%llu", 741 __entry->domain_id, __entry->denials) 742 ); 743 744 /** 745 * landlock_check_rule_inode - Inode rule evaluated during access check 746 * 747 * @domain: Enforcing domain (never NULL). 748 * @rule: Matching rule with per-layer access masks (never NULL). 749 * @access_request: Access mask evaluated against the rule (the domain's 750 * handled mask during rename/link double-checks). 751 * @dentry: Filesystem dentry being checked (never NULL). 752 * 753 * Emitted for each rule that matches during a filesystem access check. 754 * The grants array shows the requested rights the rule grants at each 755 * domain layer. See Documentation/trace/events-landlock.rst for how to 756 * interpret it. 757 */ 758 TRACE_EVENT(landlock_check_rule_inode, 759 760 TP_PROTO(const struct landlock_domain *domain, 761 const struct landlock_rule *rule, 762 u64 access_request, const struct dentry *dentry), 763 764 TP_ARGS(domain, rule, access_request, dentry), 765 766 TP_STRUCT__entry( 767 __field( u64, domain_id ) 768 __field( access_mask_t, access_request ) 769 __field( dev_t, dev ) 770 __field( ino_t, ino ) 771 __dynamic_array(access_mask_t, grants, 772 domain->num_layers) 773 ), 774 775 TP_fast_assign( 776 __entry->domain_id = domain->hierarchy->id; 777 __entry->access_request = access_request; 778 __entry->dev = dentry->d_sb->s_dev; 779 __entry->ino = d_backing_inode(dentry)->i_ino; 780 781 __trace_landlock_fill_layers(__get_dynamic_array(grants), 782 __get_dynamic_array_len(grants) / 783 sizeof(access_mask_t), 784 rule, 785 (access_mask_t)access_request); 786 ), 787 788 TP_printk("domain=%llx access_request=%s dev=%u:%u ino=%lu grants=%s", 789 __entry->domain_id, 790 __print_flags(__entry->access_request, "|", _LANDLOCK_ACCESS_FS_NAMES), 791 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, 792 __print_landlock_layers(grants, _LANDLOCK_ACCESS_FS_NAMES)) 793 ); 794 795 /** 796 * landlock_check_rule_net_port - Network port rule evaluated 797 * 798 * @domain: Enforcing domain (never NULL). 799 * @rule: Matching rule with per-layer access masks (never NULL). 800 * @access_request: Access mask being requested. 801 * @port: Network port being checked (host endianness). 802 * 803 * Emitted for each rule that matches during a network access check. The 804 * grants array shows the requested rights the rule grants at each domain 805 * layer. See Documentation/trace/events-landlock.rst for how to 806 * interpret it. 807 */ 808 TRACE_EVENT(landlock_check_rule_net_port, 809 810 TP_PROTO(const struct landlock_domain *domain, 811 const struct landlock_rule *rule, 812 u64 access_request, u64 port), 813 814 TP_ARGS(domain, rule, access_request, port), 815 816 TP_STRUCT__entry( 817 __field( u64, domain_id ) 818 __field( access_mask_t, access_request ) 819 __field( u64, port ) 820 __dynamic_array(access_mask_t, grants, 821 domain->num_layers) 822 ), 823 824 TP_fast_assign( 825 __entry->domain_id = domain->hierarchy->id; 826 __entry->access_request = access_request; 827 __entry->port = port; 828 829 __trace_landlock_fill_layers(__get_dynamic_array(grants), 830 __get_dynamic_array_len(grants) / 831 sizeof(access_mask_t), 832 rule, 833 (access_mask_t)access_request); 834 ), 835 836 TP_printk("domain=%llx access_request=%s port=%llu grants=%s", 837 __entry->domain_id, 838 __print_flags(__entry->access_request, "|", _LANDLOCK_ACCESS_NET_NAMES), 839 __entry->port, 840 __print_landlock_layers(grants, _LANDLOCK_ACCESS_NET_NAMES)) 841 ); 842 843 /** 844 * landlock_deny_access_fs - Filesystem access denied 845 * 846 * @hierarchy: Denying domain's hierarchy node (never NULL); its id is the 847 * domain field. 848 * @same_exec: Whether the current task entered the denying domain itself. 849 * @logged: The domain's audit-logging decision for this denial. 850 * @blockers: Request type and final missing access subset (never NULL). 851 * @path: Filesystem path that was denied (never NULL). 852 * @pathname: Resolved path string (never NULL; an error placeholder on 853 * resolution failure). 854 * 855 * Emitted when a Landlock domain denies a filesystem access. 856 */ 857 TRACE_EVENT(landlock_deny_access_fs, 858 859 TP_PROTO(const struct landlock_hierarchy *hierarchy, bool same_exec, 860 bool logged, const struct landlock_blockers *blockers, 861 const struct path *path, const char *pathname), 862 863 TP_ARGS(hierarchy, same_exec, logged, blockers, path, pathname), 864 865 TP_STRUCT__entry( 866 __field( u64, domain_id ) 867 __field( bool, same_exec ) 868 __field( bool, logged ) 869 __field( enum landlock_request_type, blockers_type ) 870 __field( access_mask_t, blockers_access ) 871 __field( dev_t, dev ) 872 __field( ino_t, ino ) 873 __string( pathname, pathname ) 874 ), 875 876 TP_fast_assign( 877 const struct inode *inode = d_backing_inode(path->dentry); 878 879 __entry->domain_id = hierarchy->id; 880 __entry->same_exec = same_exec; 881 __entry->logged = logged; 882 __entry->blockers_type = blockers->type; 883 __entry->blockers_access = blockers->access; 884 __entry->dev = path->dentry->d_sb->s_dev; 885 /* 886 * A negative dentry has no backing inode, so mirror the 887 * guard in dump_common_audit_data() and report inode 0. 888 */ 889 __entry->ino = inode ? inode->i_ino : 0; 890 __assign_str(pathname); 891 ), 892 893 TP_printk("domain=%llx same_exec=%d logged=%d blockers=%s dev=%u:%u ino=%lu path=%s", 894 __entry->domain_id, __entry->same_exec, __entry->logged, 895 __entry->blockers_type == LANDLOCK_REQUEST_FS_ACCESS ? 896 __print_flags(__entry->blockers_access, "|", _LANDLOCK_ACCESS_FS_NAMES) : 897 __print_symbolic(__entry->blockers_type, 898 _LANDLOCK_FS_BLOCKER_TYPE_NAMES), 899 MAJOR(__entry->dev), MINOR(__entry->dev), __entry->ino, 900 __trace_print_untrusted_str(p, __get_str(pathname), 901 __get_dynamic_array_len(pathname) - 1)) 902 ); 903 904 static_assert(offsetof(struct sockaddr_in, sin_port) == 905 offsetof(struct sockaddr_in6, sin6_port)); 906 static_assert(sizeof_field(struct sockaddr_in, sin_port) == 907 sizeof_field(struct sockaddr_in6, sin6_port)); 908 909 /** 910 * landlock_deny_access_net - Network access denied 911 * 912 * @hierarchy: Denying domain's hierarchy node (never NULL); its id is the 913 * domain field. 914 * @same_exec: Whether the current task entered the denying domain itself. 915 * @logged: The domain's audit-logging decision for this denial. 916 * @blockers: Request type and final missing access subset (never NULL). 917 * @sk: Socket object (never NULL), read without a socket lock, so its fields 918 * are a best-effort snapshot. 919 * @socket_family: Socket-family snapshot used by the verdict. 920 * @address: Authoritative address checked by the verdict (never NULL). 921 * The producer copies @addrlen bytes from the checked address and 922 * zeroes the remaining storage before emission. The 923 * &sockaddr_in.sin_port or &sockaddr_in6.sin6_port member, when 924 * present, remains in network endianness. 925 * @addrlen: Validated signed length of @address. 926 * 927 * Emitted when a Landlock domain denies a network operation. The blocker 928 * identifies whether the address is a bind or connect/send policy object. 929 * The flattened port field is converted from the checked address to host 930 * endianness, or is -1 when no port was checked. Zero is a valid checked 931 * port. 932 */ 933 TRACE_EVENT(landlock_deny_access_net, 934 935 TP_PROTO(const struct landlock_hierarchy *hierarchy, bool same_exec, 936 bool logged, const struct landlock_blockers *blockers, 937 const struct sock *sk, u16 socket_family, 938 const struct sockaddr_storage *address, int addrlen), 939 940 TP_ARGS(hierarchy, same_exec, logged, blockers, sk, socket_family, 941 address, addrlen), 942 943 TP_STRUCT__entry( 944 __field( u64, domain_id ) 945 __field( bool, same_exec ) 946 __field( bool, logged ) 947 __field( enum landlock_request_type, blockers_type ) 948 __field( access_mask_t, blockers_access ) 949 __field( s64, port ) 950 ), 951 952 TP_fast_assign( 953 const struct sockaddr *const addr = 954 (const struct sockaddr *)address; 955 const bool has_port = 956 addrlen >= (int)offsetofend(struct sockaddr_in, sin_port) && 957 (addr->sa_family == AF_INET || 958 addr->sa_family == AF_INET6 || 959 (addr->sa_family == AF_UNSPEC && 960 socket_family == AF_INET)); 961 962 __entry->domain_id = hierarchy->id; 963 __entry->same_exec = same_exec; 964 __entry->logged = logged; 965 __entry->blockers_type = blockers->type; 966 __entry->blockers_access = blockers->access; 967 __entry->port = 968 has_port ? 969 ntohs(((const struct sockaddr_in *)addr)->sin_port) : 970 -1; 971 ), 972 973 TP_printk("domain=%llx same_exec=%d logged=%d blockers=%s port=%lld", 974 __entry->domain_id, __entry->same_exec, __entry->logged, 975 __entry->blockers_type == LANDLOCK_REQUEST_NET_ACCESS ? 976 __print_flags(__entry->blockers_access, "|", _LANDLOCK_ACCESS_NET_NAMES) : 977 "unknown", 978 __entry->port) 979 ); 980 981 /** 982 * landlock_deny_permission_namespace - Namespace use denied 983 * 984 * @hierarchy: Denying domain's hierarchy node (never NULL); its id is the 985 * domain field. 986 * @same_exec: Whether the current task entered the denying domain itself. 987 * @logged: Whether this denial was selected for audit logging. 988 * @blockers: Request type and final missing permission subset (never NULL). 989 * @namespace_type: CLONE_NEW* namespace type that was denied. 990 * @namespace_id: Namespace ID, or 0 when creation was denied. 991 * 992 * Emitted when a Landlock domain denies namespace use. 993 */ 994 TRACE_EVENT(landlock_deny_permission_namespace, 995 996 TP_PROTO(const struct landlock_hierarchy *hierarchy, bool same_exec, 997 bool logged, const struct landlock_blockers *blockers, 998 u32 namespace_type, u64 namespace_id), 999 1000 TP_ARGS(hierarchy, same_exec, logged, blockers, namespace_type, 1001 namespace_id), 1002 1003 TP_STRUCT__entry( 1004 __field( u64, domain_id ) 1005 __field( bool, same_exec ) 1006 __field( bool, logged ) 1007 __field( enum landlock_request_type, blockers_type ) 1008 __field( access_mask_t, blockers_access ) 1009 __field( u32, namespace_type ) 1010 __field( u64, namespace_id ) 1011 ), 1012 1013 TP_fast_assign( 1014 __entry->domain_id = hierarchy->id; 1015 __entry->same_exec = same_exec; 1016 __entry->logged = logged; 1017 __entry->blockers_type = blockers->type; 1018 __entry->blockers_access = blockers->access; 1019 __entry->namespace_type = namespace_type; 1020 __entry->namespace_id = namespace_id; 1021 ), 1022 1023 TP_printk("domain=%llx same_exec=%d logged=%d blockers=%s namespace_type=0x%x namespace_id=%llu", 1024 __entry->domain_id, __entry->same_exec, __entry->logged, 1025 __entry->blockers_type == LANDLOCK_REQUEST_NAMESPACE ? 1026 __print_flags(__entry->blockers_access, "|", 1027 _LANDLOCK_PERMISSION_BLOCKER_NAMES) : 1028 "unknown", 1029 __entry->namespace_type, __entry->namespace_id) 1030 ); 1031 1032 /** 1033 * landlock_deny_permission_capability - Capability use denied 1034 * 1035 * @hierarchy: Denying domain's hierarchy node (never NULL); its id is the 1036 * domain field. 1037 * @same_exec: Whether the current task entered the denying domain itself. 1038 * @logged: Whether this denial was selected for audit logging. 1039 * @blockers: Request type and final missing permission subset (never NULL). 1040 * @capability: CAP_* number that was denied. 1041 * 1042 * Emitted when a Landlock domain denies capability use, except for checks 1043 * made with CAP_OPT_NOAUDIT, which are denied without emitting this event. 1044 */ 1045 TRACE_EVENT(landlock_deny_permission_capability, 1046 1047 TP_PROTO(const struct landlock_hierarchy *hierarchy, bool same_exec, 1048 bool logged, const struct landlock_blockers *blockers, 1049 int capability), 1050 1051 TP_ARGS(hierarchy, same_exec, logged, blockers, capability), 1052 1053 TP_STRUCT__entry( 1054 __field( u64, domain_id ) 1055 __field( bool, same_exec ) 1056 __field( bool, logged ) 1057 __field( enum landlock_request_type, blockers_type ) 1058 __field( access_mask_t, blockers_access ) 1059 __field( int, capability ) 1060 ), 1061 1062 TP_fast_assign( 1063 __entry->domain_id = hierarchy->id; 1064 __entry->same_exec = same_exec; 1065 __entry->logged = logged; 1066 __entry->blockers_type = blockers->type; 1067 __entry->blockers_access = blockers->access; 1068 __entry->capability = capability; 1069 ), 1070 1071 TP_printk("domain=%llx same_exec=%d logged=%d blockers=%s capability=%d", 1072 __entry->domain_id, __entry->same_exec, __entry->logged, 1073 __entry->blockers_type == LANDLOCK_REQUEST_CAPABILITY ? 1074 __print_flags(__entry->blockers_access, "|", 1075 _LANDLOCK_PERMISSION_BLOCKER_NAMES) : 1076 "unknown", 1077 __entry->capability) 1078 ); 1079 1080 /** 1081 * landlock_deny_ptrace - Ptrace access denied by a Landlock domain 1082 * 1083 * @hierarchy: Denying domain's hierarchy node (never NULL); its id is the 1084 * domain field. 1085 * @same_exec: Whether the tracer entered the denying domain itself. 1086 * @logged: The domain's audit-logging decision for this denial. 1087 * @tracee_domain_id: The tracee's Landlock domain ID, or 0 if the tracee 1088 * is unsandboxed. 1089 * @tracee: The target task ptrace acted on (never NULL). tracee_pid is 1090 * the init-namespace TGID (like audit's opid). 1091 * @tracer: The tracer or proposed tracer (never NULL); for PTRACE_TRACEME 1092 * this is the parent, not the syscall caller. 1093 * 1094 * Emitted when a Landlock domain denies a ptrace operation. 1095 */ 1096 TRACE_EVENT(landlock_deny_ptrace, 1097 1098 TP_PROTO(const struct landlock_hierarchy *hierarchy, bool same_exec, 1099 bool logged, u64 tracee_domain_id, 1100 const struct task_struct *tracee, 1101 const struct task_struct *tracer), 1102 1103 TP_ARGS(hierarchy, same_exec, logged, tracee_domain_id, tracee, tracer), 1104 1105 TP_STRUCT__entry( 1106 __field( u64, domain_id ) 1107 __field( bool, same_exec ) 1108 __field( bool, logged ) 1109 __field( u64, tracee_domain_id) 1110 __field( pid_t, tracee_pid ) 1111 __string( tracee_comm, tracee->comm ) 1112 ), 1113 1114 TP_fast_assign( 1115 __entry->domain_id = hierarchy->id; 1116 __entry->same_exec = same_exec; 1117 __entry->logged = logged; 1118 __entry->tracee_domain_id = tracee_domain_id; 1119 __entry->tracee_pid = task_tgid_nr((struct task_struct *)tracee); 1120 __assign_str(tracee_comm); 1121 ), 1122 1123 TP_printk("domain=%llx same_exec=%d logged=%d tracee_domain=%llx tracee_pid=%d tracee_comm=%s", 1124 __entry->domain_id, __entry->same_exec, __entry->logged, 1125 __entry->tracee_domain_id, __entry->tracee_pid, 1126 __trace_print_untrusted_str(p, __get_str(tracee_comm), 1127 __get_dynamic_array_len(tracee_comm) - 1)) 1128 ); 1129 1130 /** 1131 * landlock_deny_scope_signal - Signal delivery denied by 1132 * LANDLOCK_SCOPE_SIGNAL 1133 * 1134 * @hierarchy: Denying domain's hierarchy node (never NULL); its id is the 1135 * domain field. 1136 * @same_exec: Whether the policy subject entered the denying domain itself. 1137 * @logged: The domain's audit-logging decision for this denial. 1138 * @target_domain_id: The target's Landlock domain ID, or 0 if the target 1139 * is unsandboxed. 1140 * @target: The task the signal was aimed at (never NULL). target_pid is 1141 * the init-namespace TGID (like audit's opid). 1142 * @signal: The signal selected by the denied check. Zero is a permission 1143 * probe, not an absent value. 1144 * 1145 * Emitted when a Landlock domain denies signal delivery to a scoped-out 1146 * target. 1147 */ 1148 TRACE_EVENT(landlock_deny_scope_signal, 1149 1150 TP_PROTO(const struct landlock_hierarchy *hierarchy, bool same_exec, 1151 bool logged, u64 target_domain_id, 1152 const struct task_struct *target, int signal), 1153 1154 TP_ARGS(hierarchy, same_exec, logged, target_domain_id, target, signal), 1155 1156 TP_STRUCT__entry( 1157 __field( u64, domain_id ) 1158 __field( bool, same_exec ) 1159 __field( bool, logged ) 1160 __field( u64, target_domain_id) 1161 __field( pid_t, target_pid ) 1162 __string( target_comm, target->comm ) 1163 ), 1164 1165 TP_fast_assign( 1166 __entry->domain_id = hierarchy->id; 1167 __entry->same_exec = same_exec; 1168 __entry->logged = logged; 1169 __entry->target_domain_id = target_domain_id; 1170 __entry->target_pid = task_tgid_nr((struct task_struct *)target); 1171 __assign_str(target_comm); 1172 ), 1173 1174 TP_printk("domain=%llx same_exec=%d logged=%d target_domain=%llx target_pid=%d target_comm=%s", 1175 __entry->domain_id, __entry->same_exec, __entry->logged, 1176 __entry->target_domain_id, __entry->target_pid, 1177 __trace_print_untrusted_str(p, __get_str(target_comm), 1178 __get_dynamic_array_len(target_comm) - 1)) 1179 ); 1180 1181 /** 1182 * landlock_deny_scope_abstract_unix_socket - Abstract unix socket access 1183 * denied by LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET 1184 * 1185 * @hierarchy: Denying domain's hierarchy node (never NULL); its id is the 1186 * domain field. 1187 * @same_exec: Whether the current task entered the denying domain itself. 1188 * @logged: The domain's audit-logging decision for this denial. 1189 * @peer_domain_id: The peer's Landlock domain ID, or 0 if the peer is 1190 * unsandboxed. 1191 * @peer: Peer socket (never NULL). peer_pid is best-effort: it is 0 for 1192 * a datagram peer (no SO_PEERCRED), so sun_path is the reliable 1193 * peer identifier. 1194 * 1195 * Emitted when a Landlock domain denies access to a scoped-out abstract 1196 * unix socket. 1197 */ 1198 TRACE_EVENT(landlock_deny_scope_abstract_unix_socket, 1199 1200 TP_PROTO(const struct landlock_hierarchy *hierarchy, bool same_exec, 1201 bool logged, u64 peer_domain_id, const struct sock *peer), 1202 1203 TP_ARGS(hierarchy, same_exec, logged, peer_domain_id, peer), 1204 1205 TP_STRUCT__entry( 1206 __field( u64, domain_id ) 1207 __field( bool, same_exec ) 1208 __field( bool, logged ) 1209 __field( u64, peer_domain_id ) 1210 __field( pid_t, peer_pid ) 1211 /* 1212 * Abstract socket names are untrusted binary data from 1213 * user space. Use __string_len because abstract names 1214 * are not NUL-terminated; their length is determined by 1215 * addr->len. unix_sk(peer)->addr is stable here because 1216 * the caller (hook_unix_stream_connect or 1217 * hook_unix_may_send) holds unix_state_lock(peer). 1218 */ 1219 __string_len( sun_path, 1220 unix_sk(peer)->addr ? 1221 unix_sk(peer)->addr->name->sun_path + 1 : 1222 "", 1223 unix_sk(peer)->addr ? 1224 unix_sk(peer)->addr->len - 1225 offsetof(struct sockaddr_un, 1226 sun_path) - 1 : 1227 0) 1228 ), 1229 1230 TP_fast_assign( 1231 struct pid *peer_pid; 1232 1233 lockdep_assert_held(&unix_sk(peer)->lock); 1234 __entry->domain_id = hierarchy->id; 1235 __entry->same_exec = same_exec; 1236 __entry->logged = logged; 1237 __entry->peer_domain_id = peer_domain_id; 1238 /* 1239 * Best-effort (0 for a datagram peer). The caller holds the 1240 * peer's AF_UNIX state lock, serializing published peercred 1241 * updates. The peer socket keeps a reference to sk_peer_pid 1242 * through pid_nr(); sun_path is the reliable identifier. 1243 */ 1244 peer_pid = READ_ONCE(peer->sk_peer_pid[PIDTYPE_TGID]); 1245 __entry->peer_pid = peer_pid ? pid_nr(peer_pid) : 0; 1246 __assign_str(sun_path); 1247 ), 1248 1249 TP_printk("domain=%llx same_exec=%d logged=%d peer_domain=%llx peer_pid=%d sun_path=%s", 1250 __entry->domain_id, __entry->same_exec, __entry->logged, 1251 __entry->peer_domain_id, __entry->peer_pid, 1252 __trace_print_untrusted_str(p, __get_str(sun_path), 1253 __get_dynamic_array_len(sun_path) - 1)) 1254 ); 1255 1256 #undef _LANDLOCK_FS_BLOCKER_TYPE_NAMES 1257 #undef _LANDLOCK_NAME_ENTRY 1258 1259 #endif /* _TRACE_LANDLOCK_H */ 1260 1261 /* This part must be outside protection */ 1262 #include <trace/define_trace.h> 1263 1264 /* clang-format on */ 1265