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

Add detailed logging to libxrdp #1742

Merged
merged 34 commits into from
Feb 4, 2021

Conversation

aquesnel
Copy link
Contributor

@aquesnel aquesnel commented Dec 5, 2020

Follow up pull request from #1738 to add logs with more detailed information to the libxrdp code.

This code conflicts with #1738 and should therefore wait to to be merge until after #1738

TODO

@metalefty metalefty modified the milestone: v0.9.15 Dec 16, 2020
@metalefty
Copy link
Member

Removed v0.9.15 milestone based on discussion on gitter chat.
https://gitter.im/neutrinolabs/xrdp?at=5fd83fc091e8cb3e8c00b463

@aquesnel
Copy link
Contributor Author

I've rebased this change to devel, and it is now ready to be reviewed.
@matt335672 I'd like your feedback for this pull request.

@matt335672
Copy link
Member

Hi @aquesnel - I've started to review this, but I'm sure you appreciate it may take me a while! What you've done looks very thorough. Thanks for structuring it the way you have - it should help a lot.

@aquesnel
Copy link
Contributor Author

@matt335672 thank you for taking the time to review this big pull request.

That's a good point about this taking a lot of time just to review. I think for the next pull request like this I'll split the request by file instead of by directory so that it can be reviewed and merged incrementally.

Copy link
Member

@matt335672 matt335672 left a comment

Choose a reason for hiding this comment

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

Three things to say up-front:-

  • Absolutely the first thing to say; this is an amazing piece of work. The extra commenting you've added against the spec is a significant contribution in itself, in addition to all the work you've put in to the logging.
  • Second thing to say is, sorry it's taken me a while. I've tried to be thorough while balancing by xrdp time against the other issues we've had come in recently.
  • Thirdly, I haven't come across anything I'd regard as a show-stopper here. There are a couple of minor functional changes but they all look OK. If this gets merged as-is, it will be a major step forward in any case.

Virtually all of my comments are along the lines of a query as to whether something should be a LOG() or LOG_DEVEL(). The reasoning I've adapted is that if an error is returned which will drop the connection, it should be logged. I suspect that in a lot of these cases a static analysis will show that this happens anyway. I've not done that analysis myself - you may well have done. Please treat these comments as queries only.

I've got one other general comment; there's a lot of code along the lines of ;

if (!s_check_rem(s, <some val>))
        {
            LOG_DEVEL(LOG_LEVEL_ERROR, "Not enough bytes in the stream "
                      "len %d, remaining %d", <some_val>, s_rem(s));
            ...
        }

It might be worth considering factoring that out into a macro like s_check_rem_and_log()

#define s_check_rem_and_log(s, n) \
    ( ((s)->p + (n) <= (s)->end) ? 1 : log_insufficient_in_stream(s, n) )

where log_insufficient_in_stream() is a function call or another lightweight macro wrapper which returns 0.

Please challenge me on anything you think I'm being unreasonable about - and thanks again for a great piece of work!

libxrdp/xrdp_caps.c Outdated Show resolved Hide resolved
libxrdp/xrdp_caps.c Outdated Show resolved Hide resolved
libxrdp/xrdp_channel.c Outdated Show resolved Hide resolved
libxrdp/xrdp_iso.c Outdated Show resolved Hide resolved
libxrdp/xrdp_iso.c Outdated Show resolved Hide resolved
libxrdp/xrdp_orders_rail.c Outdated Show resolved Hide resolved
libxrdp/xrdp_orders_rail.c Outdated Show resolved Hide resolved
libxrdp/xrdp_orders_rail.c Outdated Show resolved Hide resolved
libxrdp/xrdp_orders_rail.c Outdated Show resolved Hide resolved
libxrdp/xrdp_orders_rail.c Outdated Show resolved Hide resolved
@aquesnel
Copy link
Contributor Author

@matt335672 thank for taking the time to look at the changes.

Somehow I had missed this comment last week. I'll take a deeper look and start to implement the feedback tomorrow.

