From: Arnd Bergmann <arnd@arndb.de>
To: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
Jiri Kosina <jikos@kernel.org>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, arnd@arndb.de
Subject: [PATCH 1/5] HID: intel_ish-hid: fix potential uninitialized data usage
Date: Tue, 16 May 2017 13:09:03 +0200 [thread overview]
Message-ID: <20170516110907.3545799-2-arnd@arndb.de> (raw)
In-Reply-To: <20170516110907.3545799-1-arnd@arndb.de>
gcc points out an uninialized pointer dereference that could happen
if we ever get to recv_ishtp_cl_msg_dma() or recv_ishtp_cl_msg()
with an empty &dev->read_list:
drivers/hid/intel-ish-hid/ishtp/client.c: In function 'recv_ishtp_cl_msg_dma':
drivers/hid/intel-ish-hid/ishtp/client.c:1049:3: error: 'cl' may be used uninitialized in this function [-Werror=maybe-uninitialized]
The warning only appeared in very few randconfig builds, as the
spinlocks tend to prevent gcc from tracing the variables. I only
saw it in configurations that had neither SMP nor LOCKDEP enabled.
I have not been able to figure out whether this case can happen in
practice, but it's better to be defensive here and handle the case
explicitly by returning from the function.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/hid/intel-ish-hid/ishtp/client.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/hid/intel-ish-hid/ishtp/client.c b/drivers/hid/intel-ish-hid/ishtp/client.c
index aad61328f282..69c9d43612ec 100644
--- a/drivers/hid/intel-ish-hid/ishtp/client.c
+++ b/drivers/hid/intel-ish-hid/ishtp/client.c
@@ -829,6 +829,11 @@ void recv_ishtp_cl_msg(struct ishtp_device *dev,
}
spin_lock_irqsave(&dev->read_list_spinlock, dev_flags);
+ if (list_empty(&dev->read_list.list)) {
+ spin_unlock_irqrestore(&dev->read_list_spinlock, dev_flags);
+ goto eoi;
+ }
+
rb_count = -1;
list_for_each_entry(rb, &dev->read_list.list, list) {
++rb_count;
@@ -954,6 +959,11 @@ void recv_ishtp_cl_msg_dma(struct ishtp_device *dev, void *msg,
unsigned long flags;
spin_lock_irqsave(&dev->read_list_spinlock, dev_flags);
+ if (list_empty(&dev->read_list.list)) {
+ spin_unlock_irqrestore(&dev->read_list_spinlock, dev_flags);
+ goto eoi;
+ }
+
list_for_each_entry(rb, &dev->read_list.list, list) {
cl = rb->cl;
if (!cl || !(cl->host_client_id == hbm->host_client_id &&
--
2.9.0
next prev parent reply other threads:[~2017-05-16 11:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-16 11:09 [PATCH 0/5] HID: intel_ish-hid: various cleanups Arnd Bergmann
2017-05-16 11:09 ` Arnd Bergmann [this message]
2017-05-17 19:44 ` [PATCH 1/5] HID: intel_ish-hid: fix potential uninitialized data usage Arnd Bergmann
2017-05-16 11:09 ` [PATCH 2/5] HID: intel_ish-hid: clarify locking in client code Arnd Bergmann
2017-05-16 11:09 ` [PATCH 3/5] HID: intel_ish-hid: convert timespec to ktime_t Arnd Bergmann
2017-05-16 11:09 ` [PATCH 4/5] HID: intel_ish-hid: fix format string for size_t Arnd Bergmann
2017-05-16 11:09 ` [PATCH 5/5] HID: intel_ish-hid: enable compile testing Arnd Bergmann
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=20170516110907.3545799-2-arnd@arndb.de \
--to=arnd@arndb.de \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=srinivas.pandruvada@linux.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
all inboxes | Powered by JetHome®