]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
mqprio: fix potential null pointer dereference on opt
authorColin Ian King <colin.king@canonical.com>
Tue, 17 Oct 2017 15:01:30 +0000 (16:01 +0100)
committerDavid S. Miller <davem@davemloft.net>
Thu, 19 Oct 2017 12:13:14 +0000 (13:13 +0100)
The pointer opt has a null check however before for this check opt is
dereferenced when len is initialized, hence we potentially have a null
pointer deference on opt.  Avoid this by checking for a null opt before
dereferencing it.

Detected by CoverityScan, CID#1458234 ("Dereference before null check")

Fixes: 4e8b86c06269 ("mqprio: Introduce new hardware offload mode and shaper in mqprio")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sched/sch_mqprio.c

index cae91b4b08a60a3f8520e836583f34c7ee657989..51c2b289c69b87e83a8cc80de448b8d968a56d64 100644 (file)
@@ -142,7 +142,7 @@ static int mqprio_init(struct Qdisc *sch, struct nlattr *opt)
        struct nlattr *tb[TCA_MQPRIO_MAX + 1];
        struct nlattr *attr;
        int rem;
-       int len = nla_len(opt) - NLA_ALIGN(sizeof(*qopt));
+       int len;
 
        BUILD_BUG_ON(TC_MAX_QUEUE != TC_QOPT_MAX_QUEUE);
        BUILD_BUG_ON(TC_BITMASK != TC_QOPT_BITMASK);
@@ -164,6 +164,7 @@ static int mqprio_init(struct Qdisc *sch, struct nlattr *opt)
        if (mqprio_parse_opt(dev, qopt))
                return -EINVAL;
 
+       len = nla_len(opt) - NLA_ALIGN(sizeof(*qopt));
        if (len > 0) {
                err = parse_attr(tb, TCA_MQPRIO_MAX, opt, mqprio_policy,
                                 sizeof(*qopt));