From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF0141B12C9; Tue, 3 Sep 2024 12:06:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725365169; cv=none; b=dN+LVu1Rr2dlbOMLLvP9PjfdFo/r79wOIKfmucFmTA8jTjj1ZHD2288iYeMBbmNI+q1xOVBoT3iaTwV5smSKI9gi2Z3AnWAf7D3do8JrzuiTJSG14tRluqPxI+ooog+uxWBTSSh63MB76AhMP3HZbZPP3wQFF2cX1JOPcsEIsYk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725365169; c=relaxed/simple; bh=6ns+CNOslyrIe4px7RaNrndB3EuzN63fKkYymGYsRLg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=HnLOVtfClsU8QJIJf75TDjq3AicgUSHHtKS5u0Pn9VJFxtJBKuMZRNb9r7Abjt1t+IRfR0rvX++kqqSsgHa1veK5PZ8TWTfzXXjzfBt2Bzj78gFZBfZRNs5QTukEnt6XED5tgt0S7jpDH4iKLPPpeJGt0tdHt4RPlRlvrwoNRXg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jR3vbKun; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="jR3vbKun" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DECDC4CEC4; Tue, 3 Sep 2024 12:06:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1725365168; bh=6ns+CNOslyrIe4px7RaNrndB3EuzN63fKkYymGYsRLg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jR3vbKunal6cgH6N4GUoVpVE+d9fqBrwEAKXcvtkoJy8NI1F5A9Ir2HDjnQX0GTg8 z4bjGYF0ZTWXgdsN7JWzZE1nCz7qDNJg6PJVHdAl0CUT9U8jucXhoEDgsTlCA3B4/L lSl25O/fmrahGfY7IdqmdPBrehiZ7WArFGm5CBvQ= Date: Tue, 3 Sep 2024 14:06:05 +0200 From: "gregkh@linuxfoundation.org" To: =?utf-8?B?6IOh6L+e5Yuk?= Cc: Michael Nazzareno Trimarchi , Prashanth K , "quic_jjohnson@quicinc.com" , "linux-usb@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "opensource.kernel" , "akpm@linux-foundation.org" Subject: Re: =?utf-8?B?562U5aSNOiBbUEFUQ0ggdjldIHVz?= =?utf-8?Q?b=3A_gadget=3A_u=5Fserial=3A_Ad?= =?utf-8?Q?d?= null pointer check in gs_read_complete & gs_write_complete Message-ID: <2024090346-bottling-mashing-e84e@gregkh> References: <2024090338-nutlike-oxymoron-90f0@gregkh> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Tue, Sep 03, 2024 at 11:58:37AM +0000, 胡连勤 wrote: > Hello linux community expert: > > >> From: Lianqin Hu > >> > >> Considering that in some extreme cases, when the unbind operation is > >> being executed, gserial_disconnect has already cleared gser->ioport, > >> triggering a gadget reconfiguration at this time and gs_read_complete > >> gets called afterwards, which results in accessing null pointer, add a > >> null pointer check to prevent this situation. > >> > >> Added a static spinlock to prevent gser->ioport from becoming null > >> after the newly added check. > > >In looking at this further, shouldn't we just be moving around where we call usb_ep_disable() in gserial_disconnect()? > > >Can't we shut down the endpoints _BEFORE_ we set the port structures to NULL? After the endpoints are stopped, then we know that there is no outstanding i/o possible and then we can clean up properly? > > >Not to say that your change doesn't fix the race condition here, but cleaning up things in the proper order might be the better way as then there can not be any race conditions at all? > > >Have you tried that? > > Thank you for your guidance, we studied and tried. I'm confused, you tried what and what happened? greg k-h