Merge branch 'sctp-process-the-error-returned-from-sctp_sock_migrate'
Xin Long says: ==================== sctp: process the error returned from sctp_sock_migrate() This patchset is to process the errs returned by sctp_auth_init_hmacs() and sctp_bind_addr_dup() from sctp_sock_migrate(). And also fix a panic caused by new ep->auth_hmacs was not set due to net->sctp.auth_enable changed by sysctl before accepting an assoc. ==================== Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
commit
f1a167050d
|
@ -471,12 +471,6 @@ int sctp_auth_init_hmacs(struct sctp_endpoint *ep, gfp_t gfp)
|
||||||
struct crypto_shash *tfm = NULL;
|
struct crypto_shash *tfm = NULL;
|
||||||
__u16 id;
|
__u16 id;
|
||||||
|
|
||||||
/* If AUTH extension is disabled, we are done */
|
|
||||||
if (!ep->auth_enable) {
|
|
||||||
ep->auth_hmacs = NULL;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the transforms are already allocated, we are done */
|
/* If the transforms are already allocated, we are done */
|
||||||
if (ep->auth_hmacs)
|
if (ep->auth_hmacs)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -107,6 +107,13 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,
|
||||||
auth_chunks->param_hdr.length =
|
auth_chunks->param_hdr.length =
|
||||||
htons(sizeof(struct sctp_paramhdr) + 2);
|
htons(sizeof(struct sctp_paramhdr) + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Allocate and initialize transorms arrays for supported
|
||||||
|
* HMACs.
|
||||||
|
*/
|
||||||
|
err = sctp_auth_init_hmacs(ep, gfp);
|
||||||
|
if (err)
|
||||||
|
goto nomem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the base structure. */
|
/* Initialize the base structure. */
|
||||||
|
@ -150,15 +157,10 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,
|
||||||
INIT_LIST_HEAD(&ep->endpoint_shared_keys);
|
INIT_LIST_HEAD(&ep->endpoint_shared_keys);
|
||||||
null_key = sctp_auth_shkey_create(0, gfp);
|
null_key = sctp_auth_shkey_create(0, gfp);
|
||||||
if (!null_key)
|
if (!null_key)
|
||||||
goto nomem;
|
goto nomem_shkey;
|
||||||
|
|
||||||
list_add(&null_key->key_list, &ep->endpoint_shared_keys);
|
list_add(&null_key->key_list, &ep->endpoint_shared_keys);
|
||||||
|
|
||||||
/* Allocate and initialize transorms arrays for supported HMACs. */
|
|
||||||
err = sctp_auth_init_hmacs(ep, gfp);
|
|
||||||
if (err)
|
|
||||||
goto nomem_hmacs;
|
|
||||||
|
|
||||||
/* Add the null key to the endpoint shared keys list and
|
/* Add the null key to the endpoint shared keys list and
|
||||||
* set the hmcas and chunks pointers.
|
* set the hmcas and chunks pointers.
|
||||||
*/
|
*/
|
||||||
|
@ -169,8 +171,8 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,
|
||||||
|
|
||||||
return ep;
|
return ep;
|
||||||
|
|
||||||
nomem_hmacs:
|
nomem_shkey:
|
||||||
sctp_auth_destroy_keys(&ep->endpoint_shared_keys);
|
sctp_auth_destroy_hmacs(ep->auth_hmacs);
|
||||||
nomem:
|
nomem:
|
||||||
/* Free all allocations */
|
/* Free all allocations */
|
||||||
kfree(auth_hmacs);
|
kfree(auth_hmacs);
|
||||||
|
|
|
@ -102,9 +102,9 @@ static int sctp_send_asconf(struct sctp_association *asoc,
|
||||||
struct sctp_chunk *chunk);
|
struct sctp_chunk *chunk);
|
||||||
static int sctp_do_bind(struct sock *, union sctp_addr *, int);
|
static int sctp_do_bind(struct sock *, union sctp_addr *, int);
|
||||||
static int sctp_autobind(struct sock *sk);
|
static int sctp_autobind(struct sock *sk);
|
||||||
static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
|
static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
|
||||||
struct sctp_association *assoc,
|
struct sctp_association *assoc,
|
||||||
enum sctp_socket_type type);
|
enum sctp_socket_type type);
|
||||||
|
|
||||||
static unsigned long sctp_memory_pressure;
|
static unsigned long sctp_memory_pressure;
|
||||||
static atomic_long_t sctp_memory_allocated;
|
static atomic_long_t sctp_memory_allocated;
|
||||||
|
@ -4891,7 +4891,11 @@ static struct sock *sctp_accept(struct sock *sk, int flags, int *err, bool kern)
|
||||||
/* Populate the fields of the newsk from the oldsk and migrate the
|
/* Populate the fields of the newsk from the oldsk and migrate the
|
||||||
* asoc to the newsk.
|
* asoc to the newsk.
|
||||||
*/
|
*/
|
||||||
sctp_sock_migrate(sk, newsk, asoc, SCTP_SOCKET_TCP);
|
error = sctp_sock_migrate(sk, newsk, asoc, SCTP_SOCKET_TCP);
|
||||||
|
if (error) {
|
||||||
|
sk_common_release(newsk);
|
||||||
|
newsk = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
release_sock(sk);
|
release_sock(sk);
|
||||||
|
@ -5639,7 +5643,12 @@ int sctp_do_peeloff(struct sock *sk, sctp_assoc_t id, struct socket **sockp)
|
||||||
/* Populate the fields of the newsk from the oldsk and migrate the
|
/* Populate the fields of the newsk from the oldsk and migrate the
|
||||||
* asoc to the newsk.
|
* asoc to the newsk.
|
||||||
*/
|
*/
|
||||||
sctp_sock_migrate(sk, sock->sk, asoc, SCTP_SOCKET_UDP_HIGH_BANDWIDTH);
|
err = sctp_sock_migrate(sk, sock->sk, asoc,
|
||||||
|
SCTP_SOCKET_UDP_HIGH_BANDWIDTH);
|
||||||
|
if (err) {
|
||||||
|
sock_release(sock);
|
||||||
|
sock = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
*sockp = sock;
|
*sockp = sock;
|
||||||
|
|
||||||
|
@ -9171,9 +9180,9 @@ static inline void sctp_copy_descendant(struct sock *sk_to,
|
||||||
/* Populate the fields of the newsk from the oldsk and migrate the assoc
|
/* Populate the fields of the newsk from the oldsk and migrate the assoc
|
||||||
* and its messages to the newsk.
|
* and its messages to the newsk.
|
||||||
*/
|
*/
|
||||||
static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
|
static int sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
|
||||||
struct sctp_association *assoc,
|
struct sctp_association *assoc,
|
||||||
enum sctp_socket_type type)
|
enum sctp_socket_type type)
|
||||||
{
|
{
|
||||||
struct sctp_sock *oldsp = sctp_sk(oldsk);
|
struct sctp_sock *oldsp = sctp_sk(oldsk);
|
||||||
struct sctp_sock *newsp = sctp_sk(newsk);
|
struct sctp_sock *newsp = sctp_sk(newsk);
|
||||||
|
@ -9182,6 +9191,7 @@ static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
|
||||||
struct sk_buff *skb, *tmp;
|
struct sk_buff *skb, *tmp;
|
||||||
struct sctp_ulpevent *event;
|
struct sctp_ulpevent *event;
|
||||||
struct sctp_bind_hashbucket *head;
|
struct sctp_bind_hashbucket *head;
|
||||||
|
int err;
|
||||||
|
|
||||||
/* Migrate socket buffer sizes and all the socket level options to the
|
/* Migrate socket buffer sizes and all the socket level options to the
|
||||||
* new socket.
|
* new socket.
|
||||||
|
@ -9210,8 +9220,20 @@ static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
|
||||||
/* Copy the bind_addr list from the original endpoint to the new
|
/* Copy the bind_addr list from the original endpoint to the new
|
||||||
* endpoint so that we can handle restarts properly
|
* endpoint so that we can handle restarts properly
|
||||||
*/
|
*/
|
||||||
sctp_bind_addr_dup(&newsp->ep->base.bind_addr,
|
err = sctp_bind_addr_dup(&newsp->ep->base.bind_addr,
|
||||||
&oldsp->ep->base.bind_addr, GFP_KERNEL);
|
&oldsp->ep->base.bind_addr, GFP_KERNEL);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
/* New ep's auth_hmacs should be set if old ep's is set, in case
|
||||||
|
* that net->sctp.auth_enable has been changed to 0 by users and
|
||||||
|
* new ep's auth_hmacs couldn't be set in sctp_endpoint_init().
|
||||||
|
*/
|
||||||
|
if (oldsp->ep->auth_hmacs) {
|
||||||
|
err = sctp_auth_init_hmacs(newsp->ep, GFP_KERNEL);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
/* Move any messages in the old socket's receive queue that are for the
|
/* Move any messages in the old socket's receive queue that are for the
|
||||||
* peeled off association to the new socket's receive queue.
|
* peeled off association to the new socket's receive queue.
|
||||||
|
@ -9296,6 +9318,8 @@ static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk,
|
||||||
}
|
}
|
||||||
|
|
||||||
release_sock(newsk);
|
release_sock(newsk);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue