Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp877253imm; Wed, 23 May 2018 06:59:30 -0700 (PDT) X-Google-Smtp-Source: AB8JxZomFuvjE6PcXJuaKd6HAfFyJvTWiMycxs1p0cCFBxO9UzqkrRYD9jSrZxwFT1LGzoD7Q2OG X-Received: by 2002:a63:42c4:: with SMTP id p187-v6mr2485206pga.345.1527083970146; Wed, 23 May 2018 06:59:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527083970; cv=none; d=google.com; s=arc-20160816; b=qH65RGS0zksffBv54CILFlhDaxMZlpQbTf0vxZMfjneuMTHH12rdh3uPw19FgOoHyj mTnTZ6093DH/FC9xfOG82vrPyL0ZS7G8tzHAEXNKenGcblCEC6DZa5zHw1mt+nTTyXAi 7E3kdFYJvnRs+BJ3wWgfey7XaiUQgLocCM2nLhsQGytjGdmeLKt4riAB6vc235sh9S0E MaodHuXUTgNUNn/CGbupu0+r/Q//Urg5pgNfVC9fNH4aG7SCx78/uyLz9EQYnqP87B5f dbz3hsBc58x+Sl82HCKtCaBWq5YfdhEa4IAlk7yQ7BVQOXtlwZHwQj30BNYO8aNXSJBP jmhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=FcM58weWeFXkVfE43yv6oyCqT4d/p56XmCMIw7ayIIw=; b=WaDE4tYhsOvc58/anznaX4JLoKA1jwZ9nptui6A/E89gMZkvMiAzM19ItLi1cxbpsQ KJnf3z5DCMBKlMN09Ro6VHSaHKLeWdBZ6Rfw1GT8t9CmjMl8Z3X+8z8OtCs3rmPW5Sjd emvy4oAqCmXo/xDVohpqrLpFmhtYp7tNpdkOvuxNyb15ChYrdNkdDo6HI4uwaG3/JRBc ToQ6OtP5PZbErTb/ewzaH7aqs/Zy35eq2wB5Y4dzIYHwOTljqPr539gTjLJfT/QdFm0T 7H7UkmpE/GRULbHjQZeg1YiVZzZKZHW5HH9gpQapsDTcOAMhQ4TBCDXEJEASRYPlZ4Ca Z4ew== 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 r2-v6si14798092pgq.157.2018.05.23.06.59.15; Wed, 23 May 2018 06:59:30 -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; 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 S933240AbeEWN5P (ORCPT + 99 others); Wed, 23 May 2018 09:57:15 -0400 Received: from zimbra.alphalink.fr ([217.15.80.77]:45379 "EHLO zimbra.alphalink.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932900AbeEWN5N (ORCPT ); Wed, 23 May 2018 09:57:13 -0400 Received: from localhost (localhost [127.0.0.1]) by mail-2-cbv2.admin.alphalink.fr (Postfix) with ESMTP id EE26A2B52071; Wed, 23 May 2018 15:57:11 +0200 (CEST) Received: from zimbra.alphalink.fr ([127.0.0.1]) by localhost (mail-2-cbv2.admin.alphalink.fr [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id UmJ9aCgIrLo0; Wed, 23 May 2018 15:57:09 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail-2-cbv2.admin.alphalink.fr (Postfix) with ESMTP id 01FE22B520B3; Wed, 23 May 2018 15:57:09 +0200 (CEST) X-Virus-Scanned: amavisd-new at mail-2-cbv2.admin.alphalink.fr Received: from zimbra.alphalink.fr ([127.0.0.1]) by localhost (mail-2-cbv2.admin.alphalink.fr [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ZaaJtYxBzyPx; Wed, 23 May 2018 15:57:08 +0200 (CEST) Received: from c-dev-0.admin.alphalink.fr (94-84-15-217.reverse.alphalink.fr [217.15.84.94]) by mail-2-cbv2.admin.alphalink.fr (Postfix) with ESMTP id BEC772B52071; Wed, 23 May 2018 15:57:08 +0200 (CEST) Received: by c-dev-0.admin.alphalink.fr (Postfix, from userid 1000) id 947DC6014B; Wed, 23 May 2018 15:57:08 +0200 (CEST) Date: Wed, 23 May 2018 15:57:08 +0200 From: Guillaume Nault To: Eric Biggers Cc: linux-ppp@vger.kernel.org, Paul Mackerras , netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, Eric Biggers Subject: Re: [PATCH] ppp: remove the PPPIOCDETACH ioctl Message-ID: <20180523135708.GB1569@alphalink.fr> References: <20180523032958.GE658@sol.localdomain> <20180523035952.25768-1-ebiggers3@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180523035952.25768-1-ebiggers3@gmail.com> User-Agent: Mutt/1.9.5 (2018-04-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 22, 2018 at 08:59:52PM -0700, Eric Biggers wrote: > From: Eric Biggers > > The PPPIOCDETACH ioctl effectively tries to "close" the given ppp file > before f_count has reached 0, which is fundamentally a bad idea. It > does check 'f_count < 2', which excludes concurrent operations on the > file since they would only be possible with a shared fd table, in which > case each fdget() would take a file reference. However, it fails to > account for the fact that even with 'f_count == 1' the file can still be > linked into epoll instances. As reported by syzbot, this can trivially > be used to cause a use-after-free. > > Yet, the only known user of PPPIOCDETACH is pppd versions older than > ppp-2.4.2, which was released almost 15 years ago (November 2003). > Also, PPPIOCDETACH apparently stopped working reliably at around the > same time, when the f_count check was added to the kernel, e.g. see > https://lkml.org/lkml/2002/12/31/83. Also, the current 'f_count < 2' > check makes PPPIOCDETACH only work in single-threaded applications; it > always fails if called from a multithreaded application. > > All pppd versions released in the last 15 years just close() the file > descriptor instead. > > Therefore, instead of hacking around this bug by exporting epoll > internals to modules, and probably missing other related bugs, just > remove the PPPIOCDETACH ioctl and see if anyone actually notices. > > Reported-by: syzbot+16363c99d4134717c05b@syzkaller.appspotmail.com > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") > Cc: stable@vger.kernel.org > Signed-off-by: Eric Biggers > --- > Documentation/networking/ppp_generic.txt | 6 ----- > drivers/net/ppp/ppp_generic.c | 29 ------------------------ > fs/compat_ioctl.c | 1 - > include/uapi/linux/ppp-ioctl.h | 1 - > 4 files changed, 37 deletions(-) > > diff --git a/Documentation/networking/ppp_generic.txt b/Documentation/networking/ppp_generic.txt > index 091d20273dcb..61daf4b39600 100644 > --- a/Documentation/networking/ppp_generic.txt > +++ b/Documentation/networking/ppp_generic.txt > @@ -300,12 +300,6 @@ unattached instance are: > The ioctl calls available on an instance of /dev/ppp attached to a > channel are: > > -* PPPIOCDETACH detaches the instance from the channel. This ioctl is > - deprecated since the same effect can be achieved by closing the > - instance. In order to prevent possible races this ioctl will fail > - with an EINVAL error if more than one file descriptor refers to this > - instance (i.e. as a result of dup(), dup2() or fork()). > - > * PPPIOCCONNECT connects this channel to a PPP interface. The > argument should point to an int containing the interface unit > number. It will return an EINVAL error if the channel is already > diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c > index dc7c7ec43202..dce8812fe802 100644 > --- a/drivers/net/ppp/ppp_generic.c > +++ b/drivers/net/ppp/ppp_generic.c > @@ -603,35 +603,6 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg) > goto out; > } > > - if (cmd == PPPIOCDETACH) { > - /* > - * We have to be careful here... if the file descriptor > - * has been dup'd, we could have another process in the > - * middle of a poll using the same file *, so we had > - * better not free the interface data structures - > - * instead we fail the ioctl. Even in this case, we > - * shut down the interface if we are the owner of it. > - * Actually, we should get rid of PPPIOCDETACH, userland > - * (i.e. pppd) could achieve the same effect by closing > - * this fd and reopening /dev/ppp. > - */ > - err = -EINVAL; > - if (pf->kind == INTERFACE) { > - ppp = PF_TO_PPP(pf); > - rtnl_lock(); > - if (file == ppp->owner) > - unregister_netdevice(ppp->dev); > - rtnl_unlock(); > - } > - if (atomic_long_read(&file->f_count) < 2) { > - ppp_release(NULL, file); > - err = 0; > - } else > - pr_warn("PPPIOCDETACH file->f_count=%ld\n", > - atomic_long_read(&file->f_count)); > - goto out; > - } > - I'd rather add + if (cmd == PPPIOCDETACH) { + err = -EINVAL; + goto out; + } Making PPPIOCDETACH unknown to ppp_generic means that the ioctl would be handled by the underlying channel when pf->kind == CHANNEL (see the chan->ops->ioctl() call further down). That shouldn't be a problem per se, but even though PPPIOCDETACH is unsupported, I feel that it should remain a ppp_generic thing. I don't really want its value to be reused for other purposes in the future or have different behaviour depending on the underlying channel. Also PPPIOCDETACH can already fail with -EINVAL. Therefore, if ever there really were programs out there using this call, they'd already have to handle this case. Unconditionally returning -EINVAL would further minimise possibilities for breakage.