cxgb4: cm: fix a incorrect NULL check on list iterator
Subsystems (3)
PATCH 1/1 cxgb4: cm: fix a incorrect NULL check on list iterator
The bug is here:
if (!pdev) {The list iterator value 'pdev' will *always* be set and non-NULL by for_each_netdev(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element found (in this case, the check 'if (!pdev)' can be bypassed as it always be false unexpectly).
To fix the bug, use a new variable 'iter' as the list iterator, while use the original variable 'pdev' as a dedicated pointer to point to the found element.
--- drivers/infiniband/hw/cxgb4/cm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/infiniband/hw/cxgb4/cm.c +5 -5
@@ -2071,7 +2071,7 @@ static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip, {struct neighbour *n;int err, step; -struct net_device *pdev; +struct net_device *pdev =NULL , *iter; n =dst_neigh_lookup (dst, peer_ip);if (!n)
@@ -2083,14 +2083,14 @@ static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,if (iptype ==4 ) pdev =ip_dev_find (&init_net, *(__be32 *)peer_ip);else if (IS_ENABLED (CONFIG_IPV6 )) -for_each_netdev (&init_net, pdev) { +for_each_netdev (&init_net, iter) {if (ipv6_chk_addr (&init_net, (struct in6_addr *)peer_ip, - pdev,1 )) + iter,1 )) { + pdev = iter;break ; + } } -else - pdev =NULL ;if (!pdev) { err = -ENODEV ;
Signature · 1 line
2.17.1
Quoted 9 lines · Xiaomeng Tong
The bug is here:
if (!pdev) {The list iterator value 'pdev' will *always* be set and non-NULL by
for_each_netdev(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element found (in this case, the check 'if (!pdev)' can be bypassed as it always be false unexpectly).
Quoted 3 lines
To fix the bug, use a new variable 'iter' as the list iterator, while use the original variable 'pdev' as a dedicated pointer to point to the found element.
I don't think that the description is correct.
We are talking about loopback interface which received packet, the pdev will always exist. Most likely. the check of "if (!pdev)" is to catch impossible situation where IPV6 packet was sent over loopback, but IPV6 is not enabled.
Thanks
Quoted 43 lines
Fixes 830662f6f032f ("RDMA/cxgb4: Add support for active and passive open connection with IPv6 address")Signed-off-by Xiaomeng Tong <[email protected]>--- drivers/infiniband/hw/cxgb4/cm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)drivers/infiniband/hw/cxgb4/cm.c +5
-5@@ -2071,7 +2071,7 @@ static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip, {struct neighbour *n;int err, step; -struct net_device *pdev; +struct net_device *pdev =NULL , *iter; n =dst_neigh_lookup (dst, peer_ip);if (!n)@@ -2083,14 +2083,14 @@ static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,if (iptype ==4 ) pdev =ip_dev_find (&init_net, *(__be32 *)peer_ip);else if (IS_ENABLED (CONFIG_IPV6 )) -for_each_netdev (&init_net, pdev) { +for_each_netdev (&init_net, iter) {if (ipv6_chk_addr (&init_net, (struct in6_addr *)peer_ip, - pdev,1 )) + iter,1 )) { + pdev = iter;break ; + } } -else - pdev =NULL ;if (!pdev) { err = -ENODEV ;Signature · 1 line
2.17.1
Quoted 11 lines · Leon Romanovsky
Quoted 9 lines · Xiaomeng Tong
The bug is here:
if (!pdev) {The list iterator value 'pdev' will *always* be set and non-NULL by
for_each_netdev(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element found (in this case, the check 'if (!pdev)' can be bypassed as it always be false unexpectly).
Quoted 6 lines
Quoted 3 lines
To fix the bug, use a new variable 'iter' as the list iterator, while use the original variable 'pdev' as a dedicated pointer to point to the found element.
I don't think that the description is correct.
We are talking about loopback interface which received packet, the pdev will always exist.
Do the both conditions impossible?
1. the list is empty or
2. we can not found a pdev due to this check
if (ipv6_chk_addr(&init_net, (struct in6_addr *)peer_ip, pdev, 1)) iter, 1))
Quoted 2 lines
Most likely. the check of "if (!pdev)" is to catch impossible situation where IPV6 packet was sent over loopback, but IPV6 is not enabled.
--
Xiaomeng Tong
Quoted 19 lines · Xiaomeng Tong
Quoted 11 lines · Leon Romanovsky
Quoted 9 lines · Xiaomeng Tong
The bug is here:
if (!pdev) {The list iterator value 'pdev' will *always* be set and non-NULL by
for_each_netdev(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element found (in this case, the check 'if (!pdev)' can be bypassed as it always be false unexpectly).Quoted 6 lines
Quoted 3 lines
To fix the bug, use a new variable 'iter' as the list iterator, while use the original variable 'pdev' as a dedicated pointer to point to the found element.
I don't think that the description is correct.
We are talking about loopback interface which received packet, the pdev will always exist.
Quoted 7 lines
Do the both conditions impossible?
1. the list is empty or
2. we can not found a pdev due to this checkif (ipv6_chk_addr(&init_net, (struct in6_addr *)peer_ip, pdev, 1)) iter, 1))
Yes, both are impossible.
Thanks
Quoted 6 lines
Quoted 3 lines
Most likely. the check of "if (!pdev)" is to catch impossible situation where IPV6 packet was sent over loopback, but IPV6 is not enabled.
--
Xiaomeng Tong