NVIDIA / NVIDIA/edk2-nvidia

L4TLauncher: buffer overrun / crash in ReadAndroidStyleKernelPartition with encrypted images and 2KB signatures

Open
#161 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
145
Forks
66
PR merge metrics
No merged PRs in 30d

Description

Mostly caused by e6fd382 "fix: verify signature with alignment 4KB and 2KB" (first included in L4T R36.5.0) but originally sourced to 21ff46f "L4T Launcher: enable UEFI to load encrypted payloads from partition". These are the buggy lines:
https://github.com/NVIDIA/edk2-nvidia/blob/fd77facdc6252a394f66b9c8dbd35d7f0166fa73/Silicon/NVIDIA/Application/L4TLauncher/L4TLauncher.c#L2057-L2059

  1. SignatureOffset is aligned up to 4KB, which may be beyond DecryptedImageBufferSize when 2KB alignment was used to produce the image
  2. SignatureSize underflows and becomes extremely large
  3. CopyMem crashes due to a very large length parameter

There are also other issues here:

  1. ImageBufferSize should ideally be checked to ensure it is not larger than DecryptedImageBufferSize before any of this code runs. That could cause a similar buffer overrun just with a corrupted image.
  2. If there is even more than 4KB of padding at the end of the image, SignatureSize can become larger than the actual size of SignatureBuffer and cause a heap overrun.

Basically, SignatureSize should be clamped between 0 and the previous value of SignatureSize (4KB) on this line to resolve all issues.

The same issue exists in ReadAndroidStyleDtbPartition too, where SignatureSize can underflow:
https://github.com/NVIDIA/edk2-nvidia/blob/fd77facdc6252a394f66b9c8dbd35d7f0166fa73/Silicon/NVIDIA/Application/L4TLauncher/L4TLauncher.c#L2314

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 Silicon/NVIDIA/Application/L4TLauncher/L4TLauncher.c at ReadAndroidStyleKernelPartition around lines 2057-2059, then inspect ReadAndroidStyleDtbPartition around line 2314. Exercise encrypted images using 2KB signatures, plus corrupted images and images with extra padding; done means SignatureSize cannot underflow or exceed its buffer and neither path overruns or crashes.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
62/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.