Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp840490imm; Wed, 23 May 2018 06:26:58 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpK4wYI6q23hdiFgTR7/wc5y9JYfgjvAxd/Pc50HBo9Ri8DHPaHNJoJE56gRJxIymoLhgCs X-Received: by 2002:a63:7317:: with SMTP id o23-v6mr2415086pgc.59.1527082018859; Wed, 23 May 2018 06:26:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527082018; cv=none; d=google.com; s=arc-20160816; b=OTIN2dFLtP1whCFr+UOxD29eH/EKIhmxwDNr3gr8UhzPN1KR0PMr9Hnl/+B6MiQ0Sg Layg8LGJNyzmfya+Adbo7NsQ5IgjeqjtFYAn1oKbNKE0CTonN5aB8KNTM2ttF9gMWme+ QJb5//RxJRHUtLySFV7MeBHJfoSNAMXSDkL74TIMETcd3wmQhpMGEOtaChSsUHJ6EXtS 3guVmZwTReqLFrSssaNryeTuUhPa/dsvfOqheRUyhpYHv1fAqdpk4Gk6Zzs8XI/eGpDe TtR1INKFUSkA0XMeboGKqo9B3Vwp10yenJRkS1MBIClRcMiKP/oguDinrmHHOovlEaqU cEQg== 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=32OMld0D8cqKP4kvzwMP0MIgRy0Xp5beMAyJLq+gG/0=; b=Qpd5RgdtpzAJy0NF3oZTHhesptSvLaHdC6W13X/9BFu/F/tExvC5s8J7xWZz1QMscJ ymolVLg6qtVSLKbUMNyNeE6d/99FXD+fVztRf5OKC2OCbFjRiIMVNEHcEym17miuF/hQ uiS7kuQRgJ+MUEJnEMSFOrLBKP5HpsWz0ylsYGVqt7G9GnRXg+pZevXxuaOfC8ivjQ5I MBGsmcfwONeDiI7O49J+K22jKN97xoKfq6aB1J7TS2IRt6g/MuGZMklKLH31SCl3ZDLj bxXjgrHtaHfCcVoBF19xbpNFhkaLjj4iGcmsgCHaFFI1D6Aodr1ysemu8MFxSryY+knB Bmog== 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 f5-v6si18732872pfb.314.2018.05.23.06.26.43; Wed, 23 May 2018 06:26:58 -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 S933048AbeEWN00 (ORCPT + 99 others); Wed, 23 May 2018 09:26:26 -0400 Received: from zimbra.alphalink.fr ([217.15.80.77]:41561 "EHLO zimbra.alphalink.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932845AbeEWN0W (ORCPT ); Wed, 23 May 2018 09:26:22 -0400 Received: from localhost (localhost [127.0.0.1]) by mail-2-cbv2.admin.alphalink.fr (Postfix) with ESMTP id 7245E2B52071; Wed, 23 May 2018 15:26:20 +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 2dMEqIFyMO_a; Wed, 23 May 2018 15:26:19 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail-2-cbv2.admin.alphalink.fr (Postfix) with ESMTP id 0179D2B520C7; Wed, 23 May 2018 15:26:18 +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 qSq1_rrqPCmf; Wed, 23 May 2018 15:26:18 +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 AE4362B52071; Wed, 23 May 2018 15:26:18 +0200 (CEST) Received: by c-dev-0.admin.alphalink.fr (Postfix, from userid 1000) id 782626014B; Wed, 23 May 2018 15:26:18 +0200 (CEST) Date: Wed, 23 May 2018 15:26:18 +0200 From: Guillaume Nault To: Eric Biggers Cc: linux-ppp@vger.kernel.org, Paul Mackerras , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, syzbot , viro@zeniv.linux.org.uk Subject: Re: KASAN: use-after-free Read in remove_wait_queue (2) Message-ID: <20180523132618.GA1569@alphalink.fr> References: <20180514061155.GL677@sol.localdomain> <20180518160223.GF1534@alphalink.fr> <20180523032958.GE658@sol.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180523032958.GE658@sol.localdomain> 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:29:58PM -0700, Eric Biggers wrote: > On Fri, May 18, 2018 at 06:02:23PM +0200, Guillaume Nault wrote: > > On Sun, May 13, 2018 at 11:11:55PM -0700, Eric Biggers wrote: > > > [+ppp list and maintainer] > > > > > > This is a bug in ppp_generic.c; it still happens on Linus' tree and it's easily > > > reproducible, see program below. The bug is that the PPPIOCDETACH ioctl doesn't > > > consider that the file can still be attached to epoll instances even when > > > ->f_count == 1. > > > > Right. What would it take to remove the file for the epoll instances? > > Sorry for the naive question, but I'm not familiar with VFS and didn't > > find a helper function we could call. > > > > There is eventpoll_release_file(), but it's not exported to modules. It might > work to call it, but it seems like a hack. > > > > Also, the reproducer doesn't test this but I think ppp_poll(), > > > ppp_read(), and ppp_write() can all race with PPPIOCDETACH, causing > > > use-after-frees as well. > > > > I also believe so. ppp_release() resets ->private_data, and even though > > functions like ppp_read() test ->private_data before executing, there's > > no synchronisation mechanism to ensure that the update is visible > > before the unit or channel is destroyed. Is that the kind of race you > > had in mind? > > Yes, though after looking into it more I *think* these additional races aren't > actually possible, due to the 'f_count < 2' check. These races could only > happen with a shared fd table, but in that case fdget() would increment f_count > for the duration of each operation, resulting in 'f_count >= 2' if both ioctl() > and something else is running on the same file concurrently. > > Note that this also means PPPIOCDETACH doesn't work at all if called from a > multithreaded application... > > > > > > Any chance that PPPIOCDETACH can simply be removed, > > > given that it's apparently been "deprecated" for 16 years? > > > Does anyone use it? > > > > The only users I'm aware of are pppd versions older than ppp-2.4.2 > > (released in November 2003). But even at that time, there were issues > > with PPPIOCDETACH as pppd didn't seem to react properly when this call > > failed. An Internet search on the "PPPIOCDETACH file->f_count=" kernel > > log string, or on the "Couldn't release PPP unit: Invalid argument" > > error message of pppd, returns several related bug reports. > > > > Originally, PPPIOCDETACH never failed, but testing ->f_count was > > later introduced to fix crashes when the file descriptor had been > > duplicated. It seems that this was motivated by polling issues too. > > > > Long story short, it looks like PPPIOCDETACH never has worked well > > and we have at least two more bugs to fix. Given how it has proven > > fragile, I wouldn't be surprised if there were even more lurking > > around. I'd say that it's probably safer to drop it than to add more > > workarounds and playing wack-a-mole with those bugs. > > IMO, if we can get away with removing it without any users noticing, that would > be much better than trying to fix it with a VFS-level hack, and probably missing > some cases. I'll send a patch to get things started... > Yes, I fully agree. That looks much safer, and given the track record of this ioctl I very much doubt anyone would depend on it.