Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp2223290ybg; Thu, 24 Oct 2019 06:43:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqz0CzWtYROT2E4MPIeucGzYTUj3s4IMX3KZIastmNwEvtXglGpjVqGQkU77SqLsjw2P7ipU X-Received: by 2002:a05:6402:1547:: with SMTP id p7mr32504568edx.28.1571924638886; Thu, 24 Oct 2019 06:43:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571924638; cv=none; d=google.com; s=arc-20160816; b=wPyQBGiwO62veTY1DiR+ID/nNwiqz5Axx6JYAY7fg4cBUS93SnMpzq1P4zko8IuBGV +I0QeORyeTcAfeRZIhtYJRo7iMeHtcCnJmWkzWY58kGqN5r0Xpg9A0aGNJiWRYdS1i54 rLnIj8NT2NdSs/acDCKHj5ZFsqC+LE8VYIdm2F9euQqSdYbAl7UYe1tOihxEYTW2guI4 zaX3uNozPvXSfalSCQN/gl6vcpZlaSm2BsSIsf6WRjjy6oARDn3KBuFoNC2hweggrAMx chpINeiQ9qHfKlmA1c6QRV6AhTe4xA0t9n+qFMuqeQx+M5wmEfuR5L8TUFx37MjzHVLL bztQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:mail-followup-to :message-id:subject:to:from:date:dkim-signature; bh=+OWjpvr+IZedd7nljlYA8XWBRBItw4xtW0mvQ/KD8Fk=; b=PVk6CWXInE90+UG+B4wTFDjZlOLN2qOqW/YwXuXf2+mF9Z4XU8Bs0248g++UF9vw+/ Xnl/8EP1t1ZUSpungmvgIcSr1mmW7BPhaM4JOkLDgh4YJZS7ik/SpUMF+vFIj9qQMK1y PweoTXlKeKqWpuDQrbr40e/F+sMKaS34dFUvuZ0wNhRo765ckNacCPR86dUSK3GHkXWk DBhNMSEk4DSOkCocakpo9KpXap/+pxHlt5UuT11t4lkkWUjlIsbdO31flhl9B0KvQHR2 oXEhIOb7m8O51aXKriF2i2Sy+0zfZlR2tyD5tfa1HnhsiGDz3RjFx58zBnOBEdB0CSqL KN4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@ffwll.ch header.s=google header.b=M95LDREg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ov32si14116222ejb.411.2019.10.24.06.43.33; Thu, 24 Oct 2019 06:43:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@ffwll.ch header.s=google header.b=M95LDREg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391011AbfJWTAB (ORCPT + 99 others); Wed, 23 Oct 2019 15:00:01 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:34084 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387929AbfJWTAB (ORCPT ); Wed, 23 Oct 2019 15:00:01 -0400 Received: by mail-wr1-f65.google.com with SMTP id t16so18130672wrr.1 for ; Wed, 23 Oct 2019 11:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=sender:date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=+OWjpvr+IZedd7nljlYA8XWBRBItw4xtW0mvQ/KD8Fk=; b=M95LDREgblcKjvAHssdy4GOnOy+idPXh9WTEOZZdiOlwBVlvkmYF8XPlBP0lSR3FUJ PhSUgbLA9MuLMfPxCT7kyPf4tDIinnMjcd6POSe8NgDzz7Tux6+w57eymqpz9vtYVSB3 30QGpwWmCbAdm1D3IBvAg+C2kg9CjJSyUfU9I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=+OWjpvr+IZedd7nljlYA8XWBRBItw4xtW0mvQ/KD8Fk=; b=L4q8uxEQ4UaAfn4bnlhaqE29mIZnb97nrX/PY0LUCm/8tr2YnGKa8WFZ7FWXlchjbZ wYIiW+0NMnN6y2jXWRFwEhjYk46f7g7LmLqmeKBkjSaUc/47G2aeQ19iYqgVsp2EhAGt FADOV1eHSbMCREEzcy/BzmYjRG+n6Bygb/3Se78COpslpn1/jLL7tCJMmHhoJDkX/H5v o7xEO4c/rNy1C3U/q1KrePuJtwFRPOZv71x050Uy/0YTlCmEPnI/l7t00C55iMII1lNv tL1+y7k4pNcGI7bFAIg7/X88kZwUJ3qQ1ntkTDtJB1aPrpNTQ+QUgZgHeT+X8ytvaltc XvVg== X-Gm-Message-State: APjAAAUuyqaJ06H39a5KUebzEUM/1ylWX9ulHMqt4Vu+0Jg0V9gDVF08 SbUfiRJ7UNFPyo8JAlSbY2RG4Q== X-Received: by 2002:a5d:4a8a:: with SMTP id o10mr205718wrq.101.1571857198467; Wed, 23 Oct 2019 11:59:58 -0700 (PDT) Received: from phenom.ffwll.local (212-51-149-96.fiber7.init7.net. [212.51.149.96]) by smtp.gmail.com with ESMTPSA id r3sm38184702wre.29.2019.10.23.11.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 11:59:55 -0700 (PDT) Date: Wed, 23 Oct 2019 20:59:52 +0200 From: Daniel Vetter To: Navid Emamdoost , Navid Emamdoost , Kangjie Lu , Stephen McCamant , Eric Anholt , David Airlie , dri-devel@lists.freedesktop.org, LKML Subject: Re: [PATCH] drm/v3d: Fix memory leak in v3d_submit_cl_ioctl Message-ID: <20191023185952.GZ11828@phenom.ffwll.local> Mail-Followup-To: Navid Emamdoost , Navid Emamdoost , Kangjie Lu , Stephen McCamant , Eric Anholt , David Airlie , dri-devel@lists.freedesktop.org, LKML References: <20191021185250.26130-1-navid.emamdoost@gmail.com> <20191022093654.GF11828@phenom.ffwll.local> <20191023091601.GX11828@phenom.ffwll.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191023091601.GX11828@phenom.ffwll.local> X-Operating-System: Linux phenom 5.2.0-2-amd64 User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 23, 2019 at 11:16:01AM +0200, Daniel Vetter wrote: > On Tue, Oct 22, 2019 at 10:53:57PM -0500, Navid Emamdoost wrote: > > On Tue, Oct 22, 2019 at 4:36 AM Daniel Vetter wrote: > > > > > > On Mon, Oct 21, 2019 at 01:52:49PM -0500, Navid Emamdoost wrote: > > > > In the impelementation of v3d_submit_cl_ioctl() there are two memory > > > > leaks. One is when allocation for bin fails, and the other is when bin > > > > initialization fails. If kcalloc fails to allocate memory for bin then > > > > render->base should be put. Also, if v3d_job_init() fails to initialize > > > > bin->base then allocated memory for bin should be released. > > > > > > > > Fixes: a783a09ee76d ("drm/v3d: Refactor job management.") > > > > Signed-off-by: Navid Emamdoost > > > > --- > > > > drivers/gpu/drm/v3d/v3d_gem.c | 5 ++++- > > > > 1 file changed, 4 insertions(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/gpu/drm/v3d/v3d_gem.c b/drivers/gpu/drm/v3d/v3d_gem.c > > > > index 5d80507b539b..19c092d75266 100644 > > > > --- a/drivers/gpu/drm/v3d/v3d_gem.c > > > > +++ b/drivers/gpu/drm/v3d/v3d_gem.c > > > > @@ -557,13 +557,16 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data, > > > > > > > > if (args->bcl_start != args->bcl_end) { > > > > bin = kcalloc(1, sizeof(*bin), GFP_KERNEL); > > > > - if (!bin) > > > > + if (!bin) { > > > > + v3d_job_put(&render->base); > > > > > > The job isn't initialized yet, this doesn't work. > > Do you mean we have to release render via kfree() here? > > > > > > > > > return -ENOMEM; > > > > + } > > > > > > > > ret = v3d_job_init(v3d, file_priv, &bin->base, > > > > v3d_job_free, args->in_sync_bcl); > > > > if (ret) { > > > > v3d_job_put(&render->base); > > > > > > v3d_job_put will call kfree, if you chase the callchain long enough (in > > > v3d_job_free). So no bug here, this would lead to a double kfree and > > > crash. > > Yes, v3d_job_put() takes care of render, > > > > > -Daniel > > > > > > > + kfree(bin); > > but how about leaking bin? > > Sorry, I totally missed that this is bin, no render. Patch looks correct > to me. > > Reviewed-by: Daniel Vetter Double-checked with Eric and applied to drm-misc-fixes. -Daniel > > > > > > > return ret; > > > > } > > > > > > > > -- > > > > 2.17.1 > > > > > > > > > > -- > > > Daniel Vetter > > > Software Engineer, Intel Corporation > > > http://blog.ffwll.ch > > > > > > > > -- > > Navid. > > -- > Daniel Vetter > Software Engineer, Intel Corporation > http://blog.ffwll.ch -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch