Received: by 10.192.165.148 with SMTP id m20csp2462620imm; Sun, 22 Apr 2018 07:33:07 -0700 (PDT) X-Google-Smtp-Source: AIpwx49i8kHx0m9BU7n1ahgGhq0gu2pMnuNpVTx6/LOU4dBhvu9mO9SG+cwveSQuPWLvY1yEkQwq X-Received: by 2002:a17:902:b28:: with SMTP id 37-v6mr17423524plq.207.1524407587718; Sun, 22 Apr 2018 07:33:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524407587; cv=none; d=google.com; s=arc-20160816; b=h/znnqKwQaCpU66w0HooFr+fEt5/MyPg34efCnA6i1/Bo0hYkedIFv13HUHbPcfpjp mLek3sL3IUkms4CapjXh2m7IQiq/Tq6Nz5M1r3esKzqMhrsKBi5fIZVLLBXNe4So4Rcb ESggR5Bj2W2s2M5S30Ma1RYeK25oksbdxiicbeH25fsVBaHECShYmhnpyqMxgW0ngj5G K+OX4T67Usvasw7+lf/Jg8NcyK5FEwsFHjewbH61zEb73xu/zKMTew+QzYiKiCbwkVWG hM0hWvSxrLkRjldc3sJp7/E0pO0vuOaLuJnZpP/SUQ637PcPsNnWa8MSKOQ/BpcgvGIf 6hcg== 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=lUkU1/3pcCyj/OFrRfbkwFbYHCi4GeO5IgXbdVU/pjc=; b=Zt1dtpj12Ok+pKTWnu2h801NGzXcHr7MWkBStKUF9TlzvIY457f6qAiZcrLcp77L90 7skwl64IDe/x4n3vI8OBs7mlLuXr+Wq6BgR3mSzr2j4y64yIsf0lIOnouq9fAlAPoKgI Y+Uakj9TeUDztZi8shkdA0LOMt7Uvoi2g6lcCPv4FmnChbaRUieAbn5CmMWhk7P5M6NO LYs5S4XD/FYGjVj8lX4wfJKL2oFrYFLMFoP0FHNtZC4sXhMQkQsuPXOX6pht8An083yC ySg3WhrnDOESYRkN7X1D8Iai8FxlOBcgC1BQgXTvNaYxwH7ArAUlsd3OkgWxscPFnK3L 49fQ== 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 v12-v6si10268917plo.29.2018.04.22.07.32.53; Sun, 22 Apr 2018 07:33:07 -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 S1757503AbeDVOb2 (ORCPT + 99 others); Sun, 22 Apr 2018 10:31:28 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60398 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757406AbeDVOUY (ORCPT ); Sun, 22 Apr 2018 10:20:24 -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 5243F486; Sun, 22 Apr 2018 14:20:23 +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 3.18 18/52] HID: i2c-hid: fix size check and type usage Date: Sun, 22 Apr 2018 15:53:51 +0200 Message-Id: <20180422135316.112014588@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135315.254787616@linuxfoundation.org> References: <20180422135315.254787616@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 3.18-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 @@ -136,10 +136,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 */ @@ -373,7 +373,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) @@ -398,7 +399,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;