Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp443358pxt; Fri, 6 Aug 2021 05:58:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzknNo6QY7HZ42Q4bhqXgOMHD5y7vUvYnWl9aVJlg9QGn+IJWlzj+06DbX27kgysy98H4hs X-Received: by 2002:a6b:8f4a:: with SMTP id r71mr211298iod.12.1628254707894; Fri, 06 Aug 2021 05:58:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628254707; cv=none; d=google.com; s=arc-20160816; b=zbu92OSVE3zqrMimEDLwDHwIWYcodG8/I4ewkYmqGxh5FBRoisgxK5KraZPl45A/Cw aJmpNXqur5yoBVQuKHauuZ5ZoK4nxuLEg6BC2a7BtqPKm6I2I7+8+kX2NtoZal1trVpk H2aH6UEO5o8vX2Nr0/a7/AbprODaCc9nvYwR5TbNF5n0Jo9eE6dXYd0b1U0UAA76TpV2 wKuCLemQgk6YFgQDR/3vR+MRsg0HnBvz39ld0U8OdoeCqBdLlq9xIz5DqEDnN3Qb+Z2G yA7B0gNnd44V+YFyeXOnhZ5FMA0qXwmC6S8Ll28i6fL3Jpj71pfdWgFBRGH2szFy/Lhw jmlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=pnNXV/q+KlLke7tTruTsa9BqRT5sgam+QQANrxmydno=; b=X4/KOqObB8xa/+mbuiQ3x92O098ppl4YHgklwRms1ChWOQfA7FEJSlo0vSAmj4DMlJ qcSEto5Lq0x0RU3zag3gvKI8p1D033rafsGc5pmipgYO4NRSIYN52qn9or8PlHRru9nj Xwovj15Or1/HccfQnw6kgis00lFpcXtObY6SuWl0VHN0rPuHirJmfStdDJnl0DavXUXn dhJJeSRqz2P5uXBnTS40Zq78Thwq3iqszrvERACXiUoyYvxigHryCJ7v0535Wlh1rW9/ 4VX/rAL6sJJiRW2cMmTI7e1K+J8J0Q54V3owqaT/B38Zh9nm1RO8pkY+/Bi2GNspmBPu W+Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ptl5NGtJ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z41si10260335jah.89.2021.08.06.05.58.15; Fri, 06 Aug 2021 05:58:27 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ptl5NGtJ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243364AbhHFINA (ORCPT + 99 others); Fri, 6 Aug 2021 04:13:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:43204 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230384AbhHFINA (ORCPT ); Fri, 6 Aug 2021 04:13:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3489660238; Fri, 6 Aug 2021 08:12:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628237563; bh=6ksPby0Roy9tu9p+osT6wamK/zd65frJk2QyzffxK4s=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ptl5NGtJYH14Rc4q+WTR8UFQNOw7H+R8ogPntlA4v/2hnouqksIexSau3qGJiRGFG canUd3Mv/I+BobAfcxrjxLQQl/oE7tHZAzPvYpn64wYQMiwjQlON3SSHOxzvZM304P e+qVYSAgGBEguhXlpOBc6N977j1U0ln2M2CmHHEw= Date: Fri, 6 Aug 2021 10:12:41 +0200 From: Greg Kroah-Hartman To: Daehwan Jung Cc: Felipe Balbi , "open list:USB GADGET/PERIPHERAL SUBSYSTEM" , open list , taehyun cho Subject: Re: usb: gadget: u_serial: check Null pointer in EP callback Message-ID: References: <1628236406-185160-1-git-send-email-dh10.jung@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1628236406-185160-1-git-send-email-dh10.jung@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 06, 2021 at 04:53:26PM +0900, Daehwan Jung wrote: > From: taehyun cho > > Endpoint complete function in u_serial can be executed > when 'gs_port' is Null. This situation happens when > 'dwc3_gadget_pullup' returns ETIMEDOUT. The reason why > ETIMEDOUT is returned is that whole system is out of order > including interrupt regardless of USB. > > pc : __lock_acquire+0x54/0x5ec > lr : lock_acquire+0xe8/0x198 > sp : ffffffc03914b9d0 > x29: ffffffc03914b9d0 x28: ffffff895f13b680 > x27: 0000000000000000 x26: 0000000000000000 > x25: 00000000000003c8 x24: 0000000000000080 > x23: ffffffc010a8f650 x22: 0000000000000000 > x21: 0000000000000000 x20: 0000000000000000 > x19: ffffffc010a8f650 x18: ffffffc02d70a0b0 > x17: 0000000000000000 x16: 00000000000229e0 > x15: 0000000000000004 x14: 00000000000004f2 > x13: ffffffc0120fe178 x12: 0000000000000003 > x11: 00000000ffffffff x10: 0000000100000001 > x9 : 0000000000000001 x8 : 00000000000003c8 > x7 : 0000000000000000 x6 : ffffffc010a8f650 > x5 : 0000000000000000 x4 : 0000000000000080 > x3 : 0000000000000000 x2 : 0000000000000000 > x1 : 0000000000000000 x0 : 00000000000003c8 > Call trace: > __lock_acquire+0x54/0x5ec > lock_acquire+0xe8/0x198 > _raw_spin_lock+0x70/0x88 > gs_read_complete+0x48/0xac > usb_gadget_giveback_request+0x48/0x80 > dwc3_gadget_giveback+0xcc/0xe8 > dwc3_remove_requests+0xa8/0x188 > __dwc3_gadget_ep_disable+0x98/0x110 > dwc3_gadget_ep_disable+0x50/0xbc > usb_ep_disable+0x44/0x94 > gserial_disconnect+0xc0/0x250 > acm_free_func+0x30/0x48 > usb_put_function+0x34/0x68 > config_usb_cfg_unlink+0xdc/0xf8 > configfs_unlink+0x144/0x264 > vfs_unlink+0x134/0x218 > do_unlinkat+0x13c/0x2a0 > __arm64_sys_unlinkat+0x48/0x60 > el0_svc_common.llvm.10277270529376503802+0xb8/0x1b4 > do_el0_svc+0x24/0x8c > el0_svc+0x10/0x1c > el0_sync_handler+0x68/0xac > el0_sync+0x18c/0x1c0 > > Signed-off-by: taehyun cho > --- > drivers/usb/gadget/function/u_serial.c | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c > index 6f68cbe..af08a18 100644 > --- a/drivers/usb/gadget/function/u_serial.c > +++ b/drivers/usb/gadget/function/u_serial.c > @@ -450,6 +450,15 @@ static void gs_read_complete(struct usb_ep *ep, struct usb_request *req) > { > struct gs_port *port = ep->driver_data; > > + /* > + * Port became NULL when 'dwc3_gadget_pullup' returns ETIMEDOUT. > + * Return here to avoid panic. > + */ > + if (!port) { > + pr_err("%s, failed to get port\n", __func__); > + return; > + } > + What prevents port from being null right after checking this? Where is the lock to prevent this? > /* Queue all received data until the tty layer is ready for it. */ > spin_lock(&port->port_lock); > list_add_tail(&req->list, &port->read_queue); > @@ -461,6 +470,15 @@ static void gs_write_complete(struct usb_ep *ep, struct usb_request *req) > { > struct gs_port *port = ep->driver_data; > > + /* > + * port became NULL when 'dwc3_gadget_pullup' returns ETIMEDOUT. > + * Return here to avoid panic. > + */ > + if (!port) { > + pr_err("%s, failed to get port\n", __func__); > + return; > + } Same here, where is the lock? And why report an error, what can a user do about it? thanks, greg k-h