Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3783014ybi; Mon, 29 Jul 2019 12:32:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqya/JgNdwB/fDOx/Q7VeuRBJBetaW9IAnCi3CXBeHrv8rD9qD8/X67gv8yBxKvPAKgd5azl X-Received: by 2002:a17:90a:35e5:: with SMTP id r92mr115197566pjb.34.1564428736914; Mon, 29 Jul 2019 12:32:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564428736; cv=none; d=google.com; s=arc-20160816; b=o7bW30IDOLTwSEiRHFbwPV4D8914+HBR5I4w5L3G2GY2xbUBxzvxT+on49K3gFOdBp r/uoI4h/HLHNsnBAtyKJnaIeMhOol0w5lolAxGa+xH6v67TuU2ZnAOuo8FD9OMYtLMt2 P4gDlac448v10lu1XNlfd289WWfHi9c/IBDEmeMyhCVCns3A9qBtpA0efXlm4DFpQY0l 4gyoAZwiXUGXNu5bNvsBOpcbcscxaL4VcuV55qKushjdQvk03Ad6RUIKJJaaIw5lY6/d IVlKuSm6TfrblRQC1HF0N8SvapKk0KCHhr3GFtw8naDQNu44q7zdorFktUFUY0pnfFGy sz5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hriD4KBGJyzStxXs6MAmbp2O/HFhtaDEy+YUg2vK0aI=; b=C2+DTB0FFdiy0ocd4B0mYKI4wdIVNRCKCj1/V3Jin9PjNW3W+qQG/r0K9sINGdB1iC pbygyxUGMyAvtEQrtqpaIov15mRiRDL5fWi+/7T9iHbLDc969nmyTWC0A6NgpFrfkRJM nzWTY97Q4d8z9ubX/XCpr8ZR+fyj29L0GVp7POZT2qOL6ZdRJu7JOPzZ5HKEs8nsFuEh SSajEuNZbmyHCiTKdhh4GCegpk2Wwz6zFZo+DkJT6ibDFhTnaMge0iY89WQ3H3wzc1bi FXHr3R8tDB9I0SYVHJDFCbzoqcjN9J/+uSoxROqPm1jyIw7Up3ek+vdpH1kYDf49I7FC ZueA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Rvaghpia; 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 b20si28287299pls.24.2019.07.29.12.32.01; Mon, 29 Jul 2019 12:32:16 -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=@kernel.org header.s=default header.b=Rvaghpia; 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 S1727946AbfG2TZm (ORCPT + 99 others); Mon, 29 Jul 2019 15:25:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:37972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728921AbfG2TZk (ORCPT ); Mon, 29 Jul 2019 15:25:40 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CCAE32070B; Mon, 29 Jul 2019 19:25:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564428339; bh=fmgSYmE0C7pvU3I+LoGPfnOvAV42bXtX0afORF5V/GY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rvaghpia/iwfU/ufvarLY2xUtOloA4g0aFJoupIgIY0q1d4IGh1vrIkkSf86wTkSO U5cXE0whx/uPhP+LUj6SLCtdXflckb0GQEmCJsZHTggdoeOQZ2XpxPD0VC5O6IZOwX F+l+Gresv+OtwlJFq5WPZ1PMLra8z+vTj6W9kwWw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Auger , Joerg Roedel , Sasha Levin Subject: [PATCH 4.14 044/293] iommu: Fix a leak in iommu_insert_resv_region Date: Mon, 29 Jul 2019 21:18:55 +0200 Message-Id: <20190729190826.252193838@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit ad0834dedaa15c3a176f783c0373f836e44b4700 ] In case we expand an existing region, we unlink this latter and insert the larger one. In that case we should free the original region after the insertion. Also we can immediately return. Fixes: 6c65fb318e8b ("iommu: iommu_get_group_resv_regions") Signed-off-by: Eric Auger Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/iommu.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 3de5c0bcb5cc..1620a6f49989 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -205,18 +205,21 @@ static int iommu_insert_resv_region(struct iommu_resv_region *new, pos = pos->next; } else if ((start >= a) && (end <= b)) { if (new->type == type) - goto done; + return 0; else pos = pos->next; } else { if (new->type == type) { phys_addr_t new_start = min(a, start); phys_addr_t new_end = max(b, end); + int ret; list_del(&entry->list); entry->start = new_start; entry->length = new_end - new_start + 1; - iommu_insert_resv_region(entry, regions); + ret = iommu_insert_resv_region(entry, regions); + kfree(entry); + return ret; } else { pos = pos->next; } @@ -229,7 +232,6 @@ static int iommu_insert_resv_region(struct iommu_resv_region *new, return -ENOMEM; list_add_tail(®ion->list, pos); -done: return 0; } -- 2.20.1