Commit 05bfd366 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David S. Miller

sctp: refactor sctp_setsockopt_bindx

Split out a sctp_setsockopt_bindx_kernel that takes a kernel pointer
to the sockaddr and make sctp_setsockopt_bindx a small wrapper around
it.  This prepares for adding a new bind_add proto op.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Acked-by: default avatarMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 40ef92c6
...@@ -972,23 +972,22 @@ int sctp_asconf_mgmt(struct sctp_sock *sp, struct sctp_sockaddr_entry *addrw) ...@@ -972,23 +972,22 @@ int sctp_asconf_mgmt(struct sctp_sock *sp, struct sctp_sockaddr_entry *addrw)
* it. * it.
* *
* sk The sk of the socket * sk The sk of the socket
* addrs The pointer to the addresses in user land * addrs The pointer to the addresses
* addrssize Size of the addrs buffer * addrssize Size of the addrs buffer
* op Operation to perform (add or remove, see the flags of * op Operation to perform (add or remove, see the flags of
* sctp_bindx) * sctp_bindx)
* *
* Returns 0 if ok, <0 errno code on error. * Returns 0 if ok, <0 errno code on error.
*/ */
static int sctp_setsockopt_bindx(struct sock *sk, static int sctp_setsockopt_bindx_kernel(struct sock *sk,
struct sockaddr __user *addrs, struct sockaddr *addrs, int addrs_size,
int addrs_size, int op) int op)
{ {
struct sockaddr *kaddrs;
int err; int err;
int addrcnt = 0; int addrcnt = 0;
int walk_size = 0; int walk_size = 0;
struct sockaddr *sa_addr; struct sockaddr *sa_addr;
void *addr_buf; void *addr_buf = addrs;
struct sctp_af *af; struct sctp_af *af;
pr_debug("%s: sk:%p addrs:%p addrs_size:%d opt:%d\n", pr_debug("%s: sk:%p addrs:%p addrs_size:%d opt:%d\n",
...@@ -997,17 +996,10 @@ static int sctp_setsockopt_bindx(struct sock *sk, ...@@ -997,17 +996,10 @@ static int sctp_setsockopt_bindx(struct sock *sk,
if (unlikely(addrs_size <= 0)) if (unlikely(addrs_size <= 0))
return -EINVAL; return -EINVAL;
kaddrs = memdup_user(addrs, addrs_size);
if (IS_ERR(kaddrs))
return PTR_ERR(kaddrs);
/* Walk through the addrs buffer and count the number of addresses. */ /* Walk through the addrs buffer and count the number of addresses. */
addr_buf = kaddrs;
while (walk_size < addrs_size) { while (walk_size < addrs_size) {
if (walk_size + sizeof(sa_family_t) > addrs_size) { if (walk_size + sizeof(sa_family_t) > addrs_size)
kfree(kaddrs);
return -EINVAL; return -EINVAL;
}
sa_addr = addr_buf; sa_addr = addr_buf;
af = sctp_get_af_specific(sa_addr->sa_family); af = sctp_get_af_specific(sa_addr->sa_family);
...@@ -1015,10 +1007,8 @@ static int sctp_setsockopt_bindx(struct sock *sk, ...@@ -1015,10 +1007,8 @@ static int sctp_setsockopt_bindx(struct sock *sk,
/* If the address family is not supported or if this address /* If the address family is not supported or if this address
* causes the address buffer to overflow return EINVAL. * causes the address buffer to overflow return EINVAL.
*/ */
if (!af || (walk_size + af->sockaddr_len) > addrs_size) { if (!af || (walk_size + af->sockaddr_len) > addrs_size)
kfree(kaddrs);
return -EINVAL; return -EINVAL;
}
addrcnt++; addrcnt++;
addr_buf += af->sockaddr_len; addr_buf += af->sockaddr_len;
walk_size += af->sockaddr_len; walk_size += af->sockaddr_len;
...@@ -1029,31 +1019,36 @@ static int sctp_setsockopt_bindx(struct sock *sk, ...@@ -1029,31 +1019,36 @@ static int sctp_setsockopt_bindx(struct sock *sk,
case SCTP_BINDX_ADD_ADDR: case SCTP_BINDX_ADD_ADDR:
/* Allow security module to validate bindx addresses. */ /* Allow security module to validate bindx addresses. */
err = security_sctp_bind_connect(sk, SCTP_SOCKOPT_BINDX_ADD, err = security_sctp_bind_connect(sk, SCTP_SOCKOPT_BINDX_ADD,
(struct sockaddr *)kaddrs, addrs, addrs_size);
addrs_size);
if (err) if (err)
goto out; return err;
err = sctp_bindx_add(sk, kaddrs, addrcnt); err = sctp_bindx_add(sk, addrs, addrcnt);
if (err) if (err)
goto out; return err;
err = sctp_send_asconf_add_ip(sk, kaddrs, addrcnt); return sctp_send_asconf_add_ip(sk, addrs, addrcnt);
break;
case SCTP_BINDX_REM_ADDR: case SCTP_BINDX_REM_ADDR:
err = sctp_bindx_rem(sk, kaddrs, addrcnt); err = sctp_bindx_rem(sk, addrs, addrcnt);
if (err) if (err)
goto out; return err;
err = sctp_send_asconf_del_ip(sk, kaddrs, addrcnt); return sctp_send_asconf_del_ip(sk, addrs, addrcnt);
break;
default: default:
err = -EINVAL; return -EINVAL;
break;
} }
}
out: static int sctp_setsockopt_bindx(struct sock *sk,
kfree(kaddrs); struct sockaddr __user *addrs,
int addrs_size, int op)
{
struct sockaddr *kaddrs;
int err;
kaddrs = memdup_user(addrs, addrs_size);
if (IS_ERR(kaddrs))
return PTR_ERR(kaddrs);
err = sctp_setsockopt_bindx_kernel(sk, kaddrs, addrs_size, op);
kfree(kaddrs);
return err; return err;
} }
......
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