From patchwork Sun Nov 8 17:37:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elias Vanderstuyft X-Patchwork-Id: 7578891 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 201D99F2F7 for ; Sun, 8 Nov 2015 17:38:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3D66220654 for ; Sun, 8 Nov 2015 17:38:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 63A192065B for ; Sun, 8 Nov 2015 17:38:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752708AbbKHRi2 (ORCPT ); Sun, 8 Nov 2015 12:38:28 -0500 Received: from mail-wm0-f41.google.com ([74.125.82.41]:36439 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752703AbbKHRi1 (ORCPT ); Sun, 8 Nov 2015 12:38:27 -0500 Received: by wmww144 with SMTP id w144so59882213wmw.1; Sun, 08 Nov 2015 09:38:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=t9vnjrlfNwyhqAew5Z3aK3T9lBmf8kwK/76Q7q+l7mI=; b=G9AiAgTiTOFENUk4XhuGCu7R8kjVz+MQR5peGm91AEstb88RfeZ14iegjOLw6ku+6W rDd8j+RgYl3GLrVX0kw7pNUlNCt1ia6WLYVSgd36RObMHwQhyWfc59fwQggFfu/nQreA HNYV+DlSZbzI3OKJLXi7zIGGZKYZH6yuAAH4aalvqfZvq0sxfjYnxMC5w0CYnOakTtEC s3vt8XhRLp/KHGQvXozOrMoIZSb6UiCbj6Gvzu/gJXz2Al4LrgxVtjGbfc4awuC1VdHo AQF9pKpXsN5g8FsWzHLAobLQKccb911uKOob/jUnf/bsfLrfVbEF11o6WOmMFoKDEXQi iJFQ== X-Received: by 10.28.11.205 with SMTP id 196mr20585712wml.83.1447004306369; Sun, 08 Nov 2015 09:38:26 -0800 (PST) Received: from localhost.localdomain (d8D877437.access.telenet.be. [141.135.116.55]) by smtp.googlemail.com with ESMTPSA id hu2sm10939630wjb.21.2015.11.08.09.38.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Nov 2015 09:38:25 -0800 (PST) From: Elias Vanderstuyft To: Dmitry Torokhov Cc: linux-input@vger.kernel.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, David Herrmann , Benjamin Tissoires , Elias Vanderstuyft Subject: [PATCH v2 2/2] Input: uinput: Sanity check on ff_effects_max and EV_FF Date: Sun, 8 Nov 2015 18:37:34 +0100 Message-Id: <1447004254-12431-1-git-send-email-elias.vds@gmail.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1442510988-3164-3-git-send-email-elias.vds@gmail.com> References: <1442510988-3164-3-git-send-email-elias.vds@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently the user can set ff_effects_max to zero with the EV_FF bit (and the FF_GAIN and/or FF_AUTOCENTER bits) set, in this case the uninitialized methods ff->set_gain and/or ff->set_autocenter can be dereferenced, resulting in a kernel oops. Check in uinput_create_device() and print a helpful message and return -EINVAL in case the check fails. Signed-off-by: Elias Vanderstuyft --- Changes in v2: - Rebase on pending patches from David Herrmann and Benjamin Tissoires: - v3 Input: uinput - add new UINPUT_DEV_SETUP and UI_ABS_SETUP ioctl - Input: uinput - rework ABS validation - Don't require EV_FF bit to be set when ff_effects_max is non-zero - Move check from uinput_setup_device() to uinput_create_device() - Update commit description At the same time, the new UINPUT_DEV_SETUP and UI_ABS_SETUP ioctls were tested as well (in both orders). The legacy write() (instead of UINPUT_DEV_SETUP) was also tested. drivers/input/misc/uinput.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c index 1d93037..b9d0713 100644 --- a/drivers/input/misc/uinput.c +++ b/drivers/input/misc/uinput.c @@ -272,6 +272,13 @@ static int uinput_create_device(struct uinput_device *udev) input_set_events_per_packet(dev, 60); } + if (test_bit(EV_FF, dev->evbit) && !udev->ff_effects_max) { + printk(KERN_DEBUG "%s: ff_effects_max should be non-zero when FF_BIT is set\n", + UINPUT_NAME); + error = -EINVAL; + goto fail1; + } + if (udev->ff_effects_max) { error = input_ff_create(dev, udev->ff_effects_max); if (error)