Nano Every - fatal security bug in Wire.h
- Dominant language
- Java
- Stars
- 14.6k
- Forks
- 7k
- PR merge metrics
- No merged PRs in 30d
Description
Hallo,
wire.begin should disable 'output and 'pullup' of pin 18 and 19 before initializing TWI as a precaution. In case someone programs pin 18 and 19 digitally and then turns on TWI. Because pin 18/19 (PortF) TWI (PortA) are different ports, electrical short circuits could occur.
Another problem is that Wire.end does not turn off its own port pullups of PA2 and PA3. Pin 18 and 19 are inputs, Wire is terminated and still the pins output 4.7 volts.
Translated with www.DeepL.com/Translator (free version)
```c++
#include
#include
const byte wait {1}; // for enventual electrical measurements
void setup(void)
{
Serial.begin(250000);
Serial.println(F("\nStart #### #### #### ####"));
showData();
Serial.println("\nInput_Pullup.18"); pinMode(18, INPUT_PULLUP);
Serial.println("Input_Pullup.19"); pinMode(19, INPUT_PULLUP);
showData();
delay(wait);
Serial.println("\nOutput.18"); pinMode(18, OUTPUT);
Serial.println("Output.19"); pinMode(19, OUTPUT);
showData();
delay(wait);
Serial.println("\nWire.begin"); Wire.begin();
showData();
delay(wait);
Serial.println("\nInput.18"); pinMode(18, INPUT);
Serial.println("Input.19"); pinMode(19, INPUT);
showData();
delay(wait);
Serial.println("\nWire.end"); Wire.end();
showData();
}
void loop(void)
{ }
void showData(void)
{
Serial << "TWI0_MCTRLA " << _HEX((uint16_t)&TWI0_MCTRLA) << '\t' << _BIN(TWI0_MCTRLA) << endl;
Serial << "TWI0_SCTRLA " << _HEX((uint16_t)&TWI0_SCTRLA) << '\t' << _BIN(TWI0_MCTRLA) << endl;
Serial << "PORTA_DIR " << _HEX((uint16_t)&PORTA_DIR) << '\t' << _BIN(PORTA_DIR) << endl;
Serial << "PORTA_PIN2CTRL " << _HEX((uint16_t)&PORTA_PIN2CTRL) << '\t' << _BIN(PORTA_PIN2CTRL) << endl;
Serial << "PORTA_PIN3CTRL " << _HEX((uint16_t)&PORTA_PIN3CTRL) << '\t' << _BIN(PORTA_PIN3CTRL) << endl;
Serial << "PORTF_DIR " << _HEX((uint16_t)&PORTF_DIR) << '\t' << _BIN(PORTF_DIR) << endl;
Serial << "PORTF_PIN2CTRL " << _HEX((uint16_t)&PORTF_PIN2CTRL) << '\t' << _BIN(PORTF_PIN2CTRL) << endl;
Serial << "PORTF_PIN3CTRL " << _HEX((uint16_t)&PORTF_PIN3CTRL) << '\t' << _BIN(PORTF_PIN3CTRL) << endl;
}
```
Contributor guide
Research direction
Start by locating the Wire.h implementation for the Nano Every and reproduce the provided sketch on the board. Check the Wire.begin and Wire.end paths against the reported PORTA and PORTF states; done means initialization prevents conflicting outputs and termination releases the Wire pullups.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100