All of lore.kernel.org
 help / color / mirror / Atom feed
* [Ocfs2-devel] [BUG] ocfs2/dlm: possible data races in dlm_drop_lockres_ref_done() and dlm_get_lock_resource()
@ 2023-06-13  7:58 ` Tuo Li
  0 siblings, 0 replies; 5+ messages in thread
From: Tuo Li via Ocfs2-devel @ 2023-06-13  7:58 UTC (permalink / raw)
  To: mark, jlbec, Joseph Qi, akpm; +Cc: baijiaju1990, Linux Kernel, ocfs2-devel

Hello,

Our static analysis tool finds some possible data races in the OCFS2 file
system in Linux 6.4.0-rc6.

In most calling contexts, the variables  such as res->lockname.name and
res->owner are accessed with holding the lock res->spinlock. Here is an
example:

   lockres_seq_start() --> Line 539 in dlmdebug.c
     spin_lock(&res->spinlock); --> Line 574 in dlmdebug.c (Lock 
res->spinlock)
     dump_lockres(res, ...); --> Line 575 in fs/ocfs2/dlm/dlmdebug.c
       stringify_lockname(res->lockname.name, ...);  --> Line 493 in 
dlmdebug.c (Access res->lockname.name)
       scnprintf(..., res->owner, ...);  -->Line 498 in dlmdebug.c 
(Access res->owner)

However, in the following calling contexts:

   dlm_deref_lockres_worker() --> Line 2439 in dlmmaster.c
     dlm_drop_lockres_ref_done() --> Line 2459 in dlmmaster.c
       lockname = res->lockname.name; --> Line 2416 in dlmmaster.c 
(Access res->lockname.name)

   dlm_get_lock_resource() --> Line 701 in dlmmaster.c
     if (res->owner != dlm->node_num) --> Line 1023 in dlmmaster.c 
(Access res->owner)

The variables res->lockname.name and res->owner are accessed respectively
without holding the lock res->spinlock, and thus data races can occur.

I am not quite sure whether these possible data races are real and how 
to fix
them if they are real.

Any feedback would be appreciated, thanks!

Reported-by: BassCheck <bass@buaa.edu.cn>

Best wishes,
Tuo Li

_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

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

* [BUG] ocfs2/dlm: possible data races in dlm_drop_lockres_ref_done() and dlm_get_lock_resource()
@ 2023-06-13  7:58 ` Tuo Li
  0 siblings, 0 replies; 5+ messages in thread
From: Tuo Li @ 2023-06-13  7:58 UTC (permalink / raw)
  To: mark, jlbec, Joseph Qi, akpm; +Cc: ocfs2-devel, Linux Kernel, baijiaju1990

Hello,

Our static analysis tool finds some possible data races in the OCFS2 file
system in Linux 6.4.0-rc6.

In most calling contexts, the variables  such as res->lockname.name and
res->owner are accessed with holding the lock res->spinlock. Here is an
example:

   lockres_seq_start() --> Line 539 in dlmdebug.c
     spin_lock(&res->spinlock); --> Line 574 in dlmdebug.c (Lock 
res->spinlock)
     dump_lockres(res, ...); --> Line 575 in fs/ocfs2/dlm/dlmdebug.c
       stringify_lockname(res->lockname.name, ...);  --> Line 493 in 
dlmdebug.c (Access res->lockname.name)
       scnprintf(..., res->owner, ...);  -->Line 498 in dlmdebug.c 
(Access res->owner)

However, in the following calling contexts:

   dlm_deref_lockres_worker() --> Line 2439 in dlmmaster.c
     dlm_drop_lockres_ref_done() --> Line 2459 in dlmmaster.c
       lockname = res->lockname.name; --> Line 2416 in dlmmaster.c 
(Access res->lockname.name)

   dlm_get_lock_resource() --> Line 701 in dlmmaster.c
     if (res->owner != dlm->node_num) --> Line 1023 in dlmmaster.c 
(Access res->owner)

The variables res->lockname.name and res->owner are accessed respectively
without holding the lock res->spinlock, and thus data races can occur.

I am not quite sure whether these possible data races are real and how 
to fix
them if they are real.

Any feedback would be appreciated, thanks!

Reported-by: BassCheck <bass@buaa.edu.cn>

Best wishes,
Tuo Li

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

