Skip to content

recvmsg: compute cmsg nexthdr end without firsthdr#1583

Open
rootvector2 wants to merge 1 commit into
axboe:masterfrom
rootvector2:recvmsg-cmsg-nexthdr-end
Open

recvmsg: compute cmsg nexthdr end without firsthdr#1583
rootvector2 wants to merge 1 commit into
axboe:masterfrom
rootvector2:recvmsg-cmsg-nexthdr-end

Conversation

@rootvector2
Copy link
Copy Markdown
Contributor

Noticed io_uring_recvmsg_cmsg_nexthdr() computes the cmsg region end as
io_uring_recvmsg_cmsg_firsthdr(o, msgh) + o->controllen. firsthdr
returns NULL when o->controllen < sizeof(struct cmsghdr), so this
becomes a non-zero offset applied to a null pointer, which is undefined
behavior. Compute end directly as name + namelen + controllen so the
arithmetic is always on a real pointer; the value matches the old
expression when firsthdr would have succeeded.

In io_uring_recvmsg_cmsg_nexthdr() the cmsg region end is computed as
io_uring_recvmsg_cmsg_firsthdr(o, msgh) + o->controllen.  firsthdr
returns NULL when o->controllen < sizeof(struct cmsghdr), and the
addition becomes a non-zero offset applied to a null pointer, which is
undefined behavior.

Compute end directly as name + namelen + controllen so the arithmetic
is always on a real pointer.  The value is identical to the old
expression when firsthdr would have succeeded, and the function still
returns NULL for any cmsg that does not fit in the cmsg region.

Signed-off-by: rootvector2 <dxbnaveed.k@gmail.com>
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.

1 participant