From patchwork Thu Feb 8 23:13:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 198648 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp514917dyd; Thu, 8 Feb 2024 15:27:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWo6aXKZa7ru/dMVoh8i75XE1hUerL70/7s7kPGZXT7n6h0CYqktrR58dUHI9e8RtbOoYTt+rGzf+5M0UImO8KDuruuVg== X-Google-Smtp-Source: AGHT+IEXj5bV/w6G+K+nDHnBpK23SEs6UAbSXquukB5KC6danWUqeJ+KvP0sEat57YPl6pqILtYo X-Received: by 2002:a05:6a20:6a0e:b0:19e:99be:c53a with SMTP id p14-20020a056a206a0e00b0019e99bec53amr1636517pzk.4.1707434841196; Thu, 08 Feb 2024 15:27:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707434841; cv=pass; d=google.com; s=arc-20160816; b=f8wB/Ev7qcigvlNdoZpP7MLqCONZTiEm0mhGLklsm6q88XBB1zjGmIQGHZ7kJqtWfL amE6n407IErYl3eXX6ouWapTmQ8GBTnvobgj6JGpikoVPwSpdCpg2braMJkxtiz9DY6C lQM+m0f/0gqfWqiHGSBeqJ0ZUNy55/gMhfonpk5h4LdGRD5eonHbrQzxzGL+hRRv+8kv UOOaJ7ghJgEb/mq/UE572SAR4M9QaLpqZpMOl7RiGz/tOegmFy8yTW0nL+FPhtlzMsq2 PWUJ7bcs7R89/kydW+r2Jyemz3Z2Vj3QcSi1cpZVZHgdpuWrjPjl/ElCBXIJL2BmzfWh FTXQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2sOcjxKmnstL/5ftZf5841vds3YmEI4sRJLRwbFI4Jw=; fh=G1xDANw3HTYVHjI5bi8cjTt7VfOY+zG0o4JxKiFL3go=; b=pAESRZ1hNpGANdOSPLSrii4omUnBeK6paYrU5I0S2QvUOFaXiy/ym1N64mL/vuSoku rmCHCGG5+P3wWPXbi7jQEv04fXwFlwKPWVIFOXOh2nhjRwa8i1KLX/OE5Zr1UWx6Ojnv m3XDz+Jx8K5C3jy586ZfRaztQFMAsgajqmuyZ/Xxq/RGh1ZSIrlz0OkusFisAccnkvRf jnbUJ0JtMtP6b2G4Yimgn1eJgXMt7kGNsGoqf2tXG53q++UpePbW2A3NarsTQt5oI74K Kamy9MPTNnhwBCGifnu3eFatiZkEdfpS5I2KFUaW8UlPEqRCHVXleOKJE9LMsVsqyUcz kpVA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=nVQssM6t; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-58819-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58819-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCXihdoTgkoarYARPCKSB8CQ+75nvTBiULM2lXjHa46Dxd7o31gZyxMiBLZykg5UwPP9JcU9+NjxNVrV0xVrrGUMt7Nd2A== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b25-20020a656699000000b005ce19c68684si608808pgw.495.2024.02.08.15.27.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:27:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58819-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=nVQssM6t; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-58819-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58819-ouuuleilei=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 A7B4D28F4A7 for ; Thu, 8 Feb 2024 23:25:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2A9CC5FB9E; Thu, 8 Feb 2024 23:14:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="nVQssM6t" 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 D1BAD50A69; Thu, 8 Feb 2024 23:14:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434081; cv=none; b=k6o0/4y/uCFNBri65Z74+SllONLrClYptR88RqhxkOlMpcFqeaNeNwxCf9YZQVjeyPFSvvwH7NAzc7v4qXekdwSyTe6MCm1TQgP8qE6SZED3J5wVO76aJhem3qOpBA/XcchQibwep9AtxarEK1UOSPEzpQdQ7Ho2sDZhUC3exJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434081; c=relaxed/simple; bh=/ctydeO9BP9IDNCKzOW84UaD1pWVBJmsNl/Vixk3Z5M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GkZY9ipzkBQjDdj7Uk898r/G9UvOY4bhQDSMXLCt0S2R3OrJKeAhQlVSAqYmnZNqxqCV8dW2ATBH6NqHhwXuWEFZQDJof4NU5FlWioP02M0rPiV7+fqyF3TZSgt1P3zyHEBmoWRJd24rmHHhbtYpoG+wj5cA4h1z2Xzahs5/0Pg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=nVQssM6t; arc=none smtp.client-ip=205.220.180.131 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 (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 418KhRQ8019816; Thu, 8 Feb 2024 23:14:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=2sOcjxKmnstL/5ftZf58 41vds3YmEI4sRJLRwbFI4Jw=; b=nVQssM6tWjWN+AaUAvEFXjHBVSCl3GR1MBZh mZFhvLraLcunmZDyhyQSOKFzRqUd/Mw3Y5IvW5xNhYUS0CpIBDF2tixyabrxLKvA e5i3Er14Y8SwtwFliKeNPHTCCF+mgIsluMGAeCDQ3Oj4J7km9R1eCIZVTsGocVh2 o4TSc7EJUvSZsRWRMpToJBnc1zBvyCf7aNJV1GnM7uw54YQTiQxp/trSTsoi+A3I rP040Qj3+mrKgJfiPDqCnFzjPAZjpewOwzYoHMv+LNfy2jE9fPswvNXeQdbS3Aoe csJQq7b6ZIahHEpZ3Diw/VNZmh+oPErw4ooZShyXh8w1GYpPgg== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4frwujtt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:17 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 418NEGP5009144 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:16 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Thu, 8 Feb 2024 15:14:15 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Mathias Nyman , Wesley Cheng Subject: [PATCH v14 01/53] xhci: fix possible null pointer dereference at secondary interrupter removal Date: Thu, 8 Feb 2024 15:13:14 -0800 Message-ID: <20240208231406.27397-2-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: UP_Bh-r2YyQE-WRxE1odBi-VgumwIQ2N X-Proofpoint-GUID: UP_Bh-r2YyQE-WRxE1odBi-VgumwIQ2N X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 malwarescore=0 spamscore=0 suspectscore=0 bulkscore=0 phishscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=999 adultscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375196075049428 X-GMAIL-MSGID: 1790375196075049428 From: Mathias Nyman Don't try to remove a secondary interrupter that is known to be invalid. Also check if the interrupter is valid inside the spinlock that protects the array of interrupters. Found by smatch static checker Reported-by: Dan Carpenter Closes: https://lore.kernel.org/linux-usb/ffaa0a1b-5984-4a1f-bfd3-9184630a97b9@moroto.mountain/ Fixes: c99b38c41234 ("xhci: add support to allocate several interrupters") Signed-off-by: Mathias Nyman Link: https://lore.kernel.org/r/20240125152737.2983959-2-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Wesley Cheng --- drivers/usb/host/xhci-mem.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 4460fa7e9fab..d00d4d937236 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -1861,14 +1861,14 @@ void xhci_remove_secondary_interrupter(struct usb_hcd *hcd, struct xhci_interrup struct xhci_hcd *xhci = hcd_to_xhci(hcd); unsigned int intr_num; + spin_lock_irq(&xhci->lock); + /* interrupter 0 is primary interrupter, don't touch it */ - if (!ir || !ir->intr_num || ir->intr_num >= xhci->max_interrupters) + if (!ir || !ir->intr_num || ir->intr_num >= xhci->max_interrupters) { xhci_dbg(xhci, "Invalid secondary interrupter, can't remove\n"); - - /* fixme, should we check xhci->interrupter[intr_num] == ir */ - /* fixme locking */ - - spin_lock_irq(&xhci->lock); + spin_unlock_irq(&xhci->lock); + return; + } intr_num = ir->intr_num;