Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 224446
b: refs/heads/master
c: 70be998
h: refs/heads/master
v: v3
  • Loading branch information
andrew hendry authored and David S. Miller committed Nov 19, 2010
1 parent a2ed29e commit b2d9625
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 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: c26aed40f4fd18f86bcc6aba557cab700b129b73
refs/heads/master: 70be998c2b44f942f11383496622500136816acb
41 changes: 38 additions & 3 deletions trunk/net/x25/af_x25.c
Original file line number Diff line number Diff line change
Expand Up @@ -1357,14 +1357,16 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
void __user *argp = (void __user *)arg;
int rc;

lock_kernel();
switch (cmd) {
case TIOCOUTQ: {
int amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
int amount;

lock_kernel();
amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
if (amount < 0)
amount = 0;
rc = put_user(amount, (unsigned int __user *)argp);
unlock_kernel();
break;
}

Expand All @@ -1375,23 +1377,29 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
* These two are safe on a single CPU system as
* only user tasks fiddle here
*/
lock_kernel();
if ((skb = skb_peek(&sk->sk_receive_queue)) != NULL)
amount = skb->len;
rc = put_user(amount, (unsigned int __user *)argp);
unlock_kernel();
break;
}

case SIOCGSTAMP:
rc = -EINVAL;
lock_kernel();
if (sk)
rc = sock_get_timestamp(sk,
(struct timeval __user *)argp);
unlock_kernel();
break;
case SIOCGSTAMPNS:
rc = -EINVAL;
lock_kernel();
if (sk)
rc = sock_get_timestampns(sk,
(struct timespec __user *)argp);
unlock_kernel();
break;
case SIOCGIFADDR:
case SIOCSIFADDR:
Expand All @@ -1410,27 +1418,36 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
rc = -EPERM;
if (!capable(CAP_NET_ADMIN))
break;
lock_kernel();
rc = x25_route_ioctl(cmd, argp);
unlock_kernel();
break;
case SIOCX25GSUBSCRIP:
lock_kernel();
rc = x25_subscr_ioctl(cmd, argp);
unlock_kernel();
break;
case SIOCX25SSUBSCRIP:
rc = -EPERM;
if (!capable(CAP_NET_ADMIN))
break;
lock_kernel();
rc = x25_subscr_ioctl(cmd, argp);
unlock_kernel();
break;
case SIOCX25GFACILITIES: {
struct x25_facilities fac = x25->facilities;
lock_kernel();
rc = copy_to_user(argp, &fac,
sizeof(fac)) ? -EFAULT : 0;
unlock_kernel();
break;
}

case SIOCX25SFACILITIES: {
struct x25_facilities facilities;
rc = -EFAULT;
lock_kernel();
if (copy_from_user(&facilities, argp,
sizeof(facilities)))
break;
Expand Down Expand Up @@ -1466,12 +1483,15 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
break;
x25->facilities = facilities;
rc = 0;
unlock_kernel();
break;
}

case SIOCX25GDTEFACILITIES: {
lock_kernel();
rc = copy_to_user(argp, &x25->dte_facilities,
sizeof(x25->dte_facilities));
unlock_kernel();
if (rc)
rc = -EFAULT;
break;
Expand All @@ -1480,6 +1500,7 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
case SIOCX25SDTEFACILITIES: {
struct x25_dte_facilities dtefacs;
rc = -EFAULT;
lock_kernel();
if (copy_from_user(&dtefacs, argp, sizeof(dtefacs)))
break;
rc = -EINVAL;
Expand All @@ -1496,45 +1517,54 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
break;
x25->dte_facilities = dtefacs;
rc = 0;
unlock_kernel();
break;
}

case SIOCX25GCALLUSERDATA: {
struct x25_calluserdata cud = x25->calluserdata;
lock_kernel();
rc = copy_to_user(argp, &cud,
sizeof(cud)) ? -EFAULT : 0;
unlock_kernel();
break;
}

case SIOCX25SCALLUSERDATA: {
struct x25_calluserdata calluserdata;

rc = -EFAULT;
lock_kernel();
if (copy_from_user(&calluserdata, argp,
sizeof(calluserdata)))
break;
rc = -EINVAL;
if (calluserdata.cudlength > X25_MAX_CUD_LEN)
break;
x25->calluserdata = calluserdata;
unlock_kernel();
rc = 0;
break;
}

case SIOCX25GCAUSEDIAG: {
struct x25_causediag causediag;
lock_kernel();
causediag = x25->causediag;
rc = copy_to_user(argp, &causediag,
sizeof(causediag)) ? -EFAULT : 0;
unlock_kernel();
break;
}

case SIOCX25SCAUSEDIAG: {
struct x25_causediag causediag;
rc = -EFAULT;
lock_kernel();
if (copy_from_user(&causediag, argp, sizeof(causediag)))
break;
x25->causediag = causediag;
unlock_kernel();
rc = 0;
break;

Expand All @@ -1543,6 +1573,7 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
case SIOCX25SCUDMATCHLEN: {
struct x25_subaddr sub_addr;
rc = -EINVAL;
lock_kernel();
if(sk->sk_state != TCP_CLOSE)
break;
rc = -EFAULT;
Expand All @@ -1553,28 +1584,33 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
if(sub_addr.cudmatchlength > X25_MAX_CUD_LEN)
break;
x25->cudmatchlength = sub_addr.cudmatchlength;
unlock_kernel();
rc = 0;
break;
}

case SIOCX25CALLACCPTAPPRV: {
rc = -EINVAL;
lock_kernel();
if (sk->sk_state != TCP_CLOSE)
break;
clear_bit(X25_ACCPT_APPRV_FLAG, &x25->flags);
unlock_kernel();
rc = 0;
break;
}

case SIOCX25SENDCALLACCPT: {
rc = -EINVAL;
lock_kernel();
if (sk->sk_state != TCP_ESTABLISHED)
break;
/* must call accptapprv above */
if (test_bit(X25_ACCPT_APPRV_FLAG, &x25->flags))
break;
x25_write_internal(sk, X25_CALL_ACCEPTED);
x25->state = X25_STATE_3;
unlock_kernel();
rc = 0;
break;
}
Expand All @@ -1583,7 +1619,6 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
rc = -ENOIOCTLCMD;
break;
}
unlock_kernel();

return rc;
}
Expand Down

0 comments on commit b2d9625

Please sign in to comment.