MPU Stack Protection

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys, when trying to setup the MPU to protect the Stack I get an error unless the size I specify is the same as the linker variable __stack_size__

 

region_size_value = (uint32_t)0x00002000 >> 10;
 print_dbg("\n\rrregion size value\n\r"); print_dbg_hex(region_size_value);
 

 if (!mpu_convert_kbsize_to_eregionsize(&region_size, region_size_value)) {
  mpu_configuration_error();
 }
 
 print_dbg("\n\rrregion size\n\n\r"); print_dbg_hex(region_size);
 dmpu_entries[REGION_2_STACK_INDEX].size = region_size;

 // Deem this protection scheme as valid.
 dmpu_entries[REGION_2_STACK_INDEX].valid = true;
 // set the mpu configuration for Region 2
 if (set_mpu_entry(&dmpu_entries[REGION_2_STACK_INDEX],
   REGION_2_STACK_INDEX)) {
  mpu_configuration_error();
 }

​Any help will be welcome.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Any takers?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you're left wanting for takers, maybe you should ask a question?

You're leaving us guessing at what your problem might be.

What have you done? Where are you stuck?

You're calling some functions (with no body here) and play a bit with var's.

 

As far as i know stack protection is usually set up by painting the whole stack with some known value before main() gets called

Use the __init_section or something like that.

And then periodically check what part of the stack is actually used (overwritten).

 

I have vague memories of some static analysis tools which can analyse stack usage, but I've never looked into them.

 

And this is a reasonably often used functionality, there are probably some libraries floating on the 'net. Maybe try searching on github?

Paul van der Hoeven.
Bunch of old projects with AVR's:
http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also the "an error"...

WHAT error?

Happy 75th anniversary to one of the best movies ever made! Rick Blane [Bogart]: "Of all the gin joints, in all the towns, in all the world, she walks into mine."

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Paulvdh wrote:
As far as i know stack protection is usually set up by painting the whole stack with some known value before main() gets called
That's not the kind of "protection" he's talking about here. An AVR32 is much more like the CPU in your PC than an AVR8. Just as Windows and Linux prevent one task from damaging another using the MMU in the CPU they run on, the AVR32 has a Memory Protection Unit (MPU). In theory you should be able to set it up so if there's an attempted write to memory that is not in a write-access region the CPU will throw an exception that can be caught. If you were ever running Windows and saw a "blue screen of death" telling you that a 0xC0000005 "access" violation had occurred then you saw this kind of thing in action ;-)

 

What OP here appears to be trying to do is to make only the "stack in the middle" writeable so that if the stack strays out of it's allocated region it will cause a CPU exception that the OS he is writing can catch.

Sadly for him there (a) doesn't seem to be a lot of AVR32 users and (b) of those that are here to help I think the likelihood that anyone else is writing an OS (pretty much the only time you really go near MMU/MPUs !) is remote in the extreme. So I guess he's on his own. Hence no traffic in this thread.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

He's not only on his own. He's also not here...

Happy 75th anniversary to one of the best movies ever made! Rick Blane [Bogart]: "Of all the gin joints, in all the towns, in all the world, she walks into mine."

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:
He's also not here...

Or no longer here - despite initial impatience ...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Fianawarrior is a regular here - dips in from time to time. Clearly not gone but he's working on this OS for AVR32 and I think he's discovering that there's quite a lot involved in doing that so may well be busy.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson, as usual your spot on.  Yes, I am writing a MPU for a OS that I have designed. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does Atmel (Microchip) still have tech support?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tech request sent, I'll let yous know what they say.