<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Protect RAM from unwanted writes</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/101578/protect-ram-from-unwanted-writes</link><description>Hi, 
 
 I&amp;#39;d like to have a memory region with some data that should only be written by some special functions, but can be read by the whole system. 
 This is to make sure that no bugs in other parts can accidentally corrupt this data. In previous projects</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 19 Jul 2023 09:13:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/101578/protect-ram-from-unwanted-writes" /><item><title>RE: Protect RAM from unwanted writes</title><link>https://devzone.nordicsemi.com/thread/437182?ContentTypeID=1</link><pubDate>Wed, 19 Jul 2023 09:13:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:46b8f0c8-2ba1-4a4a-a370-593bec98f0af</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>[quote user="colar"]While I agree that it can be accomplished user mode, I fear the overhead that comes with that. Every syscall would need magnitudes more cycles as it is demonstrated &lt;a title="Syscall performances" href="https://docs.zephyrproject.org/latest/samples/userspace/syscall_perf/README.html#syscall-performances"&gt;here&lt;/a&gt;. Since all my threads need some form of kernel objects like mutexes or dynamic memory and regularly need to access the shared memory this thread is about (and other shared memory exposed by APIs), I&amp;#39;m not sure if it&amp;#39;s worth the overhead as it&amp;#39;s a low power, battery powered system. Please correct me if I am wrong.[/quote]
&lt;p&gt;I agree that it is more overhead than using the SPU directly.&lt;/p&gt;
[quote user="colar"]This indeed generates a bus fault if writing to the protected memory region is not permitted. I chose the second way with a linker script snipped to add a memory region of size 8192 (size of memory region block of SPU) where only variables with &lt;code&gt;&lt;span style="font-family:courier new, courier;"&gt;__attribute__((section(&amp;quot;protected&amp;quot;)))&lt;/span&gt;&lt;/code&gt; should go. Is this the recommended way to add custom regions?[/quote]
&lt;p&gt;As long as you do not intend to use TrustZone for somehting else, such as TF-M at the same time, I think it sounds fine.&lt;/p&gt;
&lt;p&gt;And if you want to use TF-M after all, you can use TF-M for protected writes instead.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Sigurd Hellesvik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect RAM from unwanted writes</title><link>https://devzone.nordicsemi.com/thread/437056?ContentTypeID=1</link><pubDate>Tue, 18 Jul 2023 14:09:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:861cf41e-97a7-45fa-9d8b-9fe7213dbc58</guid><dc:creator>colar</dc:creator><description>&lt;p&gt;Hi Sigurd,&lt;/p&gt;
&lt;p&gt;thank you for your research.&lt;/p&gt;
&lt;hr /&gt;
&lt;h3 id="mcetoc_1h5kl4m3o5"&gt;MPU&lt;/h3&gt;
&lt;p&gt;So the nRF5340 does seem to have a MPU, though according to &lt;a title="Driver support overview" href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfx/drv_supp_matrix.html"&gt;Driver support overview&lt;/a&gt; the MPU HAL is not supported for the nRF5340. As you have demonstrated, it can be accessed and configured manually - but even if I would configure it, how would I enter priviledged mode then in Zephyr?&lt;/p&gt;
[quote userid="106736" url="~/f/nordic-q-a/101578/protect-ram-from-unwanted-writes/436994"]However, if the nRF Connect SDK also uses the MPU, you may get some conflicts using this method[/quote]
&lt;p&gt;With this in addition to the missing part of entering priviledged mode (if done manually could interfere with the OS), MPU may not be the right choice.&lt;/p&gt;
&lt;hr /&gt;
&lt;h3 id="mcetoc_1h5kl1phm3"&gt;User Mode&lt;/h3&gt;
[quote userid="106736" url="~/f/nordic-q-a/101578/protect-ram-from-unwanted-writes/436994"]Do you agree about my read on User Mode?[/quote]
&lt;p&gt;While I agree that it can be accomplished user mode, I fear the overhead that comes with that. Every syscall would need magnitudes more cycles as it is demonstrated &lt;a title="Syscall performances" href="https://docs.zephyrproject.org/latest/samples/userspace/syscall_perf/README.html#syscall-performances"&gt;here&lt;/a&gt;. Since all my threads need some form of kernel objects like mutexes or dynamic memory and regularly need to access the shared memory this thread is about (and other shared memory exposed by APIs), I&amp;#39;m not sure if it&amp;#39;s worth the overhead as it&amp;#39;s a low power, battery powered system. Please correct me if I am wrong.&lt;/p&gt;
&lt;hr /&gt;
&lt;h3 id="mcetoc_1h5kl221a4"&gt;SPU&lt;/h3&gt;
&lt;p&gt;In the meantime I managed to use the SPU to achieve what I was trying to:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;hal/nrf_spu.h&amp;gt;

