From patchwork Thu Dec 11 12:51:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Wu X-Patchwork-Id: 5475911 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 23C2DBEEA8 for ; Thu, 11 Dec 2014 12:53:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7459C200E0 for ; Thu, 11 Dec 2014 12:53:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8E97B200CA for ; Thu, 11 Dec 2014 12:53:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933808AbaLKMw6 (ORCPT ); Thu, 11 Dec 2014 07:52:58 -0500 Received: from lekensteyn.nl ([178.21.112.251]:35996 "EHLO lekensteyn.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932604AbaLKMve (ORCPT ); Thu, 11 Dec 2014 07:51:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lekensteyn.nl; s=s2048-2014-q3; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=IuFFZg6CXOmDQEwBKZRCedBTfttbabG0J1DLgQOcm8E=; b=DGoOieSP9KOXL3p7rg72d2RXhuK9TyYIIKoQN3mdHPO92pXO/G8zhxZZm8eYUNc99KdDvzsj2uGlKbIeEAofT0tA55PsY+KQueQnqhRTn5MhXwBFC2/mISDEOds3nSHI9MLXLoQJqKeYofs8GKlI3cMEuNM/emp2bqaFrh+Zx7Dynb02E/X6yDxBM6DZk5yhazNTl/l90jdIMGUvhjofykUnUThZvv/7X7M6RZbZcdWxBQyMjVbdD99TAnrrSLyTPCLBVBrKNqj9QwwplZbbLKZ74L9Fiv1sxCDVBlcBW87m3Md7zrqvHVzLJnZQ7pyOHyY5kyShuCmEvFdilwuOmA==; Received: by lekensteyn.nl with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA256:128) (Exim 4.80) (envelope-from ) id 1Xz3DH-00020h-R2; Thu, 11 Dec 2014 13:51:24 +0100 From: Peter Wu To: Benjamin Tissoires , Jiri Kosina , Nestor Lopez Casado Cc: Peter Hutterer , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] HID: logitech-hidpp: add boundary check for name retrieval Date: Thu, 11 Dec 2014 13:51:19 +0100 Message-Id: <1418302280-14794-4-git-send-email-peter@lekensteyn.nl> X-Mailer: git-send-email 2.1.3 In-Reply-To: <1418302280-14794-1-git-send-email-peter@lekensteyn.nl> References: <1418302280-14794-1-git-send-email-peter@lekensteyn.nl> X-Spam-Score: -0.0 (/) X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The HID response has a limited size. Do not trust the value returned by hardware, check that it really fits in the message. Signed-off-by: Peter Wu Reviewed-by: Benjamin Tissoires --- drivers/hid/hid-logitech-hidpp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 4d72c20..4292cc3 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -313,6 +313,9 @@ static char *hidpp_get_unifying_name(struct hidpp_device *hidpp_dev) len = response.rap.params[1]; + if (2 + len > sizeof(response.rap.params)) + return NULL; + name = kzalloc(len + 1, GFP_KERNEL); if (!name) return NULL;