diff mbox series

[2/3] mm/pagemap: Fix wr-protect even if PM_SCAN_WP_MATCHING not set

Message ID 20231116201547.536857-3-peterx@redhat.com (mailing list archive)
State New
Headers show
Series mm/pagemap: A few fixes to the recent PAGEMAP_SCAN | expand

Commit Message

Peter Xu Nov. 16, 2023, 8:15 p.m. UTC
The new pagemap ioctl contains a fast path for wr-protections without
looking into category masks.  It forgets to check PM_SCAN_WP_MATCHING
before applying the wr-protections.  It can cause, e.g., pte markers
installed on archs that do not even support uffd wr-protect.

WARNING: CPU: 0 PID: 5059 at mm/memory.c:1520 zap_pte_range mm/memory.c:1520 [inline]

Fixes: 12f6b01a0bcb ("fs/proc/task_mmu: add fast paths to get/clear PAGE_IS_WRITTEN flag")
Reported-by: syzbot+7ca4b2719dc742b8d0a4@syzkaller.appspotmail.com
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 fs/proc/task_mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

David Hildenbrand Nov. 16, 2023, 11:10 p.m. UTC | #1
On 16.11.23 21:15, Peter Xu wrote:
> The new pagemap ioctl contains a fast path for wr-protections without
> looking into category masks.  It forgets to check PM_SCAN_WP_MATCHING
> before applying the wr-protections.  It can cause, e.g., pte markers
> installed on archs that do not even support uffd wr-protect.
> 
> WARNING: CPU: 0 PID: 5059 at mm/memory.c:1520 zap_pte_range mm/memory.c:1520 [inline]
> 
> Fixes: 12f6b01a0bcb ("fs/proc/task_mmu: add fast paths to get/clear PAGE_IS_WRITTEN flag")
> Reported-by: syzbot+7ca4b2719dc742b8d0a4@syzkaller.appspotmail.com
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>   fs/proc/task_mmu.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index e91085d79926..d19924bf0a39 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -2171,7 +2171,7 @@ static int pagemap_scan_pmd_entry(pmd_t *pmd, unsigned long start,
>   		return 0;
>   	}
>   
> -	if (!p->vec_out) {
> +	if ((p->arg.flags & PM_SCAN_WP_MATCHING) && !p->vec_out) {
>   		/* Fast path for performing exclusive WP */
>   		for (addr = start; addr != end; pte++, addr += PAGE_SIZE) {
>   			if (pte_uffd_wp(ptep_get(pte)))

Reviewed-by: David Hildenbrand <david@redhat.com>
Andrei Vagin Nov. 17, 2023, 3:27 p.m. UTC | #2
On Thu, Nov 16, 2023 at 12:15 PM Peter Xu <peterx@redhat.com> wrote:
>
> The new pagemap ioctl contains a fast path for wr-protections without
> looking into category masks.  It forgets to check PM_SCAN_WP_MATCHING
> before applying the wr-protections.  It can cause, e.g., pte markers
> installed on archs that do not even support uffd wr-protect.
>
> WARNING: CPU: 0 PID: 5059 at mm/memory.c:1520 zap_pte_range mm/memory.c:1520 [inline]
>
> Fixes: 12f6b01a0bcb ("fs/proc/task_mmu: add fast paths to get/clear PAGE_IS_WRITTEN flag")
> Reported-by: syzbot+7ca4b2719dc742b8d0a4@syzkaller.appspotmail.com
> Signed-off-by: Peter Xu <peterx@redhat.com>

Reviewed-by: Andrei Vagin <avagin@gmail.com>

> ---
>  fs/proc/task_mmu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index e91085d79926..d19924bf0a39 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -2171,7 +2171,7 @@ static int pagemap_scan_pmd_entry(pmd_t *pmd, unsigned long start,
>                 return 0;
>         }
>
> -       if (!p->vec_out) {
> +       if ((p->arg.flags & PM_SCAN_WP_MATCHING) && !p->vec_out) {
>                 /* Fast path for performing exclusive WP */
>                 for (addr = start; addr != end; pte++, addr += PAGE_SIZE) {
>                         if (pte_uffd_wp(ptep_get(pte)))
> --
> 2.41.0
>
diff mbox series

Patch

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index e91085d79926..d19924bf0a39 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -2171,7 +2171,7 @@  static int pagemap_scan_pmd_entry(pmd_t *pmd, unsigned long start,
 		return 0;
 	}
 
-	if (!p->vec_out) {
+	if ((p->arg.flags & PM_SCAN_WP_MATCHING) && !p->vec_out) {
 		/* Fast path for performing exclusive WP */
 		for (addr = start; addr != end; pte++, addr += PAGE_SIZE) {
 			if (pte_uffd_wp(ptep_get(pte)))