Skip to content

Commit 5e865eb

Browse files
committed
fix(mavlink): align signing with MAVLink spec and fix performance regression
Remove the non-standard MAV_SIGN_CFG parameter and align the signing implementation with the MAVLink specification. Key changes: - Remove MAV_SIGN_CFG parameter that conflicted with GCS implementations - Only enable signing when a valid key is present on the SD card - Accept SETUP_SIGNING on any link, not just USB - Reject SETUP_SIGNING while the vehicle is armed - Allow disabling signing via signed all-zero key SETUP_SIGNING message - Propagate key changes to all mavlink instances - Zero CPU/bandwidth overhead when signing is not active Fixes #26893 Signed-off-by: Ramon Roche <mrpollo@gmail.com>
1 parent b48f3ef commit 5e865eb

File tree

8 files changed

+283
-147
lines changed

8 files changed

+283
-147
lines changed

docs/en/mavlink/message_signing.md

Lines changed: 79 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,27 @@ When signing is enabled, PX4 appends a 13-byte [signature](https://mavlink.io/en
1212

1313
Incoming messages are checked against the shared secret key, and unsigned or incorrectly signed messages are rejected (with [exceptions for safety-critical messages](#unsigned-message-allowlist)).
1414

15-
The signing implementation is built into the MAVLink module and is always available — no special build flags are required.
16-
It is enabled and disabled at runtime through the [MAV_SIGN_CFG](../advanced_config/parameter_reference.md#MAV_SIGN_CFG) parameter.
15+
The signing implementation is built into the MAVLink module and is always available, with no special build flags required.
1716

1817
## Enable/Disable Signing
1918

20-
The [MAV_SIGN_CFG](../advanced_config/parameter_reference.md#MAV_SIGN_CFG) parameter controls whether signing is active:
19+
Signing is controlled entirely through the standard MAVLink [SETUP_SIGNING](https://mavlink.io/en/messages/common.html#SETUP_SIGNING) message, following the [MAVLink signing specification](https://mavlink.io/en/guide/message_signing.html).
2120

22-
| Value | Mode | Description |
23-
| ----- | ------------------ | ------------------------------------------------------------------------------------------------------ |
24-
| 0 | Disabled (default) | No signing. All messages are accepted regardless of signature. |
25-
| 1 | Non-USB | Signing is enabled on all links **except** USB serial connections. USB links accept unsigned messages. |
26-
| 2 | Always | Signing is enforced on all links, including USB. |
21+
- **No key on SD card**: Signing is disabled. All messages are sent unsigned and all incoming messages are accepted.
22+
- **Valid key on SD card**: Signing is active on **all links including USB**. Outgoing messages are signed and incoming messages must be signed (with [exceptions](#unsigned-message-allowlist)).
23+
24+
To **enable** signing, send a `SETUP_SIGNING` message with a valid key on any link when no key is currently provisioned (see [Key Provisioning](#key-provisioning)).
25+
26+
To **disable** signing via MAVLink, send a `SETUP_SIGNING` message with an all-zero key and timestamp. This message **must be signed with the current active key**. An unsigned blank-key message is rejected.
27+
28+
To **disable** signing via physical access, remove the key file from the SD card (`/mavlink/mavlink-signing-key.bin`) and reboot, or remove the SD card entirely.
29+
30+
To **change** the signing key, send a `SETUP_SIGNING` message with the new key on any link. When signing is already active, the message must be signed with the current key.
2731

2832
::: warning
29-
Setting `MAV_SIGN_CFG` alone does not enable signing — a secret key must also be present (see [Key Provisioning](#key-provisioning) below).
30-
If no key has been set (or the key is all zeros with a zero timestamp), all messages are accepted regardless of this parameter.
33+
Signing key changes (enable, disable, or rotate) are **rejected while the vehicle is armed**. The vehicle must be disarmed before signing configuration can be changed.
3134
:::
3235

33-
To **disable** signing, set `MAV_SIGN_CFG` to zero.
34-
3536
## Key Provisioning
3637

3738
The signing key is set by sending the MAVLink [SETUP_SIGNING](https://mavlink.io/en/messages/common.html#SETUP_SIGNING) message (ID 256) to PX4.
@@ -40,10 +41,14 @@ This message contains:
4041
- A 32-byte secret key
4142
- A 64-bit initial timestamp
4243

44+
PX4 accepts `SETUP_SIGNING` on **any link** (USB, telemetry radio, network, and so on).
45+
46+
When signing is **not active** (no key provisioned), the first `SETUP_SIGNING` with a valid key enables signing.
47+
When signing is **already active**, key changes (including disabling) require that the `SETUP_SIGNING` message is signed with the current key.
48+
4349
::: warning
44-
For security, PX4 only accepts `SETUP_SIGNING` messages received on a **USB** connection.
45-
The message is silently ignored on all other link types (telemetry radios, network, and so on).
46-
This ensures that an attacker cannot remotely change the signing key.
50+
`SETUP_SIGNING` is rejected while the vehicle is armed. Disarm before provisioning or changing keys.
51+
`SETUP_SIGNING` is never forwarded to other links (per the MAVLink specification).
4752
:::
4853

4954
## Key Storage
@@ -64,7 +69,7 @@ The file is a 40-byte binary file:
6469
The file is created with mode `0600` (owner read/write only), and the containing `/mavlink/` directory is created with mode `0700` (owner only).
6570

6671
On startup, PX4 reads the key from this file.
67-
If the file exists and contains a non-zero key or timestamp, signing is initialized automatically.
72+
If the file exists and contains a non-zero key or timestamp, signing is activated automatically.
6873

6974
::: info
7075
The timestamp in the file is set when `SETUP_SIGNING` is received.
@@ -82,45 +87,82 @@ Note that this requires physical access to the vehicle, and therefore provides t
8287

8388
1. The MAVLink module calls `MavlinkSignControl::start()` during startup.
8489
2. The `/mavlink/` directory is created if it doesn't exist.
85-
3. The `mavlink-signing-key.bin` file is opened (or created empty).
86-
4. If a valid key is found (non-zero key or timestamp), signing is marked as initialized.
87-
5. The `accept_unsigned` callback is registered with the MAVLink library.
90+
3. The `mavlink-signing-key.bin` file is opened if it exists.
91+
4. If a valid key is found (non-zero key or timestamp), signing is activated: the signing struct is wired into the MAVLink library and outgoing messages are signed.
92+
5. If no valid key is found, the signing struct is left disconnected, and the MAVLink library operates with zero signing overhead.
8893

8994
### Outgoing Messages
9095

91-
When signing is initialized, the `MAVLINK_SIGNING_FLAG_SIGN_OUTGOING` flag is set, which causes the MAVLink library to automatically append a [SHA-256 based signature](https://mavlink.io/en/guide/message_signing.html#signature) to every outgoing MAVLink 2 message.
96+
When signing is active (valid key present), the `MAVLINK_SIGNING_FLAG_SIGN_OUTGOING` flag is set, which causes the MAVLink library to automatically append a [SHA-256 based signature](https://mavlink.io/en/guide/message_signing.html#signature) to every outgoing MAVLink 2 message.
97+
98+
When no key is present, signing is completely bypassed with no CPU or bandwidth overhead.
9299

93100
### Incoming Messages
94101

95102
For each incoming message, the MAVLink library checks whether a valid signature is present.
96103
If the message is unsigned or has an invalid signature, the library calls the `accept_unsigned` callback, which decides whether to accept or reject the message based on:
97104

98-
1. **Signing not initialized** — If no key has been loaded, all messages are accepted.
99-
2. **Allowlisted message** — Certain [safety-critical messages](#unsigned-message-allowlist) are always accepted.
100-
3. **Sign mode** — The `MAV_SIGN_CFG` parameter determines behavior:
101-
- Mode 0 (disabled): All unsigned messages are accepted.
102-
- Mode 1 (non-USB): Unsigned messages are accepted only on USB links.
103-
- Mode 2 (always): Unsigned messages are rejected on all links.
105+
1. **Signing not active**: If no key has been loaded, all messages are accepted.
106+
2. **Allowlisted message**: Certain [safety-critical messages](#unsigned-message-allowlist) are always accepted.
104107

105108
## Unsigned Message Allowlist
106109

107-
The following messages are **always** accepted unsigned, regardless of the signing mode.
110+
The following messages are **always** accepted unsigned, regardless of the signing state.
108111
These are safety-critical messages that may originate from systems that don't support signing:
109112

110-
| Message | ID | Reason |
111-
| ----------------------------------------------------------------------- | --- | -------------------------------------------------------- |
112-
| [RADIO_STATUS](https://mavlink.io/en/messages/common.html#RADIO_STATUS) | 109 | Radio link status from SiK radios and other radio modems |
113-
| [ADSB_VEHICLE](https://mavlink.io/en/messages/common.html#ADSB_VEHICLE) | 246 | ADS-B traffic information for collision avoidance |
114-
| [COLLISION](https://mavlink.io/en/messages/common.html#COLLISION) | 247 | Collision threat warnings |
113+
| Message | ID | Reason |
114+
| ------------------------------------------------------------------------- | --- | -------------------------------------------------------- |
115+
| [HEARTBEAT](https://mavlink.io/en/messages/common.html#HEARTBEAT) | 0 | System discovery and liveness detection |
116+
| [RADIO_STATUS](https://mavlink.io/en/messages/common.html#RADIO_STATUS) | 109 | Radio link status from SiK radios and other radio modems |
117+
| [ADSB_VEHICLE](https://mavlink.io/en/messages/common.html#ADSB_VEHICLE) | 246 | ADS-B traffic information for collision avoidance |
118+
| [COLLISION](https://mavlink.io/en/messages/common.html#COLLISION) | 247 | Collision threat warnings |
115119

116120
## Security Considerations
117121

118-
- **Physical access required for key setup**: The `SETUP_SIGNING` message is only accepted over USB, so an attacker must have physical access to the vehicle to provision or change the key.
122+
### Signing is enforced on all links
123+
124+
When signing is active, **all links require signed messages**, including USB. This means:
125+
126+
- An attacker cannot send unsigned commands on any link
127+
- Changing or disabling the key requires sending a `SETUP_SIGNING` message **signed with the current key**
128+
- Signing can be disabled via MAVLink by sending a signed `SETUP_SIGNING` with an all-zero key
129+
130+
### Armed guard
131+
132+
`SETUP_SIGNING` is rejected while the vehicle is armed. This prevents signing configuration from being changed during flight, whether by accident or by an attacker who has obtained the key.
133+
134+
### Lost key recovery
135+
136+
If the signing key is lost on the GCS side and no device has the current key:
137+
138+
- **Remove the SD card** and delete `/mavlink/mavlink-signing-key.bin`, then reboot
139+
- **Reflash via SWD/JTAG** if the SD card is not accessible
140+
141+
::: warning
142+
There is no software-only recovery path for a lost key. This is intentional: any MAVLink-based recovery mechanism would also be available to an attacker.
143+
Physical access to the SD card or debug port is required.
144+
:::
145+
146+
### Other considerations
147+
148+
- **Initial key provisioning**: When no key is provisioned, `SETUP_SIGNING` is accepted unsigned on any link. Once a key is active, subsequent changes require a signed message. Provision the initial key over a trusted connection.
119149
- **Key not exposed via parameters**: The secret key is stored in a separate file on the SD card, not as a MAVLink parameter, so it cannot be read back through the parameter protocol.
120-
- **SD card access**: Anyone with physical access to the SD card can read or modify the `mavlink-signing-key.bin` file, or just remove the card.
150+
- **SD card access**: Anyone with physical access to the SD card can read or modify the `mavlink-signing-key.bin` file, or remove the card entirely to disable signing.
121151
Ensure physical security of the vehicle if signing is used as a security control.
122152
- **Replay protection**: The MAVLink signing protocol includes a timestamp that prevents replay attacks.
123153
The on-disk timestamp is updated when a new key is provisioned via `SETUP_SIGNING`.
124-
A graceful shutdown also persists the current timestamp, but since most vehicles are powered off by pulling the battery, the timestamp will typically reset to the value from the last key provisioning on reboot.
125-
- **No encryption**: Message signing provides authentication and integrity, but messages are still sent in plaintext.
126-
An eavesdropper can read message contents but cannot forge or modify them without the key.
154+
A graceful shutdown also persists the current timestamp, but since most vehicles are powered off by pulling the battery, the on-disk timestamp will typically remain at the value from the last key provisioning on reboot.
155+
- **No encryption**: Message signing provides **authentication and integrity only**. Messages are still sent in plaintext.
156+
An eavesdropper can read all message contents (telemetry, commands, parameters, missions) but cannot forge or modify them without the key.
157+
- **Allowlisted messages bypass signing**: A small set of [safety-critical messages](#unsigned-message-allowlist) are always accepted unsigned. An attacker can spoof these specific messages (e.g. fake `ADSB_VEHICLE` traffic) even when signing is active.
158+
159+
### What signing does NOT protect against
160+
161+
| Attack | Why |
162+
|--------|-----|
163+
| Eavesdropping | Messages are not encrypted |
164+
| SD card extraction | Key file is readable by anyone with physical access |
165+
| Spoofed HEARTBEAT/RADIO_STATUS/ADSB/COLLISION | These are allowlisted unsigned |
166+
| Lost key without SD card access | Requires SWD reflash |
167+
| Key rotation | No automatic mechanism; manual reprovisioning required |
168+
| In-flight key changes | `SETUP_SIGNING` rejected while armed |

docs/en/mavlink/security_hardening.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,27 @@ See [Message Signing](message_signing.md) for full details.
3737

3838
Steps:
3939

40-
1. Connect the vehicle via **USB** (key provisioning only works over USB).
41-
2. Provision a 32-byte secret key using the [SETUP_SIGNING](https://mavlink.io/en/messages/common.html#SETUP_SIGNING) message.
42-
3. Set [MAV_SIGN_CFG](../advanced_config/parameter_reference.md#MAV_SIGN_CFG) to **1** (signing enabled on all links except USB) or **2** (signing on all links including USB).
43-
4. Provision the same key on all ground control stations and companion computers that need to communicate with the vehicle.
44-
5. Verify that unsigned messages from unknown sources are rejected.
40+
1. Connect to the vehicle over a **trusted link** (USB or other secure connection).
41+
2. Provision a 32-byte secret key using the [SETUP_SIGNING](https://mavlink.io/en/messages/common.html#SETUP_SIGNING) message. This works on any link, but use a trusted one for initial provisioning.
42+
3. Provision the same key on all ground control stations and companion computers that need to communicate with the vehicle.
43+
4. Verify that unsigned messages from unknown sources are rejected.
4544

4645
::: info
47-
`MAV_SIGN_CFG=1` is recommended for most deployments.
48-
This enforces signing on telemetry radios and network links while allowing unsigned access over USB for maintenance.
49-
USB connections require physical access to the vehicle, which provides equivalent security to physical key access.
46+
Once a key is provisioned, signing is enforced automatically on **all links including USB**.
47+
Changing or disabling the key requires a signed `SETUP_SIGNING` message. Signing changes are rejected while the vehicle is armed.
48+
Signing can also be disabled by physically removing the key file from the SD card.
5049
:::
5150

5251
### 2. Secure Physical Access
5352

54-
- Protect access to the SD card. The signing key is stored at `/mavlink/mavlink-signing-key.bin` and can be read or removed by anyone with physical access.
55-
- USB connections bypass signing when `MAV_SIGN_CFG=1`. Ensure USB ports are not exposed in deployed configurations.
53+
- **SD card**: The signing key is stored at `/mavlink/mavlink-signing-key.bin`. Anyone with physical access to the SD card can read, modify, or remove the key file.
54+
- **USB ports**: USB follows the same signing rules as all other links. When signing is active, USB requires signed messages.
55+
- **Debug ports (SWD/JTAG)**: If exposed, these allow full firmware reflash and bypass all software security. Not all vehicles expose debug connectors.
56+
57+
::: warning
58+
Signing protects all MAVLink links. The primary physical attack surface is the SD card (key file extraction or deletion).
59+
If your threat model includes physical access, secure the SD card slot and debug ports.
60+
:::
5661

5762
### 3. Secure Network Links
5863

@@ -64,8 +69,9 @@ USB connections require physical access to the vehicle, which provides equivalen
6469
### 4. Understand the Limitations
6570

6671
- **No encryption**: Message signing provides authentication and integrity, but messages are sent in plaintext. An eavesdropper can read telemetry and commands but cannot forge them.
67-
- **Allowlisted messages**: A small set of [safety-critical messages](message_signing.md#unsigned-message-allowlist) (RADIO_STATUS, ADSB_VEHICLE, COLLISION) are always accepted unsigned.
68-
- **Key management**: There is no automatic key rotation. Keys must be reprovisioned manually via USB if compromised.
72+
- **Allowlisted messages**: A small set of [safety-critical messages](message_signing.md#unsigned-message-allowlist) (HEARTBEAT, RADIO_STATUS, ADSB_VEHICLE, COLLISION) are always accepted unsigned on all links. An attacker could spoof these specific messages.
73+
- **Key management**: There is no automatic key rotation. Keys must be reprovisioned manually via a signed `SETUP_SIGNING` message.
74+
- **Lost key recovery**: If the signing key is lost on all GCS devices, the only recovery is physical: remove the SD card and delete the key file, or reflash via SWD/JTAG. There is no software-only recovery path. See [Message Signing: Lost Key Recovery](message_signing.md#lost-key-recovery) for details.
6975

7076
## Integrator Responsibility
7177

0 commit comments

Comments
 (0)