Message ID | 1683278317-11774-1-git-send-email-quic_prashk@quicinc.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp264142vqo; Fri, 5 May 2023 02:28:10 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ66/MC88YiqkvkgjUDH/eZ0qUKdmbSnfdgG+QiZNRHbuaFDjr9PuXlZap40mhdaqVjMlMKQ X-Received: by 2002:a17:90a:65c6:b0:24e:4b1c:74d2 with SMTP id i6-20020a17090a65c600b0024e4b1c74d2mr802299pjs.32.1683278890006; Fri, 05 May 2023 02:28:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683278889; cv=none; d=google.com; s=arc-20160816; b=fE7MEBRahubT4CIL6kX+pANz5FSKOLpaQBt+5C5CJ9HJGuZHEIlb6CrsdsRhcgnpGe g1oZqHvaekWeE2klNQUaK6nKgTeGSJEnrYGa9Z0SFWsjad+vIz/Beh9Jkc39uaxcRSM2 smS7S2LChNygg59LrL2g1zd58gxcM9bRN6wHv792XDHwdqmEIKvqkuUz6/FK+90M9ODY FQsDzRjOLlPksUmGLU5EXN5bnuqas2EVytXBlFoRMASD0DDJ50gSImYaKjgIPfouHLCg 2ZAnBc1eNkWGulsDJgyrHqaVEkOO2NW7l7ATHwo+qZnGwhB3o0Y4vT2obVfS9YLk/8k5 Pp/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=v7Ibotq0lCmPp6SgUbADSFzMro73waUPO5bKxROq51Y=; b=KbxCMsAOnda1qaxdyUA2FxLnIwGFi8peZctBL8CIO5vj8rOSYE4utOlwAbLd8EgDUl QRzHEUozoLogBP3V/XsQ76fgE3pcnBFjdfeBg0HHsLHSMviM7pXWon4rjEBl1XTyOa7b fkPwxii9IxY5nMnCN0SyB2+gerMlIPTdArhZ1EhxGqSecODgg3WwChgo4PDFGQD02jA/ vfOz+lM084GbXw/9Z6grlTg9Sn9qpJ/04TguoXw0hVforbvDTpdzzTqvLxoW9D6j+sjQ ZA3rHjOUALMksI9CIPzFulyREILWr7zUqCieO56BekSZxRTgcY5JtjVF0zpEYAHb6IE6 mIYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Q9Ovi6kx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b12-20020a63930c000000b0052c40a97d97si1541076pge.5.2023.05.05.02.27.55; Fri, 05 May 2023 02:28:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Q9Ovi6kx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231616AbjEEJSy (ORCPT <rfc822;b08248@gmail.com> + 99 others); Fri, 5 May 2023 05:18:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229568AbjEEJSw (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 5 May 2023 05:18:52 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C28F103; Fri, 5 May 2023 02:18:52 -0700 (PDT) Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3458xPCi008611; Fri, 5 May 2023 09:18:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=qcppdkim1; bh=v7Ibotq0lCmPp6SgUbADSFzMro73waUPO5bKxROq51Y=; b=Q9Ovi6kxdkjKkjcjt8u9rj2AGak+5x1Iky9aMwIW/U+ZAAFOoCzBQpyQO1DDQCeCJK/x ZKXVDo0L9soov9M5szO3ZWPgLnRhX5x1j0MjywflyYYQ1nds8b16SCNbzZWBVdK72+qX 7BgjxvbDu20D8YmPkKqVZo/dlCBmdxNIi02Gd3oJ5uvNftMX/J8ES9cKDFZnFYAszl4G 4KpEn4iLLcbs8i6AQFJo7mYrI455+GVVb5Azox6+B/pU0QOxIFNi1OKRt9jqh9svR8oE Yh6wobalG5pC6VH+0EywvOWyW4ZKhYy+HdaqqEgUEZgOomwPHVJz/XK1MkiOBOkB3szr LQ== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3qcf24hx0v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 05 May 2023 09:18:45 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3459IiIL030210 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 5 May 2023 09:18:44 GMT Received: from hu-prashk-hyd.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Fri, 5 May 2023 02:18:42 -0700 From: Prashanth K <quic_prashk@quicinc.com> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Alan Stern <stern@rowland.harvard.edu> CC: Xiu Jianfeng <xiujianfeng@huawei.com>, Christophe JAILLET <christophe.jaillet@wanadoo.fr>, <linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>, Prashanth K <quic_prashk@quicinc.com> Subject: [PATCH] usb: gadget: u_serial: Add null pointer check in gserial_suspend Date: Fri, 5 May 2023 14:48:37 +0530 Message-ID: <1683278317-11774-1-git-send-email-quic_prashk@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: nRRKmzfMZVESRDjZcsK6qApru5ymByWh X-Proofpoint-GUID: nRRKmzfMZVESRDjZcsK6qApru5ymByWh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-05_15,2023-05-04_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxscore=0 suspectscore=0 bulkscore=0 impostorscore=0 phishscore=0 priorityscore=1501 spamscore=0 malwarescore=0 clxscore=1011 mlxlogscore=621 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2305050076 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765045845514008880?= X-GMAIL-MSGID: =?utf-8?q?1765045845514008880?= |
Series |
usb: gadget: u_serial: Add null pointer check in gserial_suspend
|
|
Commit Message
Prashanth K
May 5, 2023, 9:18 a.m. UTC
Consider a case where gserial_disconnect has already cleared
gser->ioport. And if gserial_suspend gets called afterwards,
it will lead to accessing of gser->ioport and thus causing
null pointer dereference.
Avoid this by adding a null pointer check. Added a static
spinlock to prevent gser->ioport from becoming null after
the newly added null pointer check.
Fixes: aba3a8d01d62 ("usb: gadget: u_serial: add suspend resume callbacks")
Signed-off-by: Prashanth K <quic_prashk@quicinc.com>
---
drivers/usb/gadget/function/u_serial.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
Comments
On Fri, May 05, 2023 at 02:48:37PM +0530, Prashanth K wrote: > Consider a case where gserial_disconnect has already cleared > gser->ioport. And if gserial_suspend gets called afterwards, > it will lead to accessing of gser->ioport and thus causing > null pointer dereference. > > Avoid this by adding a null pointer check. Added a static > spinlock to prevent gser->ioport from becoming null after > the newly added null pointer check. > > Fixes: aba3a8d01d62 ("usb: gadget: u_serial: add suspend resume callbacks") > Signed-off-by: Prashanth K <quic_prashk@quicinc.com> > --- > drivers/usb/gadget/function/u_serial.c | 13 +++++++++++-- > 1 file changed, 11 insertions(+), 2 deletions(-) > > diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c > index a0ca47f..e5d522d 100644 > --- a/drivers/usb/gadget/function/u_serial.c > +++ b/drivers/usb/gadget/function/u_serial.c > @@ -1420,10 +1420,19 @@ EXPORT_SYMBOL_GPL(gserial_disconnect); > > void gserial_suspend(struct gserial *gser) > { > - struct gs_port *port = gser->ioport; > + struct gs_port *port; > unsigned long flags; > > - spin_lock_irqsave(&port->port_lock, flags); > + spin_lock_irqsave(&serial_port_lock, flags); > + port = gser->ioport; > + > + if (!port) { > + spin_unlock_irqrestore(&serial_port_lock, flags); > + return; > + } > + > + spin_lock(&port->port_lock); > + spin_unlock(&serial_port_lock); > port->suspended = true; > spin_unlock_irqrestore(&port->port_lock, flags); > } This looks fine to me, but I'm not a serial-gadget maintainer. In fact, it looks like we don't have a serial-gadget maintainer. Alan Stern
diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c index a0ca47f..e5d522d 100644 --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c @@ -1420,10 +1420,19 @@ EXPORT_SYMBOL_GPL(gserial_disconnect); void gserial_suspend(struct gserial *gser) { - struct gs_port *port = gser->ioport; + struct gs_port *port; unsigned long flags; - spin_lock_irqsave(&port->port_lock, flags); + spin_lock_irqsave(&serial_port_lock, flags); + port = gser->ioport; + + if (!port) { + spin_unlock_irqrestore(&serial_port_lock, flags); + return; + } + + spin_lock(&port->port_lock); + spin_unlock(&serial_port_lock); port->suspended = true; spin_unlock_irqrestore(&port->port_lock, flags); }