From: Dan Carpenter <error27@gmail.com>
To: "Ismail, Mustafa" <mustafa.ismail@intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Leon Romanovsky <leon@kernel.org>,
"Latif, Faisal" <faisal.latif@intel.com>,
"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>
Subject: Re: [bug report] iwpm: crash fix for large connections test
Date: Mon, 28 Nov 2022 10:34:17 +0300 [thread overview]
Message-ID: <Y4RkeS9mlTl9uBnO@kadam> (raw)
In-Reply-To: <PH7PR11MB640377FDDE4E242D31DE063E8B099@PH7PR11MB6403.namprd11.prod.outlook.com>
So the background here is that Smatch sees this:
kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request);
and correctly says "if we call iwpm_free_nlmsg_request() then
dereferencing nlmsg_request is a use after free". However, the code
is holding two references at this point so it will never call
iwpm_free_nlmsg_request().
Smatch already checks to see if we are holding two references, but it
doesn't parse this code correctly. Smatch could be fixed, but there are
other places with similar warnings that are more difficult to fix.
What we could do is create a kref_no_release() function that just calls
WARN(). This would silence the warning and, I think, this would make
the code more readable.
What do other people think?
regards,
dan carpenter
diff --git a/include/linux/kref.h b/include/linux/kref.h
index d32e21a2538c..f40089f61aa6 100644
--- a/include/linux/kref.h
+++ b/include/linux/kref.h
@@ -45,6 +45,11 @@ static inline void kref_get(struct kref *kref)
refcount_inc(&kref->refcount);
}
+static inline void kref_no_release(struct kref *kref)
+{
+ WARN(1, "Unexpected kref release");
+}
+
/**
* kref_put - decrement refcount for object.
* @kref: object.
diff --git a/drivers/infiniband/core/iwpm_msg.c b/drivers/infiniband/core/iwpm_msg.c
index 3c9a9869212b..1acb96bfaf9c 100644
--- a/drivers/infiniband/core/iwpm_msg.c
+++ b/drivers/infiniband/core/iwpm_msg.c
@@ -432,7 +432,7 @@ int iwpm_register_pid_cb(struct sk_buff *skb, struct netlink_callback *cb)
register_pid_response_exit:
nlmsg_request->request_done = 1;
/* always for found nlmsg_request */
- kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request);
+ kref_put(&nlmsg_request->kref, kref_no_release);
barrier();
up(&nlmsg_request->sem);
return 0;
@@ -504,7 +504,7 @@ int iwpm_add_mapping_cb(struct sk_buff *skb, struct netlink_callback *cb)
add_mapping_response_exit:
nlmsg_request->request_done = 1;
/* always for found request */
- kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request);
+ kref_put(&nlmsg_request->kref, kref_no_release);
barrier();
up(&nlmsg_request->sem);
return 0;
@@ -602,7 +602,7 @@ int iwpm_add_and_query_mapping_cb(struct sk_buff *skb,
query_mapping_response_exit:
nlmsg_request->request_done = 1;
/* always for found request */
- kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request);
+ kref_put(&nlmsg_request->kref, kref_no_release);
barrier();
up(&nlmsg_request->sem);
return 0;
@@ -801,7 +801,7 @@ int iwpm_mapping_error_cb(struct sk_buff *skb, struct netlink_callback *cb)
nlmsg_request->err_code = err_code;
nlmsg_request->request_done = 1;
/* always for found request */
- kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request);
+ kref_put(&nlmsg_request->kref, kref_no_release);
barrier();
up(&nlmsg_request->sem);
return 0;
next prev parent reply other threads:[~2022-11-28 7:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-15 13:17 [bug report] iwpm: crash fix for large connections test Dan Carpenter
2022-11-17 9:24 ` Leon Romanovsky
2022-11-18 20:44 ` Ismail, Mustafa
2022-11-19 7:31 ` Dan Carpenter
2022-11-28 7:34 ` Dan Carpenter [this message]
2023-01-20 11:13 ` Greg Kroah-Hartman
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=Y4RkeS9mlTl9uBnO@kadam \
--to=error27@gmail.com \
--cc=faisal.latif@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mustafa.ismail@intel.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