Fix operator precedence and integer width in nv_dma_buf_mmap#1072
Open
maycuatroi1 wants to merge 1 commit intoNVIDIA:mainfrom
Open
Fix operator precedence and integer width in nv_dma_buf_mmap#1072maycuatroi1 wants to merge 1 commit intoNVIDIA:mainfrom
maycuatroi1 wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
Fix two bugs in nv_dma_buf_mmap(): 1. Operator precedence error in the outer for-loop condition at line 1344. The expression `i < (priv->num_objects && (addr < vma->vm_end))` evaluates the `&&` first, producing a boolean (0 or 1). This means the loop body executes at most once (when i == 0), regardless of num_objects. For multi-object DMA-buf exports, only the first object's ranges are mapped. The function returns success despite the incomplete mapping. Fix: `(i < priv->num_objects) && (addr < vma->vm_end)` 2. Integer truncation in `total_skip_size` (NvU32) which accumulates NvU64 range sizes. For DMA-bufs larger than 4GB, the offset calculation wraps around, causing incorrect range lookups. Fix: widen `total_skip_size` from NvU32 to NvU64.
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
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.
Summary
Fix two bugs in
nv_dma_buf_mmap()(kernel-open/nvidia/nv-dmabuf.c):1. Operator precedence error (line 1344)
The outer for-loop condition:
evaluates
&&first, producing a boolean0or1. The loop runs at most once (i < 1), regardless ofnum_objects.For multi-object DMA-buf exports, only the first object's ranges are mapped. The function returns success despite the incomplete mapping. Accessing the unmapped portion of the VMA causes SIGBUS.
Fix:
2. Integer truncation in
total_skip_size(line 1233)total_skip_sizeisNvU32but accumulatesNvU64range sizes. For DMA-bufs larger than 4 GB the offset wraps, causing incorrect range lookups in the page-mapping loop.Fix: widen from
NvU32toNvU64.Verification
Operator precedence bug confirmed with standalone C reproduction:
Integer truncation confirmed:
Test plan