mirror of
https://github.com/torvalds/linux.git
synced 2026-11-20 13:03:48 +00:00
amt: require an exact IPv4-sized IFLA_AMT_{LOCAL,DISCOVERY}_IP
The netlink policy for IFLA_AMT_LOCAL_IP and IFLA_AMT_DISCOVERY_IP is an
untyped entry with .len set to the size of an IPv4 address, which netlink
validation treats as a minimum length only. Any longer payload passes,
and nla_get_in_addr() then reads just its first four bytes: an iproute2
that puts a 16-byte IPv6 literal in one of these IPv4 attributes turns
"2001:db8::" into 32.1.13.184, and the device is created with an address
the user never asked for.
Use NLA_POLICY_EXACT_LEN(sizeof(__be32)) for both, so every payload that
is not exactly four bytes long is refused with a standard extack instead
of being truncated. The range check this expands to fails the attribute
even under the liberal parsing rtnetlink applies to IFLA_INFO_DATA.
amt_get_size() and amt_fill_info() already emit exactly four bytes for
these attributes. IFLA_AMT_REMOTE_IP is only ever reported, never read
from a request, so it is left unchanged.
Triggered while writing a selftest for the AMT IPv6 outer transport:
an iproute2 without the IPv6 attributes put all 16 bytes of
"discovery 2001:db8:a::2" into IFLA_AMT_DISCOVERY_IP. On a stock
kernel the command exited 0 with no error or warning, and the device
came up as an IPv4 gateway with discovery address 32.1.13.184, the
first four bytes. There is no oops or trace; the symptom is the
silently wrong address, which fooled the selftest's capability probe.
Fixes: b9022b53ad ("amt: add control plane of amt interface")
Signed-off-by: Omar Ramadan <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
This commit is contained in:
committed by
Jakub Kicinski
parent
b4fa7f8dae
commit
144183ab4b
+2
-2
@@ -3358,9 +3358,9 @@ static const struct nla_policy amt_policy[IFLA_AMT_MAX + 1] = {
|
||||
[IFLA_AMT_RELAY_PORT] = { .type = NLA_U16 },
|
||||
[IFLA_AMT_GATEWAY_PORT] = { .type = NLA_U16 },
|
||||
[IFLA_AMT_LINK] = { .type = NLA_U32 },
|
||||
[IFLA_AMT_LOCAL_IP] = { .len = sizeof_field(struct iphdr, daddr) },
|
||||
[IFLA_AMT_LOCAL_IP] = NLA_POLICY_EXACT_LEN(sizeof(__be32)),
|
||||
[IFLA_AMT_REMOTE_IP] = { .len = sizeof_field(struct iphdr, daddr) },
|
||||
[IFLA_AMT_DISCOVERY_IP] = { .len = sizeof_field(struct iphdr, daddr) },
|
||||
[IFLA_AMT_DISCOVERY_IP] = NLA_POLICY_EXACT_LEN(sizeof(__be32)),
|
||||
[IFLA_AMT_MAX_TUNNELS] = { .type = NLA_U32 },
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user