From patchwork Fri Oct 27 12:04:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13438569 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 82FB4C25B67 for ; Fri, 27 Oct 2023 12:05:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ADE6610E986; Fri, 27 Oct 2023 12:05:03 +0000 (UTC) Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by gabe.freedesktop.org (Postfix) with ESMTPS id 093DC10E986 for ; Fri, 27 Oct 2023 12:05:02 +0000 (UTC) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-507b96095abso2878648e87.3 for ; Fri, 27 Oct 2023 05:05:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698408300; x=1699013100; darn=lists.freedesktop.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=hPBeFfhGzz7b9reukuJd9y/UBu4JJXA38Z99vzaShGU=; b=JJbE5ZtWhvaEmJY7XVh1qNNntFt4hBvc9UfIR53/Vj5jzUpWF43AUYCtfZslYJnpho yUhqLcAvdkBYncTIekNBeOncdiXnD2FpCubbp4+AgwtJoRLEEKzxSXMp4TiGeUEgGKv3 7W2dvsStnVJ4UR69CgRoEWmsWecAYOq39QAe0xSxb7B4d6IaoKXRZhXW9jpkWO4mvLSD qSRhaODNKlUdDjaoGtPvoshzvELU5qgC6ng5WyhQEJ2cIxBOpZOH3N7DhHShPW4oiFeL h6PoGOKyrfXlMxICfUQPq6YiECZ8J03xHnjQ0o1TZSH/GskD0tcQVAiNwdLSKJP5kD7W 9I2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698408300; x=1699013100; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hPBeFfhGzz7b9reukuJd9y/UBu4JJXA38Z99vzaShGU=; b=SWv22xn/fLCSyk570KUwChy814xa3gLBO8HKav287WqkXX0Awvfad0UjpVhLhhwIgx 459c8YjodWlleeKjZUtYv1fDUcK7/aVUcW+QgHL753iXPdVWcGKp1WY7Ls3W4zGpza/b XnL1mPUWWFlHoWx81aDVlI7AiaffgWOOqJ+pXl0o0uxoHa3L8UpWtuAV9+E/bKBvce82 Who/znZH3qv7ZctI4aiWow/bHmqLjsE2egOcPQnfs0f2rkK+laoIE9Qsdmh24xaNLE82 4pehu8TsK+rKcFn4XAbc/Pm3S/MggqMkmPDq70hy1E0O5Zm8/2fC3u9yuRDkX9tEr+hV 3fHw== X-Gm-Message-State: AOJu0YynAOVOyOiwswlHHTRNanCPC5Z1Kun59Ui1toeK7vSoN1vHX9Uo zjRqlEGfgrILSzrhkHc44J2OBw== X-Google-Smtp-Source: AGHT+IE2TD3mcdg9qAax1VoYDY/yTuv41aG+a5xNuJLSiW9RCK7h0wL0oxjupUYN1A9aWv+pqg0YQQ== X-Received: by 2002:a05:6512:2807:b0:502:d35b:5058 with SMTP id cf7-20020a056512280700b00502d35b5058mr2101718lfb.4.1698408300149; Fri, 27 Oct 2023 05:05:00 -0700 (PDT) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b00401b242e2e6sm4962968wmq.47.2023.10.27.05.04.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 05:04:59 -0700 (PDT) Date: Fri, 27 Oct 2023 15:04:56 +0300 From: Dan Carpenter To: Helge Deller Subject: [PATCH 1/2] fbdev/imsttfb: fix double free in probe() Message-ID: <014c0272-0d53-4625-8517-e8b4aa68f4dd@moroto.mountain> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fbdev@vger.kernel.org, kernel-janitors@vger.kernel.org, Javier Martinez Canillas , dri-devel@lists.freedesktop.org, Thomas Zimmermann , Zheng Wang , Sam Ravnborg Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The init_imstt() function calls framebuffer_release() on error and then the probe() function calls it again. It should only be done in probe. Fixes: 518ecb6a209f ("fbdev: imsttfb: Fix error path of imsttfb_probe()") Signed-off-by: Dan Carpenter --- drivers/video/fbdev/imsttfb.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/video/fbdev/imsttfb.c b/drivers/video/fbdev/imsttfb.c index e7e03e920729..acb943f85700 100644 --- a/drivers/video/fbdev/imsttfb.c +++ b/drivers/video/fbdev/imsttfb.c @@ -1421,7 +1421,6 @@ static int init_imstt(struct fb_info *info) if ((info->var.xres * info->var.yres) * (info->var.bits_per_pixel >> 3) > info->fix.smem_len || !(compute_imstt_regvals(par, info->var.xres, info->var.yres))) { printk("imsttfb: %ux%ux%u not supported\n", info->var.xres, info->var.yres, info->var.bits_per_pixel); - framebuffer_release(info); return -ENODEV; } @@ -1453,14 +1452,11 @@ static int init_imstt(struct fb_info *info) FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_YPAN; - if (fb_alloc_cmap(&info->cmap, 0, 0)) { - framebuffer_release(info); + if (fb_alloc_cmap(&info->cmap, 0, 0)) return -ENODEV; - } if (register_framebuffer(info) < 0) { fb_dealloc_cmap(&info->cmap); - framebuffer_release(info); return -ENODEV; } From patchwork Fri Oct 27 12:05:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13438570 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B95EBC25B47 for ; Fri, 27 Oct 2023 12:05:51 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 22DEB10E0C4; Fri, 27 Oct 2023 12:05:51 +0000 (UTC) Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2EDA810E0C4 for ; Fri, 27 Oct 2023 12:05:49 +0000 (UTC) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-507a98517f3so2743681e87.0 for ; Fri, 27 Oct 2023 05:05:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698408347; x=1699013147; darn=lists.freedesktop.org; h=in-reply-to:content-disposition:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Rtys4OVP5ZzVlnIPSorJGpGjoOL2VcdIqIpp51DIOc0=; b=z3JnjTwMfrcqEfHdB6i+JRHFYNUbpExKMP8RLPQdnxVfSz5a68ds2g0/GjulfLj4dC TduLvkej3ULhtArLtzW04U819lDVy+YMaoMpYJSAKTMK0OnXkMyh/zF9veQR3lhG0G3m XHW/2rX7DnyUNrJLlg5V87TFwXcNnLvS1EEjqMKhFaV6R63njenty2z2zA3AIkoDv1aG 0Bx0RNglquMdFJJqa9WU91vrgDexYaEFdI5/o2fWfPZNtRL9nkwqTl5RDm06K1MOIggA rUz22KLM8I77tELZc4lJkN//m8MJE00BRnNeqqePOsTwYHeeIREYpk5dyJZ6GFQz7QKo ULQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698408347; x=1699013147; h=in-reply-to:content-disposition:mime-version:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Rtys4OVP5ZzVlnIPSorJGpGjoOL2VcdIqIpp51DIOc0=; b=PhUsiuV8m2dq3R331VO6N8G65J0emjFdOvfdfq6WbltUBcmg3ETb8MfEV7dqeNQmJu u1uQBW2Li2jA5ABfPSCn3dbEaAm+AwUdtLfNsVloX2JfVbJjCARu1by5kUS3rC4aXrzn 4NTPaE9Y1fbea8f/OvGapvbf0igk+7I4AjcLzyp80KFu3O+Ut4Of/RII8fat0FlIjurV deTrUwT28ed0jkWe3JvRMXdLKqsgKbLOu0Qgr2F6dx0+ydzA1ceur456T4O/2QuZMlXc 4M2ripJXytIgQQjwORCkbCw7NlAaiN4vnHBlfWfZE0Hu2VP8qzWGaEEwkGVdLIy8gHlT Ts/w== X-Gm-Message-State: AOJu0Yxm5S7NIYrolZtz+cg7+4HmzYWq755dkrRZ2PQNnQ9pmfhRMtE+ f7ZnihYW28WeSt1koBDCrkEZRNMov/GFs1ing+M= X-Google-Smtp-Source: AGHT+IEwMLdMiT1DpGl66JFRaW3Jkd9s7CFvWo0aNUOb8/tWmvL7FTmnMQJ10tzgk46/kJ10FHVi5Q== X-Received: by 2002:a05:6512:48d1:b0:500:bf33:3add with SMTP id er17-20020a05651248d100b00500bf333addmr1543741lfb.47.1698408347447; Fri, 27 Oct 2023 05:05:47 -0700 (PDT) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id t20-20020a0560001a5400b0032ddc3b88e9sm1663138wry.0.2023.10.27.05.05.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 05:05:47 -0700 (PDT) Date: Fri, 27 Oct 2023 15:05:44 +0300 From: Dan Carpenter To: Zheng Wang Subject: [PATCH 2/2] fbdev/imsttfb: fix a resource leak in probe Message-ID: <71f55328-2275-4e53-98f2-f8a88cbd3399@moroto.mountain> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <014c0272-0d53-4625-8517-e8b4aa68f4dd@moroto.mountain> X-Mailer: git-send-email haha only kidding X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-fbdev@vger.kernel.org, Helge Deller , kernel-janitors@vger.kernel.org, Javier Martinez Canillas , dri-devel@lists.freedesktop.org, Thomas Zimmermann , Sam Ravnborg Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" I've re-written the error handling but the bug is that if init_imstt() fails we need to call iounmap(par->cmap_regs). Fixes: c75f5a550610 ("fbdev: imsttfb: Fix use after free bug in imsttfb_probe") Signed-off-by: Dan Carpenter --- drivers/video/fbdev/imsttfb.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/drivers/video/fbdev/imsttfb.c b/drivers/video/fbdev/imsttfb.c index acb943f85700..660499260f46 100644 --- a/drivers/video/fbdev/imsttfb.c +++ b/drivers/video/fbdev/imsttfb.c @@ -1496,8 +1496,8 @@ static int imsttfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (!request_mem_region(addr, size, "imsttfb")) { printk(KERN_ERR "imsttfb: Can't reserve memory region\n"); - framebuffer_release(info); - return -ENODEV; + ret = -ENODEV; + goto release_info; } switch (pdev->device) { @@ -1514,36 +1514,39 @@ static int imsttfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) printk(KERN_INFO "imsttfb: Device 0x%x unknown, " "contact maintainer.\n", pdev->device); ret = -ENODEV; - goto error; + goto release_mem_region; } info->fix.smem_start = addr; info->screen_base = (__u8 *)ioremap(addr, par->ramdac == IBM ? 0x400000 : 0x800000); if (!info->screen_base) - goto error; + goto release_mem_region; info->fix.mmio_start = addr + 0x800000; par->dc_regs = ioremap(addr + 0x800000, 0x1000); if (!par->dc_regs) - goto error; + goto unmap_screen_base; par->cmap_regs_phys = addr + 0x840000; par->cmap_regs = (__u8 *)ioremap(addr + 0x840000, 0x1000); if (!par->cmap_regs) - goto error; + goto unmap_dc_regs; info->pseudo_palette = par->palette; ret = init_imstt(info); if (ret) - goto error; + goto unmap_cmap_regs; pci_set_drvdata(pdev, info); - return ret; + return 0; -error: - if (par->dc_regs) - iounmap(par->dc_regs); - if (info->screen_base) - iounmap(info->screen_base); +unmap_cmap_regs: + iounmap(par->cmap_regs); +unmap_dc_regs: + iounmap(par->dc_regs); +unmap_screen_base: + iounmap(info->screen_base); +release_mem_region: release_mem_region(addr, size); +release_info: framebuffer_release(info); return ret; }