Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3414938rwa; Tue, 23 Aug 2022 04:31:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR4FkRbafoWLf8X0F58tTDn560y6tNVZ3PsA6UFTX9V2fZd9K8C4s+YW4YD7CpvfkG4OVwOP X-Received: by 2002:a05:6a02:115:b0:41c:4d5f:876 with SMTP id bg21-20020a056a02011500b0041c4d5f0876mr20798236pgb.419.1661254146880; Tue, 23 Aug 2022 04:29:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254146; cv=none; d=google.com; s=arc-20160816; b=hMDN6Msen6exm83Kakpg9gB6jEO/OYo0Rj/MKqUFT63JlWMi+/jwTn1Vwlk5E06eMx AcEvd3KpY5+mrCtv5k/51T/vftfBM0bXpkoylZNuTV7cLV005NuBI/Ty2U0B/CX8jSxF uQT4bhjDJvq2TD7Wq7+F9x+rgTINvMmy5J6md49GJED6+jT4vYMDND2B131+UExnKw+J I5tqaxkwjTsz0EV+1N/nQF2GM9dHr+I8rREsCxJgOVhbTFj+KY0tYggLzEGePBGsQnvA k+vEigY7D7rj26HrlkQIM/jqOpatVl/BnkhUIzZD68v1M5KpEybwxlbxRuBJvTcIumE/ IvPQ== 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=/QMbiICwQFGW5w4OZLqN4RDCQJbba0Mn5R4pwgTXqlc=; b=NkiemtxmnvqyF25pD+pMjBoSyhxCSZq4uRWUCNkJzc4Iqya45hhU7SV6fsPPkdFbwt vR9BIY4kkJ7j5QBRT513kNgaHJcJDlpEcwZKO44raNuKjzu9fVSBbbMOd0gJ4iYtrroG 2hVoCqamkyDIAdo3rriGuvpF21/gRbtTTNimdFnRVFFb7PI9kCrTr+X72DrvwRkqb2h4 7OP5IB6egd96LXjKTnaQz0f1yuPQlPrxUyFubIK/Uvb8wLmvhoONU3Lv2cyUnRH5Gzsa 5bVRAcOCQzJmZT4luWQe9zSCJ+XUP/7VzPufuO7sDQKOqmveMZPKjpaODoIYGrovOmz6 cidg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="R/GaJmr3"; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u6-20020a17090341c600b00158643c240asi5584164ple.87.2022.08.23.04.28.55; Tue, 23 Aug 2022 04:29:06 -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=@linuxfoundation.org header.s=korg header.b="R/GaJmr3"; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356202AbiHWKlk (ORCPT + 99 others); Tue, 23 Aug 2022 06:41:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354273AbiHWK1c (ORCPT ); Tue, 23 Aug 2022 06:27:32 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66A7B84ED3; Tue, 23 Aug 2022 02:06:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1C6DFB81C86; Tue, 23 Aug 2022 09:05:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7673BC43148; Tue, 23 Aug 2022 09:05:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245557; bh=ZWz5xNRGqs4DFUsiTNXMxvF7ZS3YmBi3o4+3EdUiwWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R/GaJmr3oa9em2R1XO6AiqjF/nnjPK+u/yoTLODznWYpVkq/gM273BnB9Jz9zmwKi JiMWxqtK1XtBSUBN+PPWfAOCoUvK9p5PcPiCttKodudtN675uvpp3UVZNH6IErXMiD GBFJIMbk3l3pR95Ct4jBrovpSfPhFFpeZMscC+jk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Harshit Mogalapalli , Jiri Kosina , Sasha Levin Subject: [PATCH 4.19 116/287] HID: cp2112: prevent a buffer overflow in cp2112_xfer() Date: Tue, 23 Aug 2022 10:24:45 +0200 Message-Id: <20220823080104.297228396@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Harshit Mogalapalli [ Upstream commit 381583845d19cb4bd21c8193449385f3fefa9caf ] Smatch warnings: drivers/hid/hid-cp2112.c:793 cp2112_xfer() error: __memcpy() 'data->block[1]' too small (33 vs 255) drivers/hid/hid-cp2112.c:793 cp2112_xfer() error: __memcpy() 'buf' too small (64 vs 255) The 'read_length' variable is provided by 'data->block[0]' which comes from user and it(read_length) can take a value between 0-255. Add an upper bound to 'read_length' variable to prevent a buffer overflow in memcpy(). Fixes: 542134c0375b ("HID: cp2112: Fix I2C_BLOCK_DATA transactions") Signed-off-by: Harshit Mogalapalli Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/hid-cp2112.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/hid/hid-cp2112.c b/drivers/hid/hid-cp2112.c index 6f65f5257236..637a7ce281c6 100644 --- a/drivers/hid/hid-cp2112.c +++ b/drivers/hid/hid-cp2112.c @@ -794,6 +794,11 @@ static int cp2112_xfer(struct i2c_adapter *adap, u16 addr, data->word = le16_to_cpup((__le16 *)buf); break; case I2C_SMBUS_I2C_BLOCK_DATA: + if (read_length > I2C_SMBUS_BLOCK_MAX) { + ret = -EINVAL; + goto power_normal; + } + memcpy(data->block + 1, buf, read_length); break; case I2C_SMBUS_BLOCK_DATA: -- 2.35.1