* [Ocfs2-devel] [BUG] ocfs2/dlm: possible data races in dlm_drop_lockres_ref_done() and dlm_get_lock_resource()
@ 2023-06-13  8:23 Tuo Li via Ocfs2-devel
  2023-06-16  2:11 ` Joseph Qi via Ocfs2-devel
  0 siblings, 1 reply; 5+ messages in thread
From: Tuo Li via Ocfs2-devel @ 2023-06-13  8:23 UTC (permalink / raw)
  To: mark, jlbec, Joseph Qi, akpm; +Cc: baijiaju1990, Linux Kernel, ocfs2-devel


[-- Attachment #1.1: Type: text/plain, Size: 1428 bytes --]

Hello,

Our static analysis tool finds some possible data races in the OCFS2 file
system in Linux 6.4.0-rc6.

In most calling contexts, the variables  such as res->lockname.name and
res->owner are accessed with holding the lock res->spinlock. Here is an
example:

  lockres_seq_start() --> Line 539 in dlmdebug.c
    spin_lock(&res->spinlock); --> Line 574 in dlmdebug.c (Lock
res->spinlock)
    dump_lockres(res, ...); --> Line 575 in fs/ocfs2/dlm/dlmdebug.c
      stringify_lockname(res->lockname.name, ...);  --> Line 493 in
dlmdebug.c (Access res->lockname.name)
      scnprintf(..., res->owner, ...);  -->Line 498 in dlmdebug.c (Access
res->owner)

However, in the following calling contexts:

  dlm_deref_lockres_worker() --> Line 2439 in dlmmaster.c
    dlm_drop_lockres_ref_done() --> Line 2459 in dlmmaster.c
      lockname = res->lockname.name; --> Line 2416 in dlmmaster.c (Access
res->lockname.name)

  dlm_get_lock_resource() --> Line 701 in dlmmaster.c
    if (res->owner != dlm->node_num) --> Line 1023 in dlmmaster.c (Access
res->owner)

The variables res->lockname.name and res->owner are accessed respectively
without holding the lock res->spinlock, and thus data races can occur.

I am not quite sure whether these possible data races are real and how to
fix
them if they are real.

Any feedback would be appreciated, thanks!

Reported-by: BassCheck <bass@buaa.edu.cn> <bass@buaa.edu.cn>

Best wishes,
Tuo Li

[-- Attachment #1.2: Type: text/html, Size: 2033 bytes --]

[-- Attachment #2: Type: text/plain, Size: 151 bytes --]

_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

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

* Re: [Ocfs2-devel] [BUG] ocfs2/dlm: possible data races in dlm_drop_lockres_ref_done() and dlm_get_lock_resource()
  2023-06-13  8:23 [Ocfs2-devel] " Tuo Li via Ocfs2-devel
@ 2023-06-16  2:11 ` Joseph Qi via Ocfs2-devel
  2023-06-16  3:27   ` Tuo Li via Ocfs2-devel
  0 siblings, 1 reply; 5+ messages in thread
From: Joseph Qi via Ocfs2-devel @ 2023-06-16  2:11 UTC (permalink / raw)
  To: Tuo Li, mark, jlbec, akpm; +Cc: baijiaju1990, Linux Kernel, ocfs2-devel

Hi,

On 6/13/23 4:23 PM, Tuo Li wrote:
> Hello,
> 
> Our static analysis tool finds some possible data races in the OCFS2 file
> system in Linux 6.4.0-rc6.
> 
> In most calling contexts, the variables  such as res->lockname.name and
> res->owner are accessed with holding the lock res->spinlock. Here is an
> example:
> 
>   lockres_seq_start() --> Line 539 in dlmdebug.c
>     spin_lock(&res->spinlock); --> Line 574 in dlmdebug.c (Lock
> res->spinlock)
>     dump_lockres(res, ...); --> Line 575 in fs/ocfs2/dlm/dlmdebug.c
>       stringify_lockname(res->lockname.name, ...);  --> Line 493 in
> dlmdebug.c (Access res->lockname.name)
>       scnprintf(..., res->owner, ...);  -->Line 498 in dlmdebug.c (Access
> res->owner)
> 
> However, in the following calling contexts:
> 
>   dlm_deref_lockres_worker() --> Line 2439 in dlmmaster.c
>     dlm_drop_lockres_ref_done() --> Line 2459 in dlmmaster.c
>       lockname = res->lockname.name; --> Line 2416 in dlmmaster.c (Access
> res->lockname.name)

lockname won't changed during the lockres lifecycle.
So this won't cause any real problem since now it holds a reference.

> 
>   dlm_get_lock_resource() --> Line 701 in dlmmaster.c
>     if (res->owner != dlm->node_num) --> Line 1023 in dlmmaster.c (Access
> res->owner)

Do you mean in dlm_wait_for_lock_mastery()?
Even if owner changes suddenly, it will recheck, so I think it is also fine.

Thanks,
Joseph

> 
> The variables res->lockname.name and res->owner are accessed respectively
> without holding the lock res->spinlock, and thus data races can occur.
> 
> I am not quite sure whether these possible data races are real and how to
> fix
> them if they are real.
> 
> Any feedback would be appreciated, thanks!
> 
> Reported-by: BassCheck <bass@buaa.edu.cn> <bass@buaa.edu.cn>
> 
> Best wishes,
> Tuo Li
> 

_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

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

* Re: [Ocfs2-devel] [BUG] ocfs2/dlm: possible data races in dlm_drop_lockres_ref_done() and dlm_get_lock_resource()
  2023-06-16  2:11 ` Joseph Qi via Ocfs2-devel
