Received: by 10.213.65.68 with SMTP id h4csp2118274imn; Sun, 8 Apr 2018 20:09:35 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/56G3gPYPvnsb+CGSBtH9Uw4HHvn9SzKn5SgXx30ix8QPqVvOiJjM0FkNZWQdKwG7uL0I1 X-Received: by 10.98.9.147 with SMTP id 19mr21315306pfj.125.1523243375425; Sun, 08 Apr 2018 20:09:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243375; cv=none; d=google.com; s=arc-20160816; b=Jaq8i75cKfuHTgoDP4l8ThDJ2kmZTjbe0zwmiOVn5nYzCMXAS/ud4IdRj5lxc+5PJ8 CW01QlaQSLYXWOlb67DzLUlwyut84vuWHPXVKKmE6PBfLwQrQk2EfWdUMeBe2QGGnncg B7d40d+FNICVpxRgsKlSw0ijDyd4c1801ovmXGVcWbQVdwDRdN8sCI28iQClB1M+24Py lUfoh757QjHTFi3eWvfsd9IkWPpt2MQgKing5bweUx++7saZzzhqX7HGjrz9CV41UA4L O2Wg7/pNaplYKlWLTZjYrdLALblfRa3SX648eQCJm9/iv1TTw60GOEwa+yEo+iv4ryPd fA6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=DOZOIUhljiOXM+4G7JQaI4aEELKlR3ldjaJa/bHEXiA=; b=x1WJ1iDyuuhlM6JAdC97Tr7F6xbk5kyoA9EDIiFTpJPZySGUqpentbafyK+CwNONVp ZTG7eo8KvGVX4Zx+0/5qMTTn8Vzj0e43FS3Ax15lagkRSpHzntpskoGtKkjgXT8ZGYLC D2fSNOBkDYN+3CTr9a5Sg9Y8hB3hxg/AXLqBpK9HIREUP9HMNbPFleeWcp2fg0nllYqh GOZMfPYcoxpsk/oIZNqSjbQTlZZkqHl6fZhJrlcOqoW6PZrT/p2XWdHeJEpft59uz7hF 7oql6ci2TAXiYywzsdwbjRCwLDyNjMGxkhLvced04dTVay5+P60Fmr2EUoTVa9/b5toO TjfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=JDx/MnKW; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u7si9417037pgv.251.2018.04.08.20.08.58; Sun, 08 Apr 2018 20:09:35 -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=pass header.i=@microsoft.com header.s=selector1 header.b=JDx/MnKW; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757642AbeDIChO (ORCPT + 99 others); Sun, 8 Apr 2018 22:37:14 -0400 Received: from mail-cys01nam02on0094.outbound.protection.outlook.com ([104.47.37.94]:22752 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755613AbeDIA1e (ORCPT ); Sun, 8 Apr 2018 20:27:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=DOZOIUhljiOXM+4G7JQaI4aEELKlR3ldjaJa/bHEXiA=; b=JDx/MnKWT7dDYDD5NdmsDKsbPe+kLUCa8Pp6bv2GQifI/M8Rp2semIQTcXHZwTBIBe+ODs+8v1R2qXKtX9yewqDI/uksJFluCZkmIxi4AQXnTjRL76QagcjkBZE+rfMDWTfRjtDnmyhmW3vwTcoxqaIFrZ1+2SuXQnUuAyoYuPk= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1031.namprd21.prod.outlook.com (52.132.128.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:27:28 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:27:28 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Christophe JAILLET , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 048/293] drm/vc4: Fix resource leak in 'vc4_get_hang_state_ioctl()' in error handling path Thread-Topic: [PATCH AUTOSEL for 4.9 048/293] drm/vc4: Fix resource leak in 'vc4_get_hang_state_ioctl()' in error handling path Thread-Index: AQHTz5j6eJd1i067wUybzutI4QRO6w== Date: Mon, 9 Apr 2018 00:23:27 +0000 Message-ID: <20180409002239.163177-48-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1031;7:VS4u/Tr4Zqq+ptuNShCtQStvUrmZT7DNYQOCtvtwVATeNky70XMW/Nj7NnPRPMI8YyAjUaSbzdL1tpaTPrFGeBBeAmuH23aKMzHFx0EVYrrUuNO9W6dP0R3N4PZFBEeNs2qqZah8T0ClOvGyiO7JikdJcVrQKkbjA1AlKlw/akSLz048Zp/wtzPJ/ldp3YJ2GdXlnF7O0rUDj+lFu+TPH3awGyQajviCxppg25JEQ/OAki2j5qMa+eIged1fBLxD;20:J/TThlQJP6XreEZdZuozef7ZyYLcmLZnhyKgG7AqFGOm5q9v3mdR+CQ9QFb1frq3quG2dm+36JMoChm4MCOUJFFUZS/TwljiFII3Jrwq0zrJnVFx2BbCDaad5NOr0dQuopUcXUN7bZISbjXboHPlQIVLCS8CSOw9a6MjNTFbnA8= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 8fc698d4-e60f-4d6e-e5a7-08d59db0ad31 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1031; x-ms-traffictypediagnostic: DM5PR2101MB1031: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(155761271638844); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123558120)(20161123562045)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:DM5PR2101MB1031;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1031; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(376002)(366004)(39380400002)(346002)(39860400002)(189003)(199004)(2900100001)(10290500003)(99286004)(76176011)(14454004)(15760500003)(966005)(7736002)(11346002)(26005)(86612001)(72206003)(478600001)(36756003)(106356001)(66066001)(2616005)(186003)(575784001)(22452003)(86362001)(68736007)(305945005)(54906003)(102836004)(486006)(59450400001)(110136005)(316002)(6506007)(446003)(107886003)(53936002)(4326008)(105586002)(6306002)(6436002)(6486002)(476003)(6512007)(5660300001)(5250100002)(25786009)(3846002)(6116002)(1076002)(97736004)(3280700002)(2501003)(2906002)(81156014)(8676002)(10090500001)(81166006)(8936002)(3660700001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1031;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: W/MiNOFGY4bg9xJRQpwq80HS54yCDeOZMTVS4jZJFtPQz8AM5O4yFZoSNXeIQc7dC7ctNRBGqLhE+IWezN9zb935dcb8hJdNyuXUlr3O3QZw3UqLQwpFrUw+wuYvODlrOfIDFAqaoQ3USzQGW/fVuIcVNTB9E6IPRAPCWiM6zac3SAcnM/Wo2y/ScnGtxgXVI0KbOrmz7VQymYHHHet2LIBEuQZKtXOLP16Lgy/rNDkaMyRBb066iVmreJgNFyWFfGWaPlk7zAkvSHzK5oGmdH5A6o0lMEQFc2MG0c/uCBmHfKRzKx8fLq1v+1g740Ogb4XveY0v33HPlni0CZs6ZSZEOqxKNzoB4kANT31zaKRW4knNSWyCRw7++wycTkrxs0Qhx1zitg6ZbVQl1BruefOHOeMHEMB1yApQFrg0n0I= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8fc698d4-e60f-4d6e-e5a7-08d59db0ad31 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:23:27.3311 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1031 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christophe JAILLET [ Upstream commit d0b1d259a4b58b21a21ea82d7174bf7ea825e9cc ] If one 'drm_gem_handle_create()' fails, we leak somes handles and some memory. In order to fix it: - move the 'free(bo_state)' at the end of the function so that it is also called in the eror handling path. This has the side effect to also try to free it if the first 'kcalloc' fails. This is harmless. - add a new label, err_delete_handle, in order to delete already allocated handles in error handling path - remove the now useless 'err' label The way the code is now written will also delete the handles if the 'copy_to_user()' call fails. Signed-off-by: Christophe JAILLET Reviewed-by: Eric Anholt Link: http://patchwork.freedesktop.org/patch/msgid/20170512123803.1886-1-ch= ristophe.jaillet@wanadoo.fr Signed-off-by: Sasha Levin --- drivers/gpu/drm/vc4/vc4_gem.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_gem.c b/drivers/gpu/drm/vc4/vc4_gem.c index ab3016982466..b608cd463d4e 100644 --- a/drivers/gpu/drm/vc4/vc4_gem.c +++ b/drivers/gpu/drm/vc4/vc4_gem.c @@ -110,8 +110,8 @@ vc4_get_hang_state_ioctl(struct drm_device *dev, void *= data, &handle); =20 if (ret) { - state->bo_count =3D i - 1; - goto err; + state->bo_count =3D i; + goto err_delete_handle; } bo_state[i].handle =3D handle; bo_state[i].paddr =3D vc4_bo->base.paddr; @@ -123,13 +123,16 @@ vc4_get_hang_state_ioctl(struct drm_device *dev, void= *data, state->bo_count * sizeof(*bo_state))) ret =3D -EFAULT; =20 - kfree(bo_state); +err_delete_handle: + if (ret) { + for (i =3D 0; i < state->bo_count; i++) + drm_gem_handle_delete(file_priv, bo_state[i].handle); + } =20 err_free: - vc4_free_hang_state(dev, kernel_state); + kfree(bo_state); =20 -err: return ret; } =20 --=20 2.15.1