From patchwork Tue Mar 5 13:06:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 2219171 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id C769D3FCF2 for ; Tue, 5 Mar 2013 13:08:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755523Ab3CENIe (ORCPT ); Tue, 5 Mar 2013 08:08:34 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:46668 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755343Ab3CENIe (ORCPT ); Tue, 5 Mar 2013 08:08:34 -0500 Received: from ucsinet21.oracle.com (ucsinet21.oracle.com [156.151.31.93]) by userp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r25D7nBb002763 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 5 Mar 2013 13:07:50 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by ucsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r25D7mae004521 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 5 Mar 2013 13:07:49 GMT Received: from abhmt109.oracle.com (abhmt109.oracle.com [141.146.116.61]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r25D7mDt031233; Tue, 5 Mar 2013 07:07:48 -0600 Received: from longonot.mountain (/41.202.240.10) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 05 Mar 2013 05:07:47 -0800 Date: Tue, 5 Mar 2013 16:06:26 +0300 From: Dan Carpenter To: Jiri Kosina Cc: linux-input@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch] HID: hid-logitech-dj: add some range checks Message-ID: <20130305130626.GA17801@longonot.mountain> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: ucsinet21.oracle.com [156.151.31.93] Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org We can't trust dj_report->device_index because it comes from the user and hasn't been range checked. It is used as an offset into the djrcv_dev->paired_dj_devices[] array which has 7 elements. There is one range check already in logi_dj_recv_add_djhid_device() and I have copy and pasted that here. DJ_DEVICE_INDEX_MIN is 1. DJ_DEVICE_INDEX_MAX is 6. Signed-off-by: Dan Carpenter --- This is a static checker fix and I'm not certain it's correct, please look it over carefully. I do not know this code well, so I don't know why a zero index is invalid. -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c index 9500f2f..c01cd25 100644 --- a/drivers/hid/hid-logitech-dj.c +++ b/drivers/hid/hid-logitech-dj.c @@ -701,6 +701,13 @@ static int logi_dj_raw_event(struct hid_device *hdev, * anything else with it. */ + if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) || + (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) { + dev_err(&hdev->dev, "%s: invalid device index:%d\n", __func__, + dj_report->device_index); + return true; + } + spin_lock_irqsave(&djrcv_dev->lock, flags); if (dj_report->report_id == REPORT_ID_DJ_SHORT) { switch (dj_report->report_type) {