@ 2023-06-16  3:27   ` Tuo Li via Ocfs2-devel
  0 siblings, 0 replies; 5+ messages in thread
From: Tuo Li via Ocfs2-devel @ 2023-06-16  3:27 UTC (permalink / raw)
  To: Joseph Qi; +Cc: Linux Kernel, baijiaju1990, ocfs2-devel


[-- Attachment #1.1: Type: text/plain, Size: 2565 bytes --]

Hello,

Thanks for your reply! It is very helpful!

Do you mean in dlm_wait_for_lock_mastery()?
>

Yes, it is dlm_wait_for_lock_mastery(). I am sorry to confuse you.

Even if owner changes suddenly, it will recheck, so I think it is also
> fine.


Does 'recheck' here mean if owner changes, it will go to the label
'recheck' at Line 1011.
If so, when rechecking, the race can occur again at Line 1023. And thus can
cause infinite rechecking in extreme cases.

Thanks,
Tuo Li

On Fri, Jun 16, 2023 at 10:11 AM Joseph Qi <joseph.qi@linux.alibaba.com>
wrote:

> Hi,
>
> On 6/13/23 4:23 PM, Tuo Li wrote:
> > Hello,
> >
> > Our static analysis tool finds some possible data races in the OCFS2 file
> > system in Linux 6.4.0-rc6.
> >
> > In most calling contexts, the variables  such as res->lockname.name and
> > res->owner are accessed with holding the lock res->spinlock. Here is an
> > example:
> >
> >   lockres_seq_start() --> Line 539 in dlmdebug.c
> >     spin_lock(&res->spinlock); --> Line 574 in dlmdebug.c (Lock
> > res->spinlock)
> >     dump_lockres(res, ...); --> Line 575 in fs/ocfs2/dlm/dlmdebug.c
> >       stringify_lockname(res->lockname.name, ...);  --> Line 493 in
> > dlmdebug.c (Access res->lockname.name)
> >       scnprintf(..., res->owner, ...);  -->Line 498 in dlmdebug.c (Access
> > res->owner)
> >
> > However, in the following calling contexts:
> >
> >   dlm_deref_lockres_worker() --> Line 2439 in dlmmaster.c
> >     dlm_drop_lockres_ref_done() --> Line 2459 in dlmmaster.c
> >       lockname = res->lockname.name; --> Line 2416 in dlmmaster.c
> (Access
> > res->lockname.name)
>
> lockname won't changed during the lockres lifecycle.
> So this won't cause any real problem since now it holds a reference.
>
> >
> >   dlm_get_lock_resource() --> Line 701 in dlmmaster.c
> >     if (res->owner != dlm->node_num) --> Line 1023 in dlmmaster.c (Access
> > res->owner)
>
> Do you mean in dlm_wait_for_lock_mastery()?
> Even if owner changes suddenly, it will recheck, so I think it is also
> fine.
>
> Thanks,
> Joseph
>
> >
> > The variables res->lockname.name and res->owner are accessed
> respectively
> > without holding the lock res->spinlock, and thus data races can occur.
> >
> > I am not quite sure whether these possible data races are real and how to
> > fix
> > them if they are real.
> >
> > Any feedback would be appreciated, thanks!
> >
> > Reported-by: BassCheck <bass@buaa.edu.cn> <bass@buaa.edu.cn>
> >
> > Best wishes,
> > Tuo Li
> >
>

[-- Attachment #1.2: Type: text/html, Size: 4182 bytes --]

[-- Attachment #2: Type: text/plain, Size: 151 bytes --]

_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel@oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

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

end of thread, other threads:[~2023-06-16  3:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-13  7:58 [Ocfs2-devel] [BUG] ocfs2/dlm: possible data races in dlm_drop_lockres_ref_done() and dlm_get_lock_resource() Tuo Li via Ocfs2-devel
2023-06-13  7:58 ` Tuo Li
  -- strict thread matches above, loose matches on Subject: below --
2023-06-13  8:23 [Ocfs2-devel] " Tuo Li via Ocfs2-devel
2023-06-16  2:11 ` Joseph Qi via Ocfs2-devel
2023-06-16  3:27   ` Tuo Li via Ocfs2-devel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.