/*
The protected region has to be defined and added to the linker script 
There are at least two options I found:
1. Add the following to the device tree (in an overlay file)

    protected_sram: sram@20060000 {  // Name doesn&amp;#39;t seem to matter
        compatible = &amp;quot;zephyr,memory-region&amp;quot;, &amp;quot;mmio-sram&amp;quot;;
        reg = &amp;lt; 0x20060000 0x2000 &amp;gt;;
        zephyr,memory-region = &amp;quot;protected&amp;quot;; // This will specify the name of the memory region AND the section
    };

2. Add the contents to the linker script with zephyr_linker_sources() (see zephyr/cmake/modules/extensions for the functions)
	In CMakeLists.txt: zephyr_linker_sources(RAM_SECTIONS custom_region.ld)
	In custom_region.ld:
		SECTION_PROLOGUE (protected, (NOLOAD), ALIGN(8192))
		{ 
			__protected_start = .;   
			KEEP(*(SORT_BY_NAME(&amp;quot;protected*&amp;quot;)))
			. = ALIGN(8192);
			__protected_end = .;
		} GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION) 
*/

extern uint16_t __protected_start;
extern uint16_t __protected_end;

__attribute__((section(&amp;quot;protected&amp;quot;))) static int testVar;
static int otherVars[1000];

