Thread (43 messages) 43 messages, 3 authors, 2021-04-26

Re: [PATCH v25 19/30] mm: Update can_follow_write_pte() for shadow stack

From: Kirill A. Shutemov <hidden>
Date: 2021-04-23 10:25:32
Also in: linux-arch, linux-doc, linux-mm, lkml

On Thu, Apr 15, 2021 at 03:14:08PM -0700, Yu-cheng Yu wrote:
quoted hunk ↗ jump to hunk
Can_follow_write_pte() ensures a read-only page is COWed by checking the
FOLL_COW flag, and uses pte_dirty() to validate the flag is still valid.

Like a writable data page, a shadow stack page is writable, and becomes
read-only during copy-on-write, but it is always dirty.  Thus, in the
can_follow_write_pte() check, it belongs to the writable page case and
should be excluded from the read-only page pte_dirty() check.  Apply
the same changes to can_follow_write_pmd().

While at it, also split the long line into smaller ones.

Signed-off-by: Yu-cheng Yu <redacted>
Cc: Kees Cook <redacted>
Cc: Kirill A. Shutemov <redacted>
---
v25:
- Split long line into smaller ones.
v24:
- Change arch_shadow_stack_mapping() to is_shadow_stack_mapping().

 mm/gup.c         | 16 ++++++++++++----
 mm/huge_memory.c | 16 ++++++++++++----
 2 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/mm/gup.c b/mm/gup.c
index ef7d2da9f03f..f2813cf4d07b 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -356,10 +356,18 @@ static int follow_pfn_pte(struct vm_area_struct *vma, unsigned long address,
  * FOLL_FORCE can write to even unwritable pte's, but only
  * after we've gone through a COW cycle and they are dirty.
  */
-static inline bool can_follow_write_pte(pte_t pte, unsigned int flags)
+static inline bool can_follow_write_pte(pte_t pte, unsigned int flags,
+					vm_flags_t vm_flags)
 {
It might be cleaner to pass down vma pointer and dereference it within the
function: can_follow_write_pte(vma, pte, gup_flags).

Otherwise looks good to me:

Reviewed-by: Kirill A. Shutemov <redacted>

-- 
 Kirill A. Shutemov
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help