-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
pagekitec: add patch to fix use after free leading to segfault #24982
Open
plan44
wants to merge
1
commit into
openwrt:master
Choose a base branch
from
plan44:PR/pagekitec-fix-use-after-free
base: master
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.
+46
−1
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 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
45 changes: 45 additions & 0 deletions
45
net/pagekitec/patches/0003-fix-use-after-free-in-pkproto.c.patch
This file contains 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,45 @@ | ||
From ef75e4d5e517ed12d6057b2211d401fa1ce84f4a Mon Sep 17 00:00:00 2001 | ||
From: Lukas Zeller <[email protected]> | ||
Date: Tue, 17 Sep 2024 00:53:40 +0200 | ||
Subject: [PATCH] pkproto.c: fix use-after-free that did cause pagekite to | ||
SIGSEGV occasionally, with higher probability on faster/multicore systems | ||
|
||
Observation: | ||
- programs using libpagekitec did crash with SIGSEGV on startup on RPi3,4 | ||
while having worked fine for years on RPi1+2 | ||
|
||
Explantation: | ||
- the final "judgement" test were done on pointers into the `copy` buffer | ||
freed on line 766 instead of on the safe copies of those strings in `kite` | ||
and `kite_r`. | ||
- this opened a very short race condition window, however the crash was | ||
caught happening while a tight loop (`pkb_start_blockers`) fired up 16 | ||
of those threads in rapid succession. | ||
So probably if the next thread got to allocate memory before the | ||
"judgements" tests, accessing the just freed `copy` would cause a segfault. | ||
|
||
Fix: | ||
- check the safe copies of the strings instead of pointers into freed `copy`. | ||
|
||
Signed-off-by: Lukas Zeller <[email protected]> | ||
--- | ||
libpagekite/pkproto.c | 6 +++--- | ||
1 file changed, 3 insertions(+), 3 deletions(-) | ||
|
||
diff --git a/libpagekite/pkproto.c b/libpagekite/pkproto.c | ||
index 3d4ccd6..4ee7e0f 100644 | ||
--- a/libpagekite/pkproto.c | ||
+++ b/libpagekite/pkproto.c | ||
@@ -766,9 +766,9 @@ char *pk_parse_kite_request( | ||
free(copy); | ||
|
||
/* Pass judgement */ | ||
- if ('\0' == *public_domain) return pk_err_null(ERR_PARSE_NO_KITENAME); | ||
- if ('\0' == *bsalt) return pk_err_null(ERR_PARSE_NO_BSALT); | ||
- if ('\0' == *fsalt) return pk_err_null(ERR_PARSE_NO_FSALT); | ||
+ if ('\0' == *(kite->public_domain)) return pk_err_null(ERR_PARSE_NO_KITENAME); | ||
+ if ('\0' == *(kite_r->bsalt)) return pk_err_null(ERR_PARSE_NO_BSALT); | ||
+ if ('\0' == *(kite_r->fsalt)) return pk_err_null(ERR_PARSE_NO_FSALT); | ||
return kite->public_domain; | ||
} | ||
|
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.
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 patch is part of upstream repository or it was sent to upstream?
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.
Not yet part of upstream, but I made a PR: pagekite/libpagekite#79
But as it is a total dealbreaker for pagekite remote maintainance when it hits (and it does for example on Rpi 3), I had to fix it for my builds immediately and independently of the upstream integration timeline, and decided sharing the openwrt level patch makes sense.
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.
Could you backport the patch from this url: https://patch-diff.githubusercontent.com/raw/pagekite/libpagekite/pull/79.patch ? I just added .patch to the URL and keep the patch as it is? I mean, it adds Git header to this current situation. The Git header includes important details like who created the patch, who does those changes, commit subject, commit description, etc?
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.
Hi @BKPepe, I just updated the PR so that the patch within does contain the git headers.
Originally I created the patch using quilt configured as recommended for the "preferred format", apparently this is out of sync with current recommended format. Of course it makes total sense to have the context in the patch itself and not only in the metapatch.