int main(void)
{
	int regionNumber = ((uint32_t)&amp;amp;__protected_start - (uint32_t)_SRAM_BASE_ADDR) / 8192;
	printk(&amp;quot;Address of testvar: 0x%x, region no: %i, __protected_start=0x%x, __protected_end=0x%x, addr otherVars = 0x%x\n&amp;quot;, 
		&amp;amp;testVar, regionNumber, &amp;amp;__protected_start, &amp;amp;__protected_end, otherVars);

	testVar = 100;
	printk(&amp;quot;Written 100 to testvar\n&amp;quot;);

	// Should not change anything
	nrf_spu_ramregion_set(NRF_SPU_S, regionNumber, false, NRF_SPU_MEM_PERM_READ | NRF_SPU_MEM_PERM_WRITE, false);
	printk(&amp;quot;Set to r/w\n&amp;quot;);
	printk(&amp;quot;Testvar = %i\n&amp;quot;, testVar);
	testVar = 200;
	printk(&amp;quot;Written 200 to testvar\n&amp;quot;);

	// Now set it as read only
	nrf_spu_ramregion_set(NRF_SPU_S, regionNumber, false, NRF_SPU_MEM_PERM_READ, false);
	printk(&amp;quot;Set to ro\n&amp;quot;);
	printk(&amp;quot;Testvar = %i\n&amp;quot;, testVar); // Reading is okay, this will print
	testVar = 300;  // This will give a bus fault since this region is now protected by SPU to be read only
	printk(&amp;quot;Written 300 to testvar\n&amp;quot;); // We&amp;#39;ll never reach this point
	k_sleep(K_MSEC(1000));
	
	return 0;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This indeed generates a bus fault if writing to the protected memory region is not permitted. I chose the second way with a linker script snipped to add a memory region of size 8192 (size of memory region block of SPU) where only variables with &lt;code&gt;&lt;span style="font-family:courier new, courier;"&gt;__attribute__((section(&amp;quot;protected&amp;quot;)))&lt;/span&gt;&lt;/code&gt; should go. Is this the recommended way to add custom regions?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Lars&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect RAM from unwanted writes</title><link>https://devzone.nordicsemi.com/thread/436994?ContentTypeID=1</link><pubDate>Tue, 18 Jul 2023 11:58:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:26946f74-7c79-4e66-8167-7bc37562b831</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>[quote user="Sigurd Hellesvik"]When using the MPU as I did in the STM32, I would have to enable/disable priviledged mode. How would I do that in Zephyr?[/quote]
&lt;p&gt;From searching the internet, I found some docs for the MPU at &lt;a href="https://documentation-service.arm.com/static/5ef61f08dbdee951c1ccdd48"&gt;https://documentation-service.arm.com/static/5ef61f08dbdee951c1ccdd48&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Using the hello world sample, I can read out the MPU CTRL register:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/*
 * Copyright (c) 2012-2014 Wind River Systems, Inc.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include &amp;lt;zephyr/kernel.h&amp;gt;

int main(void)
{

  uint32_t i = MPU-&amp;gt;CTRL;

	printk(&amp;quot;Hello World! %d\n&amp;quot;, i);

  
	return 0;
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;for the nrf5340dk_nrf5340_cpuapp, this prints &amp;quot;5&amp;quot;, which seems to fit well with &amp;quot;4.2 MPU_CTRL&amp;quot; from the MPU docs above.&lt;br /&gt;Using the sampe method for MPU control would probably be the easiest and most direct way to do this.&lt;br /&gt;However, if the nRF Connect SDK also uses the MPU, you may get some conflicts using this method.&lt;/p&gt;
&lt;p&gt;For &amp;quot;The Zephyr way&amp;quot;:&lt;br /&gt; I realize that I did not hit the correct link previously with the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/hardware/arch/arm_cortex_m.html#memory-map-and-mpu-considerations"&gt;Memory map and MPU considerations&lt;/a&gt;. Now I see that this is more for the people writing Zephyr than actual users.&lt;/p&gt;
&lt;p&gt;Instead, I now think that &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/kernel/usermode/index.html"&gt;User Mode&lt;/a&gt; is what would be right: &amp;quot;Zephyr offers the capability to run threads at a reduced privilege level which we call user mode. The current implementation is designed for devices with MPU hardware.&amp;quot;.&lt;/p&gt;
&lt;p&gt;And especially the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/kernel/usermode/memory_domain.html#memory-protection-design"&gt;Memory Protection Design &lt;/a&gt;would probably be what you need.&lt;br /&gt;This is more complex, but I think it would be more &amp;quot;The Zephyr Way&amp;quot;.&lt;/p&gt;
&lt;p&gt;Do you agree about my read on User Mode?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect RAM from unwanted writes</title><link>https://devzone.nordicsemi.com/thread/436541?ContentTypeID=1</link><pubDate>Fri, 14 Jul 2023 14:53:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:06adb68b-8f5f-4d71-9ba8-ca1b342ee610</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>[quote user="colar"]so the nRF5340 actually has an MPU and a SPU? I thought, since it was not documented, only the SPU was available in this Chip (HAL may be for other chips?).[/quote]
&lt;p&gt;It is documented exactly here, as far as I know: &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/chapters/cpu/doc/cpu.html?cp=4_0_0_4_1_2#reference_ns1_fkb_2r"&gt;CPU and support module configuration&lt;/a&gt;.&lt;/p&gt;
[quote user="colar"]And when using the SPU, how would I then write to the protected memory? Simply temporarily disable the protection?[/quote]
&lt;p&gt;I think so yes. Might not be that easy, but probably worth a try.&lt;br /&gt;From SPU docs, I see they specify &amp;quot;For each region, permissions can be set and then locked to prevent subsequent modifications by using the &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/spu.html?cp=4_0_0_6_31_2#register.RAMREGION.PERM"&gt;RAMREGION[n].PERM&lt;/a&gt;.LOCK bit.&amp;quot;. &lt;br /&gt;This implies that as long as you do not lock this, you can change permissions.&lt;/p&gt;
[quote user="colar"]When using the MPU as I did in the STM32, I would have to enable/disable priviledged mode. How would I do that in Zephyr?[/quote]
&lt;p&gt;I will look into this and return with more info early next week.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect RAM from unwanted writes</title><link>https://devzone.nordicsemi.com/thread/436527?ContentTypeID=1</link><pubDate>Fri, 14 Jul 2023 14:18:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ede75cb3-de53-4678-b828-3255b44bd9c6</guid><dc:creator>colar</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote userid="106736" url="~/f/nordic-q-a/101578/protect-ram-from-unwanted-writes/436419"]In addition, have a look at Zephyrs &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/hardware/arch/arm_cortex_m.html#memory-map-and-mpu-considerations"&gt;Memory map and MPU considerations&lt;/a&gt;.&lt;br /&gt;Also see the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/arch/mpu/mpu_test/README.html"&gt;Memory Protection Unit (MPU) Sample&lt;/a&gt; for this.[/quote]
&lt;p&gt;so the nRF5340 actually has an MPU and a SPU? I thought, since it was not documented, only the SPU was available in this Chip (HAL may be for other chips?).&lt;/p&gt;
&lt;p&gt;When using the MPU as I did in the STM32, I would have to enable/disable priviledged mode. How would I do that in Zephyr?&lt;/p&gt;
[quote userid="106736" url="~/f/nordic-q-a/101578/protect-ram-from-unwanted-writes/436419"]&lt;p&gt;So the Secure/Non-secure attribute is separate from the Write attribute.&lt;br /&gt;Therefore, I think you can use this for only Write protect.&lt;/p&gt;
&lt;p&gt;By the way, If you build without TF-M, the whole application runs as &amp;quot;Secure&amp;quot; from the SPUs perspective.&lt;/p&gt;[/quote]
&lt;p&gt;And when using the SPU, how would I then write to the protected memory? Simply temporarily disable the protection?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Lars&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect RAM from unwanted writes</title><link>https://devzone.nordicsemi.com/thread/436419?ContentTypeID=1</link><pubDate>Fri, 14 Jul 2023 08:53:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dde3e6c2-3ec3-4e35-b288-cc36ee088400</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Seems the MPU is a feature of our chips I did not know so much about yet.&lt;br /&gt;Thank you for giving some pushback here, so I found out about this feature.&lt;/p&gt;
&lt;p&gt;From what I understand, we have not documented the MPU in our Product Specification.&lt;br /&gt;That is because we still use a Cortex-M. So I asked a collegue about this and he says that the MPU in our chips should be the same as the one in STM, since both use Cortex-M.&lt;br /&gt;However, we have an &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfx/drivers/mpu/hal.html"&gt;MPU HAL&lt;/a&gt; available.&lt;/p&gt;
&lt;p&gt;In addition, have a look at Zephyrs &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/hardware/arch/arm_cortex_m.html#memory-map-and-mpu-considerations"&gt;Memory map and MPU considerations&lt;/a&gt;.&lt;br /&gt;Also see the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/arch/mpu/mpu_test/README.html"&gt;Memory Protection Unit (MPU) Sample&lt;/a&gt; for this.&lt;/p&gt;
&lt;p&gt;Then I think you should be able to use one of those, whichever you find fits you best.&lt;/p&gt;
&lt;p&gt;Is this what you are looking for?&lt;/p&gt;
[quote user="colar"]With the SPU in nRF5340, I only see the option to specifiy permissions for secure and non-secure domains, not for priviledged/inpriviledged, so to use that feature I MUST use secure/non-secure domains. Am I right with that?[/quote]
&lt;p&gt;I think that the SPU does not have to depend on domains. From &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/spu.html?cp=4_0_0_6_31_8_21#register.RAMREGION.PERM:"&gt;https://infocenter.nordicsemi.com/topic/ps_nrf5340/spu.html?cp=4_0_0_6_31_8_21#register.RAMREGION.PERM:&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/2783.pastedimage1689324630477v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;So the Secure/Non-secure attribute is separate from the Write attribute.&lt;br /&gt;Therefore, I think you can use this for only Write protect.&lt;/p&gt;
&lt;p&gt;By the way, If you build without TF-M, the whole application runs as &amp;quot;Secure&amp;quot; from the SPUs perspective.&lt;/p&gt;
[quote user="colar"]And to read/write from non-secure code (no matter if with the application RoT services or not), all accesses have to go over an API, then IPC from non-secure to secure image and then back, right?[/quote]
&lt;p&gt;Yes, but only if you have TF-M enabled. See my previous sentence.&lt;/p&gt;
[quote user="colar"]Are there other options to that or have I misunderstood some aspect of the nRF5340&amp;#39;s features?[/quote]
&lt;p&gt;I started this comment with describing the MPU, see that.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect RAM from unwanted writes</title><link>https://devzone.nordicsemi.com/thread/436394?ContentTypeID=1</link><pubDate>Fri, 14 Jul 2023 07:41:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a8e4cf8-53bc-43f1-a67f-1a59adcaafbb</guid><dc:creator>colar</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve already looked into that and think it is a bit too much overhead.&lt;/p&gt;
&lt;p&gt;With the STM32L4 it was as simple as configuring the MPU to only allow writing in priviledged mode, so I could read my &amp;quot;variables&amp;quot; from everywhere but only write to them by switching to priviledged mode first. This induced almost no overhead and is what I intend to do with the nRF5340.&lt;/p&gt;
&lt;p&gt;With the SPU in nRF5340, I only see the option to specifiy permissions for secure and non-secure domains, not for priviledged/inpriviledged, so to use that feature I MUST use secure/non-secure domains. Am I right with that?&lt;/p&gt;
&lt;p&gt;And to read/write from non-secure code (no matter if with the application RoT services or not), all accesses have to go over an API, then IPC from non-secure to secure image and then back, right? This sounds like a lot of runtime overhead.&lt;/p&gt;
&lt;p&gt;Are there other options to that or have I misunderstood some aspect of the nRF5340&amp;#39;s features?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Lars&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect RAM from unwanted writes</title><link>https://devzone.nordicsemi.com/thread/435933?ContentTypeID=1</link><pubDate>Wed, 12 Jul 2023 10:29:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db852d12-87be-4935-aed3-5bdfde43dcc8</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;TF-M levearges the &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/spu.html?cp=4_0_0_6_31"&gt;SPU&lt;/a&gt; for its memory protection.&lt;/p&gt;
&lt;p&gt;You could maybe implement SPU functionality for the SPU to do &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf5340/spu.html?cp=4_0_0_6_31_2#ram_access_control"&gt;RAM access control&lt;/a&gt;.&lt;br /&gt;To control this, I think you can have a look at &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfx/drivers/spu/hal.html"&gt;SPU hal&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;TF-M uses the SPU as well, so you might have to be careful if you intend to use both at the same time.&lt;/p&gt;
&lt;p&gt;For the record, I recommend that you use TF-M application RoT Services instead&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect RAM from unwanted writes</title><link>https://devzone.nordicsemi.com/thread/435912?ContentTypeID=1</link><pubDate>Wed, 12 Jul 2023 09:38:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc569726-8570-4f2f-a092-ac02e585198d</guid><dc:creator>colar</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t think that this fits my application since the whole application should be able to access the variables (read) directly without any overhead.&lt;/p&gt;
&lt;p&gt;The whole application should also be able to write to variables, but only in a function made for that. What I imagine is something like&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;__attribute__((__section__(&amp;quot;.protected_region&amp;quot;))) int variables[1024];

int read_variable(int index) {
    return variables[index];
}

void write_variable(int index, int value) {
    k_sched_lock();
    enable_write_to_protected_region();
    variables[index] = value;
    disable_write_to_protected_region();
    k_sched_unlock();
}

// This should throw an error:
void write_unallowed_stuff() {
    variables[0] = 123; // throws a fault since write access has not been aquired
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Lars&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect RAM from unwanted writes</title><link>https://devzone.nordicsemi.com/thread/435885?ContentTypeID=1</link><pubDate>Wed, 12 Jul 2023 08:27:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a7851059-8a76-47af-b38f-869d9a530a8e</guid><dc:creator>Sigurd Hellesvik</dc:creator><description>&lt;p&gt;Hi Lars,&lt;/p&gt;
&lt;p&gt;First, I was wrong before.&lt;br /&gt;I told Hieu that the PSA Persistent Storage API supports volatile storage. And today I found out that it does not support volatile information.&lt;/p&gt;
&lt;p&gt;I will continue helping in this case.&lt;/p&gt;
[quote user="colar"]My main goal is not to protect against malicious attacks, but rather to protect special memory regions against some bugs I create elsewhere. For example a thread that has a buffer overflow or is writing to an invalid location should not be able to overwrite some important data (to guarantee this, data shall only be manipulated by functions with some priviledged mode).[/quote]
&lt;p&gt;In my explanation, I will use NSPE and SPE. See &amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/an-introduction-to-trusted-firmware-m-t-m"&gt;An Introduction to Trusted Firmware-M (TF-M)&lt;/a&gt; for an explanation of these.&lt;/p&gt;
&lt;p&gt;Since PSA Protected Storage does not RAM, I think that is not what you need after all.&lt;/p&gt;
&lt;p&gt;But if you only need some RAM storage, you can leverage TF-M without using its PS Protected Storage.&lt;br /&gt;You can create a &lt;a href="https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/an-introduction-to-trusted-firmware-m-t-m#AnintroductiontoTrustedFirmwareM(TFM)-ApplicationRoTServices"&gt;custom Application RoT Services&lt;/a&gt; which just saves a variable. This variable will live inside the SPE, which your NSPE can not access.&lt;br /&gt;This way, you assure that any bugs you do create in the NSPE will not affect your stored variable.&lt;/p&gt;
&lt;p&gt;Does this sound like what you need?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect RAM from unwanted writes</title><link>https://devzone.nordicsemi.com/thread/435854?ContentTypeID=1</link><pubDate>Wed, 12 Jul 2023 06:49:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5a2866b6-0f1d-4258-9b40-b983d7923317</guid><dc:creator>colar</dc:creator><description>&lt;p&gt;Hi Hieu,&lt;/p&gt;
&lt;p&gt;thanks for your answer.&lt;/p&gt;
&lt;p&gt;My main goal is not to protect against malicious attacks, but rather to protect special memory regions against some bugs I create elsewhere. For example a thread that has a buffer overflow or is writing to an invalid location should not be able to overwrite some important data (to guarantee this, data shall only be manipulated by functions with some priviledged mode).&lt;/p&gt;
&lt;p&gt;All code running on the device can be trusted as it is written by myself, though of course it may contain afromentioned bugs. So user mode is probably not the right choice due to its overhead with syscalls that I use extensively.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Lars&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect RAM from unwanted writes</title><link>https://devzone.nordicsemi.com/thread/435804?ContentTypeID=1</link><pubDate>Tue, 11 Jul 2023 19:24:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a690c5b0-a568-4412-8a8c-5d6a67311f40</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi Lars,&lt;/p&gt;
&lt;p&gt;Could you clarify further what you want to protect this RAM region against? Is it against certain malicious attack?&lt;/p&gt;
&lt;p&gt;If security of the data is your concern, then you can consider the&amp;nbsp;PSA Protected Storage. My colleague Sigurd has a blog on&amp;nbsp;persistent storage&amp;nbsp;here:&amp;nbsp;&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/nordic/nordic-blog/b/blog/posts/persistent-storage-of-keys-and-data-using-the-nrf-connect-sdk"&gt;Persistent storage of keys and data using the nRF Connect SDK&lt;/a&gt;&amp;nbsp;.&lt;/p&gt;
&lt;p&gt;The blog is on persistent storage, but&amp;nbsp;PSA Protected Storage also supports volatile storage.&amp;nbsp;The information therefore will still be applicable.&lt;/p&gt;
&lt;p&gt;Please reply and let me know if it this suits your need. I will actually be out of office from tomorrow, but another engineer will&amp;nbsp;be assigned if you need any further help.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect RAM from unwanted writes</title><link>https://devzone.nordicsemi.com/thread/435152?ContentTypeID=1</link><pubDate>Fri, 07 Jul 2023 08:52:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2de786a-1d77-420c-8f35-01a2d90993cc</guid><dc:creator>Hieu</dc:creator><description>&lt;p&gt;Hi Lars,&lt;/p&gt;
&lt;p&gt;Please be informed that I have started an internal query about this. However, it is likely that the response will take some time because we are currently understaffed due to the summer vacation period.&lt;/p&gt;
&lt;p&gt;Please excuse some delays in response over the coming weeks. Our apologies for the inconvenience.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Hieu&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>