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

Make sure to call connection_is_allowed on xwayland sessions #2835

Closed
wants to merge 1 commit into from

Conversation

mariogrip
Copy link
Contributor

@mariogrip mariogrip commented Feb 14, 2023

As xwayland/x11 has no way of telling us gid uid so we get this by stat() its proc path

Note i return a nullptr if session is not allowed and then closes the xwayland session, but im not sure if this is the best way of doing this.

@mariogrip mariogrip marked this pull request as draft February 14, 2023 22:09
@@ -80,6 +84,11 @@ auto mf::XWaylandClientManager::session_for_client(pid_t client_pid) -> std::sha
}
else
{
if (!session_authorizer->connection_is_allowed({client_pid, getuid(), getgid()}))
Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming client_pid is sensible, there ought to be a way to get gid/uid from that. This seems clunky but...

struct stat proc_stat;
stat(std::format("/proc/{}", client_pid).c_str(), &proc_stat);
auto const uid = proc_stat.st_uid;
auto const gid = proc_stat.st_gid;

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 was considering the exact same thing, so i'll try to add this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented this, but did not use std::format as that require gcc 13++

As xwayland/x11 has no way of telling us gid uid we assume it's
the same as mir itself.
Comment on lines +92 to +94
stat(proc.c_str(), &proc_stat);
auto const uid = proc_stat.st_uid;
auto const gid = proc_stat.st_gid;
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably needs some error handling to avoid potentially reading uninitialized data

Comment on lines +698 to +701
if (!local_client_session) {
rejected = true;
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!local_client_session) {
rejected = true;
return;
}
if (!local_client_session)
{
rejected = true;
return;
}

Comment on lines +717 to +721
if (rejected) {
scene_surface_close_requested();
close();
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (rejected) {
scene_surface_close_requested();
close();
return;
}
if (rejected)
{
scene_surface_close_requested();
close();
return;
}

@AlanGriffiths
Copy link
Contributor

@mariogrip feel free to resubmit when the build errors, etc are addressed.

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.

None yet

2 participants