Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions include/trace/events/landlock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright © 2025 Microsoft Corporation
*/

#undef TRACE_SYSTEM
#define TRACE_SYSTEM landlock

#if !defined(_TRACE_LANDLOCK_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_LANDLOCK_H

#include <linux/tracepoint.h>

struct landlock_domain_index;

TRACE_EVENT(
landlock_domain_hash_find,
TP_PROTO(
const struct landlock_domain_index* indices_arr,
u32 num_indices,
int hash_bits,
const struct landlock_domain_index* elem_to_find,
u32 collisions_followed
),

TP_ARGS(indices_arr, num_indices, hash_bits, elem_to_find, collisions_followed),
TP_STRUCT__entry(
__field(const struct landlock_domain_index *, indices_arr)
__field(u32, num_indices)
__field(u32, hash_bits)
__field(uintptr_t, key)
__field(u32, collisions_followed)
),

TP_fast_assign(
__entry->indices_arr = indices_arr;
__entry->num_indices = num_indices;
__entry->hash_bits = hash_bits;
__entry->key = *(uintptr_t *)elem_to_find;
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsafe type cast in tracepoint. Line 39 casts elem_to_find (a const struct landlock_domain_index*) directly to uintptr_t* and dereferences it. This assumes that the first field of landlock_domain_index is the key, but this is fragile. If the struct layout changes, this will silently break. Use elem_to_find->key.data instead for type-safe access to the key field.

Suggested change
__entry->key = *(uintptr_t *)elem_to_find;
__entry->key = elem_to_find->key.data;

Copilot uses AI. Check for mistakes.
__entry->collisions_followed = collisions_followed;
),

TP_printk(
"indices_arr=%p num_indices=%u hash_bits=%u, key=%lx collisions_followed=%u",
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Inconsistent spacing in tracepoint format string. The TP_printk format string has inconsistent spacing around the comma after hash_bits=%u. There's a comma followed by a space before key=%lx, but all other fields are separated by spaces only. Consider using consistent spacing: either hash_bits=%u key=%lx or hash_bits=%u, key=%lx, collisions_followed=%u for all fields.

Suggested change
"indices_arr=%p num_indices=%u hash_bits=%u, key=%lx collisions_followed=%u",
"indices_arr=%p num_indices=%u hash_bits=%u key=%lx collisions_followed=%u",

Copilot uses AI. Check for mistakes.
__entry->indices_arr,
__entry->num_indices,
__entry->hash_bits,
__entry->key,
__entry->collisions_followed
)
);

#endif /* _TRACE_LANDLOCK_H */

/* This part must be outside protection */
#include <trace/define_trace.h>
5 changes: 2 additions & 3 deletions security/landlock/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
obj-$(CONFIG_SECURITY_LANDLOCK) := landlock.o

landlock-y := setup.o syscalls.o object.o ruleset.o \
cred.o task.o fs.o
cred.o task.o fs.o domain.o trace.o

landlock-$(CONFIG_INET) += net.o

landlock-$(CONFIG_AUDIT) += \
id.o \
audit.o \
domain.o
audit.o
8 changes: 4 additions & 4 deletions security/landlock/audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static void log_domain(struct landlock_hierarchy *const hierarchy)
}

static struct landlock_hierarchy *
get_hierarchy(const struct landlock_ruleset *const domain, const size_t layer)
get_hierarchy(const struct landlock_domain *const domain, const size_t layer)
{
struct landlock_hierarchy *hierarchy = domain->hierarchy;
ssize_t i;
Expand Down Expand Up @@ -167,7 +167,7 @@ static void test_get_hierarchy(struct kunit *const test)
.parent = &dom1_hierarchy,
.id = 30,
};
struct landlock_ruleset dom2 = {
struct landlock_domain dom2 = {
.hierarchy = &dom2_hierarchy,
.num_layers = 3,
};
Expand All @@ -180,7 +180,7 @@ static void test_get_hierarchy(struct kunit *const test)

#endif /* CONFIG_SECURITY_LANDLOCK_KUNIT_TEST */

static size_t get_denied_layer(const struct landlock_ruleset *const domain,
static size_t get_denied_layer(const struct landlock_domain *const domain,
access_mask_t *const access_request,
const layer_mask_t (*const layer_masks)[],
const size_t layer_masks_size)
Expand Down Expand Up @@ -218,7 +218,7 @@ static size_t get_denied_layer(const struct landlock_ruleset *const domain,

static void test_get_denied_layer(struct kunit *const test)
{
const struct landlock_ruleset dom = {
const struct landlock_domain dom = {
.num_layers = 5,
};
const layer_mask_t layer_masks[LANDLOCK_NUM_ACCESS_FS] = {
Expand Down
Loading