Received: by 10.192.165.148 with SMTP id m20csp2534932imm; Sun, 22 Apr 2018 09:03:13 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/l3P5mavIQ4z22GvIj9Ew5lC03El5DT8v5GMKbKYGpvymSdic/PCtCv+1mKtfEu7CEv8TH X-Received: by 2002:a17:902:8342:: with SMTP id z2-v6mr17464421pln.311.1524412993516; Sun, 22 Apr 2018 09:03:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524412993; cv=none; d=google.com; s=arc-20160816; b=PqyClhkj4e/dMe7/0zF/CZwgmGzMyK7gd+cdFUTVF0dsDlk2iPg1o1MHqGnAtAbaH8 JyLuGiWATKgveTfickZX/Hr7w8EUjJyfpm+SOgmf8dxvTkeOmimqyAsrfGYlgm9BeiNS +4MXI1T1l5FSe9v0Onjh2TyGu/TyKRMQH3w4zCnODaizJEN+QX+7MbVBrqXvyWi0q9sr FMsgatbsERXooWhKH+c8caOsl+ruqPVE8MY55jP3jjjosljwAjWfgXyi59aCVkl0c0Ma Sfe1rPld495k4xPOuJdWH6PitggTyrbpZJf8VfopWjWOYFdp3GWRDhCdNPuoA5ezQDu2 ckYQ== 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=CzgWlsbsBe+VO8BesllvL+k2csf/pEUfnPCaRVwN9MU=; b=LpKV2N37g7ERqMiKtcoKCOTpkpnDdd4pIiNqgg+pykndI8j+pxOu0xblzAqTSBDYZV 6TnO4SUFI1MF1zw40z/7lxzbW9gRrhO7sB9Eo0R9y9INUFWNyQumpbxOaVynEi7rru19 Qg+92knk0WLBdvPEimn/qH5ryMIB/OsUH7qo2bMmnw8Y7b+06D9qOKmBsK5CRsqPxNhA KNu7TrMXD5mMvSDV0QFfnfJeh7coJZEyI9sMT146C6xAQVLqLt4sC+nN0Jns2ankZbQZ BRJ6DlB3xANk+jmazPkfcFp4lsGM+62DNhg6ovPpO5O/EP3OvyV1grmLkYYeLE9CnbDj jBTQ== 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-v6si9350871plc.436.2018.04.22.09.02.59; Sun, 22 Apr 2018 09:03:13 -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 S1754138AbeDVN6Y (ORCPT + 99 others); Sun, 22 Apr 2018 09:58:24 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46138 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753830AbeDVN6P (ORCPT ); Sun, 22 Apr 2018 09:58:15 -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 1D14ACD8; Sun, 22 Apr 2018 13:58:13 +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.16 051/196] HID: i2c-hid: fix size check and type usage Date: Sun, 22 Apr 2018 15:51:11 +0200 Message-Id: <20180422135106.727958516@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135104.278511750@linuxfoundation.org> References: <20180422135104.278511750@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.16-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 @@ -144,10 +144,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 */ unsigned long quirks; /* Various quirks */ @@ -455,7 +455,8 @@ out_unlock: 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) @@ -480,7 +481,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;