Received: by 10.223.185.116 with SMTP id b49csp5494229wrg; Wed, 7 Mar 2018 12:45:48 -0800 (PST) X-Google-Smtp-Source: AG47ELvGffdgBfyxpcomqa1fnACkHY6PUls0Z+yD3/b+8NSxoVM8LZioMVHCB5rbRnyLs4KxK7WL X-Received: by 2002:a17:902:bc81:: with SMTP id bb1-v6mr6380755plb.425.1520455548670; Wed, 07 Mar 2018 12:45:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520455548; cv=none; d=google.com; s=arc-20160816; b=GD+kBV3J3SeaXwsc+q/sAxwWfJ9egT402iRhcecga7SIdMIOf0gbtrz9t+18bAH+/k TyFfhEWnwsHMME142Ma5LKSSgFrw04yDIAZkZLy/jtcUfEKwVzAL3v1TbdB/obiTJZLo oBc5kvbzj4/bircKd6XEVKWEsJapYLunMDyHsHeJDeP16FGixsbFRC2Hq22l4kwHhLc/ Mcno8n1oJQwRzW2QZ8w/DpcKUdwHJ9kiO7ThVhki2j3y4SxAj6Ghilcz4GrJ3wQsBVED o/LnaEpCqY7e9jOOM3/LtlsAsRB/raT6yTcKsDXR9G+NUnQwvhEzurR7D/RX3TszFYBL +MUA== 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 :arc-authentication-results; bh=VQNq1zY/n++sqR68R0m21fokcmvqZc7M8DqtSATStX0=; b=KxHTB7UkLqYtE3m/86Jy8bJWtOMH/o74zfCbuQsMvsAvKVtcNOJwlnAEXFGFx/7LYL DmJ2nNw+nLlX7vXSrqjcqrbsA835NxKKZUW1droGxHykU7ENeA6H+zGtHvBRAVAZv7Lv DadAtMmuH8EC6H8QOwWvJ0ASp2IMuRLx8JdXTxABscXMJPrgg9KJe0ekjQ7CTMLoEJTD OLOWpImrRxn+unprhgzdqh58Zbc/zYF17klfO8gYXwaOaxgPBSMZtrXzBsAlyag0JDLU q7bWCShQMVDLzBZ6jPGxHB3mAblYuiipfo0mIFgtfy+QSd1DB0MqmWE67dyUu+VmgBa9 cZmg== ARC-Authentication-Results: i=1; mx.google.com; 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 t8si11795877pgc.273.2018.03.07.12.45.33; Wed, 07 Mar 2018 12:45:48 -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; 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 S1754500AbeCGTlR (ORCPT + 99 others); Wed, 7 Mar 2018 14:41:17 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:40974 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934564AbeCGTlO (ORCPT ); Wed, 7 Mar 2018 14:41:14 -0500 Received: from localhost (unknown [185.236.200.248]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 4916BFD6; Wed, 7 Mar 2018 19:41:14 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Guillaume Nault , "David S. Miller" Subject: [PATCH 4.15 049/122] ppp: prevent unregistered channels from connecting to PPP units Date: Wed, 7 Mar 2018 11:37:41 -0800 Message-Id: <20180307191736.110010631@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180307191729.190879024@linuxfoundation.org> References: <20180307191729.190879024@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.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Guillaume Nault [ Upstream commit 77f840e3e5f09c6d7d727e85e6e08276dd813d11 ] PPP units don't hold any reference on the channels connected to it. It is the channel's responsibility to ensure that it disconnects from its unit before being destroyed. In practice, this is ensured by ppp_unregister_channel() disconnecting the channel from the unit before dropping a reference on the channel. However, it is possible for an unregistered channel to connect to a PPP unit: register a channel with ppp_register_net_channel(), attach a /dev/ppp file to it with ioctl(PPPIOCATTCHAN), unregister the channel with ppp_unregister_channel() and finally connect the /dev/ppp file to a PPP unit with ioctl(PPPIOCCONNECT). Once in this situation, the channel is only held by the /dev/ppp file, which can be released at anytime and free the channel without letting the parent PPP unit know. Then the ppp structure ends up with dangling pointers in its ->channels list. Prevent this scenario by forbidding unregistered channels from connecting to PPP units. This maintains the code logic by keeping ppp_unregister_channel() responsible from disconnecting the channel if necessary and avoids modification on the reference counting mechanism. This issue seems to predate git history (successfully reproduced on Linux 2.6.26 and earlier PPP commits are unrelated). Signed-off-by: Guillaume Nault Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ppp/ppp_generic.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/drivers/net/ppp/ppp_generic.c +++ b/drivers/net/ppp/ppp_generic.c @@ -3161,6 +3161,15 @@ ppp_connect_channel(struct channel *pch, goto outl; ppp_lock(ppp); + spin_lock_bh(&pch->downl); + if (!pch->chan) { + /* Don't connect unregistered channels */ + spin_unlock_bh(&pch->downl); + ppp_unlock(ppp); + ret = -ENOTCONN; + goto outl; + } + spin_unlock_bh(&pch->downl); if (pch->file.hdrlen > ppp->file.hdrlen) ppp->file.hdrlen = pch->file.hdrlen; hdrlen = pch->file.hdrlen + 2; /* for protocol bytes */