Received: by 10.192.165.148 with SMTP id m20csp2451516imm; Sun, 22 Apr 2018 07:19:47 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+HZakwIJNOHH45291apmoco4WypkcD0oWsijpDPKBru6yd+capMcT/O5bdRuUWlaa10n7p X-Received: by 2002:a17:902:2468:: with SMTP id m37-v6mr17915760plg.388.1524406787173; Sun, 22 Apr 2018 07:19:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524406787; cv=none; d=google.com; s=arc-20160816; b=l3Zwae5ep+Jk0BqqN/eulqGin9uzFgi1XXqjkBuDMGfX8R8stkhE19rlbXTOfwf7AI J29OEtcwVOQeeZfVx8m/Usbrd2GP961VkX9xLAnDsO2paN4RGHiD2e5aUMByeLlH6/4Y OlrYESZmpqGxQkORVIrQMmMBMUprr+eF74pdRCpJQrp0EVuXmx+OnUel1whk3a4N0H2K NuXnvVd2ZflG6NR3K6taryRXgfW+ghdafEK/ViEJzxIqk2aEvefv8lPtW20S+f4jw5NM 6BIJmTrfxkLJ5ici39rIRfd0hJrb601cJD3/rJjwGObv2xKCx2UqlMJ6Hlf7eY42YU5N SuJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=nwng4XIU3iYB1lhyWlrGZaSquqD8ORxucyTZXIJa8/k=; b=m2qsGA3hbK3eaaPqoY1Jf3jOuBq5/mtVaOk87mAYpZHJBQYjDVnGBXkjl7BlP6UsUQ rsWpwhVcOOPwtX3x59q/5LMKFobGsthLmgGURzpWNl8/hxRTiP5W2dLKw8SYCUX958gq Hz7FZU/yZxAWKq6+CR7cmA5go5VFSYwC8L/cZZk1v04J1EoRKAc1kb27DeQJZkvoVacZ KaR1OS+JzizZallJP1ltk+W6bCib0OW7zaOJuaqQuW8lC4wpnVY6WqldG0LP8cRSWKxE UBKNaLFJcYASdGMmsVfZDKBV5yTyde+5LQ2MKIKz8UOcRJFBk1guT+swsFe6XscKoUZl NAmQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 69-v6si9250694plc.436.2018.04.22.07.19.33; Sun, 22 Apr 2018 07:19:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932292AbeDVOSd (ORCPT + 99 others); Sun, 22 Apr 2018 10:18:33 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58952 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757227AbeDVOS2 (ORCPT ); Sun, 22 Apr 2018 10:18:28 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 95335D08; Sun, 22 Apr 2018 14:18:27 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aaron Ma , Jiri Kosina Subject: [PATCH 4.4 39/97] HID: i2c-hid: fix size check and type usage Date: Sun, 22 Apr 2018 15:53:17 +0200 Message-Id: <20180422135307.503753820@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135304.577223025@linuxfoundation.org> References: <20180422135304.577223025@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Aaron Ma commit ac75a041048b8c1f7418e27621ca5efda8571043 upstream. 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. Cc: stable@vger.kernel.org Signed-off-by: Aaron Ma Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/i2c-hid/i2c-hid.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c @@ -137,10 +137,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 */ @@ -387,7 +387,8 @@ static int i2c_hid_hwreset(struct i2c_cl static void i2c_hid_get_input(struct i2c_hid *ihid) { - int ret, ret_size; + int ret; + u32 ret_size; int size = le16_to_cpu(ihid->hdesc.wMaxInputLength); if (size > ihid->bufsize) @@ -412,7 +413,7 @@ static void i2c_hid_get_input(struct i2c return; } - if (ret_size > size) { + if ((ret_size > size) || (ret_size <= 2)) { dev_err(&ihid->client->dev, "%s: incomplete report (%d/%d)\n", __func__, size, ret_size); return;