aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul E. McKenney <paulmck@linux.vnet.ibm.com>2013-08-09 00:44:31 -0400
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>2013-09-23 12:16:11 -0400
commit88d6df612cc3c99f56cc18461fcc531c3a145544 (patch)
tree3f3c9e77bea5a07bf4570a4313d66eb80a58f6ee
parentf7be82093952ee4a74ffc8c729b2811f908cd9a4 (diff)
rcu: Prevent spurious-wakeup DoS attack on rcu_gp_kthread()
Spurious wakeups in the force-quiescent-state loop in rcu_gp_kthread() cause the timeout to be recalculated, which would prevent rcu_gp_fqs() from ever being called. This would in turn would prevent the grace period from ever ending for as long as there was at least one CPU in an extended quiescent state that had not yet passed through a quiescent state. This commit therefore avoids recalculating the timeout unless the previous pass's call to wait_event_interruptible_timeout() actually did time out, thus preventing the above scenario. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
-rw-r--r--kernel/rcutree.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/kernel/rcutree.c b/kernel/rcutree.c
index d679a522c0a2..62b67b78b661 100644
--- a/kernel/rcutree.c
+++ b/kernel/rcutree.c
@@ -1470,6 +1470,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
1470static int __noreturn rcu_gp_kthread(void *arg) 1470static int __noreturn rcu_gp_kthread(void *arg)
1471{ 1471{
1472 int fqs_state; 1472 int fqs_state;
1473 int gf;
1473 unsigned long j; 1474 unsigned long j;
1474 int ret; 1475 int ret;
1475 struct rcu_state *rsp = arg; 1476 struct rcu_state *rsp = arg;
@@ -1495,10 +1496,13 @@ static int __noreturn rcu_gp_kthread(void *arg)
1495 j = HZ; 1496 j = HZ;
1496 jiffies_till_first_fqs = HZ; 1497 jiffies_till_first_fqs = HZ;
1497 } 1498 }
1499 ret = 0;
1498 for (;;) { 1500 for (;;) {
1499 rsp->jiffies_force_qs = jiffies + j; 1501 if (!ret)
1502 rsp->jiffies_force_qs = jiffies + j;
1500 ret = wait_event_interruptible_timeout(rsp->gp_wq, 1503 ret = wait_event_interruptible_timeout(rsp->gp_wq,
1501 (rsp->gp_flags & RCU_GP_FLAG_FQS) || 1504 ((gf = ACCESS_ONCE(rsp->gp_flags)) &
1505 RCU_GP_FLAG_FQS) ||
1502 (!ACCESS_ONCE(rnp->qsmask) && 1506 (!ACCESS_ONCE(rnp->qsmask) &&
1503 !rcu_preempt_blocked_readers_cgp(rnp)), 1507 !rcu_preempt_blocked_readers_cgp(rnp)),
1504 j); 1508 j);
@@ -1507,7 +1511,8 @@ static int __noreturn rcu_gp_kthread(void *arg)
1507 !rcu_preempt_blocked_readers_cgp(rnp)) 1511 !rcu_preempt_blocked_readers_cgp(rnp))
1508 break; 1512 break;
1509 /* If time for quiescent-state forcing, do it. */ 1513 /* If time for quiescent-state forcing, do it. */
1510 if (ret == 0 || (rsp->gp_flags & RCU_GP_FLAG_FQS)) { 1514 if (ULONG_CMP_GE(jiffies, rsp->jiffies_force_qs) ||
1515 (gf & RCU_GP_FLAG_FQS)) {
1511 fqs_state = rcu_gp_fqs(rsp, fqs_state); 1516 fqs_state = rcu_gp_fqs(rsp, fqs_state);
1512 cond_resched(); 1517 cond_resched();
1513 } else { 1518 } else {