Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7624398rdb; Thu, 4 Jan 2024 02:26:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRqpEsq+cSrQjWZ5Yc7/oG3m4FO5V2Qj0k/akPk6/i8itAioP8B4y61e4rliwnt8GC3a7Z X-Received: by 2002:a05:6e02:18cc:b0:35f:f450:2721 with SMTP id s12-20020a056e0218cc00b0035ff4502721mr360050ilu.120.1704364017508; Thu, 04 Jan 2024 02:26:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704364017; cv=none; d=google.com; s=arc-20160816; b=MEHllBmPx0zDax8e/s7YAFKByYhqGOyEjNhU973HMiQ4SZT5pFy5/QY2+R2YU4LM8i 5G/WNFL5j0JXdy/BD4UnpgP+M9FkA7m4ztXiHRwqxl8o1dMUrAAXSMXBgsnQC9u02xLT D5ZBpV8SsgAGicUqRwIBy8xR8TaQefrea40O4DcMXbxmBD/q2r1RTCKEPGRhzUbd/z9s ATR1zxMHFMPCNTY7DXICM9GOzVzCQw4K/kQSiB4dpxM6QpBTdDkUfK6xGzGNeZJgvxYW Mx2Yu6K+ilfzEcc1+qrUtzSDbVzODdFO6Q3D5Res01wuhvFFGiRuavNJ5PPEYUPAcSq0 4UeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:subject:cc:to:from:dkim-signature; bh=r+CPXM7b5zrTJe4ATfufqi4NZPb0fXr/cFfeY3rU8JM=; fh=ScZ7LgLXi7TMbjG33QSYJs76oQwcTY7OMM33TIDKlII=; b=Kgva/Z12iPLYL7btPiRDqB3B0I5OvSJaWTcOH0YvNzMus4vQKMrT4jabTvrJEaV4TD oywqr/JmbW0jFm2QRJsl28pEHpJmem07n7s8l6FmpLM4SPLnp0fD3sZ6xjh021v8BGEz H+kyxkuFspKBKyvIBG11pRssN9y5DgWkBgNo0mCt23EdtPUBjGgg8gbOFFhXuvl37cTh Ah7gRquKYremXyVva3qVDwxtgkXXD6Z8bELmCiV5Er3bUa2faZVE/3FoTALJKmCXrV/a /uhIe6kneuMsFbItKQ0ft/rIkMukYPGvVSnS9FV1Ec4g4CKUDMaQQCXgwQGWtuPSMUGC YKBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="a8/R2dV7"; spf=pass (google.com: domain of linux-kernel+bounces-16500-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16500-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s194-20020a6377cb000000b005c67791904bsi19040797pgc.777.2024.01.04.02.26.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 02:26:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16500-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b="a8/R2dV7"; spf=pass (google.com: domain of linux-kernel+bounces-16500-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16500-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 288E0286FC8 for ; Thu, 4 Jan 2024 10:26:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C1EFD20B2C; Thu, 4 Jan 2024 10:26:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="a8/R2dV7" X-Original-To: linux-kernel@vger.kernel.org Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (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 8D11320B10; Thu, 4 Jan 2024 10:26:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 404ANFSi027684; Thu, 4 Jan 2024 10:26:36 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=r+CPXM7b5zrTJe4ATfufqi4NZPb0fXr/cFfeY3rU8JM=; b=a8 /R2dV7lWuVVxhdmZsfiSDwvwApM/bb8fYUdQE/oAIh2xKk2hU90vxIyOVvZTNtQr h29eSfzBn9LN/YBjQhI8EF6PAWPSLabxf0jTmKVMcvkn/9QvO/yU9YkPLbLOebIO ArCJe7bkNMPzCjiEOp27XxN61pOyPkisaq/3CbLMLpSKf60Re2RTh+MuPrhFgG2z bI9aEnHSNvtEK/g3jvUPJxCgn9jvGAq0mfRwcHV53QcYtifU+2TiAzzGTmKis9yJ ypYljJUYyTGnDfWwbxWbGg7Yxu89uioFhHjQxNp/JB42OSVKKPzzTW7AQX1RZb1a 6msg6HsKSQju/3LBQ0lA== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vdev61me5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 Jan 2024 10:26:35 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 404AQZri015587 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 4 Jan 2024 10:26:35 GMT Received: from hu-ugoswami-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.1118.40; Thu, 4 Jan 2024 02:26:32 -0800 From: Udipto Goswami To: Greg Kroah-Hartman , Alan Stern CC: , , "Udipto Goswami" Subject: [PATCH] usb: core: Prevent null pointer dereference in update_port_device_state Date: Thu, 4 Jan 2024 15:56:16 +0530 Message-ID: <20240104102616.20120-1-quic_ugoswami@quicinc.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain 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: R3qtnxMl7teRomJrFzsn_xrI-ocpHLYX X-Proofpoint-GUID: R3qtnxMl7teRomJrFzsn_xrI-ocpHLYX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_01,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 spamscore=0 impostorscore=0 suspectscore=0 phishscore=0 lowpriorityscore=0 mlxlogscore=805 priorityscore=1501 bulkscore=0 mlxscore=0 malwarescore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401040077 Currently,the function update_port_device_state gets the usb_hub from udev->parent by calling usb_hub_to_struct_hub. However, in case the actconfig or the maxchild is 0, the usb_hub would be NULL and upon further accessing to get port_dev would result in null pointer dereference. Fix this by introducing an if check after the usb_hub is populated. Fixes: 83cb2604f641 ("usb: core: add sysfs entry for usb device state") Signed-off-by: Udipto Goswami --- drivers/usb/core/hub.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index ffd7c99e24a3..c33ff37159c2 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -2053,9 +2053,11 @@ static void update_port_device_state(struct usb_device *udev) if (udev->parent) { hub = usb_hub_to_struct_hub(udev->parent); - port_dev = hub->ports[udev->portnum - 1]; - WRITE_ONCE(port_dev->state, udev->state); - sysfs_notify_dirent(port_dev->state_kn); + if (hub) { + port_dev = hub->ports[udev->portnum - 1]; + WRITE_ONCE(port_dev->state, udev->state); + sysfs_notify_dirent(port_dev->state_kn); + } } } -- 2.17.1