From patchwork Mon Jul 29 12:51:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 13744864 Received: from www262.sakura.ne.jp (www262.sakura.ne.jp [202.181.97.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 869DF145354; Mon, 29 Jul 2024 12:51:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.181.97.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722257515; cv=none; b=Zhvvmkc+ELIe008DRMLmXmA6VjIfUt0G9Fh0zo+o6IuBqeEvb3tjEI5dt/G6EcdHQeqqFHwNans9y1ePGU1CSwhj8gos7GL2vZeEOQabf+Q4rpPdavu28k7ocPDfwIgL9Azs8zKRedcHYmNn8DCmnMtSzLp5zmHiAn07uEPP8wY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722257515; c=relaxed/simple; bh=IQ3+fdqtrkvIO/AlkxXgBXwRp5RdhuSgLGvEw+bEuq8=; h=Message-ID:Date:MIME-Version:To:Cc:From:Subject:Content-Type; b=RXTXs0r+/qQMJ+Ly8fevKi2Nru3bz0cVxY8c2GivsD3znWpLgicXXUF0hMopzI0hIBCxKn9JVofY/y3jHVB10i0SeVE2v6oAlR6X4RUJxvnAwAyY1bmZ/TnusrD8RVWv8E9HieqjkjfHJkSMfS48Thb8L8r8uvnZksB0wjyqJus= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=I-love.SAKURA.ne.jp; spf=pass smtp.mailfrom=I-love.SAKURA.ne.jp; arc=none smtp.client-ip=202.181.97.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=I-love.SAKURA.ne.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=I-love.SAKURA.ne.jp Received: from fsav314.sakura.ne.jp (fsav314.sakura.ne.jp [153.120.85.145]) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id 46TCpUmr036751; Mon, 29 Jul 2024 21:51:30 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav314.sakura.ne.jp (F-Secure/fsigk_smtp/550/fsav314.sakura.ne.jp); Mon, 29 Jul 2024 21:51:30 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/550/fsav314.sakura.ne.jp) Received: from [192.168.1.6] (M106072142033.v4.enabler.ne.jp [106.72.142.33]) (authenticated bits=0) by www262.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id 46TCpUpT036747 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NO); Mon, 29 Jul 2024 21:51:30 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Message-ID: Date: Mon, 29 Jul 2024 21:51:30 +0900 Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Henrik Rydberg , Dmitry Torokhov , Greg Kroah-Hartman Cc: "linux-input@vger.kernel.org" , LKML , Linus Torvalds From: Tetsuo Handa Subject: [PATCH (resend)] Input: MT - limit max slots syzbot is reporting too large allocation at input_mt_init_slots(), for num_slots is supplied from userspace using ioctl(UI_DEV_CREATE). Since nobody knows possible max slots, this patch chose 1024. Reported-by: syzbot Closes: https://syzkaller.appspot.com/bug?extid=0122fa359a69694395d5 Suggested-by: Dmitry Torokhov Signed-off-by: Tetsuo Handa --- This patch was tested in linux-next between next-20240611 and next-20240729 via my tree. Who can take this patch? If nobody can, I will send to Linus. drivers/input/input-mt.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/input/input-mt.c b/drivers/input/input-mt.c index 14b53dac1253..6b04a674f832 100644 --- a/drivers/input/input-mt.c +++ b/drivers/input/input-mt.c @@ -46,6 +46,9 @@ int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots, return 0; if (mt) return mt->num_slots != num_slots ? -EINVAL : 0; + /* Arbitrary limit for avoiding too large memory allocation. */ + if (num_slots > 1024) + return -EINVAL; mt = kzalloc(struct_size(mt, slots, num_slots), GFP_KERNEL); if (!mt)