Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4057164imu; Mon, 14 Jan 2019 14:08:01 -0800 (PST) X-Google-Smtp-Source: ALg8bN4dJ27i8tBmysyoqX1atmJWkzlE9OJUkJpko3HArh66oW4POxVr8vOx2CTk1IjDRVrzUrbS X-Received: by 2002:a63:e80e:: with SMTP id s14mr692456pgh.30.1547503681012; Mon, 14 Jan 2019 14:08:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547503681; cv=none; d=google.com; s=arc-20160816; b=GnMNbJyGqL6wNiSoJBU3hRj8Fghtd+tSI0I8UI6Z6fTjN/wmYSv/c4YxDKACHPBRMb X2Mpqhg9YnilR68Eq4MrTgcWPsIllFG7d9gG/8cegqbufaucmwqRi4QzBTN470W96b/y g9LUaHu8roMO4/SOCOqGaUuRbeoi/GAvkSVpWylWXn/YS7BVlw7qc418hCQGRFDQp8t1 PLa+YT5Slv1OsbZXUohO7ZknImZdo/fV0l7JUua8ePf3I6RltWZMymUNju+UPSLzluTN qgwhDVRauae345+4fwNf1UODyS3RHYcsDBHv0smMCB1XZ8UVhkesMHukQqx7kStv4yc7 J5qQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=atdq442LD9LsMFrYiC+F33UAnilzt6PIC1hqbs+cWdM=; b=v2AWKT7fX94uk/l09wHeRGNDoVX5znqUy0pDAWN2Yusf4HXxvcn0hpkuxm0PFTDuYQ HECOuZWwJAsImCyVuVIcJsrvQPFLw7IvQ+4NgUlfgnZsuZXScbfTPXyaQb5WrdjTzvt2 JW7x7vnRpvUUKWjoRsJBeBCuevGdQ+RpZUahgusj1i2wEF2gRDe76gHogp7ejDFAoK4r NWyGvWTLbWmNOcdYeshwte1SFrxhU/xMUHxFTt44uR3Jg/3ZxCDwi+bJjMebbHwuzhfx 4o/VUVn/b5u6jPDLwx3PlK+wwDMz2hEosuoe8MxuW+oiL8YR2IiS/4kW75iLc3lx/uDt jYyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="L/cax459"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h19si1293679plr.67.2019.01.14.14.07.45; Mon, 14 Jan 2019 14:08: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=@gmail.com header.s=20161025 header.b="L/cax459"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727274AbfANWEz (ORCPT + 99 others); Mon, 14 Jan 2019 17:04:55 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:35912 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727248AbfANWEy (ORCPT ); Mon, 14 Jan 2019 17:04:54 -0500 Received: by mail-pg1-f193.google.com with SMTP id n2so259085pgm.3; Mon, 14 Jan 2019 14:04:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=atdq442LD9LsMFrYiC+F33UAnilzt6PIC1hqbs+cWdM=; b=L/cax459GXQ4hMiQcolyFnGOa4OB0J80Ag2d1dV1HDq/S0YDMgWnH8/K/P9X4F878B 6+69k0a9yvI/SJupP/vn4a6B2A1UPRlRT9XUfn4RX2YXc3mgDKEh7+3P7GR7zqc2httC ogZJhe8KY0ATXpN7r5NvSabtbbogZfHiVHRtg4bXkJ899k/9idZKmuG0bZ8oyqFAP87y lXtDljrAJzJ/I4gargWqEIXAq1awvJ2cKjutDNvbsNoHmuBzvk1Jqu0PgDKmmsFSqu4W oimc3NClMpeSXV6iLdRXtjWCSKhq0GS9OJfqDck/+ZKXN95GUDw+FORd9mw1u8iSaWDn vwLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=atdq442LD9LsMFrYiC+F33UAnilzt6PIC1hqbs+cWdM=; b=IF3DlQcAdBKxjVc+2K8wCAihkgtL3NEM0yM6jNie2JgTSMuKc80mLJSnuQhFteN7/U pbjYTfRdl3mgoh3EE5rtZ7rzlcqW7pdVyrnkOC0mWtIY+chRr7gM//se/8d61+ODXpAv d2q+Z5cJ85luQwFzzvFV9YlD9hdzWuAoITzu57lvTakakNVlVe9RQdZ9Cuyq79sDRTRD 2kvLt4HADR0dAIzUfCnzn7gsm6PLrmCjG+4l3n4tGNo91BpE+zsfjKbUqApkmGG6ymbk pZvScUM8xLcy457QOYhDiTJDiEYP8CGTkXpL+jzc3KYUxhync5DtF+NNnVmaVv7hB4AZ XOVQ== X-Gm-Message-State: AJcUukfqFgl4hH4w6rD0miwg3Wz4ZMlCKDJbFUPJiNTS8sw3p+Hx9bjs pBQXyWsNTwuw9PSfPJ2obtBiL7/s X-Received: by 2002:a63:83c1:: with SMTP id h184mr600308pge.437.1547503491647; Mon, 14 Jan 2019 14:04:51 -0800 (PST) Received: from dtor-ws ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id g15sm5325769pfj.131.2019.01.14.14.04.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Jan 2019 14:04:50 -0800 (PST) Date: Mon, 14 Jan 2019 14:04:48 -0800 From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: Byoungyoung Lee , rydberg@bitmath.org, DaeRyong Jeong , syzkaller@googlegroups.com, Peter Hutterer , linux-kernel@vger.kernel.org Subject: [PATCH] Input: uinput - fix undefined behavior in uinput_validate_absinfo() Message-ID: <20190114220448.GA241112@dtor-ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: stable@vger.kernel.org Signed-off-by: Dmitry Torokhov --- drivers/input/misc/uinput.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index 8ec483e8688b..26ec603fe220 100644 --- 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" @@ -405,7 +406,7 @@ static int uinput_open(struct inode *inode, struct file *file) 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; @@ -417,7 +418,7 @@ static int uinput_validate_absinfo(struct input_dev *dev, unsigned int code, 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); -- 2.20.1.97.g81188d93c3-goog -- Dmitry