ipset: fix a missing check of nla_parse
Subsystems (3)
PATCH 1/1 ipset: fix a missing check of nla_parse
When nla_parse fails, we should not use the results (the first argument). The fix checks if it fails, and if so, returns its error code upstream.
--- net/netfilter/ipset/ip_set_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/netfilter/ipset/ip_set_core.c +3 -1
@@ -1531,8 +1531,10 @@ call_ad(struct sock *ctnl, struct sk_buff *skb, struct ip_set *set,memcpy (&errmsg->msg, nlh, nlh->nlmsg_len); cmdattr = (void *)&errmsg->msg + min_len; -nla_parse (cda,IPSET_ATTR_CMD_MAX , cmdattr, + ret =nla_parse (cda,IPSET_ATTR_CMD_MAX , cmdattr, nlh->nlmsg_len - min_len, ip_set_adt_policy,NULL ); +if (ret) +return ret; errline =nla_data (cda[IPSET_ATTR_LINENO ]);
Signature · 1 line
2.17.2 (Apple Git-113)
Quoted 14 lines · Kangjie Lu
When
nla_parsefails, we should not use the results (the first argument). The fix checks if it fails, and if so, returns its error code upstream.Signed-off-by Kangjie Lu <[email protected]>--- net/netfilter/ipset/ip_set_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/netfilter/ipset/ip_set_core.c +0
-0
net/netfilter/ipset/ip_set_core.c call_ad(struct sock *ctnl, struct sk_buff *skb, struct ip_set *set, · line 1537
Quoted 8 lines
net/netfilter/ipset/ip_set_core.c +3
-1@@ -1531,8 +1531,10 @@ call_ad(struct sock *ctnl, struct sk_buff *skb, struct ip_set *set,memcpy (&errmsg->msg, nlh, nlh->nlmsg_len); cmdattr = (void *)&errmsg->msg + min_len; -nla_parse (cda,IPSET_ATTR_CMD_MAX , cmdattr, + ret =nla_parse (cda,IPSET_ATTR_CMD_MAX , cmdattr, nlh->nlmsg_len - min_len, ip_set_adt_policy,NULL ); +if (ret) +return ret;
In this function above nlmsg_new() allocates skb2, but I don't see, where you free it here.
Quoted 4 lines
net/netfilter/ipset/ip_set_core.c +0
-0errline =nla_data (cda[IPSET_ATTR_LINENO ]);
Pablo Neira Ayuso
maintainerQuoted 18 lines · Kirill Tkhai
Quoted 17 lines · Kangjie Lu
When
nla_parsefails, we should not use the results (the first argument). The fix checks if it fails, and if so, returns its error code upstream.Signed-off-by Kangjie Lu <[email protected]>--- net/netfilter/ipset/ip_set_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/netfilter/ipset/ip_set_core.c +0
-0@@ -1531,8 +1531,10 @@ call_ad(struct sock *ctnl, struct sk_buff *skb, struct ip_set *set,memcpy (&errmsg->msg, nlh, nlh->nlmsg_len); cmdattr = (void *)&errmsg->msg + min_len;
Quoted 3 lines
net/netfilter/ipset/ip_set_core.c call_ad(struct sock *ctnl, struct sk_buff *skb, struct ip_set *set, · line 1535
Quoted 3 lines
net/netfilter/ipset/ip_set_core.c +1
-1-nla_parse (cda,IPSET_ATTR_CMD_MAX , cmdattr, + ret =nla_parse (cda,IPSET_ATTR_CMD_MAX , cmdattr, nlh->nlmsg_len - min_len, ip_set_adt_policy,NULL );
@Kangjie: nitpick, could you align this line below? ie.
ret = nla_parse(cda, IPSET_ATTR_CMD_MAX, cmdattr,
nlh->nlmsg_len - min_len, ip_set_adt_policy,
NULL);Quoted 4 lines
net/netfilter/ipset/ip_set_core.c call_ad(struct sock *ctnl, struct sk_buff *skb, struct ip_set *set, · line 1537
Quoted 2 lines
net/netfilter/ipset/ip_set_core.c +2
-0+if (ret) +return ret;In this function above
nlmsg_new()allocates skb2, but I don't see, where you free it here.
netlink_unicast() is responsible for releasing this skb2.
Quoted 3 lines
Quoted 3 lines
net/netfilter/ipset/ip_set_core.c +0
-0errline =nla_data (cda[IPSET_ATTR_LINENO ]);
Quoted 29 lines · Pablo Neira Ayuso
Quoted 18 lines · Kirill Tkhai
Quoted 17 lines · Kangjie Lu
When
nla_parsefails, we should not use the results (the first argument). The fix checks if it fails, and if so, returns its error code upstream.Signed-off-by Kangjie Lu <[email protected]>--- net/netfilter/ipset/ip_set_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/netfilter/ipset/ip_set_core.c +0
-0@@ -1531,8 +1531,10 @@ call_ad(struct sock *ctnl, struct sk_buff *skb, struct ip_set *set,memcpy (&errmsg->msg, nlh, nlh->nlmsg_len); cmdattr = (void *)&errmsg->msg + min_len;Quoted 3 lines
net/netfilter/ipset/ip_set_core.c call_ad(struct sock *ctnl, struct sk_buff *skb, struct ip_set *set, · line 1535
Quoted 3 lines
net/netfilter/ipset/ip_set_core.c +1
-1-nla_parse (cda,IPSET_ATTR_CMD_MAX , cmdattr, + ret =nla_parse (cda,IPSET_ATTR_CMD_MAX , cmdattr, nlh->nlmsg_len - min_len, ip_set_adt_policy,NULL );@Kangjie: nitpick, could you align this line below? ie.
ret = nla_parse(cda, IPSET_ATTR_CMD_MAX, cmdattr, nlh->nlmsg_len - min_len, ip_set_adt_policy, NULL);
Quoted 6 lines
Quoted 4 lines
net/netfilter/ipset/ip_set_core.c call_ad(struct sock *ctnl, struct sk_buff *skb, struct ip_set *set, · line 1537
Quoted 2 lines
net/netfilter/ipset/ip_set_core.c +2
-0+if (ret) +return ret;In this function above
nlmsg_new()allocates skb2, but I don't see, where you free it here.
netlink_unicast()is responsible for releasing this skb2.
We return earlier at "if (ret)", so netlink_unicast() is not called.
Quoted 1 line
Quoted 1 line
net/netfilter/ipset/ip_set_core.c call_ad(struct sock *ctnl, struct sk_buff *skb, struct ip_set *set, · line 1539
Quoted 1 line
net/netfilter/ipset/ip_set_core.c +0
-0errline =nla_data (cda[IPSET_ATTR_LINENO ]);
Kirill