Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp658514pxb; Tue, 5 Apr 2022 17:37:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyy+q4PJImzGwpmiJcSHIPCEsZ8Bk9jBvwdYe/xa/wilIOXaLuw2p2WMlj4NROiKQRDuQc X-Received: by 2002:a17:902:7006:b0:156:3cbe:6b04 with SMTP id y6-20020a170902700600b001563cbe6b04mr5972256plk.68.1649205326335; Tue, 05 Apr 2022 17:35:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649205326; cv=none; d=google.com; s=arc-20160816; b=s5qRc44ZOMicqPc98qXTqoIzE5UhXmcREIrjhteofu1BOT6ED65edE5ZWjU6ixITro jDpLyyt/rMvaeojZhE2vD0wDZ3QG2o8fGVXEnnXo1El1xbBnP2nbR4bn3YTU4k7Q78nV BwulUn8ErKWzacYcDFi66qGp0kpkRmZ+PkJl1VDAuYPRORuOU7UX1J0HcmygtVnjkIYy TIkQ67jbja35ny5vROu8nueBCSd6+1A1ikHvChG5+cjzEgfZHislT5oXMN/FAhotEnY2 JZz8vO6rcMVRtQ7hf478z0RgwuQfby0nIv8imA1+3ykYAmDtLWR79F2MAR06wMa8VsyV gpEA== 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=OxMDgG1L2HMJE/ujNTUtn9dBNAUGg8Ghfngj6RWugu8=; b=oS5CveL7WeMuDbh7ViiVUCba0Yq73EDX7iffC5pJg2Y0DeixOVhOaNTXTRX/pEPbIV 1RC2VtKO/blUxkIuJyym/vbH2+GrHUAYlPffQcUPCFG7EVijVVyQIb3s4w+v7gcfCEHQ D+EI9rKIwyxR+fhqTR3Xryk9GU3vVIlySVCFkxyCIqETvTxBVQwQZEbhT6Ec21Olhr3I 8vNPheHSTN+WPQA5EZVBM6Tti+D7LP8oxK9/NR4LfClmUCF6bIHZFHmzGysH9N0SyQl5 23E0WEr7egp7hawZYMXrrD/LGujPuSkmATxDzAd9fJRsY6QxKs/qyxxEjr+Zrgx4hQ7T N9Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IXrqBlvc; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t6-20020a170902e84600b00153ba5786bfsi15915573plg.437.2022.04.05.17.35.11; Tue, 05 Apr 2022 17:35:26 -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=IXrqBlvc; 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 S1383377AbiDEMZp (ORCPT + 99 others); Tue, 5 Apr 2022 08:25:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245101AbiDEIyC (ORCPT ); Tue, 5 Apr 2022 04:54:02 -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 475F3F31; Tue, 5 Apr 2022 01:51:28 -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 D33E761504; Tue, 5 Apr 2022 08:51:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E21FDC385A0; Tue, 5 Apr 2022 08:51:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649148687; bh=0C40SgLp/lwFglandYY9iJGkhMxzFWz9IyNwKsYpjig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IXrqBlvc5yLbfHWT1TJzThmCXbzREgERTwlsTwT3N0uaC3j5bq3fpW6dQTiR44J+a R1cSOGZFjeF6r7O0obNmu80N7vkySFBQFA7IMOF+hBBPObjo28DLC941eeCG8ULdbQ GzoC7TIBfHglTDvOJDzEOAmYN+vIpQBATuVpJ7wk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhou Qingyang , Lyude Paul , Sasha Levin Subject: [PATCH 5.16 0428/1017] drm/nouveau/acr: Fix undefined behavior in nvkm_acr_hsfw_load_bl() Date: Tue, 5 Apr 2022 09:22:21 +0200 Message-Id: <20220405070406.997309903@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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,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-kernel@vger.kernel.org From: Zhou Qingyang [ Upstream commit 2343bcdb4747d4f418a4daf2e898b94f86c24a59 ] In nvkm_acr_hsfw_load_bl(), the return value of kmalloc() is directly passed to memcpy(), which could lead to undefined behavior on failure of kmalloc(). Fix this bug by using kmemdup() instead of kmalloc()+memcpy(). This bug was found by a static analyzer. Builds with 'make allyesconfig' show no new warnings, and our static analyzer no longer warns about this code. Fixes: 22dcda45a3d1 ("drm/nouveau/acr: implement new subdev to replace "secure boot"") Signed-off-by: Zhou Qingyang Reviewed-by: Lyude Paul Signed-off-by: Lyude Paul Link: https://patchwork.freedesktop.org/patch/msgid/20220124165856.57022-1-zhou1615@umn.edu Signed-off-by: Sasha Levin --- drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c b/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c index 667fa016496e..a6ea89a5d51a 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/acr/hsfw.c @@ -142,11 +142,12 @@ nvkm_acr_hsfw_load_bl(struct nvkm_acr *acr, const char *name, int ver, hsfw->imem_size = desc->code_size; hsfw->imem_tag = desc->start_tag; - hsfw->imem = kmalloc(desc->code_size, GFP_KERNEL); - memcpy(hsfw->imem, data + desc->code_off, desc->code_size); - + hsfw->imem = kmemdup(data + desc->code_off, desc->code_size, GFP_KERNEL); nvkm_firmware_put(fw); - return 0; + if (!hsfw->imem) + return -ENOMEM; + else + return 0; } int -- 2.34.1