Skip to content

Commit aea199f

Browse files
Asbjørn Sloth Tønnesenzx2c4
authored andcommitted
wireguard: netlink: validate nested arrays in policy
Use NLA_POLICY_NESTED_ARRAY() to perform nested array validation in the policy validation step. The nested policy was already enforced through nla_parse_nested(), however extack wasn't passed previously, so no fancy error messages. With the nested attributes being validated directly in the policy, the policy argument can be set to NULL in the calls to nla_parse_nested(). Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 parent e0e1b6d commit aea199f

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

drivers/net/wireguard/netlink.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <crypto/utils.h>
1919

2020
static struct genl_family genl_family;
21+
static const struct nla_policy peer_policy[WGPEER_A_MAX + 1];
22+
static const struct nla_policy allowedip_policy[WGALLOWEDIP_A_MAX + 1];
2123

2224
static const struct nla_policy device_policy[WGDEVICE_A_MAX + 1] = {
2325
[WGDEVICE_A_IFINDEX] = { .type = NLA_U32 },
@@ -27,7 +29,7 @@ static const struct nla_policy device_policy[WGDEVICE_A_MAX + 1] = {
2729
[WGDEVICE_A_FLAGS] = NLA_POLICY_MASK(NLA_U32, __WGDEVICE_F_ALL),
2830
[WGDEVICE_A_LISTEN_PORT] = { .type = NLA_U16 },
2931
[WGDEVICE_A_FWMARK] = { .type = NLA_U32 },
30-
[WGDEVICE_A_PEERS] = { .type = NLA_NESTED }
32+
[WGDEVICE_A_PEERS] = NLA_POLICY_NESTED_ARRAY(peer_policy),
3133
};
3234

3335
static const struct nla_policy peer_policy[WGPEER_A_MAX + 1] = {
@@ -39,7 +41,7 @@ static const struct nla_policy peer_policy[WGPEER_A_MAX + 1] = {
3941
[WGPEER_A_LAST_HANDSHAKE_TIME] = NLA_POLICY_EXACT_LEN(sizeof(struct __kernel_timespec)),
4042
[WGPEER_A_RX_BYTES] = { .type = NLA_U64 },
4143
[WGPEER_A_TX_BYTES] = { .type = NLA_U64 },
42-
[WGPEER_A_ALLOWEDIPS] = { .type = NLA_NESTED },
44+
[WGPEER_A_ALLOWEDIPS] = NLA_POLICY_NESTED_ARRAY(allowedip_policy),
4345
[WGPEER_A_PROTOCOL_VERSION] = { .type = NLA_U32 }
4446
};
4547

@@ -467,7 +469,7 @@ static int set_peer(struct wg_device *wg, struct nlattr **attrs)
467469

468470
nla_for_each_nested(attr, attrs[WGPEER_A_ALLOWEDIPS], rem) {
469471
ret = nla_parse_nested(allowedip, WGALLOWEDIP_A_MAX,
470-
attr, allowedip_policy, NULL);
472+
attr, NULL, NULL);
471473
if (ret < 0)
472474
goto out;
473475
ret = set_allowedip(peer, allowedip);
@@ -593,7 +595,7 @@ static int wg_set_device(struct sk_buff *skb, struct genl_info *info)
593595

594596
nla_for_each_nested(attr, info->attrs[WGDEVICE_A_PEERS], rem) {
595597
ret = nla_parse_nested(peer, WGPEER_A_MAX, attr,
596-
peer_policy, NULL);
598+
NULL, NULL);
597599
if (ret < 0)
598600
goto out;
599601
ret = set_peer(wg, peer);

0 commit comments

Comments
 (0)