Hi, On Wed, Sep 11, 2024 at 02:33:59PM +0000, Fares Mehanna wrote: > In a series posted a few years ago [1], a proposal was put forward to allow the > kernel to allocate memory local to a mm and thus push it out of reach for > current and future speculation-based cross-process attacks. We still believe > this is a nice thing to have. > > However, in the time passed since that post Linux mm has grown quite a few new > goodies, so we'd like to explore possibilities to implement this functionality > with less effort and churn leveraging the now available facilities. > > An RFC was posted few months back [2] to show the proof of concept and a simple > test driver. > > In this RFC, we're using the same approach of implementing mm-local allocations > piggy-backing on memfd_secret(), using regular user addresses but pinning the > pages and flipping the user/supervisor flag on the respective PTEs to make them > directly accessible from kernel. > In addition to that we are submitting 5 patches to use the secret memory to hide > the vCPU gp-regs and fp-regs on arm64 VHE systems. > > The generic drawbacks of using user virtual addresses mentioned in the previous > RFC [2] still hold, in addition to a more specific one: > > - While the user virtual addresses allocated for kernel secret memory are not > directly accessible by userspace as the PTEs restrict that, copy_from_user() > and copy_to_user() can operate on those ranges, so that e.g. the usermode can > guess the address and pass it as the target buffer for read(), making the > kernel overwrite it with the user-controlled content. Effectively making the > secret memory in the current implementation missing confidentiality and > integrity guarantees. Having a VMA in user mappings for kernel memory seems weird to say the least. Core MM does not expect to have VMAs for kernel memory. What will happen if userspace ftruncates that VMA? Or registers it with userfaultfd? > In the specific case of vCPU registers, this is fine because the owner process > can read and write to them using KVM IOCTLs anyway. But in the general case this > represents a security concern and needs to be addressed. > > A possible way forward for the arch-agnostic implementation is to limit the user > virtual addresses used for kernel to specific range that can be checked against > in copy_from_user() and copy_to_user(). > > For arch specific implementation, using separate PGD is the way to go. > > [1] https://lore.kernel.org/lkml/20190612170834.14855-1-mhillenb@xxxxxxxxx/ This approach seems much more reasonable and it's not that it was entirely arch-specific. There is some plumbing at arch level, but the allocator is anyway arch-independent. -- Sincerely yours, Mike.