Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3064428rwb; Mon, 15 Aug 2022 17:14:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR7pMP59XMOse+YOrvWIwT3L7D54I7rsKkrQLi60kmXFntuCASbNsqvQpTKkzSUrhN0uRiYY X-Received: by 2002:a17:907:2672:b0:734:a952:439a with SMTP id ci18-20020a170907267200b00734a952439amr11465238ejc.539.1660608876207; Mon, 15 Aug 2022 17:14:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660608876; cv=none; d=google.com; s=arc-20160816; b=QzpmRn4MU31mszmtHie+t0eAdx3Rx5lcJ9cKE8PhSukKR5EbsJT5x9bC7MGFlN488e DU1kRfkuKz7elZCbxVherEtKzBNElqTutRyTMTrP9IikqRpsyBODh5juQ3pd4xkYUPAE /EsiWFvAx9nPuelmkOEKgMN4z/weBJGPVupvTH0loz7yglNaZztJ3vf592LNirX4Ny4C uHQ9baW0dmsVOVnx8r2xTpyPn94+2udHLIbOm4E1cTiXDv/Sie39q4/dwflbIQLu/+Wh bKfrFiogEFRDrWp+atvoxd+D8ASirfbZQJaCQUHjetpbvACxA2MTHC817uoPQjeXHuCY r10w== 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=ATBcCWvn+IcMOtIIr/xSfZYCQQEgQO74qYrt/jwc8zY=; b=0XN0MBXI4a6BP/ZJRMlkntDbmNcnwgz2t9FvOhS9d7ElDLlZV5x+/7BnHA5utdwSFD 8RZA1Yk9KcWt11P5vzDMworrdNPIbWKmv0ztfEiSFGUq3wHBXMudE4kSk6GLKQlERz9n AX0NwCOm9+YHgnyd1MEnCyPtOAbyD//B8HFDuk/63Lq5DAiVDG2tXwuPM+Vcb8WZDR+t 3Qww5nx4mX8NDFEhSjUBSOAmAD+6ajMpbQF6Y6ZKLKKMdmg88y56DnbFK8FqWtNmmvXK UfxYPSCVOXK2RVxGgi9h2/Sh+Pv8gvLWnvkrDjlTYG1bqXjTVmFeGLdBK0l4m8ZFlGZA C/jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=n6Os2QTF; 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 ji6-20020a170907980600b007317ad1f97bsi10552762ejc.317.2022.08.15.17.14.04; Mon, 15 Aug 2022 17:14:36 -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=n6Os2QTF; 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 S1352186AbiHPAIz (ORCPT + 99 others); Mon, 15 Aug 2022 20:08:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352715AbiHPAA1 (ORCPT ); Mon, 15 Aug 2022 20:00:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89D2C61DB0; Mon, 15 Aug 2022 13:21:44 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 1355F61057; Mon, 15 Aug 2022 20:21:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC819C433D7; Mon, 15 Aug 2022 20:21:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594903; bh=aZcGBsdZmldfbvVLdPKlPrR+pTlUOeweKXXlUsFE84I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n6Os2QTFk/SQWFta9qr4KfT0RQhmPpov+6q1xZ/78hX+cdqpRZ2xrmgpZVPiPj5XZ ESPFTQYmNxfG9eFPWicX2+bp3FFmcO7qIBYf7OHVEm6eAhv6nIg46aO27TL1mbtB2v zbtq6wFCmlhD6pwU3PgaS/s9f+OAOL4rmaVA+PgE= 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.19 0596/1157] HID: cp2112: prevent a buffer overflow in cp2112_xfer() Date: Mon, 15 Aug 2022 19:59:12 +0200 Message-Id: <20220815180503.499512051@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@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 ece147d1a278..1e16b0fa310d 100644 --- a/drivers/hid/hid-cp2112.c +++ b/drivers/hid/hid-cp2112.c @@ -790,6 +790,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