From patchwork Thu Jan 4 06:06:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Ma X-Patchwork-Id: 855374 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3zBy3q4fNKz9s7s; Thu, 4 Jan 2018 17:06:31 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1eWyfY-00082r-LT; Thu, 04 Jan 2018 06:06:24 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1eWyfW-00082d-UQ for kernel-team@lists.ubuntu.com; Thu, 04 Jan 2018 06:06:22 +0000 Received: from [123.118.220.177] (helo=localhost.localdomain) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1eWyfV-00053R-Gm; Thu, 04 Jan 2018 06:06:22 +0000 From: Aaron Ma To: kernel-team@lists.ubuntu.com, timo.aaltonen@canonical.com, aaron.ma@canonical.com Subject: [PATCH 1/2] HID: core: i2c-hid: fix size check and type usage Date: Thu, 4 Jan 2018 14:06:07 +0800 Message-Id: <20180104060608.11156-2-aaron.ma@canonical.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180104060608.11156-1-aaron.ma@canonical.com> References: <20180104060608.11156-1-aaron.ma@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/1741168 Link: https://patchwork.kernel.org/patch/10141099/ When convert char array with signed int, if the inbuf[x] is negative then upper bits will be set to 1. Fix this by using u8 instead of char. ret_size has to be at least 3, hid_input_report use it after minus 2 bytes. size should be more than 0 to keep memset safe. Cc: stable@vger.kernel.org Signed-off-by: Aaron Ma --- drivers/hid/hid-core.c | 4 ++-- drivers/hid/i2c-hid/i2c-hid.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index efb3501b4123..c40dc6406966 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -1506,7 +1506,7 @@ int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size, if (rsize > HID_MAX_BUFFER_SIZE) rsize = HID_MAX_BUFFER_SIZE; - if (csize < rsize) { + if ((csize < rsize) && (csize > 0)) { dbg_hid("report %d is too short, (%d < %d)\n", report->id, csize, rsize); memset(cdata + csize, 0, rsize - csize); @@ -1566,7 +1566,7 @@ int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int i report_enum = hid->report_enum + type; hdrv = hid->driver; - if (!size) { + if (size <= 0) { dbg_hid("empty report\n"); ret = -1; goto unlock; diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index 364150435c62..4b3a703f297b 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c @@ -143,10 +143,10 @@ struct i2c_hid { * register of the HID * descriptor. */ unsigned int bufsize; /* i2c buffer size */ - char *inbuf; /* Input buffer */ - char *rawbuf; /* Raw Input buffer */ - char *cmdbuf; /* Command buffer */ - char *argsbuf; /* Command arguments buffer */ + u8 *inbuf; /* Input buffer */ + u8 *rawbuf; /* Raw Input buffer */ + u8 *cmdbuf; /* Command buffer */ + u8 *argsbuf; /* Command arguments buffer */ unsigned long flags; /* device flags */ unsigned long quirks; /* Various quirks */ @@ -468,7 +468,7 @@ static void i2c_hid_get_input(struct i2c_hid *ihid) ret_size = ihid->inbuf[0] | ihid->inbuf[1] << 8; - if (!ret_size) { + if (ret_size <= 2) { /* host or device initiated RESET completed */ if (test_and_clear_bit(I2C_HID_RESET_PENDING, &ihid->flags)) wake_up(&ihid->wait);