Skip to content

Commit

Permalink
Merge branch 'tun-cleanups'
Browse files Browse the repository at this point in the history
Markus Elfring says:

====================
tun: Fine-tuning for update_filter()

A few update suggestions were taken into account
from static source code analysis.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Aug 21, 2016
2 parents 4825a4e + 3b8d2a6 commit 8238ac0
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions drivers/net/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,14 +731,9 @@ static int update_filter(struct tap_filter *filter, void __user *arg)
}

alen = ETH_ALEN * uf.count;
addr = kmalloc(alen, GFP_KERNEL);
if (!addr)
return -ENOMEM;

if (copy_from_user(addr, arg + sizeof(uf), alen)) {
err = -EFAULT;
goto done;
}
addr = memdup_user(arg + sizeof(uf), alen);
if (IS_ERR(addr))
return PTR_ERR(addr);

/* The filter is updated without holding any locks. Which is
* perfectly safe. We disable it first and in the worst
Expand All @@ -758,7 +753,7 @@ static int update_filter(struct tap_filter *filter, void __user *arg)
for (; n < uf.count; n++) {
if (!is_multicast_ether_addr(addr[n].u)) {
err = 0; /* no filter */
goto done;
goto free_addr;
}
addr_hash_set(filter->mask, addr[n].u);
}
Expand All @@ -774,8 +769,7 @@ static int update_filter(struct tap_filter *filter, void __user *arg)

/* Return the number of exact filters */
err = nexact;

done:
free_addr:
kfree(addr);
return err;
}
Expand Down

0 comments on commit 8238ac0

Please sign in to comment.