From patchwork Mon Oct 24 11:31:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9202 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp458908wru; Mon, 24 Oct 2022 06:38:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5vlf85FHtYKtvxE57YdHhz9hzXTT87vjEHQDyw9gt+LyCPCQe7brABFdkddwyb2OLQlM/d X-Received: by 2002:a17:906:8a6a:b0:79e:2efe:e0 with SMTP id hy10-20020a1709068a6a00b0079e2efe00e0mr12739979ejc.401.1666618699806; Mon, 24 Oct 2022 06:38:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618699; cv=none; d=google.com; s=arc-20160816; b=h5jiELPx4hbF/8EyQptZdZxwvvRsakdguO2QewgebzurlENKCBTVIcebhHVWGNLWIq 05BTM4d9Z9+ZZgAqa2Fvkh0wwmnKl0GLx3vkpHMTjnm/n0fgxnzhDScc6vNVDTLSQUZ/ UjqNHTKcQlvvbfi9HqK4raRmd6eLWRNwDVg93t4lRi0kTVyTVB0lGsmaVF8P+vskfWhw ks2F2mEMOA7kVHx7uhmwa1hf56xtpSdBnikzrJTxvHXjis+xKZrIWP9OnhbHn4iCr2dO nud4aGcqBGyuxfdSPhvhH+3qmn10mh9mJIVjfwj+RbXSMKL9dC/Tp246MyyvEPQsTqM4 JJtA== 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=DezC5LGKrTDiOt0yXtY3YAJjtyteT3YP8A2HwWPs8qU=; b=Jm/634WhS8X5HUE/+YauNeOoNTJeaj5UJGjagmrohmnay3Srpu1m8CG0Tl1gqa/8mf d+/03utjbcua9WeAhCEOWOgXp8KmUgFWQJRyAR023cHBpuyNm2WLSUqpDX2KFzuOU8TI 2rlRl2V8K7/b0QlYLQSQdqXHOnjIBMmchf1pb/F29BytOTXPSNHXC3HV5JwLKEEkFXjN b1F7kou8SccZt8quezpXvUJoMB/GVQn64QlYe4oUEA2HYtrgSpasLp1Q7UfHqtJDn8XD 93jmlf4sakXMZMDYFNA8gyfO5lNzTauUiLZE+k2G4t9X7y3+fYujhs3pRzFkYeUQklen kZWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=oLKWArC4; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xg11-20020a170907320b00b0073d92f673f8si26760905ejb.937.2022.10.24.06.37.35; Mon, 24 Oct 2022 06:38:19 -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=oLKWArC4; 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 S233384AbiJXN1T (ORCPT + 99 others); Mon, 24 Oct 2022 09:27:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236150AbiJXNYd (ORCPT ); Mon, 24 Oct 2022 09:24:33 -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 2FA5CA8CF0; Mon, 24 Oct 2022 05:30:56 -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 14FBF61280; Mon, 24 Oct 2022 12:29:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27905C433D7; Mon, 24 Oct 2022 12:29:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614586; bh=afOYIS3FPYL4NSLiTIHXXLe3RlmHLDq9fyBIsk/Z1Ew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oLKWArC45giydtcq55y2AZkKEauX45CeRxRvwWKJSOvc4ti9lx8KHg/9LoLPRG47B W5SiHToO+Vk1IRKYbUWMb/Mw6EROuL3lwxwhkFp2JVKRRR0uasAIrtoy9kBDOu4HA+ wUZyRctj0VNGsKQJTDKm9LhBkX5y7rVGi1bpJkuc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Herbert Xu , Sasha Levin Subject: [PATCH 5.10 288/390] crypto: cavium - prevent integer overflow loading firmware Date: Mon, 24 Oct 2022 13:31:25 +0200 Message-Id: <20221024113035.229417744@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747576369987292263?= X-GMAIL-MSGID: =?utf-8?q?1747576369987292263?= From: Dan Carpenter [ Upstream commit 2526d6bf27d15054bb0778b2f7bc6625fd934905 ] The "code_length" value comes from the firmware file. If your firmware is untrusted realistically there is probably very little you can do to protect yourself. Still we try to limit the damage as much as possible. Also Smatch marks any data read from the filesystem as untrusted and prints warnings if it not capped correctly. The "ntohl(ucode->code_length) * 2" multiplication can have an integer overflow. Fixes: 9e2c7d99941d ("crypto: cavium - Add Support for Octeon-tx CPT Engine") Signed-off-by: Dan Carpenter Signed-off-by: Herbert Xu Signed-off-by: Sasha Levin --- drivers/crypto/cavium/cpt/cptpf_main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/cavium/cpt/cptpf_main.c b/drivers/crypto/cavium/cpt/cptpf_main.c index 781949027451..d9362199423f 100644 --- a/drivers/crypto/cavium/cpt/cptpf_main.c +++ b/drivers/crypto/cavium/cpt/cptpf_main.c @@ -254,6 +254,7 @@ static int cpt_ucode_load_fw(struct cpt_device *cpt, const u8 *fw, bool is_ae) const struct firmware *fw_entry; struct device *dev = &cpt->pdev->dev; struct ucode_header *ucode; + unsigned int code_length; struct microcode *mcode; int j, ret = 0; @@ -264,11 +265,12 @@ 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; - if (!mcode->code_size) { + code_length = ntohl(ucode->code_length); + if (code_length == 0 || code_length >= INT_MAX / 2) { ret = -EINVAL; goto fw_release; } + mcode->code_size = code_length * 2; mcode->is_ae = is_ae; mcode->core_mask = 0ULL;