Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp814950rwn; Thu, 15 Sep 2022 06:56:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5JC9V59dGigK1KKgXhCf/EIDpgzpUE2cko1Czw4S00bCWEcEelvPfMM+D00yvXRNoIZxgD X-Received: by 2002:a17:90a:804a:b0:203:3947:1a9e with SMTP id e10-20020a17090a804a00b0020339471a9emr2891125pjw.118.1663250194877; Thu, 15 Sep 2022 06:56:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663250194; cv=none; d=google.com; s=arc-20160816; b=hwafRmMEWz1irzhU3rggg/DoUadkb0g9WS/AwEIlxK3EL/XOgWr77WWxl1PJN/aHhc jJ7Hu4uQw+hCRq/cvH8CbyWiNElMtXqXG0rUwrc3Ry2BadUCO+C19yAUsyK1DLohY2x+ sjdSnU4e3RhlrK5VpAkZBn60qEq/MwBrfKY/TsBZ9cxDOlYsGy8PJKrY8L7TbRJXwkxE KQxyKUMJ85c1EtHLg30wWfijh+HeaJCKkehXdDmh81DohVi7X8rPE1NyXvS9TR7eiExg rsUaoOuBRXiAEvIevHuzeZfFgB9gWd8ZwJTv2DzW2/Vc2qVoUw/s8lBJdUFm6zxkd3kz GIfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=zqEGP9voizV39p55rKhYadFInYKG2R0GjD6pDzlQRiE=; b=kM8/+E5bNorD4jR74e9Ug11huOcYv20DBZyR8XZpvt1wzVeGWrpCHIduQgF6FBhUPQ vbNfCI8hzKwydDdNl/LhX16Ul02x32pME6iN34yVAQHvuTASrXFflNyMMuUr46gjaOrS DyDdRqxXPeuxdv4fiLx8hmgLPAhjVokb1n/x6tYtAYO7tcTWVy3EEN8a2Xcc4Fp0usP/ AAYeUL6rZFRdSo9A0Q/9haaGvZm8Qb7m/k7ms53xpabs2DPtf3MlCkD8uowRtI6RkR6b Sfhrj3F0Zpg2FMwL6oNY5IoPtZO7uVMyKdHZmKAzupws4YWXaSyNJtGOwsj1dAs8AIDY M13g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q0FAK9Bg; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j8-20020a056a00130800b0052eb171b730si18963843pfu.250.2022.09.15.06.56.22; Thu, 15 Sep 2022 06:56:34 -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=@kernel.org header.s=k20201202 header.b=Q0FAK9Bg; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229824AbiIONvc (ORCPT + 99 others); Thu, 15 Sep 2022 09:51:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbiIONva (ORCPT ); Thu, 15 Sep 2022 09:51:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A041197515; Thu, 15 Sep 2022 06:51:29 -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 54BBBB8208C; Thu, 15 Sep 2022 13:51:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6DE9EC433D6; Thu, 15 Sep 2022 13:51:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663249887; bh=1G2tI40qsypf1pzSQWC49MrRmBGWTMcjQ7kM9tFd+lI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Q0FAK9Bg/zxd8zF4v6KjnNWJzsPCsdcn0ETZuoAvSVffXz433DekuenTi4Gl7PTGL jC+XyU7zk2fBd09ezXAnLdL0m5DarsYEskBnC7m/2uDs9/t7Yu8g/F1ct4cK0DrwCC hvabd1Z30moBJaVch+/JDPxJGk303wUXDCF7StQwNJH2/cidSXk+Yl1ipQ05nhr/tH ums6BtTTjhOYkb1yx6SaB4XfFsXUdywaq52L534PXGP5z5D49z4NCNUIpKqhJmLIpV e017y18bjq2xEmIMVUMnPc87Ln832dmvOU7DBhNiTPh6ZdQ0wGW/6f/933P7O+fUu/ N5U6pTRzu8+Ww== Date: Thu, 15 Sep 2022 14:51:21 +0100 From: "Gustavo A. R. Silva" To: Dan Carpenter Cc: Peter Rosin , Wolfram Sang , "Gustavo A. R. Silva" , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH] i2c: mux: harden i2c_mux_alloc() against integer overflows Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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 On Thu, Sep 15, 2022 at 02:30:58PM +0300, Dan Carpenter wrote: > A couple years back we went through the kernel an automatically > converted size calculations to use struct_size() instead. The > struct_size() calculation is protected against integer overflows. > > However it does not make sense to use the result from struct_size() > for additional math operations as that would negate any safeness. Right; there most be a couple more similar cases out there. I'll look for them and fix them. Thanks! > > Fixes: 1f3b69b6b939 ("i2c: mux: Use struct_size() in devm_kzalloc()") > Signed-off-by: Dan Carpenter Reviewed-by: Gustavo A. R. Silva -- Gustavo > --- > drivers/i2c/i2c-mux.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c > index 774507b54b57..313904be5f3b 100644 > --- a/drivers/i2c/i2c-mux.c > +++ b/drivers/i2c/i2c-mux.c > @@ -243,9 +243,10 @@ struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent, > int (*deselect)(struct i2c_mux_core *, u32)) > { > struct i2c_mux_core *muxc; > + size_t mux_size; > > - muxc = devm_kzalloc(dev, struct_size(muxc, adapter, max_adapters) > - + sizeof_priv, GFP_KERNEL); > + mux_size = struct_size(muxc, adapter, max_adapters); > + muxc = devm_kzalloc(dev, size_add(mux_size, sizeof_priv), GFP_KERNEL); > if (!muxc) > return NULL; > if (sizeof_priv) > -- > 2.35.1 >