From patchwork Wed Dec 5 14:02:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Tissoires X-Patchwork-Id: 1841401 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 35F313FCF2 for ; Wed, 5 Dec 2012 14:04:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753351Ab2LEOEF (ORCPT ); Wed, 5 Dec 2012 09:04:05 -0500 Received: from mail-we0-f174.google.com ([74.125.82.174]:44051 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751869Ab2LEODJ (ORCPT ); Wed, 5 Dec 2012 09:03:09 -0500 Received: by mail-we0-f174.google.com with SMTP id x10so2053523wey.19 for ; Wed, 05 Dec 2012 06:03:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references; bh=1AwJzayAHfnOqjfzxDOAfPXlnYqhUGp5pXFlPDU/JAg=; b=ysCBDRQDohhCQ1Chqg9N1eomT47OHUqjQXUKCpb1yGcA+c0WL0racsAqy2Pm6XTS9h L6cOdHQSN6GFrJO+3xBjTkHHPCo/MQbvPaD6h4C4tTWpBiIX3UXdJMXNoJE+0OjhAtME hAYgMVHkVwpj/7Bjq318adC8LMdFjs0Ls7T/XW4SULhF+PF6qhg5HFy/OSxd7yAz6nAR WkF7LnggbR4cjcQeFIgJODwlrq+aeykz6R4lkAvLHedum7UNDf+hPjG1HcT1g7nIsedt BDL5yEujtqk+rjDtXitX+Z1T3Xq5eD6/3hFDzpNbpDEHTaYtuXt9BfYIinlPp3CgpfAl CvCg== Received: by 10.216.208.165 with SMTP id q37mr6724217weo.114.1354716187932; Wed, 05 Dec 2012 06:03:07 -0800 (PST) Received: from localhost.localdomain.com (lan31-8-82-247-176-67.fbx.proxad.net. [82.247.176.67]) by mx.google.com with ESMTPS id cf6sm6544288wib.3.2012.12.05.06.03.06 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 05 Dec 2012 06:03:07 -0800 (PST) From: Benjamin Tissoires To: Benjamin Tissoires , Jiri Kosina , Jean Delvare , linux-input@vger.kernel.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/4] HID: i2c-hid: fix memory corruption due to missing hid declaration Date: Wed, 5 Dec 2012 15:02:53 +0100 Message-Id: <1354716176-12558-2-git-send-email-benjamin.tissoires@gmail.com> X-Mailer: git-send-email 1.8.0.1 In-Reply-To: <1354716176-12558-1-git-send-email-benjamin.tissoires@gmail.com> References: <1354716176-12558-1-git-send-email-benjamin.tissoires@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org HID descriptors contains 4 bytes of reserved field. The previous implementation was overriding the next fields in struct i2c_hid. Signed-off-by: Benjamin Tissoires Reviewed-by: Jean Delvare --- drivers/hid/i2c-hid/i2c-hid.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index 7062df2..34cca42 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c @@ -69,6 +69,7 @@ struct i2c_hid_desc { __le16 wVendorID; __le16 wProductID; __le16 wVersionID; + __le32 reserved; } __packed; struct i2c_hid_cmd { @@ -776,7 +777,13 @@ static int __devinit i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid) } dsize = le16_to_cpu(hdesc->wHIDDescLength); - if (!dsize || dsize > HID_MAX_DESCRIPTOR_SIZE) { + /* + * the size of the HID descriptor should at least contain + * its size and the bcdVersion (4 bytes), and should not be greater + * than sizeof(struct i2c_hid_desc) as we directly fill this struct + * through i2c_hid_command. + */ + if (dsize < 4 || dsize > sizeof(struct i2c_hid_desc)) { dev_err(&client->dev, "weird size of HID descriptor (%u)\n", dsize); return -ENODEV;