linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: Use rcu_dereference in in_vfork
@ 2021-02-21 19:42 Matthew Wilcox (Oracle)
  2021-02-22  1:44 ` Miaohe Lin
  2021-02-22  8:30 ` Michal Hocko
  0 siblings, 2 replies; 3+ messages in thread
From: Matthew Wilcox (Oracle) @ 2021-02-21 19:42 UTC (permalink / raw)
  To: linux-mm, Andrew Morton
  Cc: Matthew Wilcox (Oracle), linux-kernel, Michal Hocko

Fix a sparse warning by using rcu_dereference().  Technically this is a
bug and a sufficiently aggressive compiler could reload the `real_parent'
pointer outside the protection of the rcu lock (and access freed memory),
but I think it's pretty unlikely to happen.

Fixes: b18dc5f291c0 ("mm, oom: skip vforked tasks from being selected")
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/sched/mm.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
index 1ae08b8462a4..90b2a0bce11c 100644
--- a/include/linux/sched/mm.h
+++ b/include/linux/sched/mm.h
@@ -140,7 +140,8 @@ static inline bool in_vfork(struct task_struct *tsk)
 	 * another oom-unkillable task does this it should blame itself.
 	 */
 	rcu_read_lock();
-	ret = tsk->vfork_done && tsk->real_parent->mm == tsk->mm;
+	ret = tsk->vfork_done &&
+			rcu_dereference(tsk->real_parent)->mm == tsk->mm;
 	rcu_read_unlock();
 
 	return ret;
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: Use rcu_dereference in in_vfork
  2021-02-21 19:42 [PATCH] mm: Use rcu_dereference in in_vfork Matthew Wilcox (Oracle)
@ 2021-02-22  1:44 ` Miaohe Lin
  2021-02-22  8:30 ` Michal Hocko
  1 sibling, 0 replies; 3+ messages in thread
From: Miaohe Lin @ 2021-02-22  1:44 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle)
  Cc: linux-kernel, Michal Hocko, linux-mm, Andrew Morton

On 2021/2/22 3:42, Matthew Wilcox (Oracle) wrote:
> Fix a sparse warning by using rcu_dereference().  Technically this is a
> bug and a sufficiently aggressive compiler could reload the `real_parent'
> pointer outside the protection of the rcu lock (and access freed memory),
> but I think it's pretty unlikely to happen.
> 
> Fixes: b18dc5f291c0 ("mm, oom: skip vforked tasks from being selected")
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

Looks good to me. Thanks!
Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>

> ---
>  include/linux/sched/mm.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
> index 1ae08b8462a4..90b2a0bce11c 100644
> --- a/include/linux/sched/mm.h
> +++ b/include/linux/sched/mm.h
> @@ -140,7 +140,8 @@ static inline bool in_vfork(struct task_struct *tsk)
>  	 * another oom-unkillable task does this it should blame itself.
>  	 */
>  	rcu_read_lock();
> -	ret = tsk->vfork_done && tsk->real_parent->mm == tsk->mm;
> +	ret = tsk->vfork_done &&
> +			rcu_dereference(tsk->real_parent)->mm == tsk->mm;
>  	rcu_read_unlock();
>  
>  	return ret;
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: Use rcu_dereference in in_vfork
  2021-02-21 19:42 [PATCH] mm: Use rcu_dereference in in_vfork Matthew Wilcox (Oracle)
  2021-02-22  1:44 ` Miaohe Lin
@ 2021-02-22  8:30 ` Michal Hocko
  1 sibling, 0 replies; 3+ messages in thread
From: Michal Hocko @ 2021-02-22  8:30 UTC (permalink / raw)
  To: Matthew Wilcox (Oracle); +Cc: linux-mm, Andrew Morton, linux-kernel

On Sun 21-02-21 19:42:06, Matthew Wilcox wrote:
> Fix a sparse warning by using rcu_dereference().  Technically this is a
> bug and a sufficiently aggressive compiler could reload the `real_parent'
> pointer outside the protection of the rcu lock (and access freed memory),
> but I think it's pretty unlikely to happen.
> 
> Fixes: b18dc5f291c0 ("mm, oom: skip vforked tasks from being selected")
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

I must have missed the RCU part.
Thanks!

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  include/linux/sched/mm.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
> index 1ae08b8462a4..90b2a0bce11c 100644
> --- a/include/linux/sched/mm.h
> +++ b/include/linux/sched/mm.h
> @@ -140,7 +140,8 @@ static inline bool in_vfork(struct task_struct *tsk)
>  	 * another oom-unkillable task does this it should blame itself.
>  	 */
>  	rcu_read_lock();
> -	ret = tsk->vfork_done && tsk->real_parent->mm == tsk->mm;
> +	ret = tsk->vfork_done &&
> +			rcu_dereference(tsk->real_parent)->mm == tsk->mm;
>  	rcu_read_unlock();
>  
>  	return ret;
> -- 
> 2.29.2
> 

-- 
Michal Hocko
SUSE Labs


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-22  8:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-21 19:42 [PATCH] mm: Use rcu_dereference in in_vfork Matthew Wilcox (Oracle)
2021-02-22  1:44 ` Miaohe Lin
2021-02-22  8:30 ` Michal Hocko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).