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

alibabacloud: don't use ReadAll in metadata response read #22479

Closed
wants to merge 1 commit into from

Conversation

nebril
Copy link
Member

@nebril nebril commented Dec 1, 2022

This change limits how big metadata response can be to avoid leaking memory by potential attackers doctoring very big HTTP responses.

Signed-off-by: Maciej Kwiek maciej@isovalent.com

@nebril nebril added the release-note/misc This PR makes changes that have no direct user impact. label Dec 1, 2022
@nebril nebril requested a review from a team as a code owner December 1, 2022 12:10
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.12.5 Dec 1, 2022
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.10.18 Dec 1, 2022
@maintainer-s-little-helper maintainer-s-little-helper bot added this to Needs backport from master in 1.11.12 Dec 1, 2022
Comment on lines 73 to 82
respBytes := make([]byte, 0, resp.ContentLength)
_, err = reader.Read(respBytes)

if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
respBytes := make([]byte, 0, resp.ContentLength)
_, err = reader.Read(respBytes)
if err != nil {
respBytes := make([]byte, 0, resp.ContentLength)
n, err = reader.Read(respBytes)
if err != nil {
...
}
if n == bufferSize && respBytes[n-1] != EOF {
// Double buffersize and try again. If it still fails, log an error: "AlibabaCloud metadata buffer size too small in Please report to developers"
}

Is it worth checking if the last byte received is EOF, in the case the metadata payload size ever increases passed 1MB?

Copy link
Member Author

Choose a reason for hiding this comment

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

Might as well make the buffer 2MB then. Do you think 1MB is not enough for alibaba node metadata?

Copy link
Member

Choose a reason for hiding this comment

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

I just have no idea how much metadata could be returned. I'm interested to make Cilium more robust in case of failures where we've defined hard limits. I'd rather that we find a way to warn somehow when we've reached a limit, rather than just silently bomb out. I'm less concerned about the buffer size.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe what I'm saying here is that if we think 1MB is more than enough, then let's keep it at that. But let's also add the logic to detect if the metadata exceeded that buffer, and warn if so.

Copy link
Member Author

Choose a reason for hiding this comment

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

@christarazi As far as I could tell, all instances of getMetadata are logging the error returned from this call. I will add logging here, but am concerned this will cause the same error to be logged twice. On the other hand I agree that having the buffer be to small is a good thing to get fixed as soon as possible.

@christarazi christarazi marked this pull request as draft December 6, 2022 21:30
@christarazi christarazi added kind/enhancement This would improve or streamline existing functionality. area/alibaba Impacts Alibaba based IPAM. labels Dec 6, 2022
@christarazi
Copy link
Member

@nebril ping

This change limits how big metadata response can be to avoid
leaking memory by potential attackers doctoring very big HTTP responses.

Signed-off-by: Maciej Kwiek <maciej@isovalent.com>
@nebril nebril marked this pull request as ready for review December 7, 2022 11:04
Comment on lines +86 to +89
if _, err := reader.ReadByte(); err == nil {
log.Error("Buffer size too small. Please report to developers")
return "", io.ErrShortBuffer
}
Copy link
Member

Choose a reason for hiding this comment

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

Why are we checking for nil error? I don't think I'm understanding

Copy link
Member Author

Choose a reason for hiding this comment

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

My initial implementation was wrong, I assumed that buffered reader would return error if the size of buffer would be exceeded which ended up not being the case.

ReadByte returns error if there is no new byte to read. err == nil means that there are more bytes to read, which means that the response is bigger than 1MB, so we log an error and return.

@aanm aanm added the needs-backport/1.13 This PR / issue needs backporting to the v1.13 branch label Dec 9, 2022
@christarazi
Copy link
Member

christarazi commented Dec 9, 2022

It seems like #22602 is a more generic solution to the problem this PR is solving. Should we prefer that PR @nebril?

@nebril
Copy link
Member Author

nebril commented Dec 12, 2022

Superseded by #22602

@nebril nebril closed this Dec 12, 2022
@aanm
Copy link
Member

aanm commented Dec 12, 2022

@christarazi @nebril Maybe we should keep this one open because we would like to backport this to all branches.

@joestringer joestringer added this to Needs backport from master in 1.10.19 Dec 15, 2022
@joestringer joestringer removed this from Needs backport from master in 1.10.18 Dec 15, 2022
@joestringer joestringer added this to Needs backport from master in 1.11.13 Dec 15, 2022
@joestringer joestringer removed this from Needs backport from master in 1.11.12 Dec 15, 2022
@joestringer joestringer removed this from Needs backport from master in 1.12.5 Dec 15, 2022
@joestringer joestringer removed the needs-backport/1.13 This PR / issue needs backporting to the v1.13 branch label Dec 22, 2022
@joestringer joestringer removed this from Needs backport from master in 1.10.19 Dec 22, 2022
@michi-covalent michi-covalent added this to Needs backport from master in 1.11.14 Jan 26, 2023
@michi-covalent michi-covalent removed this from Needs backport from master in 1.11.13 Jan 26, 2023
@joestringer joestringer added this to Needs backport from master in 1.11.15 Feb 13, 2023
@joestringer joestringer removed this from Needs backport from master in 1.11.14 Feb 13, 2023
@nebril nebril added this to Needs backport from master in 1.11.16 Mar 10, 2023
@nebril nebril removed this from Needs backport from master in 1.11.15 Mar 10, 2023
@michi-covalent michi-covalent added this to Needs backport from master in 1.11.17 Apr 14, 2023
@michi-covalent michi-covalent removed this from Needs backport from master in 1.11.16 Apr 14, 2023
@jrajahalme jrajahalme added this to Needs backport from main in 1.11.18 May 12, 2023
@jrajahalme jrajahalme removed this from Needs backport from main in 1.11.17 May 12, 2023
@michi-covalent michi-covalent added this to Needs backport from main in 1.11.19 Jun 14, 2023
@michi-covalent michi-covalent removed this from Needs backport from main in 1.11.18 Jun 14, 2023
@gentoo-root gentoo-root added this to Needs backport from main in 1.11.20 Jul 26, 2023
@gentoo-root gentoo-root removed this from Needs backport from main in 1.11.19 Jul 26, 2023
@nebril nebril added this to Needs backport from main in 1.11.21 Aug 10, 2023
@nebril nebril removed this from Needs backport from main in 1.11.20 Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/alibaba Impacts Alibaba based IPAM. kind/enhancement This would improve or streamline existing functionality. release-note/misc This PR makes changes that have no direct user impact.
Projects
No open projects
1.11.21
Needs backport from main
Development

Successfully merging this pull request may close these issues.

None yet

4 participants