Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D716C6FD1C for ; Tue, 14 Mar 2023 15:58:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231307AbjCNP6P (ORCPT ); Tue, 14 Mar 2023 11:58:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230176AbjCNP6M (ORCPT ); Tue, 14 Mar 2023 11:58:12 -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 777D17FD47; Tue, 14 Mar 2023 08:58:09 -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 ED00F61812; Tue, 14 Mar 2023 15:58:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BD7DC433D2; Tue, 14 Mar 2023 15:58:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678809488; bh=BgMk4i31f2UPRQv6nUIFJd7c91enlTxExm1X254lxPc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AKyt1qoJTB4gsbjLZHxEDHowQQtn436EZrP2hV50t/0NiSHeZUsNOHTtPT58FoLCg uYmZxD99oz2/I+Uu6Jveue1B+vDhrS89M+g73W6skf926NhAZGfMU/Uze6f6kH7JlU IEK7W2XKqiImCcJui4fw/phleUqYfxvMYqumhlx27uc1WkvY/xdV1ppTrCUT3T2Cft JJ4/I6FoFJBW4OwRzVFBjaWdgKFHLc5k1Y1SqpGPZNVEW3kR7UM89zYrXNYmvmKOAj i8EUsx7Ncvd+ChjA6L3xzRRoT0aqytkAZM0M7UIgzi8gGlrV1/jzXVV4gRNWew6PWL GqXuih9vP9rpA== Date: Tue, 14 Mar 2023 16:57:59 +0100 From: Andi Shyti To: Wei Chen Cc: Andi Shyti , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] i2c: xgene-slimpro: Fix out-of-bounds bug in xgene_slimpro_i2c_xfer() Message-ID: <20230314155759.ej2gax7r4ek7itmh@intel.intel> References: <20230314135734.2792944-1-harperchen1110@gmail.com> <20230314141036.lnwvpputzfcyeiyz@intel.intel> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Wei, On Tue, Mar 14, 2023 at 11:43:41PM +0800, Wei Chen wrote: > The data->block[0] variable comes from user and is a number between > 0-255. Without a 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. > > Signed-off-by: Wei Chen I forgot to check earlier, can you also add: Fixes: f6505fbabc42 ("i2c: add SLIMpro I2C device driver on APM X-Gene platform") Cc: stable@vger.kernel.org > --- > Changes in v2: > - Put length check inside slimpro_i2c_blkwr > > drivers/i2c/busses/i2c-xgene-slimpro.c | 3 +++ > 1 file changed, 3 insertions(+) > > 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; > + There is something odd looking here. Can you please fix the formatting and leave one blank line from the variable declaration and the 'if (...'. Remember, please, to run checkpatch.pl before sending the patch. Andi