Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert if soref() is called on an already-released socket. #703

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions usrsctplib/user_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ static void
sodealloc(struct socket *so)
{

KASSERT(so->so_count == 0, ("sodealloc(): so_count %d", so->so_count));
KASSERT(so->so_count <= 0, ("sodealloc(): so_count %d", so->so_count));
KASSERT(so->so_pcb == NULL, ("sodealloc(): so_pcb != NULL"));

SOCKBUF_COND_DESTROY(&so->so_snd);
Expand All @@ -254,7 +254,7 @@ sofree(struct socket *so)
/* SS_NOFDREF unset in accept call. this condition seems irrelevant
* for __Userspace__...
*/
if (so->so_count != 0 ||
if (so->so_count > 0 ||
(so->so_state & SS_PROTOREF) || (so->so_qstate & SQ_COMP)) {
SOCK_UNLOCK(so);
ACCEPT_UNLOCK();
Expand Down
2 changes: 2 additions & 0 deletions usrsctplib/user_socketvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ void sofree(struct socket *so);

#define soref(so) do { \
SOCK_LOCK_ASSERT(so); \
KASSERT((so)->so_count >= 0, ("soref")); \
++(so)->so_count; \
SCTPDBG(SCTP_DEBUG_USR, "soref(%p) -> %d, %s:%s:%d\n", \
(so), (so)->so_count, \
Expand All @@ -417,6 +418,7 @@ void sofree(struct socket *so);
SCTPDBG(SCTP_DEBUG_USR, "sorele(%p) -> %d, %s:%s:%d\n", \
(so), (so)->so_count, \
__func__, __FILE__, __LINE__) \
(so)->so_count = -1; \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we actually do this, sofree() will return early, since so->so_count != 0 would be true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right; see my follow-up commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix merge conflict.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've rebased it.

sofree(so); \
} \
else { \
Expand Down
Loading