From: Vinicius Costa Gomes <vinicius.gomes@intel.com>
To: netdev@vger.kernel.org
Cc: Vinicius Costa Gomes <vinicius.gomes@intel.com>,
jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us,
olteanv@gmail.com, timo.koskiahde@tttech.com,
m-karicheri2@ti.com
Subject: [RFC net-next v1 1/6] taprio: Fix potencial use of invalid memory during dequeue()
Date: Tue, 9 Apr 2019 17:33:00 -0700 [thread overview]
Message-ID: <20190410003305.24646-2-vinicius.gomes@intel.com> (raw)
In-Reply-To: <20190410003305.24646-1-vinicius.gomes@intel.com>
Right now, this isn't a problem, but the next commit allows schedules
to be added during runtime. When a new schedule transitions from the
inactive to the active state ("admin" -> "oper") the previous one is
free'd, if it's free'd just after the RCU read lock is released, we
may access an invalid 'entry'.
So, we should take care to protect the dequeue() flow, so all the
places that access the entries are protected by the RCU read lock.
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
---
net/sched/sch_taprio.c | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
index c7041999eb5d..1fb5eae46bc6 100644
--- a/net/sched/sch_taprio.c
+++ b/net/sched/sch_taprio.c
@@ -124,8 +124,8 @@ static struct sk_buff *taprio_dequeue(struct Qdisc *sch)
{
struct taprio_sched *q = qdisc_priv(sch);
struct net_device *dev = qdisc_dev(sch);
+ struct sk_buff *skb = NULL;
struct sched_entry *entry;
- struct sk_buff *skb;
u32 gate_mask;
int i;
@@ -137,10 +137,9 @@ static struct sk_buff *taprio_dequeue(struct Qdisc *sch)
* "AdminGateSates"
*/
gate_mask = entry ? entry->gate_mask : TAPRIO_ALL_GATES_OPEN;
- rcu_read_unlock();
if (!gate_mask)
- return NULL;
+ goto done;
for (i = 0; i < dev->num_tx_queues; i++) {
struct Qdisc *child = q->qdiscs[i];
@@ -170,26 +169,35 @@ static struct sk_buff *taprio_dequeue(struct Qdisc *sch)
* guard band ...
*/
if (gate_mask != TAPRIO_ALL_GATES_OPEN &&
- ktime_after(guard, entry->close_time))
- return NULL;
+ ktime_after(guard, entry->close_time)) {
+ skb = NULL;
+ goto done;
+ }
/* ... and no budget. */
if (gate_mask != TAPRIO_ALL_GATES_OPEN &&
- atomic_sub_return(len, &entry->budget) < 0)
- return NULL;
+ atomic_sub_return(len, &entry->budget) < 0) {
+ skb = NULL;
+ goto done;
+ }
skb = child->ops->dequeue(child);
if (unlikely(!skb))
- return NULL;
+ goto done;
+
qdisc_bstats_update(sch, skb);
qdisc_qstats_backlog_dec(sch, skb);
sch->q.qlen--;
- return skb;
+ goto done;
}
- return NULL;
+done:
+ rcu_read_unlock();
+
+ return skb;
+
}
static bool should_restart_cycle(const struct taprio_sched *q,
--
2.21.0
next prev parent reply other threads:[~2019-04-10 0:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-10 0:32 [RFC net-next v1 0/6] RFC: taprio change schedules + offload Vinicius Costa Gomes
2019-04-10 0:33 ` Vinicius Costa Gomes [this message]
2019-04-10 0:33 ` [RFC net-next v1 2/6] taprio: Add support adding an admin schedule Vinicius Costa Gomes
2019-04-10 0:33 ` [RFC net-next v1 3/6] taprio: Add support for setting the cycle-time manually Vinicius Costa Gomes
2019-04-10 0:33 ` [RFC net-next v1 4/6] taprio: Add support for cycle-time-extension Vinicius Costa Gomes
2019-04-10 0:33 ` [RFC net-next v1 5/6] taprio: Add support for frame-preemption Vinicius Costa Gomes
2019-04-10 0:33 ` [RFC net-next v1 6/6] taprio: Add support for hardware offloading Vinicius Costa Gomes
2019-05-13 19:40 ` [RFC net-next v1 0/6] RFC: taprio change schedules + offload Murali Karicheri
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190410003305.24646-2-vinicius.gomes@intel.com \
--to=vinicius.gomes@intel.com \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=m-karicheri2@ti.com \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=timo.koskiahde@tttech.com \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).