Commit 70be998c authored by andrew hendry's avatar andrew hendry Committed by David S. Miller

X25: pushdown bkl in ioctls

Push down the bkl in the ioctls so they can be removed one at a time.
Signed-off-by: default avatarAndrew Hendry <andrew.hendry@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c26aed40
...@@ -1357,14 +1357,16 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ...@@ -1357,14 +1357,16 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
int rc; int rc;
lock_kernel();
switch (cmd) { switch (cmd) {
case TIOCOUTQ: { 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) if (amount < 0)
amount = 0; amount = 0;
rc = put_user(amount, (unsigned int __user *)argp); rc = put_user(amount, (unsigned int __user *)argp);
unlock_kernel();
break; break;
} }
...@@ -1375,23 +1377,29 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ...@@ -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 * These two are safe on a single CPU system as
* only user tasks fiddle here * only user tasks fiddle here
*/ */
lock_kernel();
if ((skb = skb_peek(&sk->sk_receive_queue)) != NULL) if ((skb = skb_peek(&sk->sk_receive_queue)) != NULL)
amount = skb->len; amount = skb->len;
rc = put_user(amount, (unsigned int __user *)argp); rc = put_user(amount, (unsigned int __user *)argp);
unlock_kernel();
break; break;
} }
case SIOCGSTAMP: case SIOCGSTAMP:
rc = -EINVAL; rc = -EINVAL;
lock_kernel();
if (sk) if (sk)
rc = sock_get_timestamp(sk, rc = sock_get_timestamp(sk,
(struct timeval __user *)argp); (struct timeval __user *)argp);
unlock_kernel();
break; break;
case SIOCGSTAMPNS: case SIOCGSTAMPNS:
rc = -EINVAL; rc = -EINVAL;
lock_kernel();
if (sk) if (sk)
rc = sock_get_timestampns(sk, rc = sock_get_timestampns(sk,
(struct timespec __user *)argp); (struct timespec __user *)argp);
unlock_kernel();
break; break;
case SIOCGIFADDR: case SIOCGIFADDR:
case SIOCSIFADDR: case SIOCSIFADDR:
...@@ -1410,27 +1418,36 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ...@@ -1410,27 +1418,36 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
rc = -EPERM; rc = -EPERM;
if (!capable(CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
break; break;
lock_kernel();
rc = x25_route_ioctl(cmd, argp); rc = x25_route_ioctl(cmd, argp);
unlock_kernel();
break; break;
case SIOCX25GSUBSCRIP: case SIOCX25GSUBSCRIP:
lock_kernel();
rc = x25_subscr_ioctl(cmd, argp); rc = x25_subscr_ioctl(cmd, argp);
unlock_kernel();
break; break;
case SIOCX25SSUBSCRIP: case SIOCX25SSUBSCRIP:
rc = -EPERM; rc = -EPERM;
if (!capable(CAP_NET_ADMIN)) if (!capable(CAP_NET_ADMIN))
break; break;
lock_kernel();
rc = x25_subscr_ioctl(cmd, argp); rc = x25_subscr_ioctl(cmd, argp);
unlock_kernel();
break; break;
case SIOCX25GFACILITIES: { case SIOCX25GFACILITIES: {
struct x25_facilities fac = x25->facilities; struct x25_facilities fac = x25->facilities;
lock_kernel();
rc = copy_to_user(argp, &fac, rc = copy_to_user(argp, &fac,
sizeof(fac)) ? -EFAULT : 0; sizeof(fac)) ? -EFAULT : 0;
unlock_kernel();
break; break;
} }
case SIOCX25SFACILITIES: { case SIOCX25SFACILITIES: {
struct x25_facilities facilities; struct x25_facilities facilities;
rc = -EFAULT; rc = -EFAULT;
lock_kernel();
if (copy_from_user(&facilities, argp, if (copy_from_user(&facilities, argp,
sizeof(facilities))) sizeof(facilities)))
break; break;
...@@ -1466,12 +1483,15 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ...@@ -1466,12 +1483,15 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
break; break;
x25->facilities = facilities; x25->facilities = facilities;
rc = 0; rc = 0;
unlock_kernel();
break; break;
} }
case SIOCX25GDTEFACILITIES: { case SIOCX25GDTEFACILITIES: {
lock_kernel();
rc = copy_to_user(argp, &x25->dte_facilities, rc = copy_to_user(argp, &x25->dte_facilities,
sizeof(x25->dte_facilities)); sizeof(x25->dte_facilities));
unlock_kernel();
if (rc) if (rc)
rc = -EFAULT; rc = -EFAULT;
break; break;
...@@ -1480,6 +1500,7 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ...@@ -1480,6 +1500,7 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
case SIOCX25SDTEFACILITIES: { case SIOCX25SDTEFACILITIES: {
struct x25_dte_facilities dtefacs; struct x25_dte_facilities dtefacs;
rc = -EFAULT; rc = -EFAULT;
lock_kernel();
if (copy_from_user(&dtefacs, argp, sizeof(dtefacs))) if (copy_from_user(&dtefacs, argp, sizeof(dtefacs)))
break; break;
rc = -EINVAL; rc = -EINVAL;
...@@ -1496,13 +1517,16 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ...@@ -1496,13 +1517,16 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
break; break;
x25->dte_facilities = dtefacs; x25->dte_facilities = dtefacs;
rc = 0; rc = 0;
unlock_kernel();
break; break;
} }
case SIOCX25GCALLUSERDATA: { case SIOCX25GCALLUSERDATA: {
struct x25_calluserdata cud = x25->calluserdata; struct x25_calluserdata cud = x25->calluserdata;
lock_kernel();
rc = copy_to_user(argp, &cud, rc = copy_to_user(argp, &cud,
sizeof(cud)) ? -EFAULT : 0; sizeof(cud)) ? -EFAULT : 0;
unlock_kernel();
break; break;
} }
...@@ -1510,6 +1534,7 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ...@@ -1510,6 +1534,7 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
struct x25_calluserdata calluserdata; struct x25_calluserdata calluserdata;
rc = -EFAULT; rc = -EFAULT;
lock_kernel();
if (copy_from_user(&calluserdata, argp, if (copy_from_user(&calluserdata, argp,
sizeof(calluserdata))) sizeof(calluserdata)))
break; break;
...@@ -1517,24 +1542,29 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ...@@ -1517,24 +1542,29 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
if (calluserdata.cudlength > X25_MAX_CUD_LEN) if (calluserdata.cudlength > X25_MAX_CUD_LEN)
break; break;
x25->calluserdata = calluserdata; x25->calluserdata = calluserdata;
unlock_kernel();
rc = 0; rc = 0;
break; break;
} }
case SIOCX25GCAUSEDIAG: { case SIOCX25GCAUSEDIAG: {
struct x25_causediag causediag; struct x25_causediag causediag;
lock_kernel();
causediag = x25->causediag; causediag = x25->causediag;
rc = copy_to_user(argp, &causediag, rc = copy_to_user(argp, &causediag,
sizeof(causediag)) ? -EFAULT : 0; sizeof(causediag)) ? -EFAULT : 0;
unlock_kernel();
break; break;
} }
case SIOCX25SCAUSEDIAG: { case SIOCX25SCAUSEDIAG: {
struct x25_causediag causediag; struct x25_causediag causediag;
rc = -EFAULT; rc = -EFAULT;
lock_kernel();
if (copy_from_user(&causediag, argp, sizeof(causediag))) if (copy_from_user(&causediag, argp, sizeof(causediag)))
break; break;
x25->causediag = causediag; x25->causediag = causediag;
unlock_kernel();
rc = 0; rc = 0;
break; break;
...@@ -1543,6 +1573,7 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ...@@ -1543,6 +1573,7 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
case SIOCX25SCUDMATCHLEN: { case SIOCX25SCUDMATCHLEN: {
struct x25_subaddr sub_addr; struct x25_subaddr sub_addr;
rc = -EINVAL; rc = -EINVAL;
lock_kernel();
if(sk->sk_state != TCP_CLOSE) if(sk->sk_state != TCP_CLOSE)
break; break;
rc = -EFAULT; rc = -EFAULT;
...@@ -1553,21 +1584,25 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ...@@ -1553,21 +1584,25 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
if(sub_addr.cudmatchlength > X25_MAX_CUD_LEN) if(sub_addr.cudmatchlength > X25_MAX_CUD_LEN)
break; break;
x25->cudmatchlength = sub_addr.cudmatchlength; x25->cudmatchlength = sub_addr.cudmatchlength;
unlock_kernel();
rc = 0; rc = 0;
break; break;
} }
case SIOCX25CALLACCPTAPPRV: { case SIOCX25CALLACCPTAPPRV: {
rc = -EINVAL; rc = -EINVAL;
lock_kernel();
if (sk->sk_state != TCP_CLOSE) if (sk->sk_state != TCP_CLOSE)
break; break;
clear_bit(X25_ACCPT_APPRV_FLAG, &x25->flags); clear_bit(X25_ACCPT_APPRV_FLAG, &x25->flags);
unlock_kernel();
rc = 0; rc = 0;
break; break;
} }
case SIOCX25SENDCALLACCPT: { case SIOCX25SENDCALLACCPT: {
rc = -EINVAL; rc = -EINVAL;
lock_kernel();
if (sk->sk_state != TCP_ESTABLISHED) if (sk->sk_state != TCP_ESTABLISHED)
break; break;
/* must call accptapprv above */ /* must call accptapprv above */
...@@ -1575,6 +1610,7 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ...@@ -1575,6 +1610,7 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
break; break;
x25_write_internal(sk, X25_CALL_ACCEPTED); x25_write_internal(sk, X25_CALL_ACCEPTED);
x25->state = X25_STATE_3; x25->state = X25_STATE_3;
unlock_kernel();
rc = 0; rc = 0;
break; break;
} }
...@@ -1583,7 +1619,6 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ...@@ -1583,7 +1619,6 @@ static int x25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
rc = -ENOIOCTLCMD; rc = -ENOIOCTLCMD;
break; break;
} }
unlock_kernel();
return rc; return rc;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment