Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2231846ybc; Wed, 20 Nov 2019 10:50:37 -0800 (PST) X-Google-Smtp-Source: APXvYqzt4O1ZPuDlAIQZdiMH/n6ICCiDRQEdCL4oiNmRoCobMRN8LuFP716VXgCIkzeOxel+BSHX X-Received: by 2002:a05:600c:2945:: with SMTP id n5mr5511858wmd.80.1574275837391; Wed, 20 Nov 2019 10:50:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574275837; cv=none; d=google.com; s=arc-20160816; b=Pf7mhE2DV3sq09Q1VuQAkiDbZOAeEQ/PPiCpbt+xRCwE+/hI66J31wGyouLdjA/4cP bxDON50juq70H98wuZZmRHG42qsCrpI5gE9FMR4BQMElJHBk+IJNP37o+Rrl6aWzfod2 KxDAAD26D0hUhLaQx6ZGr63Aj8/KicsDwDOMHce4b4rf8ZMl1thUsJnNWUQyUozWKmx1 EF1JXpTalL059fG/bSqCnPYLI7VxymGVxzkGdSMsyG08shRuGwkTXM4euYojUBIpc1Eo AqjnlEXePIWCIoawVTkz4KjEID/Di6zwupBlXn9qQv6j/ezoeuIT8EVVydfNjgddUiRT 6pDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to :subject:cc:to:from:date; bh=qXK7Nlzkv35+QhoqBJUrvck+JGpl4qcMwv+UgSGCkoc=; b=yTq5uVtxi2ilOICLX17ncL/Rf+/mDQAd1vi8y87BdB1af383jsCEJIpZFeqTh19PKy 1+v8v2t7QBPZt3TDLx2ggQJEqd6ZcYL689VzocsE5cW1TXB3nfHb/6UaFSw6TolmEYbA ikWX3eHzw6jZJZ5CDC29IbcyQwdnnuwvetTABFahmc42s4/820Szmuv8HMs4LyoDBfOb t2OqUzRZtNO2ckTk6bqh+o8PMqzQlo0Qj4IxQIZIMSYSN6ZnrUbEbdo1jUGA4S2rIbA8 Vj96FAUo2bNAFLa75x7UkK1Z/+Zh64GpPHhqSbc6xFCekLiVthz3QVF+MKjqCEg+YkLL GE3w== 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 x50si225075eda.155.2019.11.20.10.50.12; Wed, 20 Nov 2019 10:50:37 -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 S1726685AbfKTSrB (ORCPT + 99 others); Wed, 20 Nov 2019 13:47:01 -0500 Received: from iolanthe.rowland.org ([192.131.102.54]:35010 "HELO iolanthe.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1726023AbfKTSrB (ORCPT ); Wed, 20 Nov 2019 13:47:01 -0500 Received: (qmail 4620 invoked by uid 2102); 20 Nov 2019 13:47:00 -0500 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 20 Nov 2019 13:47:00 -0500 Date: Wed, 20 Nov 2019 13:47:00 -0500 (EST) From: Alan Stern X-X-Sender: stern@iolanthe.rowland.org To: Pete Zaitcev cc: syzbot , , , , , , Kernel development list , USB list , , , Subject: Re: possible deadlock in mon_bin_vma_fault In-Reply-To: <20191120111235.7d306f23@suzdal.zaitcev.lan> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 20 Nov 2019, Pete Zaitcev wrote: > On Wed, 20 Nov 2019 11:14:05 -0500 (EST) > Alan Stern wrote: > > > As it happens, I spent a little time investigating this bug report just > > yesterday. It seems to me that the easiest fix would be to disallow > > resizing the buffer while it is mapped by any users. (Besides, > > allowing that seems like a bad idea in any case.) > > > > Pete, does that seem reasonable to you? > > Yes, it does seem reasonable. > > I think I understand it now. My fallacy was thinking that since everything > is nailed down as long as fetch_lock is held, it was okay to grab whatever > page from our pagemap. What happens later is an attempt to get pages of the > new buffer while looking at them through the old VMA, in mon_bin_vma_fault. > > It seems to me that the use counter, mmap_active, is correct and sufficient > to check in the ioctl. > > -- Pete > > P.S. One thing that vaguely bothers me on this is that the bot > bisected to the commit that clearly fixed worse issues. > > P.P.S. Like this? > > diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c > index ac2b4fcc265f..e27d99606adb 100644 > --- a/drivers/usb/mon/mon_bin.c > +++ b/drivers/usb/mon/mon_bin.c > @@ -1020,6 +1020,9 @@ static long mon_bin_ioctl(struct file *file, unsigned int cmd, unsigned long arg > int size; > struct mon_pgmap *vec; > > + if (rp->mmap_active) > + return -EBUSY; > + > if (arg < BUFF_MIN || arg > BUFF_MAX) > return -EINVAL; Like that, yes, but the test has to be made while fetch_lock is held. Otherwise there's still a race: One thread could pass the test and then do the resize, and in between another thread could map the buffer and incur a fault. Incidentally, the comment for fetch_lock says that it protects b_read and b_out, but mon_bin_vma_fault doesn't use either of those fields. Alan Stern