Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp368115rwn; Thu, 8 Sep 2022 02:56:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR6vJA6O/JpEnexjIoc/0Ctw7wxcHpPp/1koAFM6HjIvvUvTPmmxw7BMDDHEvrlCr/TL+13U X-Received: by 2002:a17:906:5a4d:b0:76f:bb35:48f4 with SMTP id my13-20020a1709065a4d00b0076fbb3548f4mr5262024ejc.686.1662631004075; Thu, 08 Sep 2022 02:56:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662631004; cv=none; d=google.com; s=arc-20160816; b=WUp/l5vtdBsZ3Yjp/i0SKXilQO5u20OP1t2pfE4rqtehfgC2pwnXoNEmiLwguGFOXj FStiLe2uG9UMbSKqkCSPv2rBQqQKnQn5lau/ThhWj76GNo6yczzU8hb0KonvhcWIb1iQ clZ+BIATHEYfjAhAdfW82s0/ar2B/pJwJgftmpkktx99DglxEm+wAiKO9WMhyh4iGcFS C4QaoZOPCGP1NAK1dHpV0jgvuXcoJZqoKQcHCg9MSvnFWCeeJ/5iq3KftW7qJvS03WhP NU9luKqfsNAGfUTyVMpY47GCZc8XekDGQp59V7H6z7IQsYSYtpBvujxrxyBKuvW6ZWyI gkMQ== 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; bh=v9/Nd1OQqxzc6+fJnKTYVu73hGlO7hpJzQrpKcFK1yM=; b=f1R7Trel5MPipqguB+QO41zqthDODxrcscgGivXEUFAXdpjSa7RwoajUFX3bSQLO+l eETYDk55rymmLGetb99Opt7mprQ9RynOj6t3v35Ww/uY4iKp4iE5ZvII9bFjKuvJpAWX 7nNBucwMiB+auDEzEzuQF8YdzUZ5ksMAbGwKyiY84GXPo/JQNkWMDCTdmIUBKNTU7dj8 0lyTpL6AmmmWS5zzyYHYAJ5OvqY1d22xb0YNlYuFAtrVbWY6B1+tUeqB5I0hRXi7BDTv QBBbeItsITHyURNzybIwEaELCzZbYWzrbTsK0uDa0kY8AsQMj86bY44fcQJAWIqeeJ34 SaAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n22-20020a1709065e1600b007307fa2da78si1512421eju.450.2022.09.08.02.56.16; Thu, 08 Sep 2022 02:56:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231140AbiIHJnK (ORCPT + 99 others); Thu, 8 Sep 2022 05:43:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229579AbiIHJnJ (ORCPT ); Thu, 8 Sep 2022 05:43:09 -0400 Received: from fornost.hmeau.com (helcar.hmeau.com [216.24.177.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90D8513B10B; Thu, 8 Sep 2022 02:43:08 -0700 (PDT) Received: from gwarestrin.arnor.me.apana.org.au ([192.168.103.7]) by fornost.hmeau.com with smtp (Exim 4.94.2 #2 (Debian)) id 1oWE3j-002Ogk-2M; Thu, 08 Sep 2022 19:42:56 +1000 Received: by gwarestrin.arnor.me.apana.org.au (sSMTP sendmail emulation); Thu, 08 Sep 2022 17:42:54 +0800 Date: Thu, 8 Sep 2022 17:42:54 +0800 From: Herbert Xu To: Dan Carpenter Cc: George Cherian , "David S. Miller" , David Daney , linux-crypto@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH] crypto: cavium - prevent integer overflow loading firmware 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=-1.9 required=5.0 tests=BAYES_00,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-crypto@vger.kernel.org On Thu, Sep 01, 2022 at 06:32:53PM +0300, Dan Carpenter wrote: > > @@ -263,7 +264,13 @@ static int cpt_ucode_load_fw(struct cpt_device *cpt, const u8 *fw, bool is_ae) > ucode = (struct ucode_header *)fw_entry->data; > mcode = &cpt->mcode[cpt->next_mc_idx]; > memcpy(mcode->version, (u8 *)fw_entry->data, CPT_UCODE_VERSION_SZ); > - mcode->code_size = ntohl(ucode->code_length) * 2; > + > + code_length = ntohl(ucode->code_length); > + if (code_length >= INT_MAX / 2) { > + ret = -EINVAL; > + goto fw_release; > + } > + mcode->code_size = code_length; Where did the "* 2" go? BTW, what is the threat model here? If the firmware metadata can't be trusted, shouldn't we be capping the firmware size at a level a lot lower than INT_MAX? Cheers, -- Email: Herbert Xu Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt