Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1052648pxv; Thu, 22 Jul 2021 20:59:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjwRQhP3wWrIXneAESrkY1v/7EHU69Kw18znEkhoiUrNZD59eI7OeF+gRSWpnCR+yCT1RC X-Received: by 2002:a17:906:f294:: with SMTP id gu20mr2924130ejb.292.1627012795761; Thu, 22 Jul 2021 20:59:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627012795; cv=none; d=google.com; s=arc-20160816; b=CdwoYNGFULGInvLg9tJFw1pjDZjFwAuncFa/aHiRiLnGqZF88DisUQnLpkUrFHULl5 OO2fZtZwVJLqBu0lRd3s7P1rm3McE8Br0WVB5qg/fpuhl1Romn2yGferfkIWw03D4vfa 59m5DY8kk4CKsOBR+94faLVeg0Qxziigbc/iL4KCEEe1ptaOFUbuqySxIKeqNOkgvYR/ FvVoEIhdcPwcm1zUjhrLbgCtpucvVgQbMJ6Ox4Tkn1QyUzV5cG5QVkNL/48DUjmRfTUa lez+4albJSj36x1DKA/7pd5T/i285N7VR8pkNWSU7NaCo6iIM5cfEXjsOBoxJCnmaSr3 do/A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8PUPQL1KQ7Bv5P4iIxkV95oGyooy2mrPvFEjGm6Gkck=; b=0jrCAJKXVdDfXthJW5fAYicXR7VthaoEE0Hkx2n9yosmsYrwPgtGImvTMBlmNeZYgh zRGQguWkImYALuDLBkV3oZbx/X86T5VP5GFkmQJlPI/yBGRqssVl8JUrch7sppA6/arQ gpfeFmPVCCboBtlU3umx6lay1nGq+oRwH4VycGGtYmB4ROHbPyMaIUxvcTwcjVLi7xoV FKw+3yrT38eq+JchP2zdjsJLRqUQZQeuFHfiXMNJ8a5FMIXQey/XAnGWBiRlRibTjjKg txS+ILDQgCbXRbxq7ItTr/VFL3GOcX0uqhfdpSbzZAcm3fRN+T0LmQSnpW8ssawvvpxU qIUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pyHMt1Ol; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m19si26078550ejn.748.2021.07.22.20.59.32; Thu, 22 Jul 2021 20:59:55 -0700 (PDT) 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=@kernel.org header.s=k20201202 header.b=pyHMt1Ol; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233822AbhGWDRP (ORCPT + 99 others); Thu, 22 Jul 2021 23:17:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:37168 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233738AbhGWDRA (ORCPT ); Thu, 22 Jul 2021 23:17:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9F8D160EC0; Fri, 23 Jul 2021 03:57:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627012654; bh=SgS92D8YtZxt1ox6McgFTvBPWgU+hwBTL57t+PUqMl8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pyHMt1OlQuL//+gTzSxKJk+/6ArMwPEV7grPbfXcJC3mwhtq/krwiiZoYuP8DhGsY AQfTkEo+AKdKaiyReSNJLXmgultAYvVIpH5b3gJKZGTwfLx7yyl1/lmUbbAFKJCTlB 9BAatMG+Fjj3lRXjXHUhT9BmjscnPgjm7/btc0MBabiGjW0wTxvKfXYWA4WEBFzCtQ +ZX5N0mb98XxG2Ke7Se0JKxVUY3XZxl6hesJEusbG7p7MJuRd5454Dn3wX+CbocXGg wMxqnHTKuPr0ERMuuTFVganO4mx5cgXGsG+X3f/SDC+x9DZ6QqeYpfZ+LGzVuSn8bZ KB6xjkJszP8Jg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zheyu Ma , =?UTF-8?q?Christian=20K=C3=B6nig?= , Sasha Levin , dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.13 10/19] drm/ttm: add a check against null pointer dereference Date: Thu, 22 Jul 2021 23:57:11 -0400 Message-Id: <20210723035721.531372-10-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210723035721.531372-1-sashal@kernel.org> References: <20210723035721.531372-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zheyu Ma [ Upstream commit 9e5c772954406829e928dbe59891d08938ead04b ] When calling ttm_range_man_fini(), 'man' may be uninitialized, which may cause a null pointer dereference bug. Fix this by checking if it is a null pointer. This log reveals it: [ 7.902580 ] BUG: kernel NULL pointer dereference, address: 0000000000000058 [ 7.905721 ] RIP: 0010:ttm_range_man_fini+0x40/0x160 [ 7.911826 ] Call Trace: [ 7.911826 ] radeon_ttm_fini+0x167/0x210 [ 7.911826 ] radeon_bo_fini+0x15/0x40 [ 7.913767 ] rs400_fini+0x55/0x80 [ 7.914358 ] radeon_device_fini+0x3c/0x140 [ 7.914358 ] radeon_driver_unload_kms+0x5c/0xe0 [ 7.914358 ] radeon_driver_load_kms+0x13a/0x200 [ 7.914358 ] ? radeon_driver_unload_kms+0xe0/0xe0 [ 7.914358 ] drm_dev_register+0x1db/0x290 [ 7.914358 ] radeon_pci_probe+0x16a/0x230 [ 7.914358 ] local_pci_probe+0x4a/0xb0 Signed-off-by: Zheyu Ma Reviewed-by: Christian König Link: https://patchwork.freedesktop.org/patch/msgid/1626274459-8148-1-git-send-email-zheyuma97@gmail.com Signed-off-by: Christian König Signed-off-by: Sasha Levin --- drivers/gpu/drm/ttm/ttm_range_manager.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/ttm/ttm_range_manager.c b/drivers/gpu/drm/ttm/ttm_range_manager.c index 707e5c152896..ed053fd15c90 100644 --- a/drivers/gpu/drm/ttm/ttm_range_manager.c +++ b/drivers/gpu/drm/ttm/ttm_range_manager.c @@ -146,6 +146,9 @@ int ttm_range_man_fini(struct ttm_device *bdev, struct drm_mm *mm = &rman->mm; int ret; + if (!man) + return 0; + ttm_resource_manager_set_used(man, false); ret = ttm_resource_manager_evict_all(bdev, man); -- 2.30.2