All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matt Ranostay <mranostay@gmail.com>
To: linux-iio@vger.kernel.org
Cc: jic23@kernel.org, Matt Ranostay <mranostay@gmail.com>,
	george.mccollister@gmail.com
Subject: [PATCH 3/3] iio: proximity: as3935: fix buffer stack trashing
Date: Sat, 21 May 2016 20:01:03 -0700	[thread overview]
Message-ID: <1463886063-20004-4-git-send-email-mranostay@gmail.com> (raw)
In-Reply-To: <1463886063-20004-1-git-send-email-mranostay@gmail.com>

Buffer wasn't of a valid size to allow the timestamp, and correct padding.
This patchset also moves the buffer off the stack, and onto the heap.

Cc: george.mccollister@gmail.com
Signed-off-by: Matt Ranostay <mranostay@gmail.com>
---
 drivers/iio/proximity/as3935.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/proximity/as3935.c b/drivers/iio/proximity/as3935.c
index 6aed024..8730451 100644
--- a/drivers/iio/proximity/as3935.c
+++ b/drivers/iio/proximity/as3935.c
@@ -64,6 +64,7 @@ struct as3935_state {
 	struct delayed_work work;
 
 	u32 tune_cap;
+	u8 buffer[16]; /* 8-bit data + 54-bit padding + 64-bit timestamp */
 	u8 buf[2] ____cacheline_aligned;
 };
 
@@ -212,9 +213,10 @@ static irqreturn_t as3935_trigger_handler(int irq, void *private)
 	ret = as3935_read(st, AS3935_DATA, &val);
 	if (ret)
 		goto err_read;
-	val &= AS3935_DATA_MASK;
 
-	iio_push_to_buffers_with_timestamp(indio_dev, &val, pf->timestamp);
+	st->buffer[0] = val & AS3935_DATA_MASK;
+	iio_push_to_buffers_with_timestamp(indio_dev, &st->buffer,
+					   pf->timestamp);
 err_read:
 	iio_trigger_notify_done(indio_dev->trig);
 
-- 
2.7.4

  parent reply	other threads:[~2016-05-22  3:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-22  3:01 [PATCH 0/3] iio: proximity: as3935: fix major drivers Matt Ranostay
2016-05-22  3:01 ` [PATCH 1/3] iio: proximity: as3935: correct IIO_CHAN_INFO_RAW output Matt Ranostay
2016-05-22 19:54   ` Jonathan Cameron
2016-05-22  3:01 ` [PATCH 2/3] iio: proximity: as3935: remove triggered buffer processing Matt Ranostay
2016-05-22 19:55   ` Jonathan Cameron
2016-05-22  3:01 ` Matt Ranostay [this message]
2016-05-22  6:28   ` [PATCH 3/3] iio: proximity: as3935: fix buffer stack trashing Matt Ranostay
2016-05-22 19:55     ` Jonathan Cameron

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=1463886063-20004-4-git-send-email-mranostay@gmail.com \
    --to=mranostay@gmail.com \
    --cc=george.mccollister@gmail.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.