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

auth: Support sd-bus authentication pipelining #48

Closed
wants to merge 1 commit into from

Conversation

evan-a-a
Copy link

Since sd-dbus clients send the BEGIN before receiving OK, ensure that we look for both to come across the bus in either order.

Fixes #21

@evan-a-a evan-a-a force-pushed the fix_sdbus_clients branch 3 times, most recently from 4a39412 to 73acc2e Compare May 11, 2023 21:06
@evan-a-a
Copy link
Author

@alexlarsson or @smcv, can you take a look at this? I believe it solves the concerns present in #26. This change is important for flathub/com.microsoft.Edge#252 and other applications that rely on sd-bus.

Since sd-dbus clients send the BEGIN before receiving OK, ensure that
we look for both to come across the bus in either order.

Fixes flatpak#21
num_messages,
flags, cancellable, error);

if (num_read <= 0)
Copy link
Member

Choose a reason for hiding this comment

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

This feels a bit wrong. We're reading N bytes, but then get an error, so we throw away the N bytes and report just the error. Typically network code doesn't want to lose data like that. However, maybe in this case it is fine, as on error we stop everything. Should have a comment about it though.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, this isn't quite true. The code does handle G_IO_ERROR_WOULD_BLOCK. So, you need to handle a partial read that returns a WOULD_BLOCK and return the partial results. And then you need to remember for the next call whether you have seen the CR.

Copy link
Member

Choose a reason for hiding this comment

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

Honestly, Its probably best to just always return error only on the first byte read, and otherwise return what you read up to now.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch, I'll rework this.


if (!auth_line_is_valid (line_start, line_end))
return FIND_AUTH_END_ABORT;
gssize new_state = client->auth_state;
Copy link
Member

Choose a reason for hiding this comment

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

This code relies on the buffer being a complete line (and nothing more than a line). The later is now true, but if you handle errors per the above that is no longer true. So you would need to handle cases where the CRLF is not yet read.

@alexlarsson
Copy link
Member

It feels a bit lame to read a byte at a time. Thats quite a lot of syscalls... Did you look at how this affects the time spent on authentication?

Anyway, i would like @smcv to look at this too. He knows the dbus stuff best.

* the final line from the client
*/
static gssize
_my_g_socket_receive_message_safe (GSocket* socket,
Copy link
Member

Choose a reason for hiding this comment

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

I would call this something like _g_socket_receive_message_auth_line.

@alexlarsson
Copy link
Member

The reading of one line a time will also cause the writing to the proxy client to be split up, so the performance is not just in the number of read calls. It will become multiple "network packets" too.

@evan-a-a
Copy link
Author

It feels a bit lame to read a byte at a time. Thats quite a lot of syscalls... Did you look at how this affects the time spent on authentication?
The reading of one line a time will also cause the writing to the proxy client to be split up, so the performance is not just in the number of read calls. It will become multiple "network packets" too.

I agree, it's quite lame. Handling the over-read with the extra buffer management seems to be a "less clean" option to me. I actually based this on how gdbus' server code fixes the handling of sd-bus clients. In GNOME/glib@8f02681, they modified their code to only read one byte at a time, which prevents the over-read case. I didn't benchmark exactly how much this slows down the auth process, but I didn't notice any responsiveness issues in the one sd-bus client I tested. I can try to set up a test harness to collect some timing info.

@evan-a-a
Copy link
Author

Actually, after looking at the reference implementation, I have a better idea about how to tackle this while avoiding the single byte reads. I will work on that improvement.

@evan-a-a evan-a-a marked this pull request as draft May 23, 2023 23:07
@bilelmoussaoui
Copy link
Member

A variant of this has been merged in #54

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.

gets confused by sd-bus clients pipelining the SASL handshake
3 participants