linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kcsan: Fix misreporting if concurrent races on same address
@ 2020-02-10 14:56 Marco Elver
  2020-02-10 15:21 ` Paul E. McKenney
  0 siblings, 1 reply; 2+ messages in thread
From: Marco Elver @ 2020-02-10 14:56 UTC (permalink / raw)
  To: elver; +Cc: paulmck, andreyknvl, glider, dvyukov, kasan-dev, linux-kernel

If there are more than 3 threads racing on the same address, it can
happen that 'other_info' is populated not by the thread that consumed
the calling thread's watchpoint but by one of the others.

To avoid deadlock, we have to consume 'other_info' regardless. In case
we observe that we only have information about readers, we discard the
'other_info' and skip the report.

Signed-off-by: Marco Elver <elver@google.com>
---
 kernel/kcsan/report.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/kernel/kcsan/report.c b/kernel/kcsan/report.c
index 3bc590e6be7e3..e046dd26a2459 100644
--- a/kernel/kcsan/report.c
+++ b/kernel/kcsan/report.c
@@ -422,6 +422,26 @@ static bool prepare_report(unsigned long *flags, const volatile void *ptr,
 			return false;
 		}
 
+		access_type |= other_info.access_type;
+		if ((access_type & KCSAN_ACCESS_WRITE) == 0) {
+			/*
+			 * This is not the other_info from the thread that
+			 * consumed our watchpoint.
+			 *
+			 * There are concurrent races between more than 3
+			 * threads on the same address. The thread that set up
+			 * the watchpoint here was a read, as well as the one
+			 * that is currently in other_info.
+			 *
+			 * It's fine if we simply omit this report, since the
+			 * chances of one of the other reports including the
+			 * same info is high, as well as the chances that we
+			 * simply re-report the race again.
+			 */
+			release_report(flags, KCSAN_REPORT_RACE_SIGNAL);
+			return false;
+		}
+
 		/*
 		 * Matching & usable access in other_info: keep other_info_lock
 		 * locked, as this thread consumes it to print the full report;
-- 
2.25.0.341.g760bfbb309-goog


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

* Re: [PATCH] kcsan: Fix misreporting if concurrent races on same address
  2020-02-10 14:56 [PATCH] kcsan: Fix misreporting if concurrent races on same address Marco Elver
@ 2020-02-10 15:21 ` Paul E. McKenney
  0 siblings, 0 replies; 2+ messages in thread
From: Paul E. McKenney @ 2020-02-10 15:21 UTC (permalink / raw)
  To: Marco Elver; +Cc: andreyknvl, glider, dvyukov, kasan-dev, linux-kernel

On Mon, Feb 10, 2020 at 03:56:39PM +0100, Marco Elver wrote:
> If there are more than 3 threads racing on the same address, it can
> happen that 'other_info' is populated not by the thread that consumed
> the calling thread's watchpoint but by one of the others.
> 
> To avoid deadlock, we have to consume 'other_info' regardless. In case
> we observe that we only have information about readers, we discard the
> 'other_info' and skip the report.
> 
> Signed-off-by: Marco Elver <elver@google.com>

Queued for testing and review, thank you!!!

							Thanx, Paul

> ---
>  kernel/kcsan/report.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/kernel/kcsan/report.c b/kernel/kcsan/report.c
> index 3bc590e6be7e3..e046dd26a2459 100644
> --- a/kernel/kcsan/report.c
> +++ b/kernel/kcsan/report.c
> @@ -422,6 +422,26 @@ static bool prepare_report(unsigned long *flags, const volatile void *ptr,
>  			return false;
>  		}
>  
> +		access_type |= other_info.access_type;
> +		if ((access_type & KCSAN_ACCESS_WRITE) == 0) {
> +			/*
> +			 * This is not the other_info from the thread that
> +			 * consumed our watchpoint.
> +			 *
> +			 * There are concurrent races between more than 3
> +			 * threads on the same address. The thread that set up
> +			 * the watchpoint here was a read, as well as the one
> +			 * that is currently in other_info.
> +			 *
> +			 * It's fine if we simply omit this report, since the
> +			 * chances of one of the other reports including the
> +			 * same info is high, as well as the chances that we
> +			 * simply re-report the race again.
> +			 */
> +			release_report(flags, KCSAN_REPORT_RACE_SIGNAL);
> +			return false;
> +		}
> +
>  		/*
>  		 * Matching & usable access in other_info: keep other_info_lock
>  		 * locked, as this thread consumes it to print the full report;
> -- 
> 2.25.0.341.g760bfbb309-goog
> 

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

end of thread, other threads:[~2020-02-10 15:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-10 14:56 [PATCH] kcsan: Fix misreporting if concurrent races on same address Marco Elver
2020-02-10 15:21 ` Paul E. McKenney

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).