Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2885232rwb; Mon, 15 Aug 2022 13:17:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR5ty2T0lOgCfAbe+D8Zb7vNZ0JAPNZI/nkdLyLWd7OF67lTWCcidqpejLfp6CwyBtpZtMec X-Received: by 2002:a05:6402:11cf:b0:43d:fc84:c51a with SMTP id j15-20020a05640211cf00b0043dfc84c51amr15426725edw.80.1660594670123; Mon, 15 Aug 2022 13:17:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660594670; cv=none; d=google.com; s=arc-20160816; b=KnxFrf16OLuqgNftuG1KLl6DY4hOGNHjan7Y9kQcbPTyESYj1AYtHysfTqy0BrYXwz aRNPinUFuq3gay2BHrhHd1De4o3JXNZA006YwWQuUqEoTkrYTXH6skiX5TUmRpJUd9nR 3e3axmxTfpTUpkdpcoTfeo34CaFAUcx/G6TD0eM5mABTPhGMK4UWGFWQMxQCi0UA1iHK OtYsYssY8/meAuO+GJS4o6DH3WEjTEOwOGb8DapxdZhCS+J5KUDKy6orW7ZKw5Y4qGLv qMkahhFFh0GaLHx8x7CoQl1Xviw3Mma6/6A9tlZ29i+V44GGeaEQX78KT8AaB39enUP0 LMvA== 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=UT7zJvWXHgvvhhbPLkQkU68hs3jYb5EBGE4CF30InjGPWaAMSYEYHm9wSW69/MlEMw 4vSSaMQiZKYPMazPP7MJHeXW8edj4HtHBWbuKyLEO12Mq5rGF5nK2ag2QkuFdukY2EwU d6NSvK3zCcnasXC028fH9An66Q2UY7/LveaBP/4NuKx+8kc6gr2cJZps6EOoCiRnxvK+ m/NjT14rcueQsFdXziBpU/z9B500wztvv24THrKx85k/Fg6U8QQd0uHDjtb1m/Tbv87u PYCPzbIFBqmvpzmUHPjJqIaamfMLQOdvf/NJ7UupirUeqxDjm6CdsHT3tGJa3Hyy+6E3 xWqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dXS6ic29; 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 r8-20020a05640251c800b0043c45284ef9si9742242edd.562.2022.08.15.13.17.22; Mon, 15 Aug 2022 13:17:50 -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=dXS6ic29; 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 S244409AbiHOTX1 (ORCPT + 99 others); Mon, 15 Aug 2022 15:23:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344259AbiHOTUs (ORCPT ); Mon, 15 Aug 2022 15:20:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C169E59272; Mon, 15 Aug 2022 11:40:05 -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 6D40D611C0; Mon, 15 Aug 2022 18:40:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 55B6AC433C1; Mon, 15 Aug 2022 18:40:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660588803; bh=AcJrX1xUykEM0PUZFgTpse9dGF07x7CuOQftmr59ePw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dXS6ic29dQJ7WOsGdnlgqqaxbXrhr107upUiwAYAWyV92ryyzFE6+SvzXf6YUcvdY GGbypMxF6ITL0KKAqTktFFGo6wBExa6kxPRpcqcH1BITXMzonG9xf6Wps8tdjuKT48 O0sOR61UtmasABEkw5FDgdHnl7bmx5qLVhnTsoIQ= 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 518/779] HID: mcp2221: prevent a buffer overflow in mcp_smbus_write() Date: Mon, 15 Aug 2022 20:02:42 +0200 Message-Id: <20220815180359.400204781@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 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