From: Johannes Berg <[email protected]>

Clear any nl80211 messages that might contain keys after
processing them to avoid leaving their data in memory
"forever" after they've been freed.

Signed-off-by: Johannes Berg <[email protected]>
Signed-off-by: Emmanuel Grumbach <[email protected]>
---
 net/wireless/nl80211.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c
index 51eb526..1dea517 100644
--- a/net/wireless/nl80211.c
+++ b/net/wireless/nl80211.c
@@ -9587,6 +9587,7 @@ static int nl80211_del_tx_ts(struct sk_buff *skb, struct 
genl_info *info)
 /* If a netdev is associated, it must be UP, P2P must be started */
 #define NL80211_FLAG_NEED_WDEV_UP      (NL80211_FLAG_NEED_WDEV |\
                                         NL80211_FLAG_CHECK_NETDEV_UP)
+#define NL80211_FLAG_CLEAR_SKB         0x20
 
 static int nl80211_pre_doit(__genl_const struct genl_ops *ops, struct sk_buff 
*skb,
                            struct genl_info *info)
@@ -9676,8 +9677,20 @@ static void nl80211_post_doit(__genl_const struct 
genl_ops *ops, struct sk_buff
                        dev_put(info->user_ptr[1]);
                }
        }
+
        if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
                rtnl_unlock();
+
+       /* If needed, clear the netlink message payload from the SKB
+        * as it might contain key data that shouldn't stick around on
+        * the heap after the SKB is freed. The netlink message header
+        * is still needed for further processing, so leave it intact.
+        */
+       if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
+               struct nlmsghdr *nlh = nlmsg_hdr(skb);
+
+               memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
+       }
 }
 
 static __genl_const struct genl_ops nl80211_ops[] = {
@@ -9745,7 +9758,8 @@ static __genl_const struct genl_ops nl80211_ops[] = {
                .policy = nl80211_policy,
                .flags = GENL_ADMIN_PERM,
                .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
-                                 NL80211_FLAG_NEED_RTNL,
+                                 NL80211_FLAG_NEED_RTNL |
+                                 NL80211_FLAG_CLEAR_SKB,
        },
        {
                .cmd = NL80211_CMD_NEW_KEY,
@@ -9753,7 +9767,8 @@ static __genl_const struct genl_ops nl80211_ops[] = {
                .policy = nl80211_policy,
                .flags = GENL_ADMIN_PERM,
                .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
-                                 NL80211_FLAG_NEED_RTNL,
+                                 NL80211_FLAG_NEED_RTNL |
+                                 NL80211_FLAG_CLEAR_SKB,
        },
        {
                .cmd = NL80211_CMD_DEL_KEY,
@@ -9931,7 +9946,8 @@ static __genl_const struct genl_ops nl80211_ops[] = {
                .policy = nl80211_policy,
                .flags = GENL_ADMIN_PERM,
                .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
-                                 NL80211_FLAG_NEED_RTNL,
+                                 NL80211_FLAG_NEED_RTNL |
+                                 NL80211_FLAG_CLEAR_SKB,
        },
        {
                .cmd = NL80211_CMD_ASSOCIATE,
@@ -10165,7 +10181,8 @@ static __genl_const struct genl_ops nl80211_ops[] = {
                .policy = nl80211_policy,
                .flags = GENL_ADMIN_PERM,
                .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
-                                 NL80211_FLAG_NEED_RTNL,
+                                 NL80211_FLAG_NEED_RTNL |
+                                 NL80211_FLAG_CLEAR_SKB,
        },
        {
                .cmd = NL80211_CMD_TDLS_MGMT,
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to