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

Limit v4l2_loopback_write calls to (streaming) writers #477

Merged
merged 1 commit into from Jun 19, 2022

Conversation

BenBE
Copy link
Contributor

@BenBE BenBE commented Jun 17, 2022

Previously whenever someone called the write function on the loopback device
the device was put in a state where no further openers could request access
to write frames to the device. While the intention of this is correct it
was missing to also make that opener doing the write operation an writer.

When an opener releases its file descriptor this output capability is
usually restored due to the fact that there's only ever one writer and
that writer should have the opener->type set to WRITER. With the
unconditional update of the dev->ready_to_output field this invariant is
broken as a file descriptor starts with a opener->type of UNKNOWN. Thus
when performing a write operation followed by close to the file descriptor
the logic to restore the output capabilities does not trigger and the
output capability is lost.

Thus instead of aiding sloppy user-land programming and guessing what
the caller desires this patch makes the write operation more strict in
its preconditions by enforcing the file descriptor to belong to an
opener with type WRITER. Failure to adhere to this is indicated by
an explicit EINVAL error return, as write operations as a non-WRITER
should not be allowed.

Fixes: #470

Previously whenever someone called the write function on the loopback device
the device was put in a state where no further openers could request access
to write frames to the device. While the intention of this is correct it
was missing to also make that opener doing the write operation an writer.

When an opener releases its file descriptor this output capability is
usually restored due to the fact that there's only ever one writer and
that writer should have the opener->type set to WRITER. With the
unconditional update of the dev->ready_to_output field this invariant is
broken as a file descriptor starts with a opener->type of UNKNOWN. Thus
when performing a write operation followed by closing the file descriptor
the logic to restore the output capabilities does not trigger and the
output capability is lost.

Thus instead of aiding sloppy user-land programming and guessing what
the caller desires this patch makes the write operation more strict in
its preconditions by enforcing the file descriptor to belong to an
opener with type WRITER. Failure to adhere to this is indicated by
an explicit EINVAL error return, as write operations as a non-WRITER
should not be allowed.

Signed-off-by: Benny Baumann <BenBE@geshi.org>
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.

Missing VIDIOC_STREAMON may cause loss of V4L2_CAP_VIDEO_OUTPUT
2 participants