-
-
Notifications
You must be signed in to change notification settings - Fork 269
libpcp: fix stack buffer overflow in __pmLogLoadMeta pmDesc name read #2682
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
Open
xiejing-dev
wants to merge
1
commit into
performancecopilot:main
Choose a base branch
from
xiejing-dev:fix-logmeta-desc-name-overflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+99
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| #!/bin/sh | ||
| # PCP QA Test No. 2110 | ||
| # Verify a crafted archive with an oversized pmDesc name length is rejected | ||
| # gracefully by __pmLogLoadMeta, instead of overflowing the fixed stack | ||
| # buffer name[MAXPATHLEN] in src/libpcp/src/logmeta.c. | ||
| # | ||
| # Copyright (c) 2026 KylinSoft Co., Ltd. All Rights Reserved. | ||
| # | ||
|
|
||
| seq=`basename $0` | ||
| echo "QA output created by $seq" | ||
|
|
||
| # get standard environment, filters and checks | ||
| . ./common.product | ||
| . ./common.filter | ||
| . ./common.check | ||
|
|
||
| command -v python3 >/dev/null 2>&1 || _notrun "python3 not installed" | ||
|
|
||
| _cleanup() | ||
| { | ||
| cd $here | ||
| $sudo rm -rf $tmp $tmp.* | ||
| } | ||
|
|
||
| _filter() | ||
| { | ||
| sed -e "s@$tmp@TMP@g" | ||
| } | ||
|
|
||
| status=1 # failure is the default! | ||
| trap "_cleanup; exit \$status" 0 1 2 3 15 | ||
|
|
||
| # real QA test starts here | ||
| # | ||
| # Build a malformed archive from a valid one: in the first TYPE_DESC | ||
| # metadata record, set the name length field to 8192 (> MAXPATHLEN, 4096) | ||
| # and pad with that many bytes. Without the bounds check in | ||
| # __pmLogLoadMeta(), the subsequent | ||
| # __pmFread(name, 1, len, f); name[len] = '\0'; | ||
| # overflows name[MAXPATHLEN] on the stack (observed: "stack smashing | ||
| # detected" / SIGABRT). With the fix, loading is rejected with | ||
| # PM_ERR_LOGREC ("Corrupted record in a PCP archive") and no crash. | ||
| # | ||
| python3 - "$tmp/evil" <<'EOF' | ||
| import struct, shutil, sys | ||
| src = "archives/19970807.09.54" | ||
| dst = sys.argv[1] | ||
| BE = ">i" | ||
| def be(x): return struct.pack(BE, x) | ||
| EVIL = 8192 # >> MAXPATHLEN (4096) | ||
| meta = open(src + ".meta", "rb").read() | ||
| label_total = struct.unpack(BE, meta[0:4])[0] | ||
| label = meta[0:label_total] | ||
| off = label_total | ||
| rec_len = struct.unpack(BE, meta[off:off+4])[0] | ||
| body = meta[off+8:off+rec_len] # pmDesc + numnames + name[len] + trailer | ||
| pmDesc = body[0:20] | ||
| numnames = struct.unpack(BE, body[20:24])[0] | ||
| new_body = pmDesc + be(numnames) + be(EVIL) + (b"A" * EVIL) | ||
| new_rec_len = 8 + len(new_body) + 4 # header + body + trailer | ||
| new_rec = be(new_rec_len) + be(1) + new_body + be(new_rec_len) | ||
| open(dst + ".meta", "wb").write(label + new_rec) | ||
| shutil.copyfile(src + ".0", dst + ".0") | ||
| shutil.copyfile(src + ".index", dst + ".index") | ||
| EOF | ||
|
|
||
| echo "=== pmlogcheck (must not crash) ===" | ||
| pmlogcheck $tmp/evil 2>&1 | _filter | ||
|
|
||
| echo | ||
| echo "=== pminfo -a (must not crash) ===" | ||
| pminfo -a $tmp/evil 2>&1 | _filter | ||
|
|
||
| # success, all done | ||
| status=0 | ||
| exit | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| QA output created by 2110 | ||
|
|
||
| === pmlogcheck (must not crash) === | ||
| pmlogcheck: cannot open archive "TMP/evil": Corrupted record in a PCP archive | ||
| Checking abandoned. | ||
|
|
||
| === pminfo -a (must not crash) === | ||
| pminfo: Cannot open archive "TMP/evil": Corrupted record in a PCP archive |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.