From: Xiaomeng Tong <xiam0nd.tong@gmail.com>
To: bharat@chelsio.com, jgg@ziepe.ca
Cc: vipul@chelsio.com, roland@purestorage.com,
linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
Xiaomeng Tong <xiam0nd.tong@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH] cxgb4: cm: fix a incorrect NULL check on list iterator
Date: Sun, 27 Mar 2022 15:35:42 +0800 [thread overview]
Message-ID: <20220327073542.10990-1-xiam0nd.tong@gmail.com> (raw)
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.
Cc: stable@vger.kernel.org
Fixes: 830662f6f032f ("RDMA/cxgb4: Add support for active and passive open connection with IPv6 address")
Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
---
drivers/infiniband/hw/cxgb4/cm.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c
index c16017f6e8db..870d8517310b 100644
--- a/drivers/infiniband/hw/cxgb4/cm.c
+++ b/drivers/infiniband/hw/cxgb4/cm.c
@@ -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;
--
2.17.1
next reply other threads:[~2022-03-27 7:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-27 7:35 Xiaomeng Tong [this message]
2022-03-27 16:38 ` [PATCH] cxgb4: cm: fix a incorrect NULL check on list iterator Leon Romanovsky
2022-03-30 12:30 ` Xiaomeng Tong
2022-03-30 12:53 ` Leon Romanovsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220327073542.10990-1-xiam0nd.tong@gmail.com \
--to=xiam0nd.tong@gmail.com \
--cc=bharat@chelsio.com \
--cc=jgg@ziepe.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=roland@purestorage.com \
--cc=stable@vger.kernel.org \
--cc=vipul@chelsio.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox