linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Input: zforce_ts - fix playload length check
@ 2015-07-27 21:06 Dmitry Torokhov
  2015-07-27 21:35 ` Heiko Stübner
  2015-07-28 10:23 ` Geert Uytterhoeven
  0 siblings, 2 replies; 8+ messages in thread
From: Dmitry Torokhov @ 2015-07-27 21:06 UTC (permalink / raw)
  To: linux-input; +Cc: Dirk Behme, Heiko Stuebner, Oleksij Rempel, linux-kernel

Commit 7d01cd261c76f95913c81554a751968a1d282d3a ("Input: zforce - don't
overwrite the stack") attempted to add a check for payload size being too
large for the supplied buffer. Unfortunately with the currently selected
buffer size the comparison is always false as buffer size is larger than
the value a single byte can hold, and that results in compiler warnings.
Additionally the check was incorrect as it was not accounting for the
already read 2 bytes of data stored in the buffer.

Fixes: 7d01cd261c76f95913c81554a751968a1d282d3a
Reported-by: kbuild test robot <fengguang.wu@intel.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---

This seems to shut up my GCC, I wonder if it is going to work gfor
everyone or we better add BUILD_BUG_ON(FRAME_MAXSIZE < 257) and a
comment and remove check.

 drivers/input/touchscreen/zforce_ts.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/zforce_ts.c b/drivers/input/touchscreen/zforce_ts.c
index 2554efd..542ff02 100644
--- a/drivers/input/touchscreen/zforce_ts.c
+++ b/drivers/input/touchscreen/zforce_ts.c
@@ -441,7 +441,9 @@ static int zforce_read_packet(struct zforce_ts *ts, u8 *buf)
 		goto unlock;
 	}
 
-	if (buf[PAYLOAD_LENGTH] == 0 || buf[PAYLOAD_LENGTH] > FRAME_MAXSIZE) {
+	if (buf[PAYLOAD_LENGTH] == 0 ||
+	    (FRAME_MAXSIZE - 2 < 255 &&
+	     buf[PAYLOAD_LENGTH] > FRAME_MAXSIZE - 2)) {
 		dev_err(&client->dev, "invalid payload length: %d\n",
 			buf[PAYLOAD_LENGTH]);
 		ret = -EIO;
-- 
2.5.0.rc2.392.g76e840b


-- 
Dmitry

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-07-28 16:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-27 21:06 [PATCH] Input: zforce_ts - fix playload length check Dmitry Torokhov
2015-07-27 21:35 ` Heiko Stübner
2015-07-27 21:44   ` Dmitry Torokhov
2015-07-27 21:53     ` Heiko Stübner
2015-07-27 22:16       ` Dmitry Torokhov
2015-07-28 10:23 ` Geert Uytterhoeven
2015-07-28 11:28   ` Dirk Behme
2015-07-28 16:30     ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).