Skip to content

Commit ed6eff1

Browse files
dsaherndavem330
authored andcommitted
net/ipv6: Update inet6_dump_addr for strict data checking
Update inet6_dump_addr for strict data checking. If the flag is set, the dump request is expected to have an ifaddrmsg struct as the header potentially followed by one or more attributes. Any data passed in the header or as an attribute is taken as a request to influence the data returned. Only values suppored by the dump handler are allowed to be non-0 or set in the request. At the moment only the IFA_TARGET_NETNSID attribute is supported. Follow on patches can add support for other fields (e.g., honor ifa_index and only return data for the given device index). Signed-off-by: David Ahern <[email protected]> Acked-by: Christian Brauner <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c33078e commit ed6eff1

File tree

1 file changed

+59
-10
lines changed

1 file changed

+59
-10
lines changed

net/ipv6/addrconf.c

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4998,9 +4998,62 @@ static int in6_dump_addrs(struct inet6_dev *idev, struct sk_buff *skb,
49984998
return err;
49994999
}
50005000

5001+
static int inet6_valid_dump_ifaddr_req(const struct nlmsghdr *nlh,
5002+
struct inet6_fill_args *fillargs,
5003+
struct net **tgt_net, struct sock *sk,
5004+
struct netlink_ext_ack *extack)
5005+
{
5006+
struct nlattr *tb[IFA_MAX+1];
5007+
struct ifaddrmsg *ifm;
5008+
int err, i;
5009+
5010+
if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) {
5011+
NL_SET_ERR_MSG_MOD(extack, "Invalid header for address dump request");
5012+
return -EINVAL;
5013+
}
5014+
5015+
ifm = nlmsg_data(nlh);
5016+
if (ifm->ifa_prefixlen || ifm->ifa_flags || ifm->ifa_scope) {
5017+
NL_SET_ERR_MSG_MOD(extack, "Invalid values in header for address dump request");
5018+
return -EINVAL;
5019+
}
5020+
if (ifm->ifa_index) {
5021+
NL_SET_ERR_MSG_MOD(extack, "Filter by device index not supported for address dump");
5022+
return -EINVAL;
5023+
}
5024+
5025+
err = nlmsg_parse_strict(nlh, sizeof(*ifm), tb, IFA_MAX,
5026+
ifa_ipv6_policy, extack);
5027+
if (err < 0)
5028+
return err;
5029+
5030+
for (i = 0; i <= IFA_MAX; ++i) {
5031+
if (!tb[i])
5032+
continue;
5033+
5034+
if (i == IFA_TARGET_NETNSID) {
5035+
struct net *net;
5036+
5037+
fillargs->netnsid = nla_get_s32(tb[i]);
5038+
net = rtnl_get_net_ns_capable(sk, fillargs->netnsid);
5039+
if (IS_ERR(net)) {
5040+
NL_SET_ERR_MSG_MOD(extack, "Invalid target network namespace id");
5041+
return PTR_ERR(net);
5042+
}
5043+
*tgt_net = net;
5044+
} else {
5045+
NL_SET_ERR_MSG_MOD(extack, "Unsupported attribute in dump request");
5046+
return -EINVAL;
5047+
}
5048+
}
5049+
5050+
return 0;
5051+
}
5052+
50015053
static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
50025054
enum addr_type_t type)
50035055
{
5056+
const struct nlmsghdr *nlh = cb->nlh;
50045057
struct inet6_fill_args fillargs = {
50055058
.portid = NETLINK_CB(cb->skb).portid,
50065059
.seq = cb->nlh->nlmsg_seq,
@@ -5009,7 +5062,6 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
50095062
.type = type,
50105063
};
50115064
struct net *net = sock_net(skb->sk);
5012-
struct nlattr *tb[IFA_MAX+1];
50135065
struct net *tgt_net = net;
50145066
int h, s_h;
50155067
int idx, ip_idx;
@@ -5022,16 +5074,13 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
50225074
s_idx = idx = cb->args[1];
50235075
s_ip_idx = ip_idx = cb->args[2];
50245076

5025-
if (nlmsg_parse(cb->nlh, sizeof(struct ifaddrmsg), tb, IFA_MAX,
5026-
ifa_ipv6_policy, cb->extack) >= 0) {
5027-
if (tb[IFA_TARGET_NETNSID]) {
5028-
fillargs.netnsid = nla_get_s32(tb[IFA_TARGET_NETNSID]);
5077+
if (cb->strict_check) {
5078+
int err;
50295079

5030-
tgt_net = rtnl_get_net_ns_capable(skb->sk,
5031-
fillargs.netnsid);
5032-
if (IS_ERR(tgt_net))
5033-
return PTR_ERR(tgt_net);
5034-
}
5080+
err = inet6_valid_dump_ifaddr_req(nlh, &fillargs, &tgt_net,
5081+
skb->sk, cb->extack);
5082+
if (err < 0)
5083+
return err;
50355084
}
50365085

50375086
rcu_read_lock();

0 commit comments

Comments
 (0)