Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4058569imu; Mon, 14 Jan 2019 14:09:39 -0800 (PST) X-Google-Smtp-Source: ALg8bN46glBhNBTIQNTKZZMzcH+t8g1AI2j7vGt9Zj99O+m7SYqPQlVkwxmXDAC0wjebDh7SK+B3 X-Received: by 2002:a65:624c:: with SMTP id q12mr629429pgv.379.1547503779910; Mon, 14 Jan 2019 14:09:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547503779; cv=none; d=google.com; s=arc-20160816; b=q7RSz5DLGCWnDAJxFrXx94rxoQLU4X7mpvKWFE+dJqFB9X9Q8nLuAIdPSk7ZTE72rR elyIx8v92qmkdwMFweLxLEiPBTa5mKQgYAuEM+UFa8T0rCOZj4MjarfzFhvZgQ0rzvrp m4SLjBICXcqKU+zF9GVAp4kyWya8cjl/RG0g9oQEe9+POJKU1O8zJNzZllkN5N7Rby7M BTb/qNuvh+06AWOId+Gud6VxHMc4CxDQTVMh/mGJ5TreX9CwuoaLqFIZcmHhzvY/S16Z vG8M1Fzsrz330hlQFOxLdyVgcoisMqQuEUmBTdhO30RjM9xvsgumOiGK6tTCdZ2yTCZT 93aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=shHou+66+RjSgcQd8m33V51MEprMke5m68diHVIUSQs=; b=eIkEHnCeMiNINLEWSAYEYGbryf32o7f8FVDCcMi1eV5tuk1i9wuXUax9g/FqH12NVZ ZMtyXjqoglJQc9OqQxoG8bGFh+pdnGv/toby5J5Fd9Su3YbK4JfZ4RvzIqqWtgWrrZFt rN1DDR5HFMPTBDp84/gPHxBa7xTBogcc7QZdYTgBX+HWmCHbtTlxygMP7alXDow7YWfn YtbAIid+I3BqvZ6L46RY8VbR94DBwmVdR5X0RBnjCdMF4wSb2IzuJ26HzyUkTGX6pxoV htA6E2+bMk3eboYKISCWNniRDe5qFkjn4v6ofD67C8yzsEH/xuvV+e1SD1Kb4UVAQqN5 rFPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=SQU+bXrO; 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 h127si1457211pfe.204.2019.01.14.14.09.23; Mon, 14 Jan 2019 14:09:39 -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=SQU+bXrO; 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 S1726875AbfANWIB (ORCPT + 99 others); Mon, 14 Jan 2019 17:08:01 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:39023 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726591AbfANWIA (ORCPT ); Mon, 14 Jan 2019 17:08:00 -0500 Received: by mail-pl1-f195.google.com with SMTP id 101so260658pld.6; Mon, 14 Jan 2019 14:08:00 -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:references:mime-version :content-disposition:in-reply-to:user-agent; bh=shHou+66+RjSgcQd8m33V51MEprMke5m68diHVIUSQs=; b=SQU+bXrOHhu6I3frFOYkIAxI1I04OlkuQHps4JykshNlzR87qkKlsLZlHYbVkcBQFW 6YBCkalfT47n9xxLJ2l9qzf+6uq4XuvIzNCi6OzKgwn3dkKJ9vUdGEhVV0Lsasq0p76W R3C/ZAGVlqhdJGMKGu6kHPIQ1CB8II/oPz30Jw4ZEB3tSGmW4ps6yTGw2bCGWX5CdJZG DDwKkQxSifhAKMplWSGBdaAkHa7qe9CHA+75JeVGGI1HBEUKTJEeeH/uKPI8xmLRpbZe smRQ4zN/hOAvPoz0CRSis5dFs53IsbEvTIMOe4hrKsVEy4c7NY7hBlSCt+y0BdJ67FL8 I9eg== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=shHou+66+RjSgcQd8m33V51MEprMke5m68diHVIUSQs=; b=X6Gs77k5coNAgZxgHihdc0EWf4lFtQLY5bD/R5dbPQ27doDjmlWJudJA+f9rnOjxN9 pXewYLeXGij+Co2t4w5B87A6QBbWKNEqLy7kF+419SP/UUBk9C+z4uw21s1nYSEFmwKm LMu6Ff5vNDRuOO2HwGSU6zZvo2mbFuEm5lOsDDqRflTk/8Xs2q3ZugfBjo/9Y88h8OuF Ejqh1/BsIcQKB4QNPW9AZzrrY5nT6BnodkZdBy/TXOFhf63+Fwlg/RONMtZH2Eb9l0DT xkS8OM6lWk+e5VV/sQd8Ck6Wc4nJnsiJxTvWFqIpr4pOxksyGiAlHtHcXgcNRUuDWVHx lQgw== X-Gm-Message-State: AJcUukdxhlwtotWYphPppGaf3B9iZ9PeLnotnpTLqGxs+SkZrkcAHfnx 6qYarJK50w/PNjvJ1adDS6q6w4TW X-Received: by 2002:a17:902:9a02:: with SMTP id v2mr725269plp.180.1547503679459; Mon, 14 Jan 2019 14:07:59 -0800 (PST) Received: from dtor-ws ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id v89sm2593155pfj.164.2019.01.14.14.07.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Jan 2019 14:07:58 -0800 (PST) Date: Mon, 14 Jan 2019 14:07:56 -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: Re: [PATCH] Input: uinput - fix undefined behavior in uinput_validate_absinfo() Message-ID: <20190114220756.GF117329@dtor-ws> References: <20190114220448.GA241112@dtor-ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190114220448.GA241112@dtor-ws> 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 On Mon, Jan 14, 2019 at 02:04:48PM -0800, Dmitry Torokhov wrote: > 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) { This should be !check_sub_overflow(...) of course. > 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 -- Dmitry