Re: [PATCH] staging: greybus: fix a possible data-inconsistency due to data race in get_serial_info()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks for your reply!
 
> The variables gb_tty->port.close_delay and gb_tty->port.closing_wait are
> ofter accessed together while holding the lock gb_tty->port.mutex. Here is
> an example in set_serial_info():
>
>   mutex_lock(&gb_tty->port.mutex);
>   ...
>   gb_tty->port.close_delay = close_delay;
>   gb_tty->port.closing_wait = closing_wait;
>   ...
>   mutex_unlock(&gb_tty->port.mutex);
>
> However, they are accessed without holding the lock gb_tty->port.mutex when
> are accessed in get_serial_info():
>
>   ss->close_delay = jiffies_to_msecs(gb_tty->port.close_delay) / 10;
>   ss->closing_wait =
>     gb_tty->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
>       ASYNC_CLOSING_WAIT_NONE :
>       jiffies_to_msecs(gb_tty->port.closing_wait) / 10;
>
> In my opinion, this may be a harmful race, because ss->close_delay can be
> inconsistent with ss->closing_wait if gb_tty->port.close_delay and
> gb_tty->port.closing_wait are updated by another thread after the
> assignment to ss->close_delay.

And how can that happen?
 
I am sorry that this data race is reported by a static analysis tool, and 
thus I do not know how to write a test case to trigger this data race.

Also you have trailing whitespace in your changelog text :(

I am sorry to bother you, and I will be careful in the subsequent patches.

> Besides, the select operator may return wrong value if
> gb_tty->port.closing_wait is updated right after the condition is
> calculated.
>
> To fix this possible data-inconsistency caused by data race, a lock and
> unlock pair is added when accessing different fields of gb_tty->port.
>
> Reported-by: BassCheck <bass@xxxxxxxxxxx>

As per the documentation for research tools like this, you need to
explain how this was tested.

I use a static analysis tool to detect this possible data race. It first collects
all struct fields that may be protected by a lock when accessed. And then, 
for each of such struct fields, it calculates the proportion of the protected 
accesses in all accesses. If the proportion is greater than a given threshold, 
the tool generates warnings for those unprotected field accesses.
Any suggestion on this static analysis tool will be appreciated.

Sincerely,
Tuo Li
_______________________________________________
greybus-dev mailing list -- greybus-dev@xxxxxxxxxxxxxxxx
To unsubscribe send an email to greybus-dev-leave@xxxxxxxxxxxxxxxx

[Index of Archives]     [Asterisk App Development]     [PJ SIP]     [Gnu Gatekeeper]     [IETF Sipping]     [Info Cyrus]     [ALSA User]     [Fedora Linux Users]     [Linux SCTP]     [DCCP]     [Gimp]     [Yosemite News]     [Deep Creek Hot Springs]     [Yosemite Campsites]     [ISDN Cause Codes]     [Asterisk Books]

  Powered by Linux