Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3329041imu; Sun, 11 Nov 2018 12:29:52 -0800 (PST) X-Google-Smtp-Source: AJdET5eDE4nW8YeGHDjhh0hK8reEtDqU2WHfpIMS/Zg/2HLN6xXOtYZQ427+Djda6+jp/OAGjhZw X-Received: by 2002:a17:902:e201:: with SMTP id ce1-v6mr17546459plb.138.1541968192819; Sun, 11 Nov 2018 12:29:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541968192; cv=none; d=google.com; s=arc-20160816; b=PvPc41C8GG1ezvc7vE2SYBwqWQZEWkoOh84gvcPg+Jv37BArjOvTJbX8xPOnmlT/md E86Jf+17/x6us5GqxNlJqshHqOtarPwb4ZKOXKkJUS/jlXMC6//i0tXwdTz0RIlK96Uj ugK5YTOLHb2EJgii4ZEu03RvQdRfrmmjrfkWEvlknK42VgdkcAWXv7W9Vl3yGaWIr5pZ fsAercJjR0+oXY91o1dfVgBQlBqXQazC64Ss8t3iCYO+ZoobKO+mO1X3aYiRxSGdR8J1 vAKGsLKdI6tbc+ULtcIumAs/GGfpWxj7Y4i5hMdhFcD1qJSGFfuTcDkWgpdiyGbNGDxj ydgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=uxSuxivSthe5otB4eNFmzO0/mND5IDeDB3DsgT250bc=; b=V5C9niYATJKEL7l2ydaFRrWZyO6T4VNAAxpG12ud6OVK+pVTN2ABzCw09oIKjBhjGY pUtp+hIS+MI2eMWGgDNgwyia4n0ipQONYHKK2i0NCxCFemxGbAqe8faJkiN8IkYxl1AC 3rUHKFqXjK3B4DklcWnCVOPC+nDzi1Ro+cWv8StCsbrrvTqAKD7Y2eAM4lWTDHQYuGWX xNvExKiO1DRnvnfdxGlW2RSd81f4RuEI2h30ROCIQmVw3RMsdxw7KVjz3rBUvIpMPjL3 u4H38gqKYt8iXN8INrsLLU2dZBgUuFJXKTqagmRfJpKPHqRBlKjA6SkLfAN3TME9lfSm eUUw== ARC-Authentication-Results: i=1; mx.google.com; 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 h3-v6si15135650pld.424.2018.11.11.12.29.37; Sun, 11 Nov 2018 12:29:52 -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; 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 S1730574AbeKLFsY (ORCPT + 99 others); Mon, 12 Nov 2018 00:48:24 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:50608 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730392AbeKLFsX (ORCPT ); Mon, 12 Nov 2018 00:48:23 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvsi-0000lK-Be; Sun, 11 Nov 2018 19:58:52 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsa-0001qy-1B; Sun, 11 Nov 2018 19:58:44 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Benjamin Tissoires" , "Tomasz Kramkowski" , "Jiri Kosina" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 334/366] HID: clamp input to logical range if no null state In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Tomasz Kramkowski commit c3883fe06488a483658ba5d849b70e49bee15e7c upstream. This patch fixes an issue in drivers/hid/hid-input.c where values outside of the logical range are not clamped when "null state" bit of the input control is not set. This was discussed on the lists [1] and this change stems from the fact due to the ambiguity of the HID specification it might be appropriate to follow Microsoft's own interpretation of the specification. As noted in Microsoft's documentation [2] in the section titled "Required HID usages for digitizers" it is noted that values reported outside the logical range "will be considered as invalid data and the value will be changed to the nearest boundary value (logical min/max)." This patch fixes an issue where the (1292:4745) Innomedia INNEX GENESIS/ATARI reports out of range values for its X and Y axis of the DPad which, due to the null state bit being unset, are forwarded to userspace as is. Now these values will get clamped to the logical range before being forwarded to userspace. This device was also used to test this patch. This patch expands on commit 3f3752705dbd ("HID: reject input outside logical range only if null state is set"). [1]: http://lkml.kernel.org/r/20170307131036.GA853@gaia.local [2]: https://msdn.microsoft.com/en-us/library/windows/hardware/dn672278(v=vs.85).asp Signed-off-by: Tomasz Kramkowski Acked-by: Benjamin Tissoires Signed-off-by: Jiri Kosina Signed-off-by: Ben Hutchings --- drivers/hid/hid-input.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -1087,19 +1087,26 @@ void hidinput_hid_event(struct hid_devic /* * Ignore out-of-range values as per HID specification, - * section 5.10 and 6.2.25. + * section 5.10 and 6.2.25, when NULL state bit is present. + * When it's not, clamp the value to match Microsoft's input + * driver as mentioned in "Required HID usages for digitizers": + * https://msdn.microsoft.com/en-us/library/windows/hardware/dn672278(v=vs.85).asp * * The logical_minimum < logical_maximum check is done so that we * don't unintentionally discard values sent by devices which * don't specify logical min and max. */ if ((field->flags & HID_MAIN_ITEM_VARIABLE) && - (field->flags & HID_MAIN_ITEM_NULL_STATE) && - (field->logical_minimum < field->logical_maximum) && - (value < field->logical_minimum || - value > field->logical_maximum)) { - dbg_hid("Ignoring out-of-range value %x\n", value); - return; + (field->logical_minimum < field->logical_maximum)) { + if (field->flags & HID_MAIN_ITEM_NULL_STATE && + (value < field->logical_minimum || + value > field->logical_maximum)) { + dbg_hid("Ignoring out-of-range value %x\n", value); + return; + } + value = clamp(value, + field->logical_minimum, + field->logical_maximum); } /*