Skip to content

Commit 10c77e7

Browse files
Roded Zatspelwell
Roded Zats
authored andcommitted
enic: Validate length of nl attributes in enic_set_vf_port
[ Upstream commit e8021b9 ] enic_set_vf_port assumes that the nl attribute IFLA_PORT_PROFILE is of length PORT_PROFILE_MAX and that the nl attributes IFLA_PORT_INSTANCE_UUID, IFLA_PORT_HOST_UUID are of length PORT_UUID_MAX. These attributes are validated (in the function do_setlink in rtnetlink.c) using the nla_policy ifla_port_policy. The policy defines IFLA_PORT_PROFILE as NLA_STRING, IFLA_PORT_INSTANCE_UUID as NLA_BINARY and IFLA_PORT_HOST_UUID as NLA_STRING. That means that the length validation using the policy is for the max size of the attributes and not on exact size so the length of these attributes might be less than the sizes that enic_set_vf_port expects. This might cause an out of bands read access in the memcpys of the data of these attributes in enic_set_vf_port. Fixes: f8bd909 ("net: Add ndo_{set|get}_vf_port support for enic dynamic vnics") Signed-off-by: Roded Zats <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 2702f29 commit 10c77e7

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/net/ethernet/cisco/enic/enic_main.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,18 +1117,30 @@ static int enic_set_vf_port(struct net_device *netdev, int vf,
11171117
pp->request = nla_get_u8(port[IFLA_PORT_REQUEST]);
11181118

11191119
if (port[IFLA_PORT_PROFILE]) {
1120+
if (nla_len(port[IFLA_PORT_PROFILE]) != PORT_PROFILE_MAX) {
1121+
memcpy(pp, &prev_pp, sizeof(*pp));
1122+
return -EINVAL;
1123+
}
11201124
pp->set |= ENIC_SET_NAME;
11211125
memcpy(pp->name, nla_data(port[IFLA_PORT_PROFILE]),
11221126
PORT_PROFILE_MAX);
11231127
}
11241128

11251129
if (port[IFLA_PORT_INSTANCE_UUID]) {
1130+
if (nla_len(port[IFLA_PORT_INSTANCE_UUID]) != PORT_UUID_MAX) {
1131+
memcpy(pp, &prev_pp, sizeof(*pp));
1132+
return -EINVAL;
1133+
}
11261134
pp->set |= ENIC_SET_INSTANCE;
11271135
memcpy(pp->instance_uuid,
11281136
nla_data(port[IFLA_PORT_INSTANCE_UUID]), PORT_UUID_MAX);
11291137
}
11301138

11311139
if (port[IFLA_PORT_HOST_UUID]) {
1140+
if (nla_len(port[IFLA_PORT_HOST_UUID]) != PORT_UUID_MAX) {
1141+
memcpy(pp, &prev_pp, sizeof(*pp));
1142+
return -EINVAL;
1143+
}
11321144
pp->set |= ENIC_SET_HOST;
11331145
memcpy(pp->host_uuid,
11341146
nla_data(port[IFLA_PORT_HOST_UUID]), PORT_UUID_MAX);

0 commit comments

Comments
 (0)