From patchwork Wed Feb 28 12:57:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashanth K X-Patchwork-Id: 207850 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3325465dyb; Wed, 28 Feb 2024 04:58:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXBNvVlh68/fHGmUBPP/cIVBRb7oo/c6IAuAoGfMeOoX7BfapRzhyMWLtWPoxW4Xa3OXPtPcyJKw2OpoL7zMXSRwLrxqw== X-Google-Smtp-Source: AGHT+IHSZyxPdv0rskhX2TWTrH3Ek0KgMudUMZu5x8NmFM8miyuN5yzzFnxcifR2L6PlbXGiN2+e X-Received: by 2002:a17:907:36e:b0:a44:1105:2046 with SMTP id rs14-20020a170907036e00b00a4411052046mr694238ejb.42.1709125106133; Wed, 28 Feb 2024 04:58:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709125106; cv=pass; d=google.com; s=arc-20160816; b=FY6Y2foP+0+sV5lVg2Zkjl1tcEY/t0k9n7T38fbGGoiTs1scRhObblfruxi95povrn j2RJSkBCNraflvWvcSmmWmDjKqa2BJuvvneNHQVgsbMrSfudRBlAKqY0K50I9C1kg1Xz 35iwhxH7i1fEKrJs+bGwmFMI6nta5DAQzj/T1K4q0wBJ56xkc4Qe9FrpkXKzIZRCjQ+e DIS1j3mrB3EaeSIuHDuNmIiia7KTKK0UgSLJvWPG/YXDhy0j9otEn0Ege8S8qSDR0ajO TQARPBSgBfc1itdwc6jtUXVC9GqfQihuYf2jDUWLbXHiUcVFZT8qwHZeHEhKXnTzG52w BXrw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=kulUHZQ+sWUZhWg1oiTqSixzXqPkzM/P81bT+Eqkzbk=; fh=Cde3xLu3TqA3zpi2MUW9bGDHSKTUjTk409SdXUQryrk=; b=x2w2g7u4NG9FcKymg+spvpwOOgh450FyFNwxjL9Z44dJ0GyOCUEyQPUYp+cfLedFXR 717t42TAaUbvcgdIpeW7lSsKYUvEqJ0aolgvJUYpI/Uikej7oSC4+N3yP3Z+hOQNWQLh BVAvpfrigwD3kFDG60qd3dZ7x/Zz/rEq6eSXzjlnkF3rpcj3tYpBYGavO8ryfkBXhW6L hEuKP2gmF48ViP/SSJj8TuMBn5L4A3aCicq4ZVQ6Wch8Z+kunwZwPDyRbLB7wMR5QHoz qMT3xjqDKjIY2TDFIBu7u510SO2xsjKVQYsfIc3h4/2k2WL/yrwLtnG9Edco3Ukcpwln 5BWQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=GRZKI6KV; 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-85048-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85048-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id lx17-20020a170906af1100b00a43f602bb67si633312ejb.83.2024.02.28.04.58.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 04:58:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85048-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=GRZKI6KV; 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-85048-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85048-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 am.mirrors.kernel.org (Postfix) with ESMTPS id BAB481F22734 for ; Wed, 28 Feb 2024 12:58:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 59FAC14AD2D; Wed, 28 Feb 2024 12:58:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="GRZKI6KV" 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 D126E145B3F; Wed, 28 Feb 2024 12:58:03 +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=1709125085; cv=none; b=MfQUJB8maxUiQ8dFkTCp+gS/aHjIDhMkMDUPg3bSUPbRHsJ+io9jq2fQncEiD3uj/4RLDE6LX5rufB82tYpw3Sv7W5jUzSVAnOAFhla/ruhf2ITRB6lCrufjjMYVhsAyAhuLxFv52+hfY2wkSs+Tk3gWurzH50qpiimpyLJXE78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125085; c=relaxed/simple; bh=xCd9FCuV0P6I+DGvJ2VP4AxODq0+yihzQbQZWXqZEcQ=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=cKXmt15TCWWBND7fsvKN8Slf80CNtkI3datIbiX8NH8PpVqmZGAkapjqHvVFh7bwroDIoNNnxBE2ZVywMwzu59mS9XVBfiwCNk6F4s0jWzF07RsqvtPkxwu0HuweLPAXZVzzFkzJq9uQJ+qIzycDdA1D52L9avX3WOuj7BVYtb0= 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=GRZKI6KV; 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 (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41S9EgMl015857; Wed, 28 Feb 2024 12:58:00 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-transfer-encoding:content-type; s=qcppdkim1; bh=kulUHZQ +sWUZhWg1oiTqSixzXqPkzM/P81bT+Eqkzbk=; b=GRZKI6KVWYHooG7yUAAXDCo KJZtl3v4CXO1H/nqNTrlytWXdG7f7u0kU6yPzkdIhyVpHoHzwv7xN/demDL5JbIZ DRlNsINsl9PMe/hmuGg+oBTXf/7IVPe0jLsln0eSMZpZ7LbkRRWKfiq9gTYw1b6X 9scCCnN655vcsxp671PnD3fRe/8ua+nxc22uYYvzn1vk9jDHgmW13R/vfIvKKbKC 1/uqAzR8Nt1H6ThTcV/b4qd95/IaQba1EGrCzRXidk7zetpyzhfAcMM+D9mZocqL gNegcKHV70PVw/nZJW4GKzVMimXXBT+gf1SnUBRFueT7vjQOXdv2hLEgrFrW2pQ= = Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wj2148hdw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 12:58:00 +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 41SCvh5p014995 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 28 Feb 2024 12:57:43 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.1118.40; Wed, 28 Feb 2024 04:57:40 -0800 From: Prashanth K To: Greg Kroah-Hartman , Mathias Nyman CC: Sergei Shtylyov , , , Prashanth K , Subject: [v2] usb: xhci: Add error handling in xhci_map_urb_for_dma Date: Wed, 28 Feb 2024 18:27:24 +0530 Message-ID: <20240228125724.1527491-1-quic_prashk@quicinc.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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: w9uZjln_i_-dGx8q_D9E4qnlsdSeQOJ6 X-Proofpoint-GUID: w9uZjln_i_-dGx8q_D9E4qnlsdSeQOJ6 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-28_05,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 malwarescore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 spamscore=0 adultscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=543 clxscore=1015 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402280103 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792131116466334488 X-GMAIL-MSGID: 1792147567278287128 Currently xhci_map_urb_for_dma() creates a temporary buffer and copies the SG list to the new linear buffer. But if the kzalloc_node() fails, then the following sg_pcopy_to_buffer() can lead to crash since it tries to memcpy to NULL pointer. So return -ENOMEM if kzalloc returns null pointer. Cc: # 5.11 Fixes: 2017a1e58472 ("usb: xhci: Use temporary buffer to consolidate SG") Signed-off-by: Prashanth K --- v2: Updated -EAGAIN to -ENOMEM drivers/usb/host/xhci.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index c057c42c36f4..35e9efdee3b2 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -1217,6 +1217,8 @@ static int xhci_map_temp_buffer(struct usb_hcd *hcd, struct urb *urb) temp = kzalloc_node(buf_len, GFP_ATOMIC, dev_to_node(hcd->self.sysdev)); + if (!temp) + return -ENOMEM; if (usb_urb_dir_out(urb)) sg_pcopy_to_buffer(urb->sg, urb->num_sgs,