Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3554399pxb; Mon, 1 Mar 2021 13:11:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJyojxozJPIystU5c//4B6aj5Z4DrdvM8dSYelXH/+ALvSBa8F3ocz4o+9kYiJ7TOBCnUocj X-Received: by 2002:a17:906:12db:: with SMTP id l27mr17496284ejb.500.1614633071150; Mon, 01 Mar 2021 13:11:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614633071; cv=none; d=google.com; s=arc-20160816; b=XI//1SblZsvzAu3r9UCjblSe+MKarkHvqIZ00lwPKhTakXEF+sk5gha0qPAqki04rm IPFunx1PHBDtABfWpFBz18eUm4vLl6XHBQueQs2j7UQZYO3+PGOGNo5hO1w8Ckhlivi+ Fw6EcnMV0nFFQ69XfaD5EoPPW4MGrw+PN/M2MJK4JO7Y690arpDrpfTAAVXHuqXkQXKG ayZQi/w9e5oPFt78cdVY9fJJQjtfxj4STnjDsyMJcmQAb0jjKH5SFK0bZamx7FI8PiOo mEXumT0MQ9PNe5tJS/olMNRXNyOHN/aOAOTEupVzNNq71yiyabIbIyoKpfu5cqVJtxQc 3Z8g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Rj6WBUG7MoSkyDaVi1F7MIgHvsyQUAa/jF6lWgOxZO8=; b=tyhgt5B0SHtT/xMtPbOhc12tioJV41dzGk7sBSAqiknZsaVHl+DuaGtKKQweMzbyvp jYrnY2BxoALP5jbuBp0e4GyYUqxgpL9I1K1We1weZEyP5O/8CPu2g1CicvKB6SzUBY/U 2+S2CV1RkgiIpmlLTcdBnzQb/sTYcU3+gucOS38CoL00hsj2LKCwW5+/mzkkNbMt+siv XwWvXgz4I/SzQW934bzXnBxnJSqljQA82L45F/FXgabVnqIkZLpPdflKnGHmcNg+4AHj CVVhGCx1JIaKDj9Hbp4UwMCeqKL5Yph+nu1lcOrnG0FLrDMJuFOs48ZJGr+AczVrGt7a pKeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JwV1XQCy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j1si11956311edt.398.2021.03.01.13.10.48; Mon, 01 Mar 2021 13:11:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JwV1XQCy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243729AbhCAVHv (ORCPT + 99 others); Mon, 1 Mar 2021 16:07:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:48196 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237781AbhCARNS (ORCPT ); Mon, 1 Mar 2021 12:13:18 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 879786502E; Mon, 1 Mar 2021 16:44:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614617049; bh=ORPCG6lNXDbkMXeS/l0DdB+Se3UxgSZObZMpSEonDEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JwV1XQCy7seugTA3jj6C4mlIhmzJR9+ge4r5Eu6rJFLuYklDVkinFOz9Tt/5Fzm0A jmrq5BKHQiBLnuYbYlgLLUCNELtFomA2zYEn0oQgyDJpoJISocMO0y6nu4cN80pd5T ZBspRezGwEdLxm0KPHb/nfdb2gG9j1yEyDAivKDY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Dmitry Torokhov Subject: [PATCH 4.19 184/247] Input: joydev - prevent potential read overflow in ioctl Date: Mon, 1 Mar 2021 17:13:24 +0100 Message-Id: <20210301161040.665826495@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dan Carpenter commit 182d679b2298d62bf42bb14b12a8067b8e17b617 upstream. The problem here is that "len" might be less than "joydev->nabs" so the loops which verfy abspam[i] and keypam[] might read beyond the buffer. Fixes: 999b874f4aa3 ("Input: joydev - validate axis/button maps before clobbering current ones") Signed-off-by: Dan Carpenter Link: https://lore.kernel.org/r/YCyzR8WvFRw4HWw6@mwanda [dtor: additional check for len being even in joydev_handle_JSIOCSBTNMAP] Cc: stable@vger.kernel.org Signed-off-by: Dmitry Torokhov Signed-off-by: Greg Kroah-Hartman --- drivers/input/joydev.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/drivers/input/joydev.c +++ b/drivers/input/joydev.c @@ -460,7 +460,7 @@ static int joydev_handle_JSIOCSAXMAP(str if (IS_ERR(abspam)) return PTR_ERR(abspam); - for (i = 0; i < joydev->nabs; i++) { + for (i = 0; i < len && i < joydev->nabs; i++) { if (abspam[i] > ABS_MAX) { retval = -EINVAL; goto out; @@ -484,6 +484,9 @@ static int joydev_handle_JSIOCSBTNMAP(st int i; int retval = 0; + if (len % sizeof(*keypam)) + return -EINVAL; + len = min(len, sizeof(joydev->keypam)); /* Validate the map. */ @@ -491,7 +494,7 @@ static int joydev_handle_JSIOCSBTNMAP(st if (IS_ERR(keypam)) return PTR_ERR(keypam); - for (i = 0; i < joydev->nkey; i++) { + for (i = 0; i < (len / 2) && i < joydev->nkey; i++) { if (keypam[i] > KEY_MAX || keypam[i] < BTN_MISC) { retval = -EINVAL; goto out;