Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932547AbdIHRzd (ORCPT ); Fri, 8 Sep 2017 13:55:33 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:35813 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932336AbdIHRzb (ORCPT ); Fri, 8 Sep 2017 13:55:31 -0400 X-Google-Smtp-Source: ADKCNb4M7tZUabhT5wTYgdpUpJ5D/Sf31/pLGOlRgD/OAgPf01JkihbMxmX0jkYJ0q5oRuacFJR7YA== Date: Fri, 8 Sep 2017 10:55:27 -0700 From: Dmitry Torokhov To: Jiri Kosina Cc: Benjamin Tissoires , Guenter Roeck , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] HID: i2c-hid: allocate hid buffers for real worst case Message-ID: <20170908175527.GA19720@dtor-ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1176 Lines: 32 From: Adrian Salido The buffer allocation is not currently accounting for an extra byte for the report id. This can cause an out of bounds access in function i2c_hid_set_or_send_report() with reportID > 15. Signed-off-by: Guenter Roeck Signed-off-by: Dmitry Torokhov --- drivers/hid/i2c-hid/i2c-hid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index 77396145d2d0..9145c2129a96 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c @@ -543,7 +543,8 @@ static int i2c_hid_alloc_buffers(struct i2c_hid *ihid, size_t report_size) { /* the worst case is computed from the set_report command with a * reportID > 15 and the maximum report length */ - int args_len = sizeof(__u8) + /* optional ReportID byte */ + int args_len = sizeof(__u8) + /* ReportID */ + sizeof(__u8) + /* optional ReportID byte */ sizeof(__u16) + /* data register */ sizeof(__u16) + /* size of the report */ report_size; /* report */ -- 2.14.1.581.gf28d330327-goog -- Dmitry