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

Enumerate input/graphics devices with udev #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

djpohly
Copy link
Contributor

@djpohly djpohly commented Jan 30, 2022

We can query udev to get a list of devices more reliably and simply. For example, the previous code does not detect controllers unless the joydev module (old API) is loaded, whereas udev has already labeled the correct event*, input*, and js* devices with ID_INPUT_JOYSTICK.

The same approach can probably be used for video/media devices, but I didn't feel as confident with how to make that change.

The added pyudev dependency is documented in the README.

We can query udev to get a list of devices more reliably and simply.
For example, the previous code does not detect controllers unless the
joydev module (old API) is loaded, whereas udev has already labeled the
correct event*, input*, and js* devices with ID_INPUT_JOYSTICK.

The same approach can probably be used for video/media devices, but I
didn't feel as confident with how to make that change.

The added pyudev dependency is documented in the README.
@igo95862
Copy link
Owner

igo95862 commented Jan 30, 2022

Thank you for submitting this Pull Request.

The code is definitely much cleaner with udev.

However, I don't really like the pyudev as it lacks modern python features such as typing and asyncio.

I think creating new ctype binds for libudev would be better. There are already separated binds for libseccomp instead of Cython based upstream ones.

I will add this to the TODO list.

@djpohly
Copy link
Contributor Author

djpohly commented Jan 30, 2022

I don't think bubblejail would need any I/O calls where asyncio would make a difference. Maybe we could submit a typing PR to the pyudev project? :)

@igo95862
Copy link
Owner

I don't think bubblejail would need any I/O calls where asyncio would make a difference.

I am planning on adding dynamic hardware binds. For example, a controller gets plugged and it would be nice if it becomes available in sandbox without restarting. Libudev lets you watch a file descriptor and look for new devices. pyudev only has sync methods and not integrated with asyncio.

@djpohly
Copy link
Contributor Author

djpohly commented Feb 1, 2022

That sounds cool, but will bwrap allow anything to add binds after it is already running?

@igo95862
Copy link
Owner

igo95862 commented Feb 2, 2022

That sounds cool, but will bwrap allow anything to add binds after it is already running?

You can access the namespaces under the /proc/[pid]/ns/ folder. I will need to make a big investigation in to this. Right now nsenter only works when running as root.

@igo95862
Copy link
Owner

I opened two issues on pyudev github about asyncio and typing.

pyudev/pyudev#449

pyudev/pyudev#450

Lets see if it gets any traction.

@igo95862
Copy link
Owner

igo95862 commented May 9, 2022

Looks like upstream is not interested.

Also libudev is actually deprecated. The replacement is sd-device component of libsystemd. Since my D-Bus library is based on libsystemd already might as well add the sd-device component. (elogind for Alpine Linux also supports that)

@djpohly
Copy link
Contributor Author

djpohly commented May 9, 2022

Good to know. I still suspect it's unlikely on the bwrap side as well. With its focus on security and simplicity, allowing dynamic changes once the sandbox is established sounds like something they'd consider a bug.

@igo95862
Copy link
Owner

igo95862 commented May 9, 2022

I still suspect it's unlikely on the bwrap side as well. With its focus on security and simplicity, allowing dynamic changes once the sandbox is established sounds like something they'd consider a bug.

I thought about that and I think I know the solution: two stage sandbox. Bubblewrap would be the second stage and would just use --dev-bind on virtual /sys and /dev that the first stage would create. First stage would not use pivot_root so it would have access to both file trees and will be able to bind new devices from outside.

@igo95862
Copy link
Owner

igo95862 commented Mar 2, 2023

New mount API provides a very easy way to create new bind mounts inside namespace: https://brauner.io/2023/02/28/mounting-into-mount-namespaces.html

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