Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 133877
b: refs/heads/master
c: a7385ba
h: refs/heads/master
i:
  133875: 8864728
v: v3
  • Loading branch information
Eric W. Biederman authored and David S. Miller committed Jan 22, 2009
1 parent 4793cb2 commit cf50f63
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 74a3e5a71c9b54c63bff978e9cafbcef67600f0b
refs/heads/master: a7385ba21102a90f902055f9f185ca02bf62fa43
48 changes: 32 additions & 16 deletions trunk/drivers/net/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,31 @@ struct tun_struct {
#endif
};

static int tun_attach(struct tun_struct *tun, struct file *file)
{
const struct cred *cred = current_cred();

ASSERT_RTNL();

if (file->private_data)
return -EINVAL;

if (tun->attached)
return -EBUSY;

/* Check permissions */
if (((tun->owner != -1 && cred->euid != tun->owner) ||
(tun->group != -1 && cred->egid != tun->group)) &&
!capable(CAP_NET_ADMIN))
return -EPERM;

file->private_data = tun;
tun->attached = 1;
get_net(dev_net(tun->dev));

return 0;
}

/* TAP filterting */
static void addr_hash_set(u32 *mask, const u8 *addr)
{
Expand Down Expand Up @@ -695,7 +720,6 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
{
struct tun_struct *tun;
struct net_device *dev;
const struct cred *cred = current_cred();
int err;

dev = __dev_get_by_name(net, ifr->ifr_name);
Expand All @@ -707,17 +731,9 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
else
return -EINVAL;

if (tun->attached)
return -EBUSY;

/* Check permissions */
if (((tun->owner != -1 &&
cred->euid != tun->owner) ||
(tun->group != -1 &&
cred->egid != tun->group)) &&
!capable(CAP_NET_ADMIN)) {
return -EPERM;
}
err = tun_attach(tun, file);
if (err < 0)
return err;
}
else {
char *name;
Expand Down Expand Up @@ -766,6 +782,10 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
err = register_netdevice(tun->dev);
if (err < 0)
goto err_free_dev;

err = tun_attach(tun, file);
if (err < 0)
goto err_free_dev;
}

DBG(KERN_INFO "%s: tun_set_iff\n", tun->dev->name);
Expand All @@ -785,10 +805,6 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
else
tun->flags &= ~TUN_VNET_HDR;

file->private_data = tun;
tun->attached = 1;
get_net(dev_net(tun->dev));

/* Make sure persistent devices do not get stuck in
* xoff state.
*/
Expand Down

0 comments on commit cf50f63

Please sign in to comment.