Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2697205ybc; Mon, 25 Nov 2019 02:39:47 -0800 (PST) X-Google-Smtp-Source: APXvYqw+d+50e2TCwacqCKptWrASdxBeZGCTw62UKYsltHFERH8GXt7ZTc0vMaxcPyiMOKlIkKZ0 X-Received: by 2002:a05:6402:51:: with SMTP id f17mr17660139edu.123.1574678387853; Mon, 25 Nov 2019 02:39:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574678387; cv=none; d=google.com; s=arc-20160816; b=SVP8ey2wMYsX20Hmym9StsIryGkiErm8EWR9zouyyJ7AvoY0oZseSi5l7fbFn1Sp/X bLHrd40ISyhtxqHjY2v+2PIKl2ux/q92f4nfxVVyifENw03GGR2+KK8U1HC4WUmIw6C/ 2gMp/HmJVQzY6VRpgSSjWZ/ucqQCYRVmG9NvvXAoE9NNBIw/Ih1Wzi4XW5vVobRxOmE/ +FQ9rwhjezrkLghZtz667gBTtAlYdW6nxi08tCkPsD5LQdxymLy3189hxJt36oa1DG0g y7h5bhSplYOKG1/t6cpQiVMStUrj36naY6HI1z0a0zSSFhi0kPoGGH7KR0tatV2rNgPn WTwQ== 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 :message-id:date:subject:to:from:dkim-signature; bh=ZMYkA3jI8+ywNR+OhV3jpIlPger7eOA5dEPy09p1d6E=; b=ipycydSe4ntL/r2KLIxTFi3h7Z0scXjklNOnso1HB2Dq53zFPEku3x50Rd7vKRZIRx ItQ23L3jWDnPIHeamXbylEx2QutddgdDaHiEgVnfA9HbwgTGo/ddxXx62pVb07bPyP0I QQUFwf/vQ99xMuByrIcw0TU7trdDjjMqv3o5ELXFNQNP80MvlnAfR8eNL0Os+q6bQgx4 zlsoLvRTRpjGpu/qLtjzc36gRKzurQJj9PlmxKB4TrfjCDCNlmILutq3QVleF4sRXHiT yZfjGn6BvR5LviVExcPjJ1ZPvekjEAbYQmvi0MnPPPbENfiPqyx97nWGM5Ua9LgEVUdI R6lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dyy2ZVwk; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e3si4241816ejt.191.2019.11.25.02.39.22; Mon, 25 Nov 2019 02:39:47 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=dyy2ZVwk; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727453AbfKYKfs (ORCPT + 99 others); Mon, 25 Nov 2019 05:35:48 -0500 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:30049 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727266AbfKYKfr (ORCPT ); Mon, 25 Nov 2019 05:35:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574678146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZMYkA3jI8+ywNR+OhV3jpIlPger7eOA5dEPy09p1d6E=; b=dyy2ZVwk9P1P6CI6YlUeRdXMkmj6h6DHx9ZsORsqi1X17W72/3ZEjvkJOIvgx3m9ld2TXV Uvtq8M8mdf6s9NdiPIamRF7qrZUtQGpUBdMiDlZld3P9c/skUY258gtks+g2R5ODR2/shS +qQELQDJeZOF1C3S/b5fbyYkOe8Q2/o= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-337-8pbgYF59MamGTDCxyCAzoQ-1; Mon, 25 Nov 2019 05:35:45 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 10B44107B765; Mon, 25 Nov 2019 10:35:44 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-37.ams2.redhat.com [10.36.116.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C39319C69; Mon, 25 Nov 2019 10:35:39 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, joro@8bytes.org, hch@lst.de, cai@lca.pw, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: [PATCH] iommu: fix KASAN use-after-free in iommu_insert_resv_region Date: Mon, 25 Nov 2019 11:35:35 +0100 Message-Id: <20191125103535.22782-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-MC-Unique: 8pbgYF59MamGTDCxyCAzoQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Store the new region type in a variable. In case the new region gets merged into another one, the new node is freed and nr shall not be used anymore. Fixes: 4dbd258ff63e ("iommu: Revisit iommu_insert_resv_region() implementation") Signed-off-by: Eric Auger Reported-by: Qian Cai CC: Stable #v5.3+ --- drivers/iommu/iommu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index d658c7c6a2ab..338769f96d17 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -293,6 +293,8 @@ int iommu_insert_resv_region(struct iommu_resv_region *= new, =09=09=09 struct list_head *regions) { =09struct iommu_resv_region *iter, *tmp, *nr, *top; +=09enum iommu_resv_type nr_type =3D new->type; + =09LIST_HEAD(stack); =20 =09nr =3D iommu_alloc_resv_region(new->start, new->length, @@ -313,7 +315,7 @@ int iommu_insert_resv_region(struct iommu_resv_region *= new, =09=09phys_addr_t top_end, iter_end =3D iter->start + iter->length - 1; =20 =09=09/* no merge needed on elements of different types than @nr */ -=09=09if (iter->type !=3D nr->type) { +=09=09if (iter->type !=3D nr_type) { =09=09=09list_move_tail(&iter->list, &stack); =09=09=09continue; =09=09} --=20 2.20.1