From mboxrd@z Thu Jan 1 00:00:00 1970 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 959A3301465; Wed, 28 Jan 2026 15:48: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=1769615309; cv=none; b=CRE6S8jTFgM0rFxLFrh2UAPjmsj/aPwDdFeyvF2CICttVfHFoEHVj43Uz2/6krntbvTbPEyAqHV9Cgeo5rGDavxrOsFUgaqpokHpu5xJIQyovZKcWNOkfXpuJWAax4zXuA//3tyHidvt3YA/XlrNpINFLHEWw9HsbkBO/I/W7gw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769615309; c=relaxed/simple; bh=NlVT/S5E72aCV8+ASps+dMHwWrANlBH98aFeADzaDfU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DMk2Y+F2B2SC4P0g9EIjUpuHkDJ/SJG8ITT2FD1N5rmufS3jfKYlSC3euKxXpA80XYsgQ91FFlVOs/jntyQXvtccyKScmjpznDeaUpEGRSjI+DRuo7UKuzaapVZQTE2dOIGARFLHleoBJcMNvGl5Pz2RtpP0KkBZZpXOqo1q3Pk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=YPRNxarl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="YPRNxarl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CA0EC4CEF7; Wed, 28 Jan 2026 15:48:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1769615309; bh=NlVT/S5E72aCV8+ASps+dMHwWrANlBH98aFeADzaDfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YPRNxarl9u/2/t/K4+mq9KC4HQ3Io4S1VcONQFij6OPPlswSiV2Zmfe4HtHqaNObq UNFJniReuC3ceNck7QZX5A2RK6FVmeHePzncUvQ5pEjV6Gx02ePcDNAj3EhAykvy0p VY+OIYj/N88zDw+2i6gisu7/pe3b6GhxNJH4jsEc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Marc Kleine-Budde Subject: [PATCH 6.12 140/169] can: ems_usb: ems_usb_read_bulk_callback(): fix URB memory leak Date: Wed, 28 Jan 2026 16:23:43 +0100 Message-ID: <20260128145339.043961598@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260128145334.006287341@linuxfoundation.org> References: <20260128145334.006287341@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Marc Kleine-Budde commit 0ce73a0eb5a27070957b67fd74059b6da89cc516 upstream. Fix similar memory leak as in commit 7352e1d5932a ("can: gs_usb: gs_usb_receive_bulk_callback(): fix URB memory leak"). In ems_usb_open(), the URBs for USB-in transfers are allocated, added to the dev->rx_submitted anchor and submitted. In the complete callback ems_usb_read_bulk_callback(), the URBs are processed and resubmitted. In ems_usb_close() the URBs are freed by calling usb_kill_anchored_urbs(&dev->rx_submitted). However, this does not take into account that the USB framework unanchors the URB before the complete function is called. This means that once an in-URB has been completed, it is no longer anchored and is ultimately not released in ems_usb_close(). Fix the memory leak by anchoring the URB in the ems_usb_read_bulk_callback() to the dev->rx_submitted anchor. Fixes: 702171adeed3 ("ems_usb: Added support for EMS CPC-USB/ARM7 CAN/USB interface") Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20260116-can_usb-fix-memory-leak-v2-1-4b8cb2915571@pengutronix.de Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- drivers/net/can/usb/ems_usb.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/drivers/net/can/usb/ems_usb.c +++ b/drivers/net/can/usb/ems_usb.c @@ -486,11 +486,17 @@ resubmit_urb: urb->transfer_buffer, RX_BUFFER_SIZE, ems_usb_read_bulk_callback, dev); + usb_anchor_urb(urb, &dev->rx_submitted); + retval = usb_submit_urb(urb, GFP_ATOMIC); + if (!retval) + return; + + usb_unanchor_urb(urb); if (retval == -ENODEV) netif_device_detach(netdev); - else if (retval) + else netdev_err(netdev, "failed resubmitting read bulk urb: %d\n", retval); }