Commit 0a833c29 authored by Michal Kubecek's avatar Michal Kubecek Committed by David S. Miller

genetlink: fix genlmsg_nlhdr()

According to the description, first argument of genlmsg_nlhdr() points to
what genlmsg_put() returns, i.e. beginning of user header. Therefore we
should only subtract size of genetlink header and netlink message header,
not user header.

This also means we don't need to pass the pointer to genetlink family and
the same is true for genl_dump_check_consistent() which is the only caller
of genlmsg_nlhdr(). (Note that at the moment, these functions are only
used for families which do not have user header so that they are not
affected.)

Fixes: 670dc283 ("netlink: advertise incomplete dumps")
Signed-off-by: default avatarMichal Kubecek <mkubecek@suse.cz>
Reviewed-by: default avatarJohannes Berg <johannes@sipsolutions.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 423852f8
...@@ -2411,7 +2411,7 @@ static int dump_secy(struct macsec_secy *secy, struct net_device *dev, ...@@ -2411,7 +2411,7 @@ static int dump_secy(struct macsec_secy *secy, struct net_device *dev,
if (!hdr) if (!hdr)
return -EMSGSIZE; return -EMSGSIZE;
genl_dump_check_consistent(cb, hdr, &macsec_fam); genl_dump_check_consistent(cb, hdr);
if (nla_put_u32(skb, MACSEC_ATTR_IFINDEX, dev->ifindex)) if (nla_put_u32(skb, MACSEC_ATTR_IFINDEX, dev->ifindex))
goto nla_put_failure; goto nla_put_failure;
......
...@@ -2805,7 +2805,7 @@ static int mac80211_hwsim_get_radio(struct sk_buff *skb, ...@@ -2805,7 +2805,7 @@ static int mac80211_hwsim_get_radio(struct sk_buff *skb,
return -EMSGSIZE; return -EMSGSIZE;
if (cb) if (cb)
genl_dump_check_consistent(cb, hdr, &hwsim_genl_family); genl_dump_check_consistent(cb, hdr);
if (data->alpha2[0] && data->alpha2[1]) if (data->alpha2[0] && data->alpha2[1])
param.reg_alpha2 = data->alpha2; param.reg_alpha2 = data->alpha2;
......
...@@ -154,15 +154,12 @@ void *genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq, ...@@ -154,15 +154,12 @@ void *genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq,
/** /**
* genlmsg_nlhdr - Obtain netlink header from user specified header * genlmsg_nlhdr - Obtain netlink header from user specified header
* @user_hdr: user header as returned from genlmsg_put() * @user_hdr: user header as returned from genlmsg_put()
* @family: generic netlink family
* *
* Returns pointer to netlink header. * Returns pointer to netlink header.
*/ */
static inline struct nlmsghdr * static inline struct nlmsghdr *genlmsg_nlhdr(void *user_hdr)
genlmsg_nlhdr(void *user_hdr, const struct genl_family *family)
{ {
return (struct nlmsghdr *)((char *)user_hdr - return (struct nlmsghdr *)((char *)user_hdr -
family->hdrsize -
GENL_HDRLEN - GENL_HDRLEN -
NLMSG_HDRLEN); NLMSG_HDRLEN);
} }
...@@ -190,16 +187,14 @@ static inline int genlmsg_parse(const struct nlmsghdr *nlh, ...@@ -190,16 +187,14 @@ static inline int genlmsg_parse(const struct nlmsghdr *nlh,
* genl_dump_check_consistent - check if sequence is consistent and advertise if not * genl_dump_check_consistent - check if sequence is consistent and advertise if not
* @cb: netlink callback structure that stores the sequence number * @cb: netlink callback structure that stores the sequence number
* @user_hdr: user header as returned from genlmsg_put() * @user_hdr: user header as returned from genlmsg_put()
* @family: generic netlink family
* *
* Cf. nl_dump_check_consistent(), this just provides a wrapper to make it * Cf. nl_dump_check_consistent(), this just provides a wrapper to make it
* simpler to use with generic netlink. * simpler to use with generic netlink.
*/ */
static inline void genl_dump_check_consistent(struct netlink_callback *cb, static inline void genl_dump_check_consistent(struct netlink_callback *cb,
void *user_hdr, void *user_hdr)
const struct genl_family *family)
{ {
nl_dump_check_consistent(cb, genlmsg_nlhdr(user_hdr, family)); nl_dump_check_consistent(cb, genlmsg_nlhdr(user_hdr));
} }
/** /**
......
...@@ -75,7 +75,7 @@ static int nfc_genl_send_target(struct sk_buff *msg, struct nfc_target *target, ...@@ -75,7 +75,7 @@ static int nfc_genl_send_target(struct sk_buff *msg, struct nfc_target *target,
if (!hdr) if (!hdr)
return -EMSGSIZE; return -EMSGSIZE;
genl_dump_check_consistent(cb, hdr, &nfc_genl_family); genl_dump_check_consistent(cb, hdr);
if (nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target->idx) || if (nla_put_u32(msg, NFC_ATTR_TARGET_INDEX, target->idx) ||
nla_put_u32(msg, NFC_ATTR_PROTOCOLS, target->supported_protocols) || nla_put_u32(msg, NFC_ATTR_PROTOCOLS, target->supported_protocols) ||
...@@ -603,7 +603,7 @@ static int nfc_genl_send_device(struct sk_buff *msg, struct nfc_dev *dev, ...@@ -603,7 +603,7 @@ static int nfc_genl_send_device(struct sk_buff *msg, struct nfc_dev *dev,
return -EMSGSIZE; return -EMSGSIZE;
if (cb) if (cb)
genl_dump_check_consistent(cb, hdr, &nfc_genl_family); genl_dump_check_consistent(cb, hdr);
if (nfc_genl_setup_device_added(dev, msg)) if (nfc_genl_setup_device_added(dev, msg))
goto nla_put_failure; goto nla_put_failure;
...@@ -1356,7 +1356,7 @@ static int nfc_genl_send_se(struct sk_buff *msg, struct nfc_dev *dev, ...@@ -1356,7 +1356,7 @@ static int nfc_genl_send_se(struct sk_buff *msg, struct nfc_dev *dev,
goto nla_put_failure; goto nla_put_failure;
if (cb) if (cb)
genl_dump_check_consistent(cb, hdr, &nfc_genl_family); genl_dump_check_consistent(cb, hdr);
if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) || if (nla_put_u32(msg, NFC_ATTR_DEVICE_INDEX, dev->idx) ||
nla_put_u32(msg, NFC_ATTR_SE_INDEX, se->idx) || nla_put_u32(msg, NFC_ATTR_SE_INDEX, se->idx) ||
......
...@@ -6291,7 +6291,7 @@ static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, ...@@ -6291,7 +6291,7 @@ static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
if (!hdr) if (!hdr)
return -1; return -1;
genl_dump_check_consistent(cb, hdr, &nl80211_fam); genl_dump_check_consistent(cb, hdr);
if (nl80211_put_regdom(regdom, msg)) if (nl80211_put_regdom(regdom, msg))
goto nla_put_failure; goto nla_put_failure;
...@@ -7722,7 +7722,7 @@ static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, ...@@ -7722,7 +7722,7 @@ static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
if (!hdr) if (!hdr)
return -1; return -1;
genl_dump_check_consistent(cb, hdr, &nl80211_fam); genl_dump_check_consistent(cb, hdr);
if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
goto nla_put_failure; goto nla_put_failure;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment