From: Ben Pfaff Date: Wed, 31 Dec 2008 18:35:42 +0000 (-0800) Subject: Make the datapath tolerate kernels that lack NLA_NUL_STRING. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9ac5cc3e191ac6aa93ef3412be1e0a107ea2c22;p=openvswitch Make the datapath tolerate kernels that lack NLA_NUL_STRING. NLA_NUL_STRING was introduced in 2.6.19. --- diff --git a/acinclude.m4 b/acinclude.m4 index 1380940e..1017ff7e 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -109,6 +109,8 @@ AC_DEFUN([OFP_CHECK_LINUX26_COMPAT], [ [OFP_DEFINE([HAVE_SKBUFF_HEADER_HELPERS])]) OFP_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [raw], [OFP_DEFINE([HAVE_MAC_RAW])]) + OFP_GREP_IFELSE([$KSRC26/include/net/netlink.h], [NLA_NUL_STRING], + [OFP_DEFINE([HAVE_NLA_NUL_STRING])]) if cmp -s datapath/linux-2.6/kcompat.h.new \ datapath/linux-2.6/kcompat.h >/dev/null 2>&1; then rm datapath/linux-2.6/kcompat.h.new diff --git a/datapath/datapath.c b/datapath/datapath.c index 286c4c02..d6f5c259 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -1116,6 +1116,9 @@ static int dp_genl_add(struct sk_buff *skb, struct genl_info *info) const char *dp_name = info->attrs[DP_GENL_A_DP_NAME] ? nla_data(info->attrs[DP_GENL_A_DP_NAME]) : NULL; + if (VERIFY_NUL_STRING(info->attrs[DP_GENL_A_DP_NAME])) + return -EINVAL; + if ((dp_idx == -1) && (!dp_name)) return -EINVAL; @@ -1157,6 +1160,9 @@ lookup_dp(struct genl_info *info) const char *dp_name = info->attrs[DP_GENL_A_DP_NAME] ? nla_data(info->attrs[DP_GENL_A_DP_NAME]) : NULL; + if (VERIFY_NUL_STRING(info->attrs[DP_GENL_A_DP_NAME])) + return ERR_PTR(-EINVAL); + if (dp_idx != -1) { struct datapath *dp = dp_get_by_idx(dp_idx); if (!dp) @@ -1260,7 +1266,8 @@ static int dp_genl_add_del_port(struct sk_buff *skb, struct genl_info *info) struct net_device *port; int err; - if (!info->attrs[DP_GENL_A_PORTNAME]) + if (!info->attrs[DP_GENL_A_PORTNAME] || + VERIFY_NUL_STRING(info->attrs[DP_GENL_A_PORTNAME])) return -EINVAL; /* Get datapath. */ diff --git a/datapath/linux-2.4/compat-2.4/include/net/netlink.h b/datapath/linux-2.4/compat-2.4/include/net/netlink.h index 46cdafd9..f4e3155b 100644 --- a/datapath/linux-2.4/compat-2.4/include/net/netlink.h +++ b/datapath/linux-2.4/compat-2.4/include/net/netlink.h @@ -1011,4 +1011,9 @@ static inline int nla_validate_nested(struct nlattr *start, int maxtype, #define nla_for_each_nested(pos, nla, rem) \ nla_for_each_attr(pos, nla_data(nla), nla_len(nla), rem) +static inline int VERIFY_NUL_STRING(struct nlattr *attr) +{ + return 0; +} + #endif diff --git a/datapath/linux-2.6/compat-2.6/include/net/netlink.h b/datapath/linux-2.6/compat-2.6/include/net/netlink.h new file mode 100644 index 00000000..0be53157 --- /dev/null +++ b/datapath/linux-2.6/compat-2.6/include/net/netlink.h @@ -0,0 +1,22 @@ +#ifndef __NET_NETLINK_WRAPPER_H +#define __NET_NETLINK_WRAPPER_H 1 + +#include_next + +#ifndef HAVE_NLA_NUL_STRING +#define NLA_NUL_STRING NLA_STRING + +static inline int VERIFY_NUL_STRING(struct nlattr *attr) +{ + return (!attr || (nla_len(attr) + && memchr(nla_data(attr), '0', nla_len(attr))) + ? 0 : EINVAL); +} +#else +static inline int VERIFY_NUL_STRING(struct nlattr *attr) +{ + return 0; +} +#endif /* !HAVE_NLA_NUL_STRING */ + +#endif /* net/netlink.h */