Skip to content

Improve sshbuf defensive measures#287

Closed
stoeckmann wants to merge 2 commits into
openssh:masterfrom
stoeckmann:sshbuf
Closed

Improve sshbuf defensive measures#287
stoeckmann wants to merge 2 commits into
openssh:masterfrom
stoeckmann:sshbuf

Conversation

@stoeckmann

Copy link
Copy Markdown
  • Keep track of reference count even if parent is set multiple times
  • Gracefully handle failed re-allocation in sshbuf_reset

Shoutout to @c3h2_ctf

This situation cannot be reached currently, so it should be a
purely defensive measure.
If recallocarray fails in sshbuf_reset, then it could happen that
SSHBUF_SIZE_INIT bytes are not available, which would lead to an
out of boundary access with explicit_bzero.

Check return value of sshbuf_check_sanity to comply with other
sshbuf functions and gracefully handle failed re-allocation.
Comment thread sshbuf.c
(r = sshbuf_check_sanity(parent)) != 0)
return r;
if (child->parent != NULL)
child->parent->refcount--;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think it makes sense for a child buffer to be "re-parented".

IMO we it would be better to explicitly disallow this, e.g.

        if (child->parent != NULL && child->parent != parent)
                return SSH_ERR_INTERNAL_ERROR;

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, in that case it makes sense to treat it as internal error.

@djmdjm

djmdjm commented Apr 8, 2022

Copy link
Copy Markdown
Contributor

Thanks - these have been applied and will be in OpenSSH 9.1

@djmdjm djmdjm closed this Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants