Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1863677rwb; Fri, 19 Aug 2022 10:38:38 -0700 (PDT) X-Google-Smtp-Source: AA6agR4Q1gOFjYuR1nFg+zRud2ZSTGY1xl/tmLy8OYSeII2Mu6d8p6j5cmN3Pmp4OWpRnqXVVeFR X-Received: by 2002:a63:68c1:0:b0:421:a023:f830 with SMTP id d184-20020a6368c1000000b00421a023f830mr7094410pgc.15.1660930718403; Fri, 19 Aug 2022 10:38:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930718; cv=none; d=google.com; s=arc-20160816; b=m7Ft2FZhRAo97lXyxioF2+NzIpT4dERsIdhj46Lk3nocL4nszCXdscYZ1AKTLtRiXo 3+tl/lCSWB6JFlUpa0GRvkrWH1IXeFytHOFzCZGjKbsHfdUx23P76UtrQ/svHplCHtJZ na88yeO8hAQyiFGMe8/o5zHFspvKeMyrS2gfAujIbDjPO+ovuM2IxRz49ZHyT8oQ6Tm5 JHImSpLxAbxuQrIsbcRfjliG/dBLMGMrlV9gCrAiZDGH0p4NlQAH0sWM/UoPGevxI4xn dIHp2txPgZrbYDKHOZpg0NQpoCQ7r9f/6mweHpYoU3U/C0BG/6Oa2TDvcX/92fwNTg97 0ijg== 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=aBq0ky4ofxSlLSVt0GEJLr5aE8axRUC4bZAg09OtnHQ=; b=f06LjfB7uPaM3HxDai+YwqY7jNAygAGqwL9ckJPOsKDadeFj2pxfKf2IYQdNle0qla 42oF9YEK7D+XE+KLYgjENgwsyMIzrJSyUN/+FPp1/SPbGjLnF7+qDkskTeD76oHLwqIu 9FamKR9mZnzG9A0kNiYiZZSNZTrRdbOvUpZC8Fxf6B+GfZO82fDNmjQIKFFuNqRlNwYG ZBBfuHWq1B7S2bw5u6rGtmtwir7o39QzDNULSRIV1+IfnCJ0R+PTFw5DH4w5ScqKCPx0 RLZmNkd8ooPh+5MEEYBgcdp7IhC+REprnfKFuhXfOcBAA2qPNYqLuijTf07S2uj7I7j3 ASbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=mBRCC2se; 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 n4-20020a654884000000b0041d17e08467si4561830pgs.381.2022.08.19.10.38.26; Fri, 19 Aug 2022 10:38:38 -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=mBRCC2se; 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 S1352742AbiHSQ1O (ORCPT + 99 others); Fri, 19 Aug 2022 12:27:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352555AbiHSQXT (ORCPT ); Fri, 19 Aug 2022 12:23:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C8BBCD539; Fri, 19 Aug 2022 09:02:57 -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 B69C1B82819; Fri, 19 Aug 2022 16:02:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D5DFC433D6; Fri, 19 Aug 2022 16:02:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660924974; bh=AcJrX1xUykEM0PUZFgTpse9dGF07x7CuOQftmr59ePw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mBRCC2semryP2zuKSI0n7yxj0xrALrlQedcR2g6QwxHGG5kXQgbvwUUN4ckoqGfAJ Z4zOwHePnaoYx8K8Yi9h6hXzr1hwdywXOMuYEbGcCHWqMR7rLzXrbP3+MtyNGvV3a6 drhzfA38VqYU8DSuojY0G1aHsBqcipv5LcYhATJ4= 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.10 341/545] HID: mcp2221: prevent a buffer overflow in mcp_smbus_write() Date: Fri, 19 Aug 2022 17:41:51 +0200 Message-Id: <20220819153844.658940181@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@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 62ac2473553a00229e67bdf3cb023b62cf7f5a9a ] Smatch Warning: drivers/hid/hid-mcp2221.c:388 mcp_smbus_write() error: __memcpy() '&mcp->txbuf[5]' too small (59 vs 255) drivers/hid/hid-mcp2221.c:388 mcp_smbus_write() error: __memcpy() 'buf' too small (34 vs 255) The 'len' variable can take a value between 0-255 as it can come from data->block[0] and it is user data. So add an bound check to prevent a buffer overflow in memcpy(). Fixes: 67a95c21463d ("HID: mcp2221: add usb to i2c-smbus host bridge") Signed-off-by: Harshit Mogalapalli Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/hid-mcp2221.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/hid/hid-mcp2221.c b/drivers/hid/hid-mcp2221.c index 4211b9839209..de52e9f7bb8c 100644 --- a/drivers/hid/hid-mcp2221.c +++ b/drivers/hid/hid-mcp2221.c @@ -385,6 +385,9 @@ static int mcp_smbus_write(struct mcp2221 *mcp, u16 addr, data_len = 7; break; default: + if (len > I2C_SMBUS_BLOCK_MAX) + return -EINVAL; + memcpy(&mcp->txbuf[5], buf, len); data_len = len + 5; } -- 2.35.1