Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp807302rdb; Tue, 5 Dec 2023 23:46:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGABF2OcUyCw815K+MewpJIZQmDQ0ztRDiox25h2UNaqP/X0PJ+T//hzyaGqwRzLKLMoebP X-Received: by 2002:a05:6a21:33a1:b0:18f:97c:b9e6 with SMTP id yy33-20020a056a2133a100b0018f097cb9e6mr249447pzb.64.1701848775977; Tue, 05 Dec 2023 23:46:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701848775; cv=none; d=google.com; s=arc-20160816; b=1F9P0rg7kZWqUayLu1yaNfB98AmM4V95JgZGLffVpkKaYMm5zEYcbrrqZuCOq8+ngq GL9duZh9kVwja9gu6hT1zolPJZnrK5BsU3az9wLvzTbFTxj48RWr9qJ/NtLrbo5+h5WJ ccGGh8kPU3DWFPXEPqZ7IwRRj9Fw66Ko5FW6gTYkuenNaW8Og6j2n2z7KExRWEO0Efew t+7WE8O1m/28hFiV5+yVSo7deXN19T1it8XBHkMa1ytNom3xsQkV6SGvqudWuGny5k6l FwcD0ykwOZcGmHEq3JE+xiWZ7Ph4W6sLwz3ok2L6qSEWPGCH8JerwiHz9fIiqhxbyBgH D0vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=z0MyNLvoxNPerxj0t3OKltNltWF97zNueCCL2EnCYNE=; fh=H2w1ZEgc3Yqlflu2Dq4gp3Ns2imKjsuv7HVE5fUT1hM=; b=nzR9vDVgbcy0yfsSFIH1w1MgIm5oXAcmbGytn6RPocGLKxOVN64W5jAdi1Ze2G3ssG JDr7BQN25Ukaw+zUHbB2u1J1QJ60lYvZ2mrXmspi5085jDIewq5h+X0K3HyUzJAtLb4H J8F5slZ4AZminRrYIWwKpzXoZxpWd3LKQVdNEFQ3Q+mXS/88CBmLDXtxVj217koVRLRk 7ZMbmrVLOwrajZCB+ADEKWszgIyJgKoF+/Pmq/lpBYnD5kGH/TYsQOeLCKy3wSHHy9JS QpCc1TqmEWJd12aBpNBpNIF0oUk26qhLVbuoc6uaD45JEDLOzHFrZTw42ucuXuAxANg1 MQgw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id e4-20020a170902744400b001d044978d21si8642857plt.349.2023.12.05.23.46.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 23:46:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id DE282802D531; Tue, 5 Dec 2023 23:45:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229965AbjLFHp0 (ORCPT + 99 others); Wed, 6 Dec 2023 02:45:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235442AbjLFHpF (ORCPT ); Wed, 6 Dec 2023 02:45:05 -0500 X-Greylist: delayed 101238 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 05 Dec 2023 23:44:58 PST Received: from zg8tmty3ljk5ljewns4xndka.icoremail.net (zg8tmty3ljk5ljewns4xndka.icoremail.net [167.99.105.149]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1A1B31BDA for ; Tue, 5 Dec 2023 23:44:57 -0800 (PST) Received: from localhost.localdomain (unknown [10.190.70.17]) by mail-app3 (Coremail) with SMTP id cC_KCgD3_99KInBl+Mp+AA--.11318S4; Wed, 06 Dec 2023 15:27:11 +0800 (CST) From: Dinghao Liu To: dinghao.liu@zju.edu.cn Cc: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/plane: fix error handling in __drm_universal_plane_init Date: Wed, 6 Dec 2023 15:27:01 +0800 Message-Id: <20231206072701.13276-1-dinghao.liu@zju.edu.cn> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: cC_KCgD3_99KInBl+Mp+AA--.11318S4 X-Coremail-Antispam: 1UD129KBjvJXoW7tr48Jw4UuFW8GF18CF4fuFg_yoW8Gw1kpa 1UCFyYkr1jywsrKrZrAFsFvFW3Wa1fGry7uryUZwsxK3W5Kr9xJ348Aa47CFyqkw47Ww13 tr9xAr1DAF15Ar7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkI1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AE w4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2 IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJr0_GcWl84ACjcxK6I8E 87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1le2I262IYc4CY6c 8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_ Jr4lYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwI xGrwACjI8F5VA0II8E6IAqYI8I648v4I1l42xK82IYc2Ij64vIr41l42xK82IY6x8ErcxF aVAv8VW8uw4UJr1UMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr 4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxG rwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8Jw CI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2 z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUbXdbUUUUUU== X-CM-SenderInfo: qrrzjiaqtzq6lmxovvfxof0/1tbiAgoTBmVsUQg4xgAcsv X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 05 Dec 2023 23:45:37 -0800 (PST) __drm_universal_plane_init() frees plane->format_types and plane->modifiers on failure. However, sometimes its callers will free these two pointers again, which may lead to a double-free. One possible call chain is: mdp5_plane_init |-> drm_universal_plane_init | |-> __drm_universal_plane_init (first free) | |-> mdp5_plane_destroy |-> drm_plane_cleanup (second free) Fix this by setting the two pointers to NULL after kfree. Signed-off-by: Dinghao Liu --- drivers/gpu/drm/drm_plane.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c index 24e7998d1731..1331b8224920 100644 --- a/drivers/gpu/drm/drm_plane.c +++ b/drivers/gpu/drm/drm_plane.c @@ -304,6 +304,7 @@ static int __drm_universal_plane_init(struct drm_device *dev, if (format_modifier_count && !plane->modifiers) { DRM_DEBUG_KMS("out of memory when allocating plane\n"); kfree(plane->format_types); + plane->format_types = NULL; drm_mode_object_unregister(dev, &plane->base); return -ENOMEM; } @@ -317,6 +318,8 @@ static int __drm_universal_plane_init(struct drm_device *dev, if (!plane->name) { kfree(plane->format_types); kfree(plane->modifiers); + plane->format_types = NULL; + plane->modifiers = NULL; drm_mode_object_unregister(dev, &plane->base); return -ENOMEM; } -- 2.17.1