Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3023886rwb; Mon, 15 Aug 2022 16:21:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR7ytjOxRCpsIxctxkCmbLUaCEz6B6Rvj4ATY403SeVhqM/ye5BQlOLFTxttiO/hFBnqdYaN X-Received: by 2002:a17:902:e750:b0:170:8891:83be with SMTP id p16-20020a170902e75000b00170889183bemr18897796plf.12.1660605594042; Mon, 15 Aug 2022 16:19:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605594; cv=none; d=google.com; s=arc-20160816; b=jN6tjgyz4LMn8OOF9xeWIotcuwzbvqQR1b/k2GtK15/36NWhMd6BgRplpYjzMOVZIn dqdQxsqdTmXbtAkgLBYu+gndLqlzR3lzik+yG5G/t2EXhfSoLrnwN2ccFiLPL0pP2StJ QEoOeRPBXC8Hf78Zb5wxfyRyuPj1OpEUy9B2zxEVQ8mOV2mugiVkNOWQoftsx0arBvSC E2cwQ2+Hsgqr76ZibW0kA32K6MJjyOqQGTNYnN1l5D2E3SoKV7SfYdRbG9RRHc8nk7ta Lfmdvs+qOAfN3vUCiduwAyxTpk0AzegvNe8OY8R4WfTl6aDlc3RpB9et29IwivzEqFfy W5rQ== 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=RD3ECwoGnPNn9ZBqjGIgrRMPgQsf/gSetikFvsuOt62s8Jw8z/w00d+SgxCemH9EzB oo1k3DUF7pfAUwHKpVqct0UJU5V1mXSVdzKPQU67dNn4BTh98ACr/BorxAKuNHDaZQH+ MH8fyuz4C0PxZoxURXAA0u5uXSYTkWGSwtTWmXGM8+gtqhZJAw+VDkRPQZelYqTM40jy csJsfGdDgWwZ0w04FyJhkbAqYiMb8D/KNzoJcn/uBgZNNmnAmQYQJi+j565E8P1LhQBn k+IKhy4WrxP4LNyl6cksYw1mDqpdDvP1WsjQUEQ2zac5lky3hEE1bAYiQft6p+0OqwaN CWKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JRSem1gt; 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 y18-20020a626412000000b005289521cdccsi11026435pfb.60.2022.08.15.16.19.42; Mon, 15 Aug 2022 16:19:54 -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=JRSem1gt; 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 S1348248AbiHOVac (ORCPT + 99 others); Mon, 15 Aug 2022 17:30:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348246AbiHOV1F (ORCPT ); Mon, 15 Aug 2022 17:27:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3177BE9AB1; Mon, 15 Aug 2022 12:23:04 -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 8132B60BB7; Mon, 15 Aug 2022 19:23:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85430C433D7; Mon, 15 Aug 2022 19:23:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660591383; bh=aZcGBsdZmldfbvVLdPKlPrR+pTlUOeweKXXlUsFE84I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JRSem1gtv+6H32Nq2jUiJNdglRzplsJkUWjDmJVNbCdp1c6oZrXfiUn8JDhcx+lDg 8uicvZGEURyp0wdDUgZqIGDFbbFj7988a0v1zOaWr/FU3Fnh+cWP5KSdnPJGVfcRt0 7K6SRpAhxVB8XXgC54YMeKUBWOy9VhV3twHHw+kA= 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.18 0562/1095] HID: cp2112: prevent a buffer overflow in cp2112_xfer() Date: Mon, 15 Aug 2022 19:59:21 +0200 Message-Id: <20220815180452.823221007@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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