Message ID | 20230417160148.60011-1-n.zhandarovich@fintech.ru |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2239487vqo; Mon, 17 Apr 2023 09:12:40 -0700 (PDT) X-Google-Smtp-Source: AKy350ZpZjNxaJVZ6yJFKJEkdGv/oYhmPASGGwlmuoNs/lX24g9Ps5iArc9DO/nefe1fm6hi7l8C X-Received: by 2002:a17:90b:198:b0:23d:500f:e826 with SMTP id t24-20020a17090b019800b0023d500fe826mr15914715pjs.14.1681747960695; Mon, 17 Apr 2023 09:12:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681747960; cv=none; d=google.com; s=arc-20160816; b=urhWFdetn10x627OYgownBIPcuCoG6SKOp0GUu3mNKfkslJm0GLhwKxoEMrNN+i+ln /ABIJqKFszA4NibbGI2urugmlilwvZHg9G/r+5roc9I/d6As3jG9Tpw+a4+FvaMSCPe3 JEFocgFztvu0kVSK06qOCuiSc0K3pQl1La4Dap0GZV20rYraIS6VdrRqrI5DcGQyYg5o /xIP2dXgfiurYaUuQzJvh6wA7069ifL5MC9j0jyuNbYHiHofV+ecqxtHTI4s2AgyQLgt Dn5yTNy5Sg+UXDoTVOQ5ZpAriTYzVrJqXxOObpMgTDgjoNyBJFirjzom+b/q52bXaK6C 23kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=xyrrtKhoL1pv8it1YZGkXFQh3Le8NHLS2C44U5sn58A=; b=DmwDTELWLgDlU8CmYIrnMc6Mn7i2yE/T3Pzmxk6wjgNwTTkthQUCjwackpM5sgOLBi wxSGNV9EQtuTOz/p4vODKgd+cdEUjWap/goq5BB2D4zDP2LNNteWhZQwlAHAjlOK64SC bPUbf2nTQ23VTBbMhqb6mmxFlxqlrVwgKic8bp90UXcz2ll8hOQB1Ioc+o+OQP4dgR/G UlwhSG77R6QOLU0iHjz3jN+4V5EzQ9jlJPmc++EMnnI3I9L0/9n0TNc8hJ4u3k7FXVVL D4c5SkUI46K60/QrqXKirMl472kUaww2GaUep+Wyu55wgcqklH3SRT9G/o0dq6rEzX04 ZSXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f9-20020a17090a638900b002343565e8b4si5782076pjj.122.2023.04.17.09.12.27; Mon, 17 Apr 2023 09:12:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230190AbjDQQCd (ORCPT <rfc822;leviz.kernel.dev@gmail.com> + 99 others); Mon, 17 Apr 2023 12:02:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231200AbjDQQCM (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 17 Apr 2023 12:02:12 -0400 Received: from exchange.fintech.ru (exchange.fintech.ru [195.54.195.159]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81F6ABBA1; Mon, 17 Apr 2023 09:02:01 -0700 (PDT) Received: from Ex16-01.fintech.ru (10.0.10.18) by exchange.fintech.ru (195.54.195.159) with Microsoft SMTP Server (TLS) id 14.3.498.0; Mon, 17 Apr 2023 19:01:53 +0300 Received: from localhost (10.0.253.138) by Ex16-01.fintech.ru (10.0.10.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2242.4; Mon, 17 Apr 2023 19:01:53 +0300 From: Nikita Zhandarovich <n.zhandarovich@fintech.ru> To: Ping Cheng <ping.cheng@wacom.com> CC: Nikita Zhandarovich <n.zhandarovich@fintech.ru>, Jason Gerecke <jason.gerecke@wacom.com>, Jiri Kosina <jikos@kernel.org>, Benjamin Tissoires <benjamin.tissoires@redhat.com>, <linux-input@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <lvc-project@linuxtesting.org> Subject: [PATCH] HID: wacom: avoid integer overflow in wacom_intuos_inout() Date: Mon, 17 Apr 2023 09:01:48 -0700 Message-ID: <20230417160148.60011-1-n.zhandarovich@fintech.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.0.253.138] X-ClientProxiedBy: Ex16-02.fintech.ru (10.0.10.19) To Ex16-01.fintech.ru (10.0.10.18) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763440549456441487?= X-GMAIL-MSGID: =?utf-8?q?1763440549456441487?= |
Series |
HID: wacom: avoid integer overflow in wacom_intuos_inout()
|
|
Commit Message
Nikita Zhandarovich
April 17, 2023, 4:01 p.m. UTC
If high bit is set to 1 in ((data[3] & 0x0f << 28), after all arithmetic
operations and integer promotions are done, high bits in
wacom->serial[idx] will be filled with 1s as well.
Avoid this, albeit unlikely, issue by specifying left operand's __u64
type for the right operand.
Found by Linux Verification Center (linuxtesting.org) with static
analysis tool SVACE.
Fixes: 3bea733ab212 ("USB: wacom tablet driver reorganization")
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
---
drivers/hid/wacom_wac.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Mon, Apr 17, 2023 at 9:03 AM Nikita Zhandarovich <n.zhandarovich@fintech.ru> wrote: > > If high bit is set to 1 in ((data[3] & 0x0f << 28), after all arithmetic > operations and integer promotions are done, high bits in > wacom->serial[idx] will be filled with 1s as well. > Avoid this, albeit unlikely, issue by specifying left operand's __u64 > type for the right operand. Thank you Nikita for the fix! It's good to avoid potential issues. > Found by Linux Verification Center (linuxtesting.org) with static > analysis tool SVACE. > > Fixes: 3bea733ab212 ("USB: wacom tablet driver reorganization") > Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru> Reviewed-by: Ping Cheng <ping.cheng@wacom.com> Cc: stable@vger.kernel.org Cheers, Ping > --- > drivers/hid/wacom_wac.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c > index 9312d611db8e..0e4404f3801e 100644 > --- a/drivers/hid/wacom_wac.c > +++ b/drivers/hid/wacom_wac.c > @@ -826,7 +826,7 @@ static int wacom_intuos_inout(struct wacom_wac *wacom) > /* Enter report */ > if ((data[1] & 0xfc) == 0xc0) { > /* serial number of the tool */ > - wacom->serial[idx] = ((data[3] & 0x0f) << 28) + > + wacom->serial[idx] = ((__u64)(data[3] & 0x0f) << 28) + > (data[4] << 20) + (data[5] << 12) + > (data[6] << 4) + (data[7] >> 4); > > -- > 2.25.1 >
On Mon, 17 Apr 2023, Nikita Zhandarovich wrote: > If high bit is set to 1 in ((data[3] & 0x0f << 28), after all arithmetic > operations and integer promotions are done, high bits in > wacom->serial[idx] will be filled with 1s as well. > Avoid this, albeit unlikely, issue by specifying left operand's __u64 > type for the right operand. > > Found by Linux Verification Center (linuxtesting.org) with static > analysis tool SVACE. > > Fixes: 3bea733ab212 ("USB: wacom tablet driver reorganization") > Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru> Applied. Thanks for the fix, and sorry for the delay.
diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 9312d611db8e..0e4404f3801e 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -826,7 +826,7 @@ static int wacom_intuos_inout(struct wacom_wac *wacom) /* Enter report */ if ((data[1] & 0xfc) == 0xc0) { /* serial number of the tool */ - wacom->serial[idx] = ((data[3] & 0x0f) << 28) + + wacom->serial[idx] = ((__u64)(data[3] & 0x0f) << 28) + (data[4] << 20) + (data[5] << 12) + (data[6] << 4) + (data[7] >> 4);