Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2011355imm; Tue, 10 Jul 2018 11:33:39 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe1IJJ+NdzQF500il4SMZ+1fTYaWU7OcCwdiZV6Nej7E1NPV5k1WUTgV1Iv7kiFEYWvdUWD X-Received: by 2002:a62:6cc7:: with SMTP id h190-v6mr27042871pfc.113.1531247619612; Tue, 10 Jul 2018 11:33:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531247619; cv=none; d=google.com; s=arc-20160816; b=ZSJqjdJLTIHvHmA7DRbD1g64Vfza5OwPHBAMGxqG76hGdomOdYuLfVQyW+zXkpdQ9g DIWDELATIF6PtxmtPAfLNDJcj1ioJNpCwy/XpUBiWCUQwiuw7KJOKGDzA9GJmDD1a48O lsTWq5tfrmIrXDA/kQ3ek1w3NSLxURs1rAdB6aSRnegoQqwBGfIXPDoWNOKKES39XNWt 7uJfNM6k/gfKx95Qs0SlTi0pe20YscdEy8uqIUcsxrQO2VksNZs/y8GXcdjPOjGkTewW XNYxYCHN12ViMw4uYzK5G7WMo7lHvRuN6BkBgDBltBIhEL3GHboNgfMWmmCxHn6bN8QZ PA7A== 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=Om0tGirt1uwrTuoTQDEDyVwcXqMVJ36hh8axz6Smr5M=; b=uCwAeEBBKCRilN+NYmHawzyCS9tGHsjjh5ygxg4Q3RdpiewmWiblCHwlPcYcktRY3M 8GXnCMlXht6LaLwZsSatnt04EQ2NgFP4zjCrBNgef+4ihcpsuBlOQjQN+wSkDVMDQDoY PONRO1FTo/K8f7iHyXuvZ/V2Pbbd/FMuMxzpxvYSMtv8j6CyI6/z6tNk4bA1ef+BMb7h 8V8lLhpyTz9nbrk2eCxd3thCB3u7+C4dxxiRtMJBZYG/s++DLMfpxV1QwlXWKBTU70fM DSbRf4sLYmU00scZ4ttrjLs19z0zJZAoAKuM7q/0PtwNtMVEtK24GGXgbgnhJUgILwxn UVDA== 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 p1-v6si17683849plb.204.2018.07.10.11.33.24; Tue, 10 Jul 2018 11:33:39 -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 S2388456AbeGJSbr (ORCPT + 99 others); Tue, 10 Jul 2018 14:31:47 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46260 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388445AbeGJSbq (ORCPT ); Tue, 10 Jul 2018 14:31:46 -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 7BCA5EEB; Tue, 10 Jul 2018 18:31:34 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Rosenberg , Benjamin Tissoires , Jiri Kosina Subject: [PATCH 4.9 39/52] HID: debug: check length before copy_to_user() Date: Tue, 10 Jul 2018 20:25:07 +0200 Message-Id: <20180710182452.938266092@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180710182449.285532226@linuxfoundation.org> References: <20180710182449.285532226@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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Daniel Rosenberg commit 717adfdaf14704fd3ec7fa2c04520c0723247eac upstream. If our length is greater than the size of the buffer, we overflow the buffer Cc: stable@vger.kernel.org Signed-off-by: Daniel Rosenberg Reviewed-by: Benjamin Tissoires Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-debug.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/drivers/hid/hid-debug.c +++ b/drivers/hid/hid-debug.c @@ -1152,6 +1152,8 @@ copy_rest: goto out; if (list->tail > list->head) { len = list->tail - list->head; + if (len > count) + len = count; if (copy_to_user(buffer + ret, &list->hid_debug_buf[list->head], len)) { ret = -EFAULT; @@ -1161,6 +1163,8 @@ copy_rest: list->head += len; } else { len = HID_DEBUG_BUFSIZE - list->head; + if (len > count) + len = count; if (copy_to_user(buffer, &list->hid_debug_buf[list->head], len)) { ret = -EFAULT; @@ -1168,7 +1172,9 @@ copy_rest: } list->head = 0; ret += len; - goto copy_rest; + count -= len; + if (count > 0) + goto copy_rest; } }