Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753551AbbG1L2h (ORCPT ); Tue, 28 Jul 2015 07:28:37 -0400 Received: from smtp6-v.fe.bosch.de ([139.15.237.11]:16708 "EHLO smtp6-v.fe.bosch.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751176AbbG1L2f (ORCPT ); Tue, 28 Jul 2015 07:28:35 -0400 Subject: Re: [PATCH] Input: zforce_ts - fix playload length check To: Dmitry Torokhov References: <20150727210619.GA2825@dtor-ws> CC: Geert Uytterhoeven , "linux-input@vger.kernel.org" , Heiko Stuebner , Oleksij Rempel , "linux-kernel@vger.kernel.org" From: Dirk Behme Organization: Robert Bosch Car Multimedia GmbH Message-ID: <55B76760.10406@de.bosch.com> Date: Tue, 28 Jul 2015 13:28:32 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.34.211.40] X-TM-AS-MML: disable X-TM-AS-Product-Ver: IMSS-7.1.0.1679-7.5.0.1018-21706.006 X-TMASE-MatchedRID: UuaOI1zLN1gOwH4pD14DsPHkpkyUphL9H2xvudIawkNxMpe96EyhT5U/ 6MX4JnBRzZ57coBobHkl8JIXl1jcoBf8OC06wpskqhL21Dav142vzXNI4No01fTCq1LILNRV7ii i6/GaBag+kbdVOBXdNcYm2R0KueQ86rdKV5hsRCDUWdZik3yrYQXAhAGZB7BnYe1mzp7dkwdKND tXyGN5SszTEEY/AY80rd1cHc8V44faZDn2hX5ZwBIRh9wkXSlF3ZrXEjaovd9cU0dNErOD+vlYo V6p/cSxTCYLG1dPgX+n5CT3lhHmzrdjTQUenVDDiFoorQjboWnZph2fCfuodxSX1u8BLtZANDv9 gnXc+skqwIFZ+JddT7jRoy53a/oJr78SC5iivxyDGx/OQ1GV8rHlqZYrZqdI+gtHj7OwNO0CpgE TeT0ynA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2735 Lines: 71 On 28.07.2015 12:23, Geert Uytterhoeven wrote: > On Mon, Jul 27, 2015 at 11:06 PM, Dmitry Torokhov > wrote: >> 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. > > The check was indeed incorrect. > >> Fixes: 7d01cd261c76f95913c81554a751968a1d282d3a >> Reported-by: kbuild test robot >> Signed-off-by: Dmitry Torokhov >> --- >> >> 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)) { > > Doesn't help with gcc 4.1.2 :-( > > Before: > > drivers/input/touchscreen/zforce_ts.c: In function ‘zforce_read_packet’: > drivers/input/touchscreen/zforce_ts.c:432: warning: comparison is > always false due to limited range of data type > > After: > > drivers/input/touchscreen/zforce_ts.c: In function ‘zforce_read_packet’: > drivers/input/touchscreen/zforce_ts.c:434: warning: comparison is > always false due to limited range of data type If it's easier, then just revert 7d01cd261c76f95913c81. Sorry! It seems that at least 4 people have overlooked this issue :( Best regards Dirk Btw: Could anybody give me a hint how to get this warning? My GCC 4.8.1 with kernel default ARM Cortex A9 kernel options doesn't give me anything about this. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/