Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2886619rwb; Mon, 15 Aug 2022 13:19:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR497Pn/cl/WI88reBKG7N1rFaYFqUGzPAKcdY1H/qP6CZ+wfrONVLcKyGUon6bA8ZQxQUXC X-Received: by 2002:aa7:dc17:0:b0:441:e5fc:7f91 with SMTP id b23-20020aa7dc17000000b00441e5fc7f91mr15753674edu.301.1660594671051; Mon, 15 Aug 2022 13:17:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660594671; cv=none; d=google.com; s=arc-20160816; b=Eol0Iixb9uB5Sz49NM6ImSkLcANyi/D/QQL/GDxbT7McXB4xVh/kbAkLLdTxlg62Zv j3Z2hyxbHWNSLZGYauNR+YzBqfHloZSTR7cbWoBpTT1BwPTbsfVJpSx4QW1KxddSKMU4 4mc2iRottWKDADS2zS0Q3DNC0+iV9ihoal7M+Bn+Px+I3aJCjRjz8OpdW35UyEGCg7Ys xs/oC+AtqZKPQlfmOZO9t8HEC1GZWnRUMbwI5p3JWG9xin60bCIQ60C+tFC2mkXhueTR xe7j8e6KjE9bdc6DMBcMho2Mx8af33Gy9aP78zh/QTMs4ItJwjDolX5SCIZcKG+pbKAQ wQVA== 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=EDP0etLqbRtV99m2ifRuv/sVFP2Tvxr+dzDMU23KV/E=; b=aUOfWHN6mj23w/m+zsV7Dnm/5RMo6aG0O24DIB7HVgr2FSqtRlfoi8+XrBVo+aYq/t qqBFh/KiShcSuBlyzuVO5F1wl02BL0dl7dveJexQbug/zhtgagncssOzdN7KpqSFqFNW Ua6Td4m8QQh6c3pzot1VuY0Dkip54d0te14NzLCOJseZc9uOdslzWWSaA2mbd85/7D7Q ZUc+4NUAKdq+O/SNXD/2hLlq7NnT3McGS0NzVxt/JRv5Qn1osIXPDFzedishv7k0dKMf VHNVVo0MOBt4vyMEXGgbhbMSjUj59hyvlGEG765L9wOxOuabY5f4YxSgGyvHH5+X+hns 9GPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DqrLD14r; 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 q15-20020a50aa8f000000b0043c58974afdsi7547673edc.491.2022.08.15.13.17.22; Mon, 15 Aug 2022 13:17:51 -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=DqrLD14r; 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 S239886AbiHOTII (ORCPT + 99 others); Mon, 15 Aug 2022 15:08:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240625AbiHOTEQ (ORCPT ); Mon, 15 Aug 2022 15:04:16 -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 3BFEC4E60E; Mon, 15 Aug 2022 11:34:11 -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 783E0B8105D; Mon, 15 Aug 2022 18:34:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0E45C433D7; Mon, 15 Aug 2022 18:34:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588448; bh=ZWJtKv6jVkqiridAY8cXFrzdiuW3E35fs+WyaR0mDGI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DqrLD14r6WVJ7VaaPADkEpcqWJB82LCj3NBk0vvOx9DBCnK0rrcMYtnEHDkW0cqOO x6e3ZmUtuNMK+OwBV34PX6UnFzgw2zHbEaxTySfUEL7QHk2jtP55FCdKSKUQfQ0mbG 2DGL0/pqSBP5EmA4uo6ECklywAeiNMgf/VJRg+qs= 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 5.15 407/779] HID: cp2112: prevent a buffer overflow in cp2112_xfer() Date: Mon, 15 Aug 2022 20:00:51 +0200 Message-Id: <20220815180354.689728618@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@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 477baa30889c..172f20e88c6c 100644 --- a/drivers/hid/hid-cp2112.c +++ b/drivers/hid/hid-cp2112.c @@ -788,6 +788,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