Skip to content

Commit 7a9f475

Browse files
author
Alexei Starovoitov
committed
Merge branch 'bpf-mm-related-minor-changes'
Yafang Shao says: ==================== These two minor patches were developed during the implementation of BPF-THP: https://lwn.net/Articles/1042138/ As suggested by Andrii, they are being submitted separately. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
2 parents c67f4ae + 7484e7c commit 7a9f475

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

kernel/bpf/verifier.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7054,6 +7054,9 @@ BTF_TYPE_SAFE_RCU(struct cgroup_subsys_state) {
70547054
/* RCU trusted: these fields are trusted in RCU CS and can be NULL */
70557055
BTF_TYPE_SAFE_RCU_OR_NULL(struct mm_struct) {
70567056
struct file __rcu *exe_file;
7057+
#ifdef CONFIG_MEMCG
7058+
struct task_struct __rcu *owner;
7059+
#endif
70577060
};
70587061

70597062
/* skb->sk, req->sk are not RCU protected, but we mark them as such
@@ -7093,6 +7096,11 @@ BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct socket) {
70937096
struct sock *sk;
70947097
};
70957098

7099+
BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct vm_area_struct) {
7100+
struct mm_struct *vm_mm;
7101+
struct file *vm_file;
7102+
};
7103+
70967104
static bool type_is_rcu(struct bpf_verifier_env *env,
70977105
struct bpf_reg_state *reg,
70987106
const char *field_name, u32 btf_id)
@@ -7134,6 +7142,7 @@ static bool type_is_trusted_or_null(struct bpf_verifier_env *env,
71347142
{
71357143
BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct socket));
71367144
BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct dentry));
7145+
BTF_TYPE_EMIT(BTF_TYPE_SAFE_TRUSTED_OR_NULL(struct vm_area_struct));
71377146

71387147
return btf_nested_type_is_trusted(&env->log, reg, field_name, btf_id,
71397148
"__safe_trusted_or_null");

tools/testing/selftests/bpf/progs/lsm.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,16 @@ SEC("lsm/file_mprotect")
8989
int BPF_PROG(test_int_hook, struct vm_area_struct *vma,
9090
unsigned long reqprot, unsigned long prot, int ret)
9191
{
92-
if (ret != 0)
92+
struct mm_struct *mm = vma->vm_mm;
93+
94+
if (ret != 0 || !mm)
9395
return ret;
9496

9597
__s32 pid = bpf_get_current_pid_tgid() >> 32;
9698
int is_stack = 0;
9799

98-
is_stack = (vma->vm_start <= vma->vm_mm->start_stack &&
99-
vma->vm_end >= vma->vm_mm->start_stack);
100+
is_stack = (vma->vm_start <= mm->start_stack &&
101+
vma->vm_end >= mm->start_stack);
100102

101103
if (is_stack && monitored_pid == pid) {
102104
mprotect_count++;

0 commit comments

Comments
 (0)