lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 9 Oct 2015 00:35:59 +0000
From:	Kosuke Tatsukawa <tatsu@...jp.nec.com>
To:	Ingo Molnar <mingo@...hat.com>,
	Peter Zijlstra <peterz@...radead.org>
CC:	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: [PATCH] wait: add comment before waitqueue_active noting memory
 barrier is required

This patch adds a comment before waitqueue_active noting that a memory
barrier is required.

Besides the original problem in drivers/tty/n_tty.c which caused a
program stall (described in https://lkml.org/lkml/2015/9/28/849), there
were several other places in the linux kernel source, which calls
waitqueue_active without a memory barrier.

  blk-mq: fix waitqueue_active without memory barrier in block/blk-mq-tag.c
  media: fix waitqueue_active without memory barrier in cpia2 driver
  mei: fix waitqueue_active without memory barrier in mei drivers
  brcmfmac: fix waitqueue_active without memory barrier in brcmfmac driver
  btrfs: fix waitqueue_active without memory barrier in btrfs
  sunrpc: fix waitqueue_active without memory barrier in sunrpc
  ALSA: seq_oss: fix waitqueue_active without memory barrier in snd-seq-oss
  kvm: fix waitqueue_active without memory barrier in virt/kvm/async_pf.c

Hopefully, the comment will make people using waitqueue_active a little
more cautious.

Signed-off-by: Kosuke Tatsukawa <tatsu@...jp.nec.com>
---
 include/linux/wait.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/include/linux/wait.h b/include/linux/wait.h
index 1e1bf9f..e385564 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -102,6 +102,14 @@ init_waitqueue_func_entry(wait_queue_t *q, wait_queue_func_t func)
 	q->func		= func;
 }
 
+/*
+ * Note: Some sort of memory barrier must be called before calling
+ * waitqueue_active on SMP, so that any writes done prior to this
+ * can be seen by other CPUs.  Also, since waitqueue_active will
+ * return 0 even when the queue is locked, the waiter must ensure
+ * that a memory barrier is called after add_wait_queue, so that
+ * following reads don't get moved up before the queue has changed.
+ */
 static inline int waitqueue_active(wait_queue_head_t *q)
 {
 	return !list_empty(&q->task_list);
-- 
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