From patchwork Fri Sep 8 17:55:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 9944793 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 76C3E6035D for ; Fri, 8 Sep 2017 17:55:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F807287B4 for ; Fri, 8 Sep 2017 17:55:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50C85287E8; Fri, 8 Sep 2017 17:55:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28CC2287B4 for ; Fri, 8 Sep 2017 17:55:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932497AbdIHRzc (ORCPT ); Fri, 8 Sep 2017 13:55:32 -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 Received: by mail-pf0-f195.google.com with SMTP id g13so1744195pfm.2; Fri, 08 Sep 2017 10:55:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=TiqP2weJSD2nmCuI+Teke4Adn6zDhk/201MfJBtB+xM=; b=Ou8CQ5f0LqNhBR9n37TWFmL23pmHiwSB4Z63uNVx4O+hfBomt581NMnsY2jyTv8P5y RgOTwX023k5Uq3m/N2ISAz1q4Z3bSF5AIQ+nKLiniDlFoUzaSL1V77OfXu2MEwUDUsXs JH72UudttWSKtcdRVBjBEuCWXWPOv8MimsoEDmHLPhBTw3b/UXb8GBiixFR2aaaoeV8A nOGJxfFT7Ximi0dmjxgG28jwctShtZjgQjfkS1y3fh5qkzvSSVOxodcH0O7U0p5A07LM X7rcUYO0nJbYIITn1wSQxgTS/ddEJeAF3/6TlbS+gqGJkyl19n48WGdwbmHHECeoCMZS kKfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=TiqP2weJSD2nmCuI+Teke4Adn6zDhk/201MfJBtB+xM=; b=cXSvNyQ/sJfvV2ahoGsMVGg3HRohndmxQ05Bm03JnkToJbgE2/+HrS+BxzxJPMV4aP vVPCrZAsiQUOfbja8onVzFPHxP/f81Vja/8YGDEeRiipiX4S93Tr8DbUJksCl76LC+7Y 7uzgWBZ9+tghDwZN+iWoqsckFE7uWLN0Rb9KoC29aR0e78cnYpIv1zAtrq5UD5e6hv9k WF0URFzJ9TLP7DGfHuWpGA3vJolZwXCnii7w0q6CSd3D+wCRakfzNeQwQFJrAHboexAE GxBfvu69ut9BvB9SbuXROiyUeIReWZLS042NWB6avPAet5eiyt/RVCXjsPLdSwSdLZvF 0lQQ== X-Gm-Message-State: AHPjjUhM1TcbyjtO3No/M7OnZZV/+ITaLisBGgOOfuK47XJ7qU6lDWMe 0xpVzI+dTAAAyQ== X-Google-Smtp-Source: ADKCNb4M7tZUabhT5wTYgdpUpJ5D/Sf31/pLGOlRgD/OAgPf01JkihbMxmX0jkYJ0q5oRuacFJR7YA== X-Received: by 10.99.95.212 with SMTP id t203mr3904254pgb.391.1504893330625; Fri, 08 Sep 2017 10:55:30 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1611:cbf:abf7:ebe4:53b3]) by smtp.gmail.com with ESMTPSA id q15sm3749739pgc.64.2017.09.08.10.55.29 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 08 Sep 2017 10:55:30 -0700 (PDT) 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-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Benson Leung --- 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 */