-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix segmentation fault in vlog.Read #1150
Merged
Merged
Conversation
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
jarifibrahim
requested review from
ashish-goswami,
manishrjain and
a team
as code owners
December 9, 2019 14:21
manishrjain
approved these changes
Dec 10, 2019
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.
Reviewed 1 of 1 files at r1.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @ashish-goswami)
jarifibrahim
pushed a commit
that referenced
this pull request
Mar 12, 2020
This commit fixes the segmentation fault in header.Decode that would happen if we tried to read from a file that was mmapped but didn't actually have any data in it. This commit fixes the issue by checking the read is within the actual file size. See #1150 for all the details. Fixes #1136 and #1131 (cherry picked from commit 7c5e6d7)
manishrjain
pushed a commit
to outcaste-io/outserv
that referenced
this pull request
Jul 6, 2022
This commit fixes the segmentation fault in header.Decode that would happen if we tried to read from a file that was mmapped but didn't actually have any data in it. This commit fixes the issue by checking the read is within the actual file size. See hypermodeinc/badger#1150 for all the details. Fixes hypermodeinc/badger#1136 and hypermodeinc/badger#1131
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #1136 and #1131
The problem
In both the reported issues the segmentation fault would occur after
vlog.DropAll
(or if the log file was deleted). In case of dropAll, here's how we delete fileshttps://github.com/dgraph-io/badger/blob/8b99eb433aa799029b2e4cecc3c6e9b19c527490/value.go#L739-L757
At the same time, there could be a read on the same vlog file. Here's the code that reads from the file
https://github.com/dgraph-io/badger/blob/8b99eb433aa799029b2e4cecc3c6e9b19c527490/value.go#L1411-L1419
The problem occurs if we try to access the
buf
returned byreadValueBytes
. There is a window in which if we try to access thebuf
, we get a segmentation fault.The following sequence of events would cause the segmentation fault.
vlog.Read
is called and the control is at line 1411https://github.com/dgraph-io/badger/blob/8b99eb433aa799029b2e4cecc3c6e9b19c527490/value.go#L1411-L1419
vlog.DropAll
is called at the same time.vlog.DropAll
completes while the control is at line 1411 invlog.Read
. This essentially means all the log files are deleted and a newvlog0
file is created. This file has afmap
(mmap buffer) of2 GB
and the file size is0
bytes (since we haven't written anything)vlog.Read
andheader.Decode
(which is were the buf accessed for the first time) crashes with Segmentation fault (SIGBUS
error). As mentioned in comment Fix value logdropAll
race condition #1140 (comment), theSIGBUS
occurs when we try to access a mmap buffer which is beyond the actual file size.With the following changes, I was able to reproduce the segmentation fault. Notice that we stop the execution at
line 1411
invlog.Read
untilDropAll
completes.This change is