Skip to content

nvme-print: fix sign extension in stdout_phy_rx_eom_descs() - #3823

Open
sahmed-ibm wants to merge 1 commit into
linux-nvme:masterfrom
sahmed-ibm:fix-nvme-print-stdout-sign-extension
Open

nvme-print: fix sign extension in stdout_phy_rx_eom_descs()#3823
sahmed-ibm wants to merge 1 commit into
linux-nvme:masterfrom
sahmed-ibm:fix-nvme-print-stdout-sign-extension

Conversation

@sahmed-ibm

Copy link
Copy Markdown
Contributor

The stdout_phy_rx_eom_descs() function computes a byte offset vsdataoffset by multiplying nrows and ncols, both uint16_t. C integer promotion rules first convert both operands to signed int before the multiply, making the product a 32-bit signed value. That signed result is then sign-extended to 64 bits when added to the sizeof() term, which is unsigned long.

If the product of nrows and ncols exceeds 0x7FFFFFFF, all upper bits of the offset become 1, producing an out-of-bounds pointer when desc is advanced by vsdataoffset.

Cast nrows to uint32_t before the multiply to force unsigned 32-bit arithmetic and prevent sign extension, and change the type of vsdataoffset from unsigned int to size_t to match its use as a pointer-arithmetic byte offset.

The stdout_phy_rx_eom_descs() function computes a byte offset
@vsdataoffset by multiplying @nrows and @NCols, both uint16_t.
C integer promotion rules first convert both operands to signed
int before the multiply, making the product a 32-bit signed
value. That signed result is then sign-extended to 64 bits when
added to the sizeof() term, which is unsigned long.

If the product of @nrows and @NCols exceeds 0x7FFFFFFF, all
upper bits of the offset become 1, producing an out-of-bounds
pointer when @desc is advanced by @vsdataoffset.

Cast @nrows to uint32_t before the multiply to force unsigned
32-bit arithmetic and prevent sign extension, and change the
type of @vsdataoffset from unsigned int to size_t to match its
use as a pointer-arithmetic byte offset.

Signed-off-by: Sarah Ahmed <sarah.ahmed@ibm.com>
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.

1 participant