-
Notifications
You must be signed in to change notification settings - Fork 18.6k
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
Validate arguments for ps
in docker top
#24358
Conversation
Thanks @AkihiroSuda ping @justincormack @nathanmcauley PTAL |
ping @NathanMcCauley PTAL |
"strconv" | ||
"strings" | ||
|
||
"github.com/docker/engine-api/types" | ||
) | ||
|
||
func validatePSArgs(psArgs string) error { | ||
re := regexp.MustCompile("-o\\s*(.*)=\\s*PID") | ||
group := re.FindStringSubmatch(psArgs) |
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 quite sufficient, as the header parsing is using strings.Fields
and that parses based on unicode whitespace, so you can do docker top d0b6b1e905ae ae -o uid= PID -o command=COMMAND
with any unicode whitespace character between the =
and PID
. Changing the code to split strictly on ASCII spaces seems to be the best fix.
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.
In fact you can relabel the columns in several ways using UTF8 whitespace eg docker top 7a709f6ac6ae axe -o 'uid=UID PID' -o pid=COMMAND -o command=
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.
Thank you, I'll update PR
Thank you @justincormack @tonistiigi Test case for unicode space (U+2003, E2 80 83):
Test case for 'o':
|
Thanks! LGTM. |
As this is a security fix I added to the 1.12 milestone. |
// So we use fieldsASCII instead of strings.Fields in parsePSOutput. | ||
// See https://github.com/docker/docker/pull/24358 | ||
re := regexp.MustCompile("\\s+([^\\s]*)=\\s*PID") | ||
group := re.FindStringSubmatch(psArgs) |
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.
Because this only matches one time it would not catch -o pid=PID2 -o uid=PID
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.
thank you, updated PR
Fix moby#24357 Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
"ae -O uid=PID": true, | ||
"ae -o pid=PID2 -o uid=PID": true, | ||
"ae -o pid=PID": false, | ||
"ae -o pid=PID -o uid=PIDX": true, // FIXME: we do not need to prohibit this |
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.
As there are no default names that match this it seems unimportant for now.
new version LGTM after @tonistiigi issue has been fixed. Will look at the test failures though. |
Test failures went away on rebuild, so green now. |
LGTM @diogomonica do you want to verify this as well? |
LGTM |
thanks @diogomonica. merging |
Fix breaking `docker top xxx m` backport from upstream fix: moby#30669 and dependent PR: moby#24358 Fix DTS: DTS2017070300837 See merge request docker/docker!635
- What I did
Fix #24357
- How I did it
Please look at
validatePSArgs
- How to verify it
Signed-off-by: Akihiro Suda suda.akihiro@lab.ntt.co.jp