Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp344951imm; Tue, 22 May 2018 20:30:37 -0700 (PDT) X-Google-Smtp-Source: AB8JxZou5LF0gvRmvWFT2Qv7I5anIAyTeK+DsLOCX5TaMBoDBi7j1cia6fx9WG46kG0CbE/JpS+Z X-Received: by 2002:a62:d605:: with SMTP id r5-v6mr1157804pfg.8.1527046237066; Tue, 22 May 2018 20:30:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527046237; cv=none; d=google.com; s=arc-20160816; b=PUkEwoR4gdgaw690i0F2FkfSZ5HQx/DIoOLB7GpnYQaMFQQUIhN9vYWFCZkESZqQXm Vj6oZTI4FuyNXha7H3na0hWpiHfCMfJwCa/cd9DMxLEgPKjZHPbdsKsxzZFTWv3Zhx5y owYaFMQcfdBe/FStBh1EZCgwdlsC1r2jDsTf1pYb8qjU/UYd4W8guoJp5ufC03WVU7DO uJJtic0ZCbr11VOPEggdWB++LGfEdldVTgUi6+cjUBIzq+BESKKBfgZzAEIm3OBM8M6p lmTDgjRER3ZyJ8Rs9ctsV30vF3p4+mVJXY95EEHn+H7o6KW6yXzNOvskggBNOfSORFKR fcjQ== 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:dkim-signature:arc-authentication-results; bh=Tz5fczG3yoMQWbwoz486W0YY5kfE7eCV8RFG8Nb3Lig=; b=Au/aMAtLIJaQ+MOu5z4g+Os3EBds+Z9reDlq1cdejQvzcKlDyMEYEBP7T3geiCu0KL WxLYF19CsSrLqLVsyyuBkBhjTqO/r33c9kaXjL0q9jmvxDOBxljQ/1OQySgi1Y5OJjsX OgYDK6D+26yG0lVKpZvXs49JFzIpqhKicmECB5TXcJBkerYIadINxZpNGKOG1qr8gJeh wBf2N41d4pDWS/aPf0w/K9CKNMfcDtjh1MuNAr+z9yWmNUgT81ZdwCFfpcWsw2UrsucP ls58YfX0af+HfCsYVzTVbZjN7qDPn8bMD1KlTI1ZG2xG93VZHMSPEggWdAWKPnUi7F3f 1vog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HM7gwuA1; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m14-v6si14244927pgs.178.2018.05.22.20.30.12; Tue, 22 May 2018 20:30:37 -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=@gmail.com header.s=20161025 header.b=HM7gwuA1; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753850AbeEWDaD (ORCPT + 99 others); Tue, 22 May 2018 23:30:03 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:40813 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753520AbeEWDaB (ORCPT ); Tue, 22 May 2018 23:30:01 -0400 Received: by mail-pg0-f68.google.com with SMTP id l2-v6so8754150pgc.7; Tue, 22 May 2018 20:30:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Tz5fczG3yoMQWbwoz486W0YY5kfE7eCV8RFG8Nb3Lig=; b=HM7gwuA1IVPyfAj1JRr5s9p/eAz6Y+FQ6s1Lk+/ntMg7JyYFXsQU4fblRwe3QQPY7E fF2XieiiFb5mtTPb4JBAhO9cXOa2eAiXcdqclVsrYhl7L+E+9uLZMNw3A5Y7b/fG3jDp 9kVI0bk9g1JqfGB0G6yw4ms9Q+HY+qOTayVc3d+PkyPKY5/t8zF/c0IVVzNrW3gWwbt6 TOZ7Z/oek8hMc1JtBeFK6WUvogr3CZ8CRS5kXy44ShaSEZTpBfTjAfBPTAVRRLT2hBA1 GKqY4Eaw3bWtltEBCYVdfQCQuqwsCOdRajXW1sLwwgr269HPSVaz09VHZw90/3BuWIwJ Ht7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Tz5fczG3yoMQWbwoz486W0YY5kfE7eCV8RFG8Nb3Lig=; b=IvwzR04OK3pP4wFNCvZNaARD/KQR+jMPql2ktDmpd9M8iXB5iJzXmk1htJZLBMCNOF fOB7rDpwWCIjf1S0dHdaqAGALXvnajrPGcuZzFc+FXRJN2E5yMgcbShMa979sufQHTKK fNXvQfqimakydXsEMF/L1qMA7fnkegSw57xKK1s6C3mUzOPUYRwm00NOZQOFPeRe1pIB 4UdR1Xft0G96vrEeeaMF4ZhoXPHgSCjPYAldmj4pqWGeOHWfn4KuJFlW17zFu5OkI50+ kX5dv7afXdDhwBA9vnnxm9zm3ynJn4u00SMNZ44xto1O4EBSeBNZqMG8ZL0ZcpnO8HI4 5sjg== X-Gm-Message-State: ALKqPweZ21wtA/uyJOZ3tMiKQml76xN+8JxKb0KJfA9pt9xsBwgZWHxR PKIZe70BgiWtHmN42e/1WpQ= X-Received: by 2002:a63:384d:: with SMTP id h13-v6mr893283pgn.209.1527046200621; Tue, 22 May 2018 20:30:00 -0700 (PDT) Received: from sol.localdomain (c-67-185-97-198.hsd1.wa.comcast.net. [67.185.97.198]) by smtp.gmail.com with ESMTPSA id n67-v6sm45832283pfh.188.2018.05.22.20.29.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 May 2018 20:29:59 -0700 (PDT) Date: Tue, 22 May 2018 20:29:58 -0700 From: Eric Biggers To: Guillaume Nault 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: <20180523032958.GE658@sol.localdomain> References: <20180514061155.GL677@sol.localdomain> <20180518160223.GF1534@alphalink.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180518160223.GF1534@alphalink.fr> 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 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... - Eric