Skip to content

Commit

Permalink
Merge #2120
Browse files Browse the repository at this point in the history
2120: arch/cortex-m3: Allow the kernel to access protected memory r=bradjc a=alistair23

### Pull Request Overview

Commit 128782d "mpu: Change the disable_mpu API" converted the
disable_app_mpu() function to not make any changes. This means when we
return from an app to the kernel we don't disable the MPU.

This resulted in some access failures when the kernel tried to access
direct write flash regions (#1873 (comment)).

We can either disable the MPU when returning to the kernel or change the
app MPU configuration permissions to not impact the kernel.

This patch converts the Cortex-M3 MPU implementation to always allow the
kernel access when configuring the app. This way we can avoid the
overhead of disabling the MPU on context switches. There is no security
gap here as the kernel could just disable the MPU anyway if it was
malicious.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

### Testing Strategy

None.

### TODO or Help Wanted

### Documentation Updated

- [X] Updated the relevant files in `/docs`, or no updates are required.

### Formatting

- [X] Ran `make prepush`.


Co-authored-by: Alistair Francis <alistair.francis@wdc.com>
  • Loading branch information
bors[bot] and alistair23 committed Sep 23, 2020
2 parents 295157f + 7542a1c commit 2502e00
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions arch/cortex-m3/src/mpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,18 @@ impl CortexMRegion {
RegionAttributes::AP::ReadWrite,
RegionAttributes::XN::Disable,
),
mpu::Permissions::ReadExecuteOnly => {
(RegionAttributes::AP::ReadOnly, RegionAttributes::XN::Enable)
}
mpu::Permissions::ReadExecuteOnly => (
RegionAttributes::AP::UnprivilegedReadOnly,
RegionAttributes::XN::Enable,
),
mpu::Permissions::ReadOnly => (
RegionAttributes::AP::ReadOnly,
RegionAttributes::AP::UnprivilegedReadOnly,
RegionAttributes::XN::Disable,
),
mpu::Permissions::ExecuteOnly => {
(RegionAttributes::AP::NoAccess, RegionAttributes::XN::Enable)
}
mpu::Permissions::ExecuteOnly => (
RegionAttributes::AP::PrivilegedOnly,
RegionAttributes::XN::Enable,
),
};

// Base address register
Expand Down

0 comments on commit 2502e00

Please sign in to comment.