Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1986788ybz; Thu, 23 Apr 2020 09:33:40 -0700 (PDT) X-Google-Smtp-Source: APiQypJJy8u4n/E4BAKfma2pOjovo9lTxQtZOIGNMlmLQB+LVCq1fz7hQC+cZ60H6oCbHzJylxiO X-Received: by 2002:a17:906:4a4e:: with SMTP id a14mr3422129ejv.363.1587659620484; Thu, 23 Apr 2020 09:33:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587659620; cv=none; d=google.com; s=arc-20160816; b=Ak/JTvt2u72v2TAb/XmKVq8QFXwbkYGGJPQxWFvsmlta7NLiTE58TbHu7hdtxU2xbG TV+eiWE1m0tzzwEFW4MMHu9wkLgTir65zMRUWw/vwrtgrJ5NX8znellGp3dREx0S0mT9 7AJW46u0AuALTezRpX9A7Og6BCqVWv1rNQ8vwT6nULi8DAAIKc33D/40dhcL5hwrvEgR pUbS3GZ6JT/mpXWIzL75DEDSZrUaZDEKMOXfRIYMPKRIIomNZ/eTqh2HOD5Ffj0YiANd R0LY7KpM9XrpeZ/yMEvBsHJ5LdprdsZ5hCgyszgzPP0cyQqGieV+qptkvD7FeMTuq33r qOUw== 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=plZuIcPkE8H1rb4sDjL2y/MR30Q1hhJfkvpQN5ALmvM=; b=KA+9ZF9KLG2DtHrd+qhXE5inPvDo1sgUH8f1cSHk9gy5yce57e+BAgPQ8RBCThgy2P vuTkiWKVUCGPQb/+CcWukjzP4FVP9cynZaY5sY70AEP8yER72lad/0EuNBTztRXxYmUH 3qgS8xDOTcihCWY3dlQdY4VbcnNWqsBNmAncgX+OFMNLoelCuU/Y/ULwul4XCAeuXKoW WFx1x4iuZikMJR50mop7GGmVeK8JLSANfNUV0i8qSsduXEQ8Cfrl1MHFFW2j/88Tqaqy TxcB+trEpOr74A/J3Lo/hHuww6Z3Fu4TYpi1NVIKR1li6KGjIZgQCwOwi3udvBa24k4R 2Vjg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d4si1051309edy.155.2020.04.23.09.33.17; Thu, 23 Apr 2020 09:33:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729698AbgDWQ3S (ORCPT + 99 others); Thu, 23 Apr 2020 12:29:18 -0400 Received: from netrider.rowland.org ([192.131.102.5]:39929 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1729527AbgDWQ3R (ORCPT ); Thu, 23 Apr 2020 12:29:17 -0400 Received: (qmail 1763 invoked by uid 500); 23 Apr 2020 12:29:15 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 23 Apr 2020 12:29:15 -0400 Date: Thu, 23 Apr 2020 12:29:15 -0400 (EDT) From: Alan Stern X-X-Sender: stern@netrider.rowland.org To: Oliver Neukum cc: Pete Zaitcev , Hillf Danton , syzbot , , , , , Subject: Re: KASAN: use-after-free Read in usblp_bulk_read In-Reply-To: <1587640413.23108.7.camel@suse.com> 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 Thu, 23 Apr 2020, Oliver Neukum wrote: > Am Donnerstag, den 23.04.2020, 00:10 -0500 schrieb Pete Zaitcev: > > > > I do not agree with this kind of workaround. The model we're following > > is for usb_kill_urb() to cancel the transfer. The usblp invokes it > > through usb_kill_anchored_urbs() and usblp_unlink_urbs(), as seen > > above. There can be no timer hitting anything once it returns. > > Right. It seems to me that the problem is not killing an existing > transfer but a failure to check in case of new transfers whether > the device has been disconnected. > > > 1104 is kzalloc for struct usblp. > > > > > > Freed by task 12266: > > > > save_stack+0x1b/0x80 mm/kasan/common.c:72 > > > > set_track mm/kasan/common.c:80 [inline] > > > > kasan_set_free_info mm/kasan/common.c:337 [inline] > > > > __kasan_slab_free+0x117/0x160 mm/kasan/common.c:476 > > > > slab_free_hook mm/slub.c:1444 [inline] > > > > slab_free_freelist_hook mm/slub.c:1477 [inline] > > > > slab_free mm/slub.c:3034 [inline] > > > > kfree+0xd5/0x300 mm/slub.c:3995 > > > > usblp_disconnect.cold+0x24/0x29 drivers/usb/class/usblp.c:1380 > > > > usb_unbind_interface+0x1bd/0x8a0 drivers/usb/core/driver.c:436 > > > > __device_release_driver drivers/base/dd.c:1137 [inline] > > > > device_release_driver_internal+0x42f/0x500 drivers/base/dd.c:1168 > > > > bus_remove_device+0x2eb/0x5a0 drivers/base/bus.c:533 > > > > 1380 is an inlined call to usblp_cleanup, which is just > > a bunch of kfree. > > But that must never happen while while the device is open. > If that ever happens something is wrong with usblp->used. > > > The bug report is still a bug report, but I'm pretty sure the > > culprit is the emulated HCD and/or the gadget layer. Unfortunately, > > I'm not up to speed in that subsystem. Maybe Alan can look at it? > > I doubt it. Operation by a timer triggering a timeout must work. The timer is not the issue. usb_kill_anchored_urbs() waits until all the URBs have completed, and those completions happen when the timer fires. The only suspicious thing I see is that usblp_resume() calls handle_bidir() without first acquiring any mutex. But resume shouldn't race with disconnect. The only other place where read URBs get submitted is under usblp_read(), which does acquire the mutex and checks for disconnection while holding it. So I'm baffled. Alan Stern