Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1964448imm; Thu, 24 May 2018 03:42:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoPsc3C0AV+ifng/PiT5KxVAbbVP2/t4rbOz5NDpFh2bCUol9UF8Hra6u2Y8/m63gpHBQhx X-Received: by 2002:a17:902:b483:: with SMTP id y3-v6mr6698384plr.157.1527158519983; Thu, 24 May 2018 03:41:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527158519; cv=none; d=google.com; s=arc-20160816; b=DimegFlTdlr5nzofK+v9s2kKdy0fQKydW77N24SbYwHxq+6O+oelrdDtjEc141qV3C 2G1iXlsJMDv5UvS/M7w2vsaCeKHWm2KbgyRQEqsRLa7cWKjG8JKNc0NkLa3SatjuYNK+ LCutD9mus6jstMEZjLQfhjcHkMaKUwN4LfQpULOnrxWRS3OXZ6dpeUFLfTDNUXpvkCBw bZBtfVckV1NSxsS1gRbZecE0aV7zO6B3oonZKfmrah3XQcAN02NeNq+tOSR1i7PAErvp ENSV4rA7RLeyhDsAcv+WIhUrgNIAX0UFbwnCkHqD/e9j0AMzp6akkMqZN7miM9c0gHOs EyIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=KOT7QynFG1Fjbrnx1pp9p3PXxIiiIK/j3wM9RA4iwoM=; b=cbvTQwTYNbHs59wZAGNHrsFzWE+iaCRco5iITuId/p0fKLnnpbj+ZKrkl3/Eq7lA6B RKnj7Qu2wwSlajwSYsv72BUwGUwsvkSAOTOVMPU02/hucXBWUG0omi1RRfv8Bq+5F6i5 OACqe1KpiN0c4sONIe4Pqf5MaPf/kLCTwWrGAjEbEIhV7+3s2dU6qYPqFqx8hB1f5cBY zi57xEiayRZHPRw2pNly6CsMbWUKCaT4fRag0Ml0zOJKnNPEZn4V9JnXPKtn7VrfES78 hI/v1H+ZrnZQZ4pVP6DMycBNXuYSxtXy7dpM2ro1Eg+FuWzxvCnEsNSmo/a7SnG7nc4y 7a1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=l9e5jdCL; 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 x61-v6si20483151plb.560.2018.05.24.03.41.45; Thu, 24 May 2018 03:41:59 -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=l9e5jdCL; 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 S1032249AbeEXKjl (ORCPT + 99 others); Thu, 24 May 2018 06:39:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:40046 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030733AbeEXJ7P (ORCPT ); Thu, 24 May 2018 05:59:15 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 438492088E; Thu, 24 May 2018 09:59:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155955; bh=HCA9tH5WZYXzlXCd/cH2pH8jtDdwXiVqQPYdKi8zURg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l9e5jdCLbhxUiOFenQRTceu9NfiqNoFcg970fyjov7EXmFNV+MPDkgw58MtbhZzM3 BRJNIqpEw5FIxYPzh+BUyWc4+ADlvj0iwSd11ARRXK6lM29x2hzwBbwHIEGpHt8l8l J+i/ChbRK32QedmWAVr/LnfHWiHrESIPbzvVu36Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrei Vagin , Jason Wang , "David S. Miller" Subject: [PATCH 4.16 012/161] tuntap: fix use after free during release Date: Thu, 24 May 2018 11:37:17 +0200 Message-Id: <20180524093019.883071948@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093018.331893860@linuxfoundation.org> References: <20180524093018.331893860@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jason Wang [ Upstream commit 7063efd33bb15abc0160347f89eb5aba6b7d000e ] After commit b196d88aba8a ("tun: fix use after free for ptr_ring") we need clean up tx ring during release(). But unfortunately, it tries to do the cleanup blindly after socket were destroyed which will lead another use-after-free. Fix this by doing the cleanup before dropping the last reference of the socket in __tun_detach(). Reported-by: Andrei Vagin Acked-by: Andrei Vagin Fixes: b196d88aba8a ("tun: fix use after free for ptr_ring") Signed-off-by: Jason Wang Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/tun.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -728,6 +728,7 @@ static void __tun_detach(struct tun_file } if (tun) xdp_rxq_info_unreg(&tfile->xdp_rxq); + ptr_ring_cleanup(&tfile->tx_ring, tun_ptr_free); sock_put(&tfile->sk); } } @@ -3157,7 +3158,6 @@ static int tun_chr_close(struct inode *i struct tun_file *tfile = file->private_data; tun_detach(tfile, true); - ptr_ring_cleanup(&tfile->tx_ring, tun_ptr_free); return 0; }