Skip to content

MPU Flash write #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed

MPU Flash write #205

wants to merge 11 commits into from

Conversation

fvincenzo
Copy link
Collaborator

This PR depends on #54. Please do not merge directly.

The new patches are the last 3.

galak and others added 7 commits May 16, 2017 09:35
Since we now select HAS_DTS from the cortex-m Kconfig we don't need it
in 96b_carbon_nrf51_defconfig.

Signed-off-by: Kumar Gala <[email protected]>
As we now only support DTS for ARM based SoCs we can remove any
associated !HAS_DTS bits in Kconfig.  The Nordic NRF5 serial driver and
the ARM CMSDK APB serial drivers had Kconfig bits related to !HAS_DTS
builds.

Signed-off-by: Kumar Gala <[email protected]>
Update Cube version for STM32L4XX family
from version: V1.6.0
to version: V1.8.0

Add support for following soc:
stm32l496xx
stm32l4a6xx

Signed-off-by: Neil Armstrong <[email protected]>
Add configuration and dts for the STM32L496 SoC STM32L4 variant.

Signed-off-by: Neil Armstrong <[email protected]>
Add configuration, pinmux, dts and documentation for the STM32L496G
Discovery board based on the STM32L496AG SoC.

Signed-off-by: Neil Armstrong <[email protected]>
Add missing dts for STM32F407.

Signed-off-by: Neil Armstrong <[email protected]>
Add configuration, documentation, flash script, pinmux and dts for the
STM32F4DISCOVERY board.

Signed-off-by: Neil Armstrong <[email protected]>
@galak galak changed the title [Depends on: https://github.com/zephyrproject-rtos/zephyr/pull/54] Flash write MPU Flash write May 16, 2017
@galak galak self-assigned this May 16, 2017
@galak galak self-requested a review May 16, 2017 14:37
Copy link
Collaborator

@galak galak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you push to arm branch instead

@galak galak requested review from mbolivar and MaureenHelm May 16, 2017 14:38
config MPU_ALLOW_FLASH_WRITE
bool "Add MPU access to write to flash"
depends on NXP_MPU
default n
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for submitting this! It will really help us.

What do people think about making this option default y if FLASH or so?

That seems less surprising; by default, asking for both the flash driver and the MPU driver would result in a config with fewer pointy edges. User effort would only be needed to get the flash driver and to allow flash reads, but not writes. @galak pointed out that this is a confusing configuration whose utility is a bit unclear, so perhaps that setup should take more effort to create.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbolivar I agree with the approach.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, yes I agree. But I wonder if there are security implications? @agross-linaro

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default options should not make things less secure. I'd rather the user have to jump through 1 more hoop if they want to specifically allow this. That's my two cents.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you're saying that asking for the MPU driver means getting a maximally locked down configuration (that can still run code), and any relaxations should require additional knobs. Is that right?

If so, it's a different point on the security / convenience curve, but that seems reasonable to me.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds fine, my only complaint is the naming. I don't like options where you have DISABLE and say Y. It's negative logic. I'd rather have a ENABLE=y, so FLASH_ENABLE_WRITE_SUPPORT.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to chime in late here, but it sounds like we're going for a seemingly more secure, and definitely more surprising configuration.

Preventing writes to flash isn't really all that much of a security improvement. In order to actually have secure boot, the bootloader has to be protected by hardware. MPU is insufficient, because it is easy to break before it is set up and then just replace the main code.

Once the bootloader is running, there is no security issue with being able to write to the code space. The images must be signed in order to be bootable.

In addition, apps using the bootloader are going to want to do OTA, which will require flash writing.

I really don't see any scenario where the flash driver would be wanted, but writes not allowed to the flash device.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, at least the k6x devices mentioned in the commit text have the ability to write protect flash regions, which is what will be needed to actually provide secure boot in a meaningful way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last point, it seems that on NXP, just probing the flash driver requires write access, whether the app tries to write or not. It kind of makes having this selectable a moot point. If you enable the flash driver, with writes disabled, it faults before main is even reached.

@fvincenzo fvincenzo changed the base branch from master to arm May 16, 2017 15:13
@fvincenzo
Copy link
Collaborator Author

@galak pushed against arm branch.

@@ -46,6 +46,13 @@ single thread: :file:`prj_single.conf`:

$ make BOARD=v2m_beetle CONF_FILE=prj_single.conf run

To build the version that allows flash write, use the supplied configuration
file: :file:`prj_allow_flash_write.conf`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no such file (there are prj_allow_flash_write_mcux.conf and prj_allow_flash_write_stm32.conf). Maybe use the same notation you use in the example below prj_allow_flash_write_.conf and tell them what the means.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I will change it. Thanks

Copy link
Contributor

@dbkinder dbkinder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recommend fixing :file: reference to prj_allow_flash_write.conf

#if defined(CONFIG_MPU_ALLOW_FLASH_WRITE)
/* Required to initialize the flash driver */
#define REGION_RAM_ATTR (MPU_REGION_READ | MPU_REGION_WRITE | \
MPU_REGION_EXEC | MPU_REGION_SU)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should bring more attention to the fact that not only are we enabling flash write, but also execution from ram. Can you mention this explicitly in the commit message? Is there a better config name to indicate this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I will make it more clear. Thanks for pointing it out.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Maureen. I'd think about a more descriptive config name if that is easy to deal with. Otherwise just deal with it in the commit msg.

