Skip to content

Conversation

@PaddyDengKC
Copy link
Contributor

Description

Instance->SfdpBasicFlash can be used before initializing.

Example code flow:

  • CreateSpiNorFlashSfdpInstance: Allocate pool for Instance

    • InitialSpiNorFlashSfdpInstance
      • ReadSfdp
        • ReadSfdpHeader
          • FillWriteBuffer: Dereferencing Instance->SfdpBasicFlash
        • ReadSfdpBasicParameterTable: Allocate pool for Instance->SfdpBasicFlash
  • Breaking change?

    • Breaking change - Does this PR cause a break in build or boot behavior?
    • Examples: Does it add a new library class or move a module to a different repo.
  • Impacts security?

    • Security - Does this PR have a direct security impact?
    • Examples: Crypto algorithm change or buffer overflow fix.
  • Includes tests?

    • Tests - Does this PR include any explicit test code?
    • Examples: Unit tests or integration tests.

How This Was Tested

Test with NULL Detection feature enabled, an exception was fixed by this code change.

Integration Instructions

NA

@tianocore-assign-reviewers
Copy link

WARNING: Cannot add some reviewers: A user specified as a reviewer for this PR is not a collaborator of the repository. Please add them as a collaborator to the repository so they can be requested in the future.

Non-collaborators requested:

Attn Admins:


Admin Instructions:

  • Add the non-collaborators as collaborators to the appropriate team(s) listed in teams
  • If they are no longer needed as reviewers, remove them from Maintainers.txt

@lgao4
Copy link
Contributor

lgao4 commented Apr 7, 2025

@PaddyDengKC , please refer to https://github.com/tianocore/tianocore.github.io/wiki/Commit-Message-Format to update the commit message.

@PaddyDengKC PaddyDengKC force-pushed the v-paddydeng/SpiNorFlashJedecSfdpNullDeref branch 2 times, most recently from 34bc9ad to a6bb5b8 Compare April 7, 2025 09:24
@PaddyDengKC
Copy link
Contributor Author

@PaddyDengKC , please refer to https://github.com/tianocore/tianocore.github.io/wiki/Commit-Message-Format to update the commit message.

@lgao4 Have updated the commit message. Sorry for the inconvenience.

@PaddyDengKC
Copy link
Contributor Author

Hi @lgao4 / @changab ,
Please help to approve the PR if no furture questions. Thank you!

@lgao4
Copy link
Contributor

lgao4 commented Apr 25, 2025

Hi @lgao4 / @changab , Please help to approve the PR if no furture questions. Thank you!

Seemly, other people still have feedback.

@lgao4

This comment was marked as abuse.

@lgao4 lgao4 closed this Apr 25, 2025
@lgao4 lgao4 reopened this Apr 25, 2025
@PaddyDengKC PaddyDengKC force-pushed the v-paddydeng/SpiNorFlashJedecSfdpNullDeref branch from bb24abb to edd74a3 Compare April 28, 2025 10:52
@slo2024
Copy link

slo2024 commented Apr 30, 2025

Hi @lgao4 @changab, please let us know if more comments, thanks.

@lgao4
Copy link
Contributor

lgao4 commented Apr 30, 2025

Hi @lgao4 @changab, please let us know if more comments, thanks.

What failure of CI build?

@PaddyDengKC PaddyDengKC force-pushed the v-paddydeng/SpiNorFlashJedecSfdpNullDeref branch 2 times, most recently from 6014601 to daf2892 Compare April 30, 2025 07:54
@slo2024
Copy link

slo2024 commented Apr 30, 2025

Hi @lgao4 @changab, please let us know if more comments, thanks.

What failure of CI build?

errors have been fixed, thanks. @lgao4

@changab
Copy link
Member

changab commented Apr 30, 2025

@apop5 , are you ok with the latest code change based on your feedback?

@PaddyDengKC PaddyDengKC force-pushed the v-paddydeng/SpiNorFlashJedecSfdpNullDeref branch 2 times, most recently from 7161e79 to 8fe13c9 Compare May 2, 2025 02:37
@apop5
Copy link
Contributor

apop5 commented May 2, 2025

@apop5 , are you ok with the latest code change based on your feedback?

Yes, I'm okay with the latest.

…ecSfdp

The pointer `Instance->SfdpBasicFlash` can be used before initializing.

