Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3257573rwb; Mon, 15 Aug 2022 22:30:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR79l1LR2VrHrcsimfx56EL2IgHcw1vrdbNLZDabYPJUQ+CdmXj/XkjWEoEdTxQoBZafqAjF X-Received: by 2002:a17:90b:358a:b0:1f4:e5b8:8f10 with SMTP id mm10-20020a17090b358a00b001f4e5b88f10mr21923778pjb.236.1660627829726; Mon, 15 Aug 2022 22:30:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660627829; cv=none; d=google.com; s=arc-20160816; b=g2JbBvxvupT8EDnBqKgrdbAv4GwAg+JGHxE62ejPcE3PY7maQfAW2QzSRIFQ1ixNbq 3HFPfjnhTGdjqVq9kXCm4t2Mj0Lc30UA8JbM8k/4XvmW72GdOCjTQ1+rwulB6kJnlMb7 fdFcS2GDFkxAKiABgnhJ9dVpmSr1iYQz1Ppjnt7nShRNhLLtsEs6YtowITLDcbvQR7nH VMy08pgRg0sdO9TSWJPFLVGpIFv9zBdCxQvicsLjgUFEpRhnDqKeiNwWiusqMjcrTApv FMJGnWcJk1WXUSUMAnq5mIPK67xJk475RWFV0BhxkXYT4N3Wz41JWK6EzSYA8rukt7VX Uk5w== 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=L2qsmYKwiP3vtBDC2MVrQfLAxPM2z0s7+miYFxLbmtvGvFGyo8PHZo6IrWiNQjs4cr kMWFF4hZ6gpgfFm9R/iox9VQ1TA0/zSPOLZpRqtX/U33BZodw7Vq1Ulx7ltiSgPQb1xU xxnqFWErr0WxdpQWeMSA5LvtZ2ooixytH1LqAk0qmxGB/6mj0o6ZMtdDjI9kOcjbUD7A 1dY3EMMV07NuYE6IWrezN2zfkxCpezUs/KICrOynaEHTmipktejubDWT8x6LyNQuW04+ RAUmtHmcjtdwNMjJEJA+lpQSmw3Aa9HKuixyexfZ8ApEO5fdJwlcXg4jImG24MXdsH5g 4Z9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HnzbR1uc; 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 h10-20020a63530a000000b0042814932da7si6702037pgb.403.2022.08.15.22.30.16; Mon, 15 Aug 2022 22:30:29 -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=HnzbR1uc; 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 S232335AbiHPEpP (ORCPT + 99 others); Tue, 16 Aug 2022 00:45:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232798AbiHPElj (ORCPT ); Tue, 16 Aug 2022 00:41:39 -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 2781517ED60; Mon, 15 Aug 2022 13:34:25 -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 DFEC960EE9; Mon, 15 Aug 2022 20:34:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE559C433C1; Mon, 15 Aug 2022 20:34:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660595663; bh=AcJrX1xUykEM0PUZFgTpse9dGF07x7CuOQftmr59ePw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HnzbR1uczoLughH+2LCILbxULfC6nHivQqaoOtVr58xOEiivlyfHFO2eBBM4bk6Bh tfFS4DECRAnLazM4sX4+f9UbtGFNcnK21gEUt2xHR+FW3DF+hFaNjjo44/5gsQ563V b/TRqs7wZt4/VtXjk2jEYcJJoQlPapHp7YQb2WAo= 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 0836/1157] HID: mcp2221: prevent a buffer overflow in mcp_smbus_write() Date: Mon, 15 Aug 2022 20:03:12 +0200 Message-Id: <20220815180512.938203773@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 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