2023-03-04 19:40:06

by SeongJae Park

[permalink] [raw]
Subject: [PATCH 0/2] mm/damon/paddr: Fix folio-use-after-put bugs

There are two folio accesses after folio_put() in mm/damon/paddr.c file.
Fix those.

SeongJae Park (2):
mm/damon/paddr: fix folio_size() call after folio_put() in
damon_pa_young()
mm/damon/paddr: fix folio_nr_pages() after folio_put() in
damon_pa_mark_accessed_or_deactivate()

mm/damon/paddr.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

--
2.25.1



2023-03-04 19:40:08

by SeongJae Park

[permalink] [raw]
Subject: [PATCH 1/2] mm/damon/paddr: fix folio_size() call after folio_put() in damon_pa_young()

damon_pa_young() is accessing a folio via folio_size() after folio_put()
for the folio has invoked. Fix it.

Fixes: 397b0c3a584b ("mm/damon/paddr: remove folio_sz field from damon_pa_access_chk_result")
Cc: <[email protected]> # 6.3.x
Signed-off-by: SeongJae Park <[email protected]>
---
mm/damon/paddr.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 3fda00a0f786..10f159b315ea 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -130,7 +130,6 @@ static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz)
accessed = false;
else
accessed = true;
- folio_put(folio);
goto out;
}

@@ -144,10 +143,10 @@ static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz)

if (need_lock)
folio_unlock(folio);
- folio_put(folio);

out:
*folio_sz = folio_size(folio);
+ folio_put(folio);
return accessed;
}

--
2.25.1


2023-03-04 19:40:20

by SeongJae Park

[permalink] [raw]
Subject: [PATCH 2/2] mm/damon/paddr: fix folio_nr_pages() after folio_put() in damon_pa_mark_accessed_or_deactivate()

damon_pa_mark_accessed_or_deactivate() is accessing a folio via
folio_nr_pages() after folio_put() for the folio has invoked. Fix it.

Fixes: f70da5ee8fe1 ("mm/damon: convert damon_pa_mark_accessed_or_deactivate() to use folios")
Cc: <[email protected]> # 6.3.x
Signed-off-by: SeongJae Park <[email protected]>
---
mm/damon/paddr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
index 10f159b315ea..0db724aec5cb 100644
--- a/mm/damon/paddr.c
+++ b/mm/damon/paddr.c
@@ -277,8 +277,8 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate(
folio_mark_accessed(folio);
else
folio_deactivate(folio);
- folio_put(folio);
applied += folio_nr_pages(folio);
+ folio_put(folio);
}
return applied * PAGE_SIZE;
}
--
2.25.1


2023-03-05 00:00:54

by Matthew Wilcox

[permalink] [raw]
Subject: Re: [PATCH 1/2] mm/damon/paddr: fix folio_size() call after folio_put() in damon_pa_young()

On Sat, Mar 04, 2023 at 07:39:48PM +0000, SeongJae Park wrote:
> damon_pa_young() is accessing a folio via folio_size() after folio_put()
> for the folio has invoked. Fix it.
>
> Fixes: 397b0c3a584b ("mm/damon/paddr: remove folio_sz field from damon_pa_access_chk_result")
> Cc: <[email protected]> # 6.3.x
> Signed-off-by: SeongJae Park <[email protected]>

Reviewed-by: Matthew Wilcox (Oracle) <[email protected]>

2023-03-05 00:00:56

by Matthew Wilcox

[permalink] [raw]
Subject: Re: [PATCH 2/2] mm/damon/paddr: fix folio_nr_pages() after folio_put() in damon_pa_mark_accessed_or_deactivate()

On Sat, Mar 04, 2023 at 07:39:49PM +0000, SeongJae Park wrote:
> damon_pa_mark_accessed_or_deactivate() is accessing a folio via
> folio_nr_pages() after folio_put() for the folio has invoked. Fix it.
>
> Fixes: f70da5ee8fe1 ("mm/damon: convert damon_pa_mark_accessed_or_deactivate() to use folios")
> Cc: <[email protected]> # 6.3.x
> Signed-off-by: SeongJae Park <[email protected]>

Reviewed-by: Matthew Wilcox (Oracle) <[email protected]>


2023-03-06 02:05:21

by Kefeng Wang

[permalink] [raw]
Subject: Re: [PATCH 0/2] mm/damon/paddr: Fix folio-use-after-put bugs



On 2023/3/5 3:39, SeongJae Park wrote:
> There are two folio accesses after folio_put() in mm/damon/paddr.c file.
> Fix those.

I saw you send the bugfixes separately :)
>
> SeongJae Park (2):
> mm/damon/paddr: fix folio_size() call after folio_put() in
> damon_pa_young()
> mm/damon/paddr: fix folio_nr_pages() after folio_put() in
> damon_pa_mark_accessed_or_deactivate()
>
> mm/damon/paddr.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>

2023-03-06 02:06:03

by Kefeng Wang

[permalink] [raw]
Subject: Re: [PATCH 2/2] mm/damon/paddr: fix folio_nr_pages() after folio_put() in damon_pa_mark_accessed_or_deactivate()



On 2023/3/5 3:39, SeongJae Park wrote:
> damon_pa_mark_accessed_or_deactivate() is accessing a folio via
> folio_nr_pages() after folio_put() for the folio has invoked. Fix it.
>

Reviewed-by: Kefeng Wang <[email protected]>

> Fixes: f70da5ee8fe1 ("mm/damon: convert damon_pa_mark_accessed_or_deactivate() to use folios")
> Cc: <[email protected]> # 6.3.x
> Signed-off-by: SeongJae Park <[email protected]>
> ---
> mm/damon/paddr.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
> index 10f159b315ea..0db724aec5cb 100644
> --- a/mm/damon/paddr.c
> +++ b/mm/damon/paddr.c
> @@ -277,8 +277,8 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate(
> folio_mark_accessed(folio);
> else
> folio_deactivate(folio);
> - folio_put(folio);
> applied += folio_nr_pages(folio);
> + folio_put(folio);
> }
> return applied * PAGE_SIZE;
> }

2023-03-06 02:09:23

by Kefeng Wang

[permalink] [raw]
Subject: Re: [PATCH 1/2] mm/damon/paddr: fix folio_size() call after folio_put() in damon_pa_young()



On 2023/3/5 3:39, SeongJae Park wrote:
> damon_pa_young() is accessing a folio via folio_size() after folio_put()
> for the folio has invoked. Fix it.
>

Reviewed-by: Kefeng Wang <[email protected]>

> Fixes: 397b0c3a584b ("mm/damon/paddr: remove folio_sz field from damon_pa_access_chk_result")
> Cc: <[email protected]> # 6.3.x
> Signed-off-by: SeongJae Park <[email protected]>
> ---
> mm/damon/paddr.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c
> index 3fda00a0f786..10f159b315ea 100644
> --- a/mm/damon/paddr.c
> +++ b/mm/damon/paddr.c
> @@ -130,7 +130,6 @@ static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz)
> accessed = false;
> else
> accessed = true;
> - folio_put(folio);
> goto out;
> }
>
> @@ -144,10 +143,10 @@ static bool damon_pa_young(unsigned long paddr, unsigned long *folio_sz)
>
> if (need_lock)
> folio_unlock(folio);
> - folio_put(folio);
>
> out:
> *folio_sz = folio_size(folio);
> + folio_put(folio);
> return accessed;
> }
>