Message ID | 20230314160416.2813398-1-harperchen1110@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1859001wrd; Tue, 14 Mar 2023 09:34:07 -0700 (PDT) X-Google-Smtp-Source: AK7set/ypq6pnb63HsEQPzBKI4GrOfbrRP97TZPNyE0C1OgnQnGskONNyQNGPtHIGRCWHbfD1eWW X-Received: by 2002:a05:6a20:7da3:b0:be:e0c3:5012 with SMTP id v35-20020a056a207da300b000bee0c35012mr15094675pzj.1.1678811646892; Tue, 14 Mar 2023 09:34:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678811646; cv=none; d=google.com; s=arc-20160816; b=CqTqcbUYiZSw4zFZosVS1uXkwUdGGghZJuyVGNr7RDDlmT4nT5hpsEw3+a7wv8p7qn +qz+BUgEZp08ilf3FEr3bDvl4pVOaN1EqCw6Cze5NHpnHNrom3gmMQg02kSTEveLzUmY 5/8umEfvDq0E5Yr//35BptV5m+3yjOQrm9yVan8fGIQKyJOkVQCPJZ7A7lZu7tjTIfcz zqdIHFG66zU/fBMnzE8gHy9OtavSmbW+5tx8LkC+aOpQjqIYWe5qvXA574dzzXXIM3bH 1n1+sKHUwgdcBnA7QlEObc/WNkD4wPe7fH0l2ojUHLads8ExOpuWTYb8d+tPNPds8mRa GZow== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=0V1xObPOu1sKOo+zU+U91XCBQL6wMo8D/re2Ep+Sd8c=; b=JAqR7QRHo0x53M3oPVrzudQTM5O3Dnal/sjegeIM14u5JFFehb9ibn2yWBVq+5Vyww HJLXeByoXLG89hm3I4CqlP4C1qFi7EUM9ftjsmD4DEoJsld5RgXTgrYlPSoYzHzLjtiu q7O4OTUq98lGMlh5QOu+SWkYc1LOoP0PpnoKNjbKtysF0cHnF8fydz2Vzb1aNZ2yr+gF JIXliR2jrCh1pBhHcV1NdYJDu1/DwgOYWpAtyQhQSN/LjQi0vc7nKGdWakDdtmA/ak4h pxEwptSApPyaKD7OaYc5b8rbDym6TnzjcWuuugNIsuNYrg0AXB1hcRwCEuUsGyTPBL2z 5x8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Nd1h0JZp; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a71-20020a63904a000000b0050768ccbf4csi2514937pge.699.2023.03.14.09.33.51; Tue, 14 Mar 2023 09:34:06 -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=@gmail.com header.s=20210112 header.b=Nd1h0JZp; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229920AbjCNQE5 (ORCPT <rfc822;realc9580@gmail.com> + 99 others); Tue, 14 Mar 2023 12:04:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230297AbjCNQEj (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 14 Mar 2023 12:04:39 -0400 Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D4D853290; Tue, 14 Mar 2023 09:04:29 -0700 (PDT) Received: by mail-ot1-x332.google.com with SMTP id p13-20020a9d744d000000b0069438f0db7eso8678579otk.3; Tue, 14 Mar 2023 09:04:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678809868; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=0V1xObPOu1sKOo+zU+U91XCBQL6wMo8D/re2Ep+Sd8c=; b=Nd1h0JZpPla3jCeVZ1zmfgs/A5lsBso9dx3o9uaMBnU7ovfuVL4Btpd4Jjb9KTw5yJ aiyrdBxue+cetazW9tJbrvTYC1pCiPbT1wnAfD9bagmSmWtwXCEFiIUEJ97LkjQ6HUA8 U3Z9z8cRe7Dh48GsbaEDxvFmJh9RtsbLLjl0bRxi5jgC6I0nlU4ArWhzEmPNpJc5AUb4 g0g4OvOY63wcQRomcoYP/ttsMIEREcU3jQCqu4mjIwuCF9CQp8+Wt/Fu+91KrV717RkQ h/hmzJ7hinywYxt1QICr9++nEECZ/N19KxG18Hsu7/q1E1zZodX5OWMAv3fO+BPOQ+oL FInw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678809868; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0V1xObPOu1sKOo+zU+U91XCBQL6wMo8D/re2Ep+Sd8c=; b=NtvMVuTnJk84kUL0ByRs2rFJuBqQIwaWcBZtzPPljs859pFxwTyU8zRCMwDigLfBE1 gJnFCM21ts+/jltPxK8L5HpEy9cwBBJVxw4kRzU287P+/GtWc5RQKaRhsyD6oPqxqkFp 8AZqQFcGFzNSedD25YB6o3eWd9lQ5NPjTJopRW3jiOY8BGoCd8+05TxaS+gTVNjoRj5u fS32s2GKPBFiM0VWMKJsl/LpM635xiHFFwVeYq76qB8/0kI8q0KQUqjPFWGnQcpeRaNR F95bnH/1Y78j9DxbpvLrQJZ9bqCJByS+XN59NwAtGO8A+ZwerPFtjB4v9BgscbYU4Vbp /UhA== X-Gm-Message-State: AO0yUKVtWQGcTQrAO5v3gjRpCwObJdzZxwMv9EMwyWNEWeTN+K4oeMl5 1cVWcPwApiS8QPotUATDTu4= X-Received: by 2002:a05:6830:6504:b0:699:221e:b07d with SMTP id cm4-20020a056830650400b00699221eb07dmr347642otb.11.1678809868351; Tue, 14 Mar 2023 09:04:28 -0700 (PDT) Received: from chcpu13.cse.ust.hk (191host119.mobilenet.cse.ust.hk. [143.89.191.119]) by smtp.gmail.com with ESMTPSA id q5-20020a4a3005000000b0051a6cb524b6sm1194392oof.2.2023.03.14.09.04.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 09:04:28 -0700 (PDT) From: Wei Chen <harperchen1110@gmail.com> To: andi.shyti@kernel.org Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Wei Chen <harperchen1110@gmail.com> Subject: [PATCH v3] i2c: xgene-slimpro: Fix out-of-bounds bug in xgene_slimpro_i2c_xfer() Date: Tue, 14 Mar 2023 16:04:16 +0000 Message-Id: <20230314160416.2813398-1-harperchen1110@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760361601133247788?= X-GMAIL-MSGID: =?utf-8?q?1760361601133247788?= |
Series |
[v3] i2c: xgene-slimpro: Fix out-of-bounds bug in xgene_slimpro_i2c_xfer()
|
|
Commit Message
Wei Chen
March 14, 2023, 4:04 p.m. UTC
The data->block[0] variable comes from user and is a number between
0-255. Without proper check, the variable may be very large to cause
an out-of-bounds when performing memcpy in slimpro_i2c_blkwr.
Fix this bug by checking the value of writelen.
Fixes: f6505fbabc42 ("i2c: add SLIMpro I2C device driver on APM X-Gene platform")
Signed-off-by: Wei Chen <harperchen1110@gmail.com>
---
Changes in v2:
- Put length check inside slimpro_i2c_blkwr
Changes in v3:
- Correct the format of patch
drivers/i2c/busses/i2c-xgene-slimpro.c | 3 +++
1 file changed, 3 insertions(+)
Comments
Hi Wei, On Tue, Mar 14, 2023 at 04:04:16PM +0000, Wei Chen wrote: > The data->block[0] variable comes from user and is a number between > 0-255. Without proper check, the variable may be very large to cause > an out-of-bounds when performing memcpy in slimpro_i2c_blkwr. > > Fix this bug by checking the value of writelen. > > Fixes: f6505fbabc42 ("i2c: add SLIMpro I2C device driver on APM X-Gene platform") > Signed-off-by: Wei Chen <harperchen1110@gmail.com> Reviewed-by: Andi Shyti <andi.shyti@kernel.org> Thanks, Andi PS Remember the Cc: tag
diff --git a/drivers/i2c/busses/i2c-xgene-slimpro.c b/drivers/i2c/busses/i2c-xgene-slimpro.c index bc9a3e7e0c96..0f7263e2276a 100644 --- a/drivers/i2c/busses/i2c-xgene-slimpro.c +++ b/drivers/i2c/busses/i2c-xgene-slimpro.c @@ -308,6 +308,9 @@ static int slimpro_i2c_blkwr(struct slimpro_i2c_dev *ctx, u32 chip, u32 msg[3]; int rc; + if (writelen > I2C_SMBUS_BLOCK_MAX) + return -EINVAL; + memcpy(ctx->dma_buffer, data, writelen); paddr = dma_map_single(ctx->dev, ctx->dma_buffer, writelen, DMA_TO_DEVICE);