Xilinx / Xilinx/embeddedsw

IPlib: spi: possible invalid SPI FIFO read

Open
#375 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
1.2k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

In the following SPI RX FIFO consumption while-loop:

https://github.com/Xilinx/embeddedsw/blob/1bb19ac1ab06ab322ba4340bed372f93ca612a18/XilinxProcessorIPLib/drivers/spi/src/xspi.c#L746-L783

As this function does not mandate the parameter ByteCount to be divisible by {1, 2, 4}-byte. It is possible that the caller can pass something like 5-byte to transmit/receive. If this is the case, then, when ByteCount (remaining bytes to receive) is nearing zero, and the DataWidth is not of XSP_DATAWIDTH_BYTE, a read can potentially consumes invalid byte(s).

Instead, would it be more robust to do something like "always test the remaining bytes to receive, and switch to XSP_DATAWIDTH_BYTE when ByteCount is less than the preset DataWidth" ? Or, we should simply add a "divisible by {1, 2, 4}-byte" check at function prologue?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in XilinxProcessorIPLib/drivers/spi/src/xspi.c at the SPI RX FIFO consumption loop around lines 746-783, and trace how ByteCount and DataWidth behave for non-divisible sizes such as 5 bytes. Determine the intended handling for the remaining bytes, then verify that the FIFO is not read beyond the requested count.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.