Skip to content

Commit

Permalink
net, sctp: convert sctp_ep_common.refcnt from atomic_t to refcount_t
Browse files Browse the repository at this point in the history
refcount_t type and corresponding API should be
used instead of atomic_t when the variable is used as
a reference counter. This allows to avoid accidental
refcounter overflows that might lead to use-after-free
situations.

Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
Signed-off-by: Hans Liljestrand <ishkamiel@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: David Windsor <dwindsor@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Reshetova, Elena authored and David S. Miller committed Jul 4, 2017
1 parent a4b2b58 commit c638457
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/net/sctp/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ struct sctp_ep_common {
* refcnt - Reference count access to this object.
* dead - Do not attempt to use this object.
*/
atomic_t refcnt;
refcount_t refcnt;
bool dead;

/* What socket does this endpoint belong to? */
Expand Down
6 changes: 3 additions & 3 deletions net/sctp/associola.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static struct sctp_association *sctp_association_init(struct sctp_association *a
asoc->base.type = SCTP_EP_TYPE_ASSOCIATION;

/* Initialize the object handling fields. */
atomic_set(&asoc->base.refcnt, 1);
refcount_set(&asoc->base.refcnt, 1);

/* Initialize the bind addr area. */
sctp_bind_addr_init(&asoc->base.bind_addr, ep->base.bind_addr.port);
Expand Down Expand Up @@ -873,15 +873,15 @@ void sctp_assoc_control_transport(struct sctp_association *asoc,
/* Hold a reference to an association. */
void sctp_association_hold(struct sctp_association *asoc)
{
atomic_inc(&asoc->base.refcnt);
refcount_inc(&asoc->base.refcnt);
}

/* Release a reference to an association and cleanup
* if there are no more references.
*/
void sctp_association_put(struct sctp_association *asoc)
{
if (atomic_dec_and_test(&asoc->base.refcnt))
if (refcount_dec_and_test(&asoc->base.refcnt))
sctp_association_destroy(asoc);
}

Expand Down
6 changes: 3 additions & 3 deletions net/sctp/endpointola.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static struct sctp_endpoint *sctp_endpoint_init(struct sctp_endpoint *ep,
ep->base.type = SCTP_EP_TYPE_SOCKET;

/* Initialize the basic object fields. */
atomic_set(&ep->base.refcnt, 1);
refcount_set(&ep->base.refcnt, 1);
ep->base.dead = false;

/* Create an input queue. */
Expand Down Expand Up @@ -285,15 +285,15 @@ static void sctp_endpoint_destroy(struct sctp_endpoint *ep)
/* Hold a reference to an endpoint. */
void sctp_endpoint_hold(struct sctp_endpoint *ep)
{
atomic_inc(&ep->base.refcnt);
refcount_inc(&ep->base.refcnt);
}

/* Release a reference to an endpoint and clean up if there are
* no more references.
*/
void sctp_endpoint_put(struct sctp_endpoint *ep)
{
if (atomic_dec_and_test(&ep->base.refcnt))
if (refcount_dec_and_test(&ep->base.refcnt))
sctp_endpoint_destroy(ep);
}

Expand Down

0 comments on commit c638457

Please sign in to comment.