Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp843959rdd; Wed, 10 Jan 2024 00:48:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IFd2fRKvEygiTJBhL566uKV7AiC0wZHsjoTrU8LLHoDSKNPvuAM8E/NXrE5CC7PT8j6uRTI X-Received: by 2002:a05:6358:730c:b0:175:7bc4:bb6a with SMTP id d12-20020a056358730c00b001757bc4bb6amr698998rwg.36.1704876521087; Wed, 10 Jan 2024 00:48:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704876520; cv=none; d=google.com; s=arc-20160816; b=ShcFbj9z8JlFqmUDyXXuwFb0I0qcvRo4sG8lXO4/WZCNkPSjCltmhv1wHbwXKQwyJW TrcnJ3JXaQr9mvaFH81oid2bF0uCjYG8Dc9mqdT+xpKVg36xlicQyqIDG9ZhKK/83htY a7nJ47oGc4Ta2vlb2iK1IgKfhrn2juj57AC24VGp+r75Qwwi4sZ3+ffABl+XEkzhTkUq oXxPEqr9wqMJPzsDRGX3z956Z4t4QZsL25UPGTEsg7mzuLSZPiLJNsBgXgm25XFFkhlH 9DfmJjMvKd+1fDY6ZggSsPcoD9M0nf+taOm1lRfA0DAR5JT1Zn02gON8I4Nf2R+qRAO9 kpig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=TSIDIGzx91eb9galuGPWbdpthE7PmbdcJStbdBlFstk=; fh=7XM323Q0xQhoPRnU727EFje3TjLpbDKN4DlH4759A3Y=; b=rLweyEzvy+Bg0pJt9K6sY1EI/DQGCfnPKZP/1rQFaYqT9tvz+su8pqcUagRdDM++1S gSH7yj1psKLPDbGI/EH4ikS64edx7smOf2/Y2kr1DpY8BwKGIQMAJmbDcHjWOMU69KhN tWg0CzpDAhIF5yTILnhu1p7dLYyY5DAa6h38rPym8+l3tBREzovJMZWt3J64Bj+UqeaY CxdSdk25ETm6y08KOyh1aSTRFMlgM3y/qDVjpqX9wMMpXv3n3KGMEC09IPXK2K6yhAlj X1d/8lc55LiBLosEmbjBLhL+46K5xIASxtBWkyQhr8jVfk8oun2OcbGZqyL3VrNhrqkI +1vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=G7KSC65h; spf=pass (google.com: domain of linux-kernel+bounces-21863-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21863-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id m66-20020a632645000000b005cdf7e87091si3183570pgm.248.2024.01.10.00.48.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 00:48:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21863-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=G7KSC65h; spf=pass (google.com: domain of linux-kernel+bounces-21863-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21863-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 1A3CAB261FD for ; Wed, 10 Jan 2024 08:48:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A04B33A8F6; Wed, 10 Jan 2024 08:48:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="G7KSC65h" Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 440EE37149; Wed, 10 Jan 2024 08:48:11 +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 (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 40A8fNNO020732; Wed, 10 Jan 2024 08:48:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= message-id:date:mime-version:subject:to:cc:references:from :in-reply-to:content-type:content-transfer-encoding; s= qcppdkim1; bh=TSIDIGzx91eb9galuGPWbdpthE7PmbdcJStbdBlFstk=; b=G7 KSC65hvc465oP3e708IoRORMfBEVGVeCZv4x5JWCobpdGxRH9Ur99JSpa5UOk9H/ f61HXmDm1cTMFnVX8Ru7Dip0fiW72Jc+qCN1Kr251NCuiwOBdt7bEwtTNzotUatl KbyRDtebgFl2oiGxEnF7AVrDviU6MOyUimA7YSRF9VFgrudXmTYRhJMgzfYhmE8i oEZ0SHcOOb+3vjAyBrDZwn2/m5KmkBGrv7xH++o7y/yVf0qj7kDZ8E0U2OgpB7WR 0RNSUmC34GC/InsNB/LVhr8x32TKtUQHZGWq3K2zQq5zPDqpg6Kt94kX9MPxvhL6 QsNrbifuRS+xfMaqbz0Q== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vhkem0hr4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 08:48:09 +0000 (GMT) Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 40A8m8Tk001399 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Jan 2024 08:48:08 GMT Received: from [10.217.219.221] (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; Wed, 10 Jan 2024 00:48:05 -0800 Message-ID: Date: Wed, 10 Jan 2024 14:18:02 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] usb: core: Prevent null pointer dereference in update_port_device_state To: Sergei Shtylyov , Greg Kroah-Hartman , Alan Stern CC: Krishna Kurapati , , , References: <20240109061708.26288-1-quic_ugoswami@quicinc.com> <3bb51617-81e1-7d19-598d-2b57164320e1@gmail.com> <5ef9db3d-1e60-4f42-8a5b-52a9800e4707@quicinc.com> <3c2b2183-b1ee-6226-be5b-f2f9fc39e247@gmail.com> Content-Language: en-US From: Udipto Goswami In-Reply-To: <3c2b2183-b1ee-6226-be5b-f2f9fc39e247@gmail.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit 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: kvLih4B66fr1EspK8GcuVM0v8HuFlS5p X-Proofpoint-GUID: kvLih4B66fr1EspK8GcuVM0v8HuFlS5p 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=1015 mlxscore=0 mlxlogscore=999 impostorscore=0 phishscore=0 bulkscore=0 suspectscore=0 lowpriorityscore=0 spamscore=0 priorityscore=1501 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401100071 On 1/9/2024 8:10 PM, Sergei Shtylyov wrote: > On 1/9/24 2:57 PM, Udipto Goswami wrote: > [...] > >>>> 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") >>>> Cc: stable@vger.kernel.org >>>> Signed-off-by: Udipto Goswami >>>> --- >>>> v3: Re-wrote the comment for better context. >>>> v2: Introduced comment for the if check & CC'ed stable. >>>> >>>>   drivers/usb/core/hub.c | 20 +++++++++++++++++--- >>>>   1 file changed, 17 insertions(+), 3 deletions(-) >>>> >>>> diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c >>>> index ffd7c99e24a3..6b514546e59b 100644 >>>> --- a/drivers/usb/core/hub.c >>>> +++ b/drivers/usb/core/hub.c >>>> @@ -2053,9 +2053,23 @@ 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); >>>> + >>>> +        /* >>>> +         * The Link Layer Validation System Driver (lvstest) >>>> +         * has procedure of unbinding the hub before running >>>> +         * the rest of the procedure. This triggers >>>> +         * hub_disconnect will set the hub's maxchild to 0. >>> >>>     I can't parse this sentence, s/th is missing... >> Thanks for the review. >> Maybe this would sound better? >> >> "This triggers hub_disconnect which will set hub's maxchild to 0" > > That seems parsable. :-) > >>>> +         * This would result usb_hub_to_struct_hub in this >>>> +         * function to return NULL. >>> >>>     "This would result in usb_hub_to_struct_hub in this function >>> returning NULL", perhaps? >> >> yah sound better. Will take care of it in next version. > > Probably "in this function" should be dropped altogether... sure, i'll remove in v4. Thanks, -Udipto