Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4565972imu; Tue, 29 Jan 2019 03:56:00 -0800 (PST) X-Google-Smtp-Source: ALg8bN5JMPmd4HJi0LwAAgq7VlYN3wohvIkllekSLokiNncBPGT3xxRuYC1RNT9hKfisyrNn/OuO X-Received: by 2002:a63:5b1f:: with SMTP id p31mr23207128pgb.56.1548762960070; Tue, 29 Jan 2019 03:56:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548762960; cv=none; d=google.com; s=arc-20160816; b=YRwKmwkA6phgr2Klc8ERZzHQK75b8b8dyjIXD7nxw/GN8bT6ISsuEokPmptuU+Cwxw h77iTQHLFPmKd+4xVMaSu63DBsqxjiRWCje6YiVK+gbQCFUeyCVNzsG8X0BgFDwCmXGI W39htG2Sh6/F2xzKtUzD4H0lECwVkTvrjryKsZxvfA6Egw/fnBTqx44FfD3zFMolnnzs jNVDIlKf9FcFeeaXZxnwQ/KW3wBcfioqHzOefADZT6nZ62ZtVOzYmBU1GZCrv/oH2/Uw B24eFycrSs4yI9tbYMgOP81SBtl8ERilMVFN7sPqAgQ3BE2t9lSlnJ3ShhprfTIXKYKW jCnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nmDXM4sxbejkj7I8jJF6z2ZASoMj7ziYOKivDoc4ZiI=; b=zFVPEtYpa+0Hj0NBlSFlKQ8CVHAbGKYGrJ4YMVGXSSkaN/maGz+HkWs2ARyfPG+nHt NubxATqezgC6p7bPhx1Zy0z2ok1cBM7GcrKiPeRkxmbq4c2C/T36b/m0qQM1xW46qjE0 CWtsR2gB0UNyzbYCxjPxrrm8FbOObjU+bFr0f4BWVtEWu9N7UYvYdqL4vJMuwu0PYOJI oIwEVecuTEu6o6Gx/5ap7UC2qIaXuiwvE8GC2ruUiUW0+cJyYvkTnQAiVUnTqg57JdAj InpVd7nPF9MpZUtA0fPH3OhrKzQTBJOGPUKcoZ1O2nRhEUp4vEdkEWkfAX9WsskG24KE e5Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=c3eu6yPL; 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 w75si35927705pfd.55.2019.01.29.03.55.44; Tue, 29 Jan 2019 03:56:00 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b=c3eu6yPL; 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 S1731883AbfA2LyZ (ORCPT + 99 others); Tue, 29 Jan 2019 06:54:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:43064 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731894AbfA2Lvd (ORCPT ); Tue, 29 Jan 2019 06:51:33 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9048C20989; Tue, 29 Jan 2019 11:51:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548762693; bh=80xxtLTTlbe+kXlwv7p3cf+4qG8F9/ibnJ7JCWnLPL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c3eu6yPLZTZLqpuufyurxMtdKbP7W6jFj+NCUX2UGEuHnkVry69IxClwY/b+9ZaY7 cj1OEkBVZiOuOh+MhzwSJNkmPbqaPY3xoxnnL0VUx4D1/RDSZ4GAD5Ou3lj8Yz+HVc zyrBMeE1gF+RkKTkqMYoAbLhyPPbuSIH+8Tnu0CA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kyungtae Kim , Peter Hutterer , Dmitry Torokhov Subject: [PATCH 4.9 26/44] Input: uinput - fix undefined behavior in uinput_validate_absinfo() Date: Tue, 29 Jan 2019 12:36:21 +0100 Message-Id: <20190129113142.033836052@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129113139.826927690@linuxfoundation.org> References: <20190129113139.826927690@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Dmitry Torokhov commit d77651a227f8920dd7ec179b84e400cce844eeb3 upstream. An integer overflow may arise in uinput_validate_absinfo() if "max - min" can't be represented by an "int". We should check for overflow before trying to use the result. Reported-by: Kyungtae Kim Reviewed-by: Peter Hutterer Cc: stable@vger.kernel.org Signed-off-by: Dmitry Torokhov Signed-off-by: Greg Kroah-Hartman --- drivers/input/misc/uinput.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include "../input-compat.h" @@ -335,7 +336,7 @@ static int uinput_open(struct inode *ino static int uinput_validate_absinfo(struct input_dev *dev, unsigned int code, const struct input_absinfo *abs) { - int min, max; + int min, max, range; min = abs->minimum; max = abs->maximum; @@ -347,7 +348,7 @@ static int uinput_validate_absinfo(struc return -EINVAL; } - if (abs->flat > max - min) { + if (!check_sub_overflow(max, min, &range) && abs->flat > range) { printk(KERN_DEBUG "%s: abs_flat #%02x out of range: %d (min:%d/max:%d)\n", UINPUT_NAME, code, abs->flat, min, max);