Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3583764pxb; Mon, 24 Jan 2022 12:49:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3QUBMQUSmWNmMi15bY9BG5pxPUqtIJSUEGAZsmw7OE4/ls0qU705Z0NxbEW3l2WLzeY4C X-Received: by 2002:a17:902:7842:b0:14a:eff6:b8c6 with SMTP id e2-20020a170902784200b0014aeff6b8c6mr15785120pln.37.1643057352644; Mon, 24 Jan 2022 12:49:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643057352; cv=none; d=google.com; s=arc-20160816; b=EG9RH61mHlV+LWcoKnKM1cV8DMu9x+pkcf2xAXMy+5IW2991H88ZKWE1oLcS/bYNLn mCrxFCO0DXDy5/UpdqgI3Ooa1LXRna10bHYQTo/7wU2nsf3SetRid2+cOEGjod7KIReO h8ie9QqRXvepHrK0SsEucHa2nhYhSeORUzjpjw+0rQOgpAye+e6b38diOlOL8mRuSIbv bFAtgsePJislRD6EOrPRlfJlJKM3SKwbAvEcnAwqjHcZlsj8wWZYAAJ9eSoPkCbdp2Yg JaeQ7kuiif0UgI/gRgQOF5XWAKlZlSVLtcIxcrTFOCSC2JrHK2D8azA91CHqW33q4poo xf6w== 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=KvaeLMfSlJWIe4U0q0N8wRqobaVORnVtT/rC0bpJHE8=; b=yhsjHFTsfLnV44NQNo5CfZz01Z3UG2dEf6b6q/nS3xjljXiTqQ+Iz//GDIg6Zv0+6+ +K8KQTafPa8Ev++uhjnYo3QA1DiiQUm0EqFaBd61LuSxYuLAMH3GFsbXp2QFX95xYdVz pcckZNTg7fbtCQytWZohSCSNGYNw/FAnSZh5RQcRalW7+q5bAZ5uJt588fh1fByOQ49L A2r4zzn7GvuIJ16a38WdfxaTu48KHetkZ5PoJptdVuAKg4IMvvZePC9NwtCU4ToSTd4J KoI6p97+3tl2MPri+JhLnTPm4D7WW6rCkECkoukoZsac0eGehYWKK6mlq9x8pBE/yQ5E de4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jGDroVWF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b5si14189578plz.335.2022.01.24.12.49.00; Mon, 24 Jan 2022 12:49:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jGDroVWF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1347265AbiAXUCi (ORCPT + 99 others); Mon, 24 Jan 2022 15:02:38 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:51910 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242910AbiAXT3S (ORCPT ); Mon, 24 Jan 2022 14:29:18 -0500 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 3AD25B8119D; Mon, 24 Jan 2022 19:29:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69F3BC340E5; Mon, 24 Jan 2022 19:29:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643052552; bh=WiPti4Hvt08D59RYFB4prrRHKNnMGFuDb65RGfn33H0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jGDroVWFT4yS9dm+z81FB5LvgDhdV6hfxWIC6bHJOHJukfmqKXhb2Ohh7F9yGBFmV C1iQpjiZxd+lrzzE0o8E7qQEh0sZqNGfh8QytwFM4qVYHNzzP3v8Nz4BSOAxun/sWj sYfJslEFULqRl7VfUkSog0ALnPx1Yo3djChamkh4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Christian=20K=C3=B6nig?= , Zhou Qingyang , Alex Deucher , Sasha Levin Subject: [PATCH 5.4 064/320] drm/radeon/radeon_kms: Fix a NULL pointer dereference in radeon_driver_open_kms() Date: Mon, 24 Jan 2022 19:40:48 +0100 Message-Id: <20220124183955.904758423@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183953.750177707@linuxfoundation.org> References: <20220124183953.750177707@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhou Qingyang [ Upstream commit ab50cb9df8896b39aae65c537a30de2c79c19735 ] In radeon_driver_open_kms(), radeon_vm_bo_add() is assigned to vm->ib_bo_va and passes and used in radeon_vm_bo_set_addr(). In radeon_vm_bo_set_addr(), there is a dereference of vm->ib_bo_va, which could lead to a NULL pointer dereference on failure of radeon_vm_bo_add(). Fix this bug by adding a check of vm->ib_bo_va. This bug was found by a static analyzer. The analysis employs differential checking to identify inconsistent security operations (e.g., checks or kfrees) between two code paths and confirms that the inconsistent operations are not recovered in the current function or the callers, so they constitute bugs. Note that, as a bug found by static analysis, it can be a false positive or hard to trigger. Multiple researchers have cross-reviewed the bug. Builds with CONFIG_DRM_RADEON=m show no new warnings, and our static analyzer no longer warns about this code. Fixes: cc9e67e3d700 ("drm/radeon: fix VM IB handling") Reviewed-by: Christian König Signed-off-by: Zhou Qingyang Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/radeon/radeon_kms.c | 36 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/radeon/radeon_kms.c b/drivers/gpu/drm/radeon/radeon_kms.c index 03d3550ecc7cb..5d04dd744af3d 100644 --- a/drivers/gpu/drm/radeon/radeon_kms.c +++ b/drivers/gpu/drm/radeon/radeon_kms.c @@ -634,6 +634,8 @@ void radeon_driver_lastclose_kms(struct drm_device *dev) int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) { struct radeon_device *rdev = dev->dev_private; + struct radeon_fpriv *fpriv; + struct radeon_vm *vm; int r; file_priv->driver_priv = NULL; @@ -646,8 +648,6 @@ int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) /* new gpu have virtual address space support */ if (rdev->family >= CHIP_CAYMAN) { - struct radeon_fpriv *fpriv; - struct radeon_vm *vm; fpriv = kzalloc(sizeof(*fpriv), GFP_KERNEL); if (unlikely(!fpriv)) { @@ -658,35 +658,39 @@ int radeon_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) if (rdev->accel_working) { vm = &fpriv->vm; r = radeon_vm_init(rdev, vm); - if (r) { - kfree(fpriv); - goto out_suspend; - } + if (r) + goto out_fpriv; r = radeon_bo_reserve(rdev->ring_tmp_bo.bo, false); - if (r) { - radeon_vm_fini(rdev, vm); - kfree(fpriv); - goto out_suspend; - } + if (r) + goto out_vm_fini; /* map the ib pool buffer read only into * virtual address space */ vm->ib_bo_va = radeon_vm_bo_add(rdev, vm, rdev->ring_tmp_bo.bo); + if (!vm->ib_bo_va) { + r = -ENOMEM; + goto out_vm_fini; + } + r = radeon_vm_bo_set_addr(rdev, vm->ib_bo_va, RADEON_VA_IB_OFFSET, RADEON_VM_PAGE_READABLE | RADEON_VM_PAGE_SNOOPED); - if (r) { - radeon_vm_fini(rdev, vm); - kfree(fpriv); - goto out_suspend; - } + if (r) + goto out_vm_fini; } file_priv->driver_priv = fpriv; } + if (!r) + goto out_suspend; + +out_vm_fini: + radeon_vm_fini(rdev, vm); +out_fpriv: + kfree(fpriv); out_suspend: pm_runtime_mark_last_busy(dev->dev); pm_runtime_put_autosuspend(dev->dev); -- 2.34.1