Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E607C433FE for ; Thu, 17 Nov 2022 04:53:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234040AbiKQExM (ORCPT ); Wed, 16 Nov 2022 23:53:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231911AbiKQExJ (ORCPT ); Wed, 16 Nov 2022 23:53:09 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBA74275CF for ; Wed, 16 Nov 2022 20:53:07 -0800 (PST) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NCSG50NLtzRp1W; Thu, 17 Nov 2022 12:52:45 +0800 (CST) Received: from kwepemm600014.china.huawei.com (7.193.23.54) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 17 Nov 2022 12:53:05 +0800 Received: from ubuntu1804.huawei.com (10.67.175.28) by kwepemm600014.china.huawei.com (7.193.23.54) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 17 Nov 2022 12:53:05 +0800 From: Yi Yang To: , , , , , , CC: , Subject: [PATCH] drm: Fix possible UAF in drm_addmap_core Date: Thu, 17 Nov 2022 12:49:54 +0800 Message-ID: <20221117044954.26277-1-yiyang13@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.175.28] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600014.china.huawei.com (7.193.23.54) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org smatch report warning as follows: drivers/gpu/drm/drm_bufs.c:365 drm_addmap_core() warn: '&list->head' not removed from list If drm_map_handle() fails in drm_addmap_core(), the list will be freed, but the list->head will not be removed from dev->maplist, then list traversal may cause UAF. Fix by removeing it from list->head before free(). Fixes: 9a298b2acd77 ("drm: Remove memory debugging infrastructure.") Signed-off-by: Yi Yang --- drivers/gpu/drm/drm_bufs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c index fcca21e8efac..e739e577902c 100644 --- a/drivers/gpu/drm/drm_bufs.c +++ b/drivers/gpu/drm/drm_bufs.c @@ -362,6 +362,7 @@ static int drm_addmap_core(struct drm_device *dev, resource_size_t offset, if (map->type == _DRM_REGISTERS) iounmap(map->handle); kfree(map); + list_del(&list->head); kfree(list); mutex_unlock(&dev->struct_mutex); return ret; -- 2.17.1