Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2298255rdb; Mon, 5 Feb 2024 02:02:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEoTmYdQskdhX8cxmuXBER1XR4/fbdVxzwzEw4kXBEW9B6GQzT/ab2pxbbD0aXJu9bmNJm X-Received: by 2002:a2e:a588:0:b0:2cd:5cb3:d7b9 with SMTP id m8-20020a2ea588000000b002cd5cb3d7b9mr6706582ljp.3.1707127339906; Mon, 05 Feb 2024 02:02:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707127339; cv=pass; d=google.com; s=arc-20160816; b=PY2Wa3uX7VNh/zlVXO78LRQx15PqVjYHi3f/G9H/nZJOaiolPnoSuQFj44A40hOWZS j4++42XbuhPl9DTB4ko74BOOF17ZQHTBYl9Xe3TDitFzJQJRXzNc3Nek1woSkwUHxi8d fUMpstwNgDi00x5SER+9jvCn2SrqRegcpD8ccYa+Po7tPGBvjUXetOshuNdL1YnX54ES FTVh7n/kb1mNfcuQW57ir6gS9BwLaHZXYykSh47uhPLzJykfzB2S6b9cXj2/pc1yx3F3 evUiWVX81cjmSKkqQP53EOGl7PnLcdrKP4Jy3ILMUvTr4t0MgS1mS4EVP2LTRa8xu392 QjaQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=kOwwgTlr2wOtfbBZN0zcvbljvb7uojVep4VeMpIsUkc=; fh=SSmkjk2V2SRfy5vKC/oVMXI24h/d2M5E6Ujtpbpy2cQ=; b=sMr2fs4QmB+7nB3hJ/1p97upWoV3F5sT4DrmDFx27YcIp81eKUuEQYamrYYsT2FLaM 6P3RoExEZ9aNGydhAUEY8hS1XBC/dGpTQoI8VKdCtHSBdm5gReTrMWWRmwSHoRduEVRX AKpLfTt2knl/CCwGzmJh2+cRcfhW35L61emPc+Fc9WIbImc89DumI6KY+2HY8J1Ct3Ei 3/ATcvhY2StCbSg0Cvgni2aNnmXswT45RCgV5xAab5AAxfsJfCmeCPhR53E/uy97ju3/ vn0opKjgYi8ELdfUeSl51DIHj3WMIiNxOEyV5SeJo+PZzmT8ySyfDEq/hpY6e6wGElQR Lk1Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jtZXS3I4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-52371-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52371-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCXzsQ+HKnsV/ym9GTunVNCXGc8HCSadJQMPcmkUvD89SVAhQwNJLl3V4/a0d56eBB6iUiU7LpxX1wplq3CKXdTgCFz+IjLqKyGrCv052Q== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id r10-20020a056402234a00b00560634c0947si1039049eda.103.2024.02.05.02.02.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 02:02:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-52371-linux.lists.archive=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=@kernel.org header.s=k20201202 header.b=jtZXS3I4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-52371-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52371-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 9FA6F1F224AD for ; Mon, 5 Feb 2024 10:02:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0AB891759C; Mon, 5 Feb 2024 10:01:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jtZXS3I4" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2A51417591; Mon, 5 Feb 2024 10:01:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707127290; cv=none; b=X/nwpfkE2XJHNLHf236nMoJdzm1z8wk1KCv9+v1DgSFuoK+KWxboRzfmU7uk83ELSP67IVZx2UWSWKgxR7EenbsUQRRO7TPOfX6iuk9y6gqav85ANdKIeyb7Zmh9QTEMwDzysnKYwm1rfAIAGjZD+qBYLQ3apeZthxqbBAFx8aY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707127290; c=relaxed/simple; bh=eJRA+3ncVCN99vSdsXxNf3NPv3pDH15qHWZrw59/uno=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=WE0SKseD1EVIxukdGNXPRRwLOcTEHWptSxunrG4ypykOI5/BToCJ7s3PBseFDTd9/gp6TkWDaCHxUU+HjfeTqsyYpS3TQ+dD7lBkjMqvCtPXKE8t0keaVcd347leHCbaEevn7xE7RhLIUtNtny+3OI2GvQQl5H68AS1tNBSRpAY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jtZXS3I4; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD2BDC433F1; Mon, 5 Feb 2024 10:01:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707127289; bh=eJRA+3ncVCN99vSdsXxNf3NPv3pDH15qHWZrw59/uno=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=jtZXS3I4ULM2OVUHLxQdXQvf1+WVJZW4OnH7bKzkSA2l2WYZlz66Wu0Si62vKLQdk eeyCxh1qJG6ZfU5Y/d/aXi/Ffw8IVloTn2dZxc5ufgQTcw0oHT2nlhs59wEdxkNPr8 58ZCwlnHyzjlVgL28zLV1pJNunpjSbkxbbe6EUVObTRpPsU9fJ3VWf0wpT+cQsqoo4 ANmi18kNyPNsFP4sE4HdfiXMpQbXxx/9y1GffI2ZhPlA0GeLJPuLp8tBPRmwFHlq3T Rrf75M9xUZtpGWHuYgmOgytCFPzPXhDPk4yxdyjBKgORRNTG1qSEWEC8+jbwJdw3Mo 6SyVUTrJIovIA== Message-ID: <72efe6e1-88e0-4b22-b7b2-00dc6903aef0@kernel.org> Date: Mon, 5 Feb 2024 12:01:25 +0200 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 v2 2/2] usb: cdns3: fix memory double free when handle zero packet Content-Language: en-US To: Frank Li Cc: felipe.balbi@linux.intel.com, gregkh@linuxfoundation.org, imx@lists.linux.dev, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, pawell@cadence.com, peter.chen@kernel.org References: <20240202154217.661867-1-Frank.Li@nxp.com> <20240202154217.661867-2-Frank.Li@nxp.com> From: Roger Quadros In-Reply-To: <20240202154217.661867-2-Frank.Li@nxp.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 02/02/2024 17:42, Frank Li wrote: > 829 if (request->complete) { > 830 spin_unlock(&priv_dev->lock); > 831 usb_gadget_giveback_request(&priv_ep->endpoint, > 832 request); > 833 spin_lock(&priv_dev->lock); > 834 } > 835 > 836 if (request->buf == priv_dev->zlp_buf) > 837 cdns3_gadget_ep_free_request(&priv_ep->endpoint, request); > > Driver append an additional zero packet request when queue a packet, which > length mod max packet size is 0. When transfer complete, run to line 831, > usb_gadget_giveback_request() will free this requestion. 836 condition is > true, so cdns3_gadget_ep_free_request() free this request again. > > Log: > > [ 1920.140696][ T150] BUG: KFENCE: use-after-free read in cdns3_gadget_giveback+0x134/0x2c0 [cdns3] > [ 1920.140696][ T150] > [ 1920.151837][ T150] Use-after-free read at 0x000000003d1cd10b (in kfence-#36): > [ 1920.159082][ T150] cdns3_gadget_giveback+0x134/0x2c0 [cdns3] > [ 1920.164988][ T150] cdns3_transfer_completed+0x438/0x5f8 [cdns3] > > Add check at line 829, skip call usb_gadget_giveback_request() if it is > additional zero length packet request. Needn't call > usb_gadget_giveback_request() because it is allocated in this driver. > > Cc: > Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver") > Signed-off-by: Frank Li Reviewed-by: Roger Quadros