All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <jakub.kicinski@netronome.com>
To: davem@davemloft.net, dsahern@gmail.com
Cc: netdev@vger.kernel.org, oss-drivers@netronome.com,
	Jakub Kicinski <jakub.kicinski@netronome.com>
Subject: [PATCH net-next 04/13] rtnetlink: ifinfo: perform strict checks also for doit handler
Date: Thu, 17 Jan 2019 14:52:51 -0800	[thread overview]
Message-ID: <20190117225300.8006-5-jakub.kicinski@netronome.com> (raw)
In-Reply-To: <20190117225300.8006-1-jakub.kicinski@netronome.com>

Make RTM_GETLINK's doit handler use strict checks when
NETLINK_F_STRICT_CHK is set.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
 net/core/rtnetlink.c | 49 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 3c134b928071..aef9cbca8358 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -3242,6 +3242,53 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
 	return ret;
 }
 
+static int rtnl_valid_getlink_req(struct sk_buff *skb,
+				  const struct nlmsghdr *nlh,
+				  struct nlattr **tb,
+				  struct netlink_ext_ack *extack)
+{
+	struct ifinfomsg *ifm;
+	int i, err;
+
+	if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) {
+		NL_SET_ERR_MSG(extack, "Invalid header for get link");
+		return -EINVAL;
+	}
+
+	if (!netlink_strict_get_check(skb))
+		return nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy,
+				   extack);
+
+	ifm = nlmsg_data(nlh);
+	if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags ||
+	    ifm->ifi_change) {
+		NL_SET_ERR_MSG(extack, "Invalid values in header for get link request");
+		return -EINVAL;
+	}
+
+	err = nlmsg_parse_strict(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy,
+				 extack);
+	if (err)
+		return err;
+
+	for (i = 0; i <= IFLA_MAX; i++) {
+		if (!tb[i])
+			continue;
+
+		switch (i) {
+		case IFLA_IFNAME:
+		case IFLA_EXT_MASK:
+		case IFLA_TARGET_NETNSID:
+			break;
+		default:
+			NL_SET_ERR_MSG(extack, "Unsupported attribute in get link request");
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
 static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh,
 			struct netlink_ext_ack *extack)
 {
@@ -3256,7 +3303,7 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh,
 	int err;
 	u32 ext_filter_mask = 0;
 
-	err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFLA_MAX, ifla_policy, extack);
+	err = rtnl_valid_getlink_req(skb, nlh, tb, extack);
 	if (err < 0)
 		return err;
 
-- 
2.19.2


  parent reply	other threads:[~2019-01-17 22:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-17 22:52 [PATCH net-next 00/13] net: use strict checks in doit handlers Jakub Kicinski
2019-01-17 22:52 ` [PATCH net-next 01/13] net: netlink: add helper to retrieve NETLINK_F_STRICT_CHK Jakub Kicinski
2019-01-17 22:52 ` [PATCH net-next 02/13] rtnetlink: stats: validate attributes in get as well as dumps Jakub Kicinski
2019-01-17 22:52 ` [PATCH net-next 03/13] rtnetlink: stats: reject requests for unknown stats Jakub Kicinski
2019-01-17 22:52 ` Jakub Kicinski [this message]
2019-01-17 22:52 ` [PATCH net-next 05/13] net: ipv4: perform strict checks also for doit handlers Jakub Kicinski
2019-01-18 14:41   ` David Ahern
2019-01-17 22:52 ` [PATCH net-next 06/13] net: namespace: " Jakub Kicinski
2019-01-18  8:17   ` Nicolas Dichtel
2019-01-18 18:00     ` Jakub Kicinski
2019-01-17 22:52 ` [PATCH net-next 07/13] net: ipv4: ipmr: " Jakub Kicinski
2019-01-18 14:24   ` David Ahern
2019-01-17 22:52 ` [PATCH net-next 08/13] net: ipv6: addr: " Jakub Kicinski
2019-01-17 22:52 ` [PATCH net-next 09/13] net: ipv6: netconf: " Jakub Kicinski
2019-01-17 22:52 ` [PATCH net-next 10/13] net: ipv6: addrlabel: " Jakub Kicinski
2019-01-17 22:52 ` [PATCH net-next 11/13] net: ipv6: route: " Jakub Kicinski
2019-01-17 22:52 ` [PATCH net-next 12/13] net: mpls: " Jakub Kicinski
2019-01-17 22:53 ` [PATCH net-next 13/13] net: mpls: netconf: " Jakub Kicinski
2019-01-18 14:45 ` [PATCH net-next 00/13] net: use strict checks in " David Ahern
2019-01-18 18:01   ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190117225300.8006-5-jakub.kicinski@netronome.com \
    --to=jakub.kicinski@netronome.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.