@aquesnel
Copy link
Contributor Author

I've implemented s_check_rem_and_log and added a message prefix to say which field is currently being parsed that is causing the error.

@aquesnel
Copy link
Contributor Author

@matt335672 I've finished implement the feedback you suggested. Can you please take another look and let me know if there is any additional feedback before this can be merged?
Thanks

Copy link
Member

@matt335672 matt335672 left a comment

Choose a reason for hiding this comment

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

Few extra minor comments

libxrdp/xrdp_mcs.c Outdated Show resolved Hide resolved
libxrdp/xrdp_mcs.c Outdated Show resolved Hide resolved
libxrdp/xrdp_mcs.c Outdated Show resolved Hide resolved
libxrdp/xrdp_mcs.c Outdated Show resolved Hide resolved
LOG_DEVEL(LOG_LEVEL_ERROR, "MCS Protocol error: length too big. "
"max length %d, len %d", 16 * 1024, len);
LOG(LOG_LEVEL_ERROR,
"Parsing [ITU-T T.125] Connect-Initial userData: length too big. "
Copy link
Member

Choose a reason for hiding this comment

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

Suggest 'invalid' rather than 'too big', as <=0 could be an error value too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Member

Choose a reason for hiding this comment

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

Could still be <= 0. Suggest 'invalid' rather than 'too big'.

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 don't think this diff got updated when I pushed commit a736ac1 where I changed the message to say "invalid length"

https://github.com/neutrinolabs/xrdp/pull/1742/files?file-filters%5B%5D=.c#diff-03b1c835c3224786c0616fdd06554b40997d7f3f5d4cdf0cc233b3a653738e3bR488

libxrdp/xrdp_rdp.c Outdated Show resolved Hide resolved
libxrdp/xrdp_rdp.c Show resolved Hide resolved
@@ -920,38 +1039,35 @@ xrdp_sec_process_logon_info(struct xrdp_sec *self, struct stream *s)
self->rdp_layer->client_info.directory);
LOG(LOG_LEVEL_DEBUG, "Client supplied domain: %s", self->rdp_layer->client_info.domain);
LOG(LOG_LEVEL_DEBUG, "Client supplied username: %s", self->rdp_layer->client_info.username);
LOG(LOG_LEVEL_DEBUG, "Client supplied password: ommitted from the log");
LOG(LOG_LEVEL_DEBUG, "Client supplied password: <ommitted from log>");
Copy link
Member

Choose a reason for hiding this comment

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

ommitted -> omitted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Member

Choose a reason for hiding this comment

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

I meant it's a spelling mistake. Should be 'omitted' rather than 'ommitted'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@matt335672
Copy link
Member

@aquesnel - this is really great work!

I've just reviewed your additional changes. I'm out-of-time today, but tomorrow I'll go through our previous conversation and resolve things.

@aquesnel
Copy link
Contributor Author

@matt335672 I've implemented the feedback you gave me, and resolved conflicts with devel. I've give you a chance to look at the minimal changes that you recommended before I rebase or squash these changes.

@matt335672
Copy link
Member

Thanks for that - looks good. I've made a few comments in reply. I should be able to approve this in the next few days, then it's over to @metalefty

@metalefty
Copy link
Member

LGTM.

@matt335672 Feel free to merge this at your convenience.

@aquesnel
Copy link
Contributor Author

aquesnel commented Feb 4, 2021

@matt335672 I've implemented the suggestions you made. Please let me know if I missed anything.

Do you want me to squash the changes before you merge them?

@matt335672 matt335672 merged commit 0ec471b into neutrinolabs:devel Feb 4, 2021
@matt335672
Copy link
Member

That's fine - I've done a squash and merge. It results in a slightly cleaner git log.

Thanks again for this - it should make debugging quite a bit easier!

@aquesnel aquesnel deleted the logging_add_libxrdp branch February 7, 2021 20:22
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.

3 participants