Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp926827pxb; Wed, 6 Apr 2022 04:30:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJDmRoJ640/X2rTflsAyOmtncOrTV7qupAhE2fpDi9msEmQoYCArovKnpbL53iOETBTCRL X-Received: by 2002:a17:902:7245:b0:156:20aa:1534 with SMTP id c5-20020a170902724500b0015620aa1534mr8237788pll.94.1649244654952; Wed, 06 Apr 2022 04:30:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649244654; cv=none; d=google.com; s=arc-20160816; b=smvx9Tpq4bsXr26O7GzGNqfy25D1YdA9ZWMxAW1Tn0fjeaLI+ACfZbaFHMvi+Sanw5 sY6BWcKJJChs/KIOJquasQJMe4bJUDv1PuarnNUkexKEaWO+ngsJkPBWB1sG7QI6qxQ4 HA7WwBQS684eYlFkPBC9c8RKz92HuCIcI5UQTJC+nz+NypLFbPuZQffYanZugHZK4rtM z2qvPKf9Y6ET9+zMLm0rnVYf3oUsR5ab5kni/WjXRo2oQ39Yu7KNz4+FqDSR4lpoDd4F R04OGnuyn6ppk30ZycYuM/9wpa10ASBz5z/mZTcYMmP6n6FHQ0+i4XcGKUFbxxsgPJ1p l5BA== 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=GbpTvH+tx8UipdHuynvriurn3giOYI67wir8hCJcCnL2bNy2kbojJA39vLO0JptxLC fKfzvtiMF4ocft+EQMNCLBq0vu5/vrXh6ku39X2VbEfuIHRak7CcE1wcXkUXYJh1xQj+ RrQIWrjT6lV4K/TqYFNK8tATbBe41AfT6CX9alz9JNgmxjljXx9HY0/U7J+0GJZOirel FpmGY7xtP2y/c/fdJtGHLwbiJfnTH5iYvvAxVVDs16jzz2VcIvzHpBYwzJ0xj0K5DKL9 BUz6j/sVkeez+Xv9uFfIrAakTSUSnNFFOWImqI0hwPK77Ma1EMzmoh0oaYtXX8ryquEu CnRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yQ8+9Yrm; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id i75-20020a636d4e000000b0039895942fb1si16026727pgc.228.2022.04.06.04.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 04:30:54 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yQ8+9Yrm; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 53660542772; Wed, 6 Apr 2022 02:52:51 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1579830AbiDEXdF (ORCPT + 99 others); Tue, 5 Apr 2022 19:33:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348844AbiDEJsk (ORCPT ); Tue, 5 Apr 2022 05:48:40 -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 5E2BCB7C4A; Tue, 5 Apr 2022 02:36:40 -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 EEE6261368; Tue, 5 Apr 2022 09:36:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AE61C385A3; Tue, 5 Apr 2022 09:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151399; bh=0C40SgLp/lwFglandYY9iJGkhMxzFWz9IyNwKsYpjig=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yQ8+9YrmkdoKF/h4gDx7if8imBk0NBJ0ohQvvyNmSYFafrNHfwubbGzcXb6F7lHnO 8guKz3N0b27KF09CmJxkPyW4mvqtWnr4EXWiYzqIIDX+AxU3Rh2r8hdyvNEHTdroRM H7R9eK0ON56PqrnLKvbWujBiLwwie1/D4VGEAOxA= 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.15 400/913] drm/nouveau/acr: Fix undefined behavior in nvkm_acr_hsfw_load_bl() Date: Tue, 5 Apr 2022 09:24:22 +0200 Message-Id: <20220405070351.837442012@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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