Message ID | 20181004213355.14899-12-dsahern@kernel.org |
---|---|
State | Changes Requested, archived |
Delegated to: | David Miller |
Headers | show |
Series | rtnetlink: Add support for rigid checking of data in dump request | expand |
On Thu, Oct 04, 2018 at 02:33:46PM -0700, David Ahern wrote: > From: David Ahern <dsahern@gmail.com> > > Update inet6_dump_ifinfo for strict data checking. If the flag is > set, the dump request is expected to have an ifinfomsg struct as > the header. All elements of the struct are expected to be 0 and no > attributes can be appended. > > Signed-off-by: David Ahern <dsahern@gmail.com> This is on top of current net-next? Are your patches ensuring that ipv6 addr requests don't generate log messages anymore when a wrong header is passed but the strict socket option is not passed? The context here doesn't seem to indicate that. :) > --- > net/ipv6/addrconf.c | 35 +++++++++++++++++++++++++++++++++++ > 1 file changed, 35 insertions(+) > > diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c > index f749a3ad721a..693199a29426 100644 > --- a/net/ipv6/addrconf.c > +++ b/net/ipv6/addrconf.c > @@ -5628,6 +5628,31 @@ static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev, > return -EMSGSIZE; > } > > +static int inet6_valid_dump_ifinfo(const struct nlmsghdr *nlh, > + struct netlink_ext_ack *extack) > +{ > + struct ifinfomsg *ifm; > + > + if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { > + NL_SET_ERR_MSG(extack, "Invalid header"); > + return -EINVAL; > + } > + > + if (nlh->nlmsg_len > nlmsg_msg_size(sizeof(*ifm))) { > + NL_SET_ERR_MSG(extack, "Invalid data after header"); > + return -EINVAL; > + } > + > + ifm = nlmsg_data(nlh); > + if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags || > + ifm->ifi_change || ifm->ifi_index) { > + NL_SET_ERR_MSG(extack, "Invalid values in header for dump request"); > + return -EINVAL; > + } > + > + return 0; > +} > + > static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) > { > struct net *net = sock_net(skb->sk); > @@ -5637,6 +5662,16 @@ static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) > struct inet6_dev *idev; > struct hlist_head *head; > > + /* only requests using strict checking can pass data to > + * influence the dump > + */ > + if (cb->strict_check) { > + int err = inet6_valid_dump_ifinfo(cb->nlh, cb->extack); > + > + if (err) > + return err; > + } > + > s_h = cb->args[0]; > s_idx = cb->args[1]; > > -- > 2.11.0 >
On Fri, Oct 05, 2018 at 07:48:27PM +0200, Christian Brauner wrote: > On Thu, Oct 04, 2018 at 02:33:46PM -0700, David Ahern wrote: > > From: David Ahern <dsahern@gmail.com> > > > > Update inet6_dump_ifinfo for strict data checking. If the flag is > > set, the dump request is expected to have an ifinfomsg struct as > > the header. All elements of the struct are expected to be 0 and no > > attributes can be appended. > > > > Signed-off-by: David Ahern <dsahern@gmail.com> > > This is on top of current net-next? Are your patches ensuring that > ipv6 addr requests don't generate log messages anymore when a wrong > header is passed but the strict socket option is not passed? The context > here doesn't seem to indicate that. :) Nm, 9/10 takes care of that. Thanks! :) > > > --- > > net/ipv6/addrconf.c | 35 +++++++++++++++++++++++++++++++++++ > > 1 file changed, 35 insertions(+) > > > > diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c > > index f749a3ad721a..693199a29426 100644 > > --- a/net/ipv6/addrconf.c > > +++ b/net/ipv6/addrconf.c > > @@ -5628,6 +5628,31 @@ static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev, > > return -EMSGSIZE; > > } > > > > +static int inet6_valid_dump_ifinfo(const struct nlmsghdr *nlh, > > + struct netlink_ext_ack *extack) > > +{ > > + struct ifinfomsg *ifm; > > + > > + if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { > > + NL_SET_ERR_MSG(extack, "Invalid header"); > > + return -EINVAL; > > + } > > + > > + if (nlh->nlmsg_len > nlmsg_msg_size(sizeof(*ifm))) { > > + NL_SET_ERR_MSG(extack, "Invalid data after header"); > > + return -EINVAL; > > + } > > + > > + ifm = nlmsg_data(nlh); > > + if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags || > > + ifm->ifi_change || ifm->ifi_index) { > > + NL_SET_ERR_MSG(extack, "Invalid values in header for dump request"); > > + return -EINVAL; > > + } > > + > > + return 0; > > +} > > + > > static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) > > { > > struct net *net = sock_net(skb->sk); > > @@ -5637,6 +5662,16 @@ static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) > > struct inet6_dev *idev; > > struct hlist_head *head; > > > > + /* only requests using strict checking can pass data to > > + * influence the dump > > + */ > > + if (cb->strict_check) { > > + int err = inet6_valid_dump_ifinfo(cb->nlh, cb->extack); > > + > > + if (err) > > + return err; > > + } > > + > > s_h = cb->args[0]; > > s_idx = cb->args[1]; > > > > -- > > 2.11.0 > >
On Thu, Oct 04, 2018 at 02:33:46PM -0700, David Ahern wrote: > From: David Ahern <dsahern@gmail.com> > > Update inet6_dump_ifinfo for strict data checking. If the flag is > set, the dump request is expected to have an ifinfomsg struct as > the header. All elements of the struct are expected to be 0 and no > attributes can be appended. > > Signed-off-by: David Ahern <dsahern@gmail.com> > --- > net/ipv6/addrconf.c | 35 +++++++++++++++++++++++++++++++++++ > 1 file changed, 35 insertions(+) > > diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c > index f749a3ad721a..693199a29426 100644 > --- a/net/ipv6/addrconf.c > +++ b/net/ipv6/addrconf.c > @@ -5628,6 +5628,31 @@ static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev, > return -EMSGSIZE; > } > > +static int inet6_valid_dump_ifinfo(const struct nlmsghdr *nlh, > + struct netlink_ext_ack *extack) > +{ > + struct ifinfomsg *ifm; > + > + if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { > + NL_SET_ERR_MSG(extack, "Invalid header"); > + return -EINVAL; > + } > + > + if (nlh->nlmsg_len > nlmsg_msg_size(sizeof(*ifm))) { Shouldn't ipv6 specific dump requests at least support IFA_TARGET_NETNSID? > + NL_SET_ERR_MSG(extack, "Invalid data after header"); > + return -EINVAL; > + } > + > + ifm = nlmsg_data(nlh); > + if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags || > + ifm->ifi_change || ifm->ifi_index) { > + NL_SET_ERR_MSG(extack, "Invalid values in header for dump request"); > + return -EINVAL; > + } > + > + return 0; > +} > + > static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) > { > struct net *net = sock_net(skb->sk); > @@ -5637,6 +5662,16 @@ static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) > struct inet6_dev *idev; > struct hlist_head *head; > > + /* only requests using strict checking can pass data to > + * influence the dump > + */ > + if (cb->strict_check) { > + int err = inet6_valid_dump_ifinfo(cb->nlh, cb->extack); > + > + if (err) > + return err; > + } > + > s_h = cb->args[0]; > s_idx = cb->args[1]; > > -- > 2.11.0 >
On 10/5/18 11:48 AM, Christian Brauner wrote: > On Thu, Oct 04, 2018 at 02:33:46PM -0700, David Ahern wrote: >> From: David Ahern <dsahern@gmail.com> >> >> Update inet6_dump_ifinfo for strict data checking. If the flag is >> set, the dump request is expected to have an ifinfomsg struct as >> the header. All elements of the struct are expected to be 0 and no >> attributes can be appended. >> >> Signed-off-by: David Ahern <dsahern@gmail.com> > This is on top of current net-next? Are your patches ensuring that > ipv6 addr requests don't generate log messages anymore when a wrong > header is passed but the strict socket option is not passed? The context > here doesn't seem to indicate that. :) > this is an AF_INET6 GETLINK handler. Why? no idea, but I think you are confusing this patch with the GETADDR patch which generated the "netlink: 16 bytes leftover after parsing attributes in process `ip'." message before this set.
On 10/5/18 11:54 AM, Christian Brauner wrote: >> +static int inet6_valid_dump_ifinfo(const struct nlmsghdr *nlh, >> + struct netlink_ext_ack *extack) >> +{ >> + struct ifinfomsg *ifm; >> + >> + if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { >> + NL_SET_ERR_MSG(extack, "Invalid header"); >> + return -EINVAL; >> + } >> + >> + if (nlh->nlmsg_len > nlmsg_msg_size(sizeof(*ifm))) { > > Shouldn't ipv6 specific dump requests at least support IFA_TARGET_NETNSID? It does not today. The AF_UNSPEC GETLINK dumps it but the AF_INET6 does not. Some one can add it later if desired.
On Fri, Oct 05, 2018 at 01:26:31PM -0600, David Ahern wrote: > On 10/5/18 11:54 AM, Christian Brauner wrote: > >> +static int inet6_valid_dump_ifinfo(const struct nlmsghdr *nlh, > >> + struct netlink_ext_ack *extack) > >> +{ > >> + struct ifinfomsg *ifm; > >> + > >> + if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { > >> + NL_SET_ERR_MSG(extack, "Invalid header"); > >> + return -EINVAL; > >> + } > >> + > >> + if (nlh->nlmsg_len > nlmsg_msg_size(sizeof(*ifm))) { > > > > Shouldn't ipv6 specific dump requests at least support IFA_TARGET_NETNSID? > > It does not today. The AF_UNSPEC GETLINK dumps it but the AF_INET6 does > not. > > Some one can add it later if desired. Weird, I thought I had sent a patch for that as well. Doesn't matter now I'll just send one once your branch lands. :) Thanks!
On Fri, Oct 05, 2018 at 01:25:22PM -0600, David Ahern wrote: > On 10/5/18 11:48 AM, Christian Brauner wrote: > > On Thu, Oct 04, 2018 at 02:33:46PM -0700, David Ahern wrote: > >> From: David Ahern <dsahern@gmail.com> > >> > >> Update inet6_dump_ifinfo for strict data checking. If the flag is > >> set, the dump request is expected to have an ifinfomsg struct as > >> the header. All elements of the struct are expected to be 0 and no > >> attributes can be appended. > >> > >> Signed-off-by: David Ahern <dsahern@gmail.com> Acked-by: Christian Brauner <christian@brauner.io> > > This is on top of current net-next? Are your patches ensuring that > > ipv6 addr requests don't generate log messages anymore when a wrong > > header is passed but the strict socket option is not passed? The context > > here doesn't seem to indicate that. :) > > > > this is an AF_INET6 GETLINK handler. Why? no idea, but I think you are > confusing this patch with the GETADDR patch which generated the > "netlink: 16 bytes leftover after parsing attributes in process `ip'." > message before this set. Yes, I realized this immediately afterwards.
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index f749a3ad721a..693199a29426 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -5628,6 +5628,31 @@ static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev, return -EMSGSIZE; } +static int inet6_valid_dump_ifinfo(const struct nlmsghdr *nlh, + struct netlink_ext_ack *extack) +{ + struct ifinfomsg *ifm; + + if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { + NL_SET_ERR_MSG(extack, "Invalid header"); + return -EINVAL; + } + + if (nlh->nlmsg_len > nlmsg_msg_size(sizeof(*ifm))) { + NL_SET_ERR_MSG(extack, "Invalid data after header"); + return -EINVAL; + } + + ifm = nlmsg_data(nlh); + if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags || + ifm->ifi_change || ifm->ifi_index) { + NL_SET_ERR_MSG(extack, "Invalid values in header for dump request"); + return -EINVAL; + } + + return 0; +} + static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) { struct net *net = sock_net(skb->sk); @@ -5637,6 +5662,16 @@ static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) struct inet6_dev *idev; struct hlist_head *head; + /* only requests using strict checking can pass data to + * influence the dump + */ + if (cb->strict_check) { + int err = inet6_valid_dump_ifinfo(cb->nlh, cb->extack); + + if (err) + return err; + } + s_h = cb->args[0]; s_idx = cb->args[1];