config MPU_ALLOW_FLASH_WRITE
bool "Add MPU access to write to flash"
depends on NXP_MPU
default n
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, yes I agree. But I wonder if there are security implications? @agross-linaro

@MaureenHelm MaureenHelm requested a review from agross-oss May 16, 2017 17:51
galak and others added 4 commits May 16, 2017 16:58
The stm32f4discovery was incorrectly named and should have been
stm32f4_disco.  Also added 96b_carbon_nrf51 that was missing from the
list.

Signed-off-by: Kumar Gala <[email protected]>
This patch adds the allow flash write CONFIG option to the NXP MPU
configuration in privileged mode.

Signed-off-by: Vincenzo Frascino <[email protected]>
This patch adds the allow flash write CONFIG option to the ARM MPU
configuration in privileged mode.

Signed-off-by: Vincenzo Frascino <[email protected]>
Signed-off-by: Michael Scott <[email protected]>
This patch adds a configuration file that tests Flash writes with MPU
enabled.

Signed-off-by: Vincenzo Frascino <[email protected]>
@galak galak added this to the v1.9 milestone May 17, 2017
@galak
Copy link
Collaborator

galak commented May 17, 2017

Do we have an example that can be added to this PR for the case in which we want to allow flash_read() to work but not flash_write()?

I feel like towards Andy's comment, that if we do allow for such an option, it would be DISABLE_WRITE_SUPPORT, and I'd think we'd make the API (flash_write) go away as part of it.

@galak galak force-pushed the arm branch 5 times, most recently from c52d348 to 41c85d8 Compare June 22, 2017 14:55
@galak galak force-pushed the arm branch 4 times, most recently from f3f7aad to a87804d Compare June 29, 2017 21:23
@d3zd3z d3zd3z mentioned this pull request Jun 30, 2017
@d3zd3z
Copy link
Collaborator

d3zd3z commented Jun 30, 2017

I've rebased these changes and put them in #654. We should close this PR and continue discussion there.

@galak galak force-pushed the arm branch 3 times, most recently from 0f36cad to 1bc2fdc Compare July 7, 2017 15:32
@galak galak force-pushed the arm branch 4 times, most recently from 0723c92 to 38db4ed Compare July 19, 2017 16:37
@mbolivar
Copy link
Contributor

Now that #654 has been approved, this should be closed.

@galak galak closed this Jul 26, 2017
@nashif nashif modified the milestones: v1.9, v1.9.0 Oct 3, 2017
nagineni pushed a commit to nagineni/zephyr that referenced this pull request Nov 20, 2017
[build] Added feature to analyze.sh to generate prj.conf options
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.

9 participants