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

pagekitec: add patch to fix use after free leading to segfault #24982

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

plan44
Copy link

@plan44 plan44 commented Sep 17, 2024

Maintainer: Karl Palsson karlp@tweak.net.au
Compile tested: bcm27xx, Rpi3, 22.03.7
Run tested: bcm27xx, Rpi3, 22.03.7

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 copy.

Comment on lines +1 to +32
--- a/libpagekite/pkproto.c
+++ b/libpagekite/pkproto.c
Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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?

Copy link
Author

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.

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 <luz@plan44.ch>
@plan44 plan44 force-pushed the PR/pagekitec-fix-use-after-free branch from ad5d77c to ed379e5 Compare September 17, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants