Author Topic: Memory Protection Exploit on WCH chips  (Read 2072 times)

0 Members and 1 Guest are viewing this topic.

Offline EEVblogTopic starter

  • Administrator
  • *****
  • Posts: 39718
  • Country: au
    • EEVblog
Memory Protection Exploit on WCH chips
« on: June 14, 2023, 04:29:56 am »
Nasty:

 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12009
  • Country: us
    • Personal site
Re: Memory Protection Exploit on WCH chips
« Reply #1 on: June 14, 2023, 05:01:50 am »
But that's not really a device issue, it is a bootloader firmware issue. Don't use vendor-supplied code.
Alex
 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 5051
  • Country: nz
Re: Memory Protection Exploit on WCH chips
« Reply #2 on: June 14, 2023, 05:06:10 am »
TLDW: it's not a memory protection thing, it's that flashing new firmware doesn't completely erase any old firmware. Easily fixed with a software update, at some cost in programming time and flash rewrite cycles.
 
The following users thanked this post: SiliconWizard

Offline peter-h

  • Super Contributor
  • ***
  • Posts: 4591
  • Country: gb
  • Doing electronics since the 1960s...
Re: Memory Protection Exploit on WCH chips
« Reply #3 on: June 14, 2023, 07:06:36 am »
Watched the video. That is a really stupid weakness, surely?

Do the 32F4 chips have this problem? IIRC, Level 2 protection disables the boot loader (RS232, USB, CAN) because STM refuses to honour warranty on L2 secured chips and they must be doing that for a reason.

Quote
it is a bootloader firmware issue. Don't use vendor-supplied code.

which almost nobody will do, because almost nobody expects this.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 7568
  • Country: pl
Re: Memory Protection Exploit on WCH chips
« Reply #4 on: June 14, 2023, 08:10:45 am »
TLDW: it's not a memory protection thing, it's that flashing new firmware doesn't completely erase any old firmware. Easily fixed with a software update, at some cost in programming time and flash rewrite cycles.
Looks like a classic MCU bootloader bug then, because I happen to know at least one other example ;)


which almost nobody will do, because almost nobody expects this.
To the first approximation, you should expect all software to be more trouble than it's worth, unless it really is worth something to you.
A bootloader on a mass produced device, probably not so much.
 

Offline peter-h

  • Super Contributor
  • ***
  • Posts: 4591
  • Country: gb
  • Doing electronics since the 1960s...
Re: Memory Protection Exploit on WCH chips
« Reply #5 on: June 14, 2023, 06:38:15 pm »
AIUI, a boot loader resides in some undocumented area of FLASH, and when the boot pins are suitably set up when /reset is de-asserted, the CPU jumps to that code.

If protection is enabled, fairly obviously the boot load stuff should be disabled otherwise anybody can boot load some short program which reads the main FLASH and sends the bytes out of a UART.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 
The following users thanked this post: rhodges

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8605
Re: Memory Protection Exploit on WCH chips
« Reply #6 on: June 15, 2023, 01:41:25 am »
Now you can do it yourself instead of paying few k$ to the existing Chinese companies who will be able to bypass the read protection for you anyway.

Their insecurity, our freedom ;)
 

Offline Sacodepatatas

  • Regular Contributor
  • *
  • Posts: 119
  • Country: es
Re: Memory Protection Exploit on WCH chips
« Reply #7 on: June 18, 2023, 02:41:18 am »
TLDW: it's not a memory protection thing, it's that flashing new firmware doesn't completely erase any old firmware. Easily fixed with a software update, at some cost in programming time and flash rewrite cycles.

That happens to me aswell with the STM32G030F6P6. My code uses the last 2kB flash page (page 31 of the hidden flash) for emulating an EEPROM. Nothing critical, it's just an optional feature for my device. Whether i use the cubeIDE or the ST-FLASH utility (if the code is bigger than 32kB), the content of the last page is unchanged because the flash image is always smaller than 62kB. In fact, if i read the full content of the flash and then write it back, my code doesn't work as intended, because a written page entirely with 0xFF values is quite different than erasing a page and then having all cells with 0xFF (I had a nightmare with that while debugging  😒)
 

Offline boB

  • Frequent Contributor
  • **
  • Posts: 341
  • Country: us
    • my work www
Re: Memory Protection Exploit on WCH chips
« Reply #8 on: June 18, 2023, 05:29:06 am »

Was that guy in the video using all  un-insulated wire ?

I would be real careful.
K7IQ
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12009
  • Country: us
    • Personal site
Re: Memory Protection Exploit on WCH chips
« Reply #9 on: June 18, 2023, 05:41:30 am »
Looks like enameled wire. Pretty typical for this kind of quick hacks. Easy to solder, reasonably robust.
Alex
 
The following users thanked this post: boB

Offline boB

  • Frequent Contributor
  • **
  • Posts: 341
  • Country: us
    • my work www
Re: Memory Protection Exploit on WCH chips
« Reply #10 on: June 18, 2023, 05:58:42 am »
It didn't look like typical enameled wire to me but maybe he has another option that looks more shiny than enameled ?

I would not want to have to strip enameled wire for prototyping this kind of stuff. 

Kynar maybe.

K7IQ
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 12009
  • Country: us
    • Personal site
Re: Memory Protection Exploit on WCH chips
« Reply #11 on: June 18, 2023, 06:11:13 am »
Looks like a typical enamel wire. Something like this https://www.amazon.com/BNTECHGO-AWG-Magnet-Wire-Transformers/dp/B07H7GS7F3/ I don't see any difference in now shiny it is.

You don't need to strip it, just heat and the enamel falls off. That's the whole advantage for quick prototyping like that. Plus very thin insulation lets you get much denser soldering, if target board is small.
Alex
 

Offline boB

  • Frequent Contributor
  • **
  • Posts: 341
  • Country: us
    • my work www
Re: Memory Protection Exploit on WCH chips
« Reply #12 on: June 19, 2023, 02:22:17 am »
OK.  Low temperature (155C) Polyurethane wire.
 
I hadn't seen that before but makes sense if it is low temp enamel.

We use those roto-blade magnet wire strippers for larger wire.

boB
« Last Edit: June 19, 2023, 02:24:00 am by boB »
K7IQ
 

Offline Dave

  • Super Contributor
  • ***
  • Posts: 1356
  • Country: si
  • I like to measure things.
Re: Memory Protection Exploit on WCH chips
« Reply #13 on: June 27, 2023, 01:23:25 pm »
AIUI, a boot loader resides in some undocumented area of FLASH, and when the boot pins are suitably set up when /reset is de-asserted, the CPU jumps to that code.

If protection is enabled, fairly obviously the boot load stuff should be disabled otherwise anybody can boot load some short program which reads the main FLASH and sends the bytes out of a UART.
Nothing wrong with keeping the ROM bootloader enabled, as long as full flash memory erasal AND RAM clearing is enforced before you're allowed to flash new firmware onto a chip with protection enabled.
<fellbuendel> it's arduino, you're not supposed to know anything about what you're doing
<fellbuendel> if you knew, you wouldn't be using it
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 7568
  • Country: pl
Re: Memory Protection Exploit on WCH chips
« Reply #14 on: June 27, 2023, 02:15:41 pm »
And that's the problem. You think the bootloader enforces it, the bootloader supplier also thinks it does, but somebody finds that sometimes it actually does not.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf