-
Notifications
You must be signed in to change notification settings - Fork 844
LogAccessHttp init strlen to 0, not -1 (master) #2102
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
LogAccessHttp init strlen to 0, not -1 (master) #2102
Conversation
jpeach
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the git user.name:
From: Unknown <acanary@yahoo-inc.com>
|
This has to go on the 7.1.x branch too ? |
|
[approve ci] |
|
Yahoo doesn't need it ported to 7.1, given that is only a rare logging error that only we are seeing. I am looking into back porting to 5.3, because that is where the issue was discovered by our analysis team. unknown user.name... I'm a git newb. |
|
On Jun 8, 2017, at 1:47 PM, a-canary ***@***.***> wrote:
Yahoo doesn't need it ported to 7.1, given that is only a rare logging error that only we are seeing. I am looking into back porting to 5.3, because that is where the issue was discovered by our analysis team.
unknown user.name... I'm a git newb.
|
dceb724 to
c336517
Compare
|
User name fixed |
|
Given that this is a write to unallocated memory, is it a potential security issue that should be fixed in latest version as well? |
|
It is not a security issue because it is contained to the log buffer memory, and output. Specifically this case it is writing past the end of it's allocated log buffer by 1 byte. It would write "-", a second thread would allocate and write that same address, then the first thread would flush the log buffer to a file, and the "-" is replaced with a random character. |
| for (LogField *f = first(); f; f = next(f)) { | ||
| if (f->type() != LogField::sINT) { | ||
| bytes += f->marshal_len(lad); | ||
| const int len = f->marshal_len(lad); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't adding a check on len > 0 here and not add it to bytes also work? This way you wouldn't have to set m_cache_lookup_url_canon_str or have INVALID_STR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The core of the problem was LogAccessHttp.cc:ln487,
len = round_strlen(m_client_req_unmapped_url_host_len + 1); // +1 for eos
When m_client_req_unmapped_url_host_len is -1, len is set to 0.
And strlen of -1 is kind of gross way to indicate that can't resolve the host name. In the future we would like to change all these to StringView, so this nudges us in that direction.
This assert is just to ensure no other code paths where having the same issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not seeing that in the code on master round_strlen(m_client_req_unmapped_url_host_len + 1);. What line are you referring to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you are referring to the ATS 5.3.x branch in your comment above. This looks like it has been resolved on master and 7.1.x. Please confirm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like commit 9399a76 patched this particular place (for TS-3841).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you're suggesting, Bryan, is different from the ink_release_assert on line 776 here. len shouldn't just be greater than zero, it should be at least INK_MIN_ALIGN.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am stating this is not an issue for master and 7.1.x, if you want to add an assert that is OK, but is it not required. I would keep what is in LogField.cc and get rid of the rest of the changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the only logging anomaly we are seeing so I suspect it is in fact an issue elsewhere. I would rather do a basic fix rather than patching after the fact.
|
My view is that |
| for (LogField *f = first(); f; f = next(f)) { | ||
| if (f->type() != LogField::sINT) { | ||
| bytes += f->marshal_len(lad); | ||
| const int len = f->marshal_len(lad); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am stating this is not an issue for master and 7.1.x, if you want to add an assert that is OK, but is it not required. I would keep what is in LogField.cc and get rid of the rest of the changes.
|
The main issues I have with this PR:
|
|
The invalid string is not expected to be printed. It is merely a non-null address so that validation does not run multiple times. In the case that lookup url or canon host fails to resolve, the _len remains 0, thus the default "-" is printed in marshal_mem. |
|
I just pushed another commit to address the concerns above. Please review. Susan is testing this on one of the ats 7 production (test) boxes. So far so good. |
|
It has survived a night in the wild. Are there any remaining concerns? |
Code was using -1 string length to signify that had not been validated yet. This caused marshal_mem to allocate 0 bytes, below the INK_MIN_ALIGN, and write to unallocated mem. Now code initializes all string length vars to 0, and upon failure to validate, the string ptr is set to INVALID_STR to prevent multiple validataions attempts. Fixes YTSATS-1240 + Removed const_cast on INVALID_STR + removed len < 0 checks. + Replaced 0 >= len checks with str == INVALID_STR format
8d6fad3 to
ed5a260
Compare
|
Fixed format and squashed. It is ready to go now. |
Aaron fixed his email problem and the commit data is good now.
Code was using -1 string length to signify that had not been validated yet. This caused marshal_mem to allocate 0 bytes, below the INK_MIN_ALIGN, and write to unallocated mem.
Now code initializes all string length vars to 0, and upon failure to validate, the string ptr is set to INVALID_STR to prevent multiple validataions attempts.
Fixes YTSATS-1240