On Fri, Sep 12, 2025 at 1:31 AM Liam R. Howlett <Liam.Howlett@xxxxxxxxxx> wrote: > > * Yafang Shao <laoar.shao@xxxxxxxxx> [250909 22:46]: > > The vma->vm_mm might be NULL and it can be accessed outside of RCU. Thus, > > we can mark it as trusted_or_null. With this change, BPF helpers can safely > > access vma->vm_mm to retrieve the associated mm_struct from the VMA. > > Then we can make policy decision from the VMA. > > I don't agree with any of that statement. > > How are you getting a vma outside an rcu lock safely? The callers of this BPF hook guarantee that the provided vm_area_struct pointer is safe to read. This means your BPF program can safely access its members, though it cannot write to them. You might question how code in lsm.c can access vma->vm_mm->start_stack without an explicit NULL check. This is because the BPF verifier has a safety feature: if vma->vm_mm is NULL, it will substitute the value 0 instead of actually performing the dereference, preventing a crash. However, while this prevents a kernel panic, it doesn't guarantee correct logic. If your program uses the value 0 for start_stack without knowing it came from a NULL pointer, it might behave incorrectly. Therefore, you must still explicitly check for NULL to ensure your program's logic is sound. The __safe_trusted_or_null marker enforces this requirement. It is a restriction that ensures program correctness, not a loosening of the rules. Alex, Andrii, please correct me if my understanding is wrong. > > vmas are RCU type safe so I don't think you can make the statement of > null or trusted. You can get a vma that has moved to another mm if you > are not careful. > > What am I missing? Surely there is more context to add to this commit > message. According to the definition of struct vm_area_struct, the comment on vm_mm states: "Unstable RCU readers are allowed to read this." This confirms that we can safely read vm_mm without holding the RCU read lock. If this were not the case, the comment would need to be corrected. struct vm_area_struct { /* * The address space we belong to. * Unstable RCU readers are allowed to read this. */ struct mm_struct *vm_mm; }; As a minor, unrelated note: Non-sleepable BPF programs always run within an RCU read-side critical section. Therefore, you do not need to explicitly acquire the RCU read lock in such programs. -- Regards Yafang