Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5249956rwr; Mon, 8 May 2023 21:32:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Zumqfr5o0Js28R8HUM6bBTQJprBmvDOeoTCBs/W8s20tVzUZXq2HLnwA0P9ynFtC6NHs0 X-Received: by 2002:a05:6a20:54a0:b0:101:457:c687 with SMTP id i32-20020a056a2054a000b001010457c687mr3402850pzk.20.1683606776142; Mon, 08 May 2023 21:32:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683606776; cv=none; d=google.com; s=arc-20160816; b=bseLScs5DT0wrnEIxHmRVOgd8G7qfoIsH//Gdk5oj4hYlPRanbxV9mLmacz20QygEF +jTp9U2hJW4L1PfHJ+A2yKPeIsmQMFxtBe91QTQzIsn3gHqbDJrrRtPwloj1mhlwZPdD g0S7485/HgA+Ib0tYMiRdoCn6gtWxI2ZIJ8P1pnMA0dxVHw/V0/iyz4QfVP77gUyG+Zb FvuTRdA1hry22G9em3m7A2ZG3S2mvLtshEkATi/zI+Mp/4OidaipYWyimS7GRiaTOss8 3TiQHa5IA4cjCwkekPMiSWr9wb4zEYTB3e4MuJkWIMpX2jhKrt6u39dcuw0sb5ZpEZnu FQ9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=/LScAQLvLy2KJzZIX1XiMv58IwV2dMEiIzwcsMUn1A4=; b=VbTdRUuMYQ5RN8NGu0DSY+MvpJe96qfw0hIEK5l6rA1tnC6gfyp+HE6EfC8Ds5tpyB 34hcP+uMnt9Ia+yeP6+dv1QAlZ0T8gIDEqDO/xZu/yuCQBzMd254dXPNVeWr+WVn1gUk Rf2TpdGsrlaWMe9Y91GN0GbArW2glVpTL0hePa1NNVSQc67nwzhPltuSJn2kIKGDVdVi 2ioB2WMP+7J+J7Gy/4g6RqGb9oYvUzwd0r8V3jXOMvm5zbS/huCNQcZCprwAwxr4bbct RQzTlcSPCDdnri+BP/iE9i1/S55wxIAZ+H5KMH9swQUMDmU1A95FwiCjFbBV8UuIaWVn CH9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=TpEG5YCu; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w20-20020a63fb54000000b00527b90936b8si642395pgj.38.2023.05.08.21.32.39; Mon, 08 May 2023 21:32:56 -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; dkim=pass header.i=@gmail.com header.s=20221208 header.b=TpEG5YCu; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234529AbjEID4v (ORCPT + 99 others); Mon, 8 May 2023 23:56:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234637AbjEID4F (ORCPT ); Mon, 8 May 2023 23:56:05 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78FE0D2C9; Mon, 8 May 2023 20:55:35 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1ab0c697c84so40647485ad.3; Mon, 08 May 2023 20:55:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683604531; x=1686196531; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=/LScAQLvLy2KJzZIX1XiMv58IwV2dMEiIzwcsMUn1A4=; b=TpEG5YCu4WuU4Td8kK/b8hkh408J24waDjpTj9REXrzkvXVOo5lts6nwF7SE3r2TFA XkbNYgYFxLtp2jcmPQov7SyiXF599dJT6TvL1SNB7bLlrR6pSaUgsDK0jE+cRU2dznWp XjBsCI/i6IBp/KD0EBs4nPL/YzYKopkxqBmr1E+tGGhRvTx+f6EKEfVaL3ftmKsG66kV +wXgHgvBoenQU7mOAmCERvQRJXcfV3gs5Zw7HsCMJASD8tv+sedGBKg/F9RIlSms2cMI 42wjEE6kSjJIazH7MDFdSFoeJTEnM9fl8chwVqjJW3IwwyyEuCxhOqG+r695lxnpy4gM IetA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683604531; x=1686196531; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/LScAQLvLy2KJzZIX1XiMv58IwV2dMEiIzwcsMUn1A4=; b=P1YE745rPC89vhf66BAYjCqmoOYKKU3I1+s5tFaD8Hjo+aXvzbcTGlrZdKWNzrbK/5 wf0eS66TUl+pxHXe8UY9NVnAaHhxOoFFOr4BZ52AloU5XSYfqObF9v/qplIyucSJkSJa KFNHILGaAsofGaJ+SNuimk7nQv5zetqT1Zicly5SjHbXIm4j5CIn0vfbr4ibJCU8j68Q Vhcr003wOjLxGz2qe0dtwcP7wUOL4YvukaEWye37Mlrl9R1gI47k8otTEuYrLzk1SyHW tnBqQp6sWv0sawVXdwCKbPB+qkgdV7bU0PgXy59laC8zf5R72pGW7MJHo1FiL38nFQRA 5mwQ== X-Gm-Message-State: AC+VfDzg+MBjSHlA8crtUfHpk3XqIoUE5v5xgr87QMJSnFsYTjfZKNnL HcPx6fRbZDP6TUspuZ7Rn+4ngMslyDs= X-Received: by 2002:a17:902:e748:b0:1a9:a478:66c5 with SMTP id p8-20020a170902e74800b001a9a47866c5mr16689358plf.63.1683604530927; Mon, 08 May 2023 20:55:30 -0700 (PDT) Received: from google.com ([2620:15c:9d:2:d72f:84b8:c441:6a95]) by smtp.gmail.com with ESMTPSA id p17-20020a170902ead100b001a1faed8707sm306760pld.63.2023.05.08.20.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 May 2023 20:55:30 -0700 (PDT) Date: Mon, 8 May 2023 20:55:27 -0700 From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, jondaniel879@gmail.com Subject: [PATCH] Input: psmouse - fix OOB access in Elantech protocol Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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: X-Mailing-List: linux-kernel@vger.kernel.org The kernel only allocate 5 MT slots; check that transmitted slot ID falls within the acceptable range. Link: https://bugzilla.kernel.org/show_bug.cgi?id=217417 Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/elantech.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c index ece97f8c6a3e..2118b2075f43 100644 --- a/drivers/input/mouse/elantech.c +++ b/drivers/input/mouse/elantech.c @@ -674,10 +674,11 @@ static void process_packet_head_v4(struct psmouse *psmouse) struct input_dev *dev = psmouse->dev; struct elantech_data *etd = psmouse->private; unsigned char *packet = psmouse->packet; - int id = ((packet[3] & 0xe0) >> 5) - 1; + int id; int pres, traces; - if (id < 0) + id = ((packet[3] & 0xe0) >> 5) - 1; + if (id < 0 || id >= ETP_MAX_FINGERS) return; etd->mt[id].x = ((packet[1] & 0x0f) << 8) | packet[2]; @@ -707,7 +708,7 @@ static void process_packet_motion_v4(struct psmouse *psmouse) int id, sid; id = ((packet[0] & 0xe0) >> 5) - 1; - if (id < 0) + if (id < 0 || id >= ETP_MAX_FINGERS) return; sid = ((packet[3] & 0xe0) >> 5) - 1; @@ -728,7 +729,7 @@ static void process_packet_motion_v4(struct psmouse *psmouse) input_report_abs(dev, ABS_MT_POSITION_X, etd->mt[id].x); input_report_abs(dev, ABS_MT_POSITION_Y, etd->mt[id].y); - if (sid >= 0) { + if (sid >= 0 && sid < ETP_MAX_FINGERS) { etd->mt[sid].x += delta_x2 * weight; etd->mt[sid].y -= delta_y2 * weight; input_mt_slot(dev, sid); -- 2.40.1.521.gf1e218fcd8-goog -- Dmitry