Example code flow:
- CreateSpiNorFlashSfdpInstance: Allocate pool for `Instance`
    - InitialSpiNorFlashSfdpInstance
        - ReadSfdp
            - ReadSfdpHeader
                - FillWriteBuffer: Dereferencing
`Instance->SfdpBasicFlash`
            - ReadSfdpBasicParameterTable: Allocate pool for
`Instance->SfdpBasicFlash`

Check both `Instance` and `Instance->SfdpBasicFlash` should have
a non null value before dereferencing it. Otherwise use the defaut
value 0.

Also terminate the function if `Instance` or `WriteBuffer` is NULL.

Signed-off-by: Paddy Deng <v-paddydeng@microsoft.com>
@PaddyDengKC PaddyDengKC force-pushed the v-paddydeng/SpiNorFlashJedecSfdpNullDeref branch from 8fe13c9 to be15dd0 Compare May 2, 2025 03:00
@slo2024
Copy link

slo2024 commented May 5, 2025

@apop5 , are you ok with the latest code change based on your feedback?

please assist in reviewing the result, thanks. @lgao4 @changab

@lgao4
Copy link
Contributor

lgao4 commented May 5, 2025

@apop5 , are you ok with the latest code change based on your feedback?

please assist in reviewing the result, thanks. @lgao4 @changab

Done

@lgao4 lgao4 merged commit 2cff874 into tianocore:master May 5, 2025
124 checks passed
PaddyDengKC added a commit to PaddyDengKC/edk2 that referenced this pull request May 9, 2025
Fix false positive assert added in tianocore#10924
Functon `FillWriteBuffer()` should able to accept NULL WriteBuffer when
WriteBytes equals 0.

Use case:
```
  // Read Status register
  TransactionBufferLength = FillWriteBuffer (
                              Instance,
                              SPI_FLASH_RDSR,
                              SPI_FLASH_RDSR_DUMMY,
                              SPI_FLASH_RDSR_ADDR_BYTES,
                              FALSE,
                              0,
                              0, // WriteBytes = 0
                              NULL // WriteBuffer can be NULL
                              );

```

Signed-off-by: Paddy Deng <v-paddydeng@microsoft.com>
mergify bot pushed a commit that referenced this pull request May 26, 2025
Fix false positive assert added in #10924
Functon `FillWriteBuffer()` should able to accept NULL WriteBuffer when
WriteBytes equals 0.

Use case:
```
  // Read Status register
  TransactionBufferLength = FillWriteBuffer (
                              Instance,
                              SPI_FLASH_RDSR,
                              SPI_FLASH_RDSR_DUMMY,
                              SPI_FLASH_RDSR_ADDR_BYTES,
                              FALSE,
                              0,
                              0, // WriteBytes = 0
                              NULL // WriteBuffer can be NULL
                              );

```

Signed-off-by: Paddy Deng <v-paddydeng@microsoft.com>
GowthamM9974 pushed a commit to GowthamM9974/edk2 that referenced this pull request Jul 8, 2025
Fix false positive assert added in tianocore#10924
Functon `FillWriteBuffer()` should able to accept NULL WriteBuffer when
WriteBytes equals 0.

Use case:
```
  // Read Status register
  TransactionBufferLength = FillWriteBuffer (
                              Instance,
                              SPI_FLASH_RDSR,
                              SPI_FLASH_RDSR_DUMMY,
                              SPI_FLASH_RDSR_ADDR_BYTES,
                              FALSE,
                              0,
                              0, // WriteBytes = 0
                              NULL // WriteBuffer can be NULL
                              );

```

Signed-off-by: Paddy Deng <v-paddydeng@microsoft.com>
garybeihl pushed a commit to garybeihl/edk2 that referenced this pull request Aug 20, 2025
Fix false positive assert added in tianocore#10924
Functon `FillWriteBuffer()` should able to accept NULL WriteBuffer when
WriteBytes equals 0.

Use case:
```
  // Read Status register
  TransactionBufferLength = FillWriteBuffer (
                              Instance,
                              SPI_FLASH_RDSR,
                              SPI_FLASH_RDSR_DUMMY,
                              SPI_FLASH_RDSR_ADDR_BYTES,
                              FALSE,
                              0,
                              0, // WriteBytes = 0
                              NULL // WriteBuffer can be NULL
                              );

```

Signed-off-by: Paddy Deng <v-paddydeng@microsoft.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.

5 participants