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 DECA23F23AA; Tue, 17 Mar 2026 16:47: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=1773766049; cv=none; b=CYkQXtDxcV9cI06LRogzsuXH0frQwjvbv/TbsNkbZB9IaKR/+j4QZuaVp5Jdlxtol8LLkaJDSWb2OcRQslUF8tXkaxDGUybXvgCIzKyCFkH/pWQlGs1DF0BHQ/+KxR7ICiS1PW3P4BvbBdXzxhSOOe6apbIjxufEJjWWjNO1/qc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773766049; c=relaxed/simple; bh=1Rxn++yDybGH0fo0VOUF4JQsHBtGXoWe+tZM3898Gro=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vqs/uoyoSswglFGJwEcUsrsOYdbH9YqDCgWLDqdgH0QSOpoiw0FwjIajW7DVHpOXc82sVRT7qm2EsZrJgz+ZyvsLva7AyoIzlUUNp3qgncPVssw80mCcHGB1bIlPBmBHWiPTYnvTv/DF/PVNOmqBejxO4glkuU9Wy4BFX/WC8Lc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=eRsFpZQn; 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="eRsFpZQn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 546FBC4CEF7; Tue, 17 Mar 2026 16:47:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1773766049; bh=1Rxn++yDybGH0fo0VOUF4JQsHBtGXoWe+tZM3898Gro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eRsFpZQnZxH0xbNXFqxgczSIZnvlXzcE6idy8gMaogR5Oi14Lcc24A7Smx63frGxr ndaHy1tpUMuVfwUYDDY6xFofvlqpnLJTf+8Z2NIkATKWhzeE4uR6kMIW31pWrKH6co 6mCF7SRJUqIeviIlT8ab1X7xfmbWcE3f9mNFdskI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, stable , Oliver Neukum , Gui-Dong Han Subject: [PATCH 6.19 158/378] usb: class: cdc-wdm: fix reordering issue in read code path Date: Tue, 17 Mar 2026 17:31:55 +0100 Message-ID: <20260317163012.824759125@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260317163006.959177102@linuxfoundation.org> References: <20260317163006.959177102@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.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Oliver Neukum commit 8df672bfe3ec2268c2636584202755898e547173 upstream. Quoting the bug report: Due to compiler optimization or CPU out-of-order execution, the desc->length update can be reordered before the memmove. If this happens, wdm_read() can see the new length and call copy_to_user() on uninitialized memory. This also violates LKMM data race rules [1]. Fix it by using WRITE_ONCE and memory barriers. Fixes: afba937e540c9 ("USB: CDC WDM driver") Cc: stable Signed-off-by: Oliver Neukum Closes: https://lore.kernel.org/linux-usb/CALbr=LbrUZn_cfp7CfR-7Z5wDTHF96qeuM=3fO2m-q4cDrnC4A@mail.gmail.com/ Reported-by: Gui-Dong Han Reviewed-by: Gui-Dong Han Link: https://patch.msgid.link/20260304130116.1721682-1-oneukum@suse.com Signed-off-by: Greg Kroah-Hartman --- drivers/usb/class/cdc-wdm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/usb/class/cdc-wdm.c +++ b/drivers/usb/class/cdc-wdm.c @@ -225,7 +225,8 @@ static void wdm_in_callback(struct urb * /* we may already be in overflow */ if (!test_bit(WDM_OVERFLOW, &desc->flags)) { memmove(desc->ubuf + desc->length, desc->inbuf, length); - desc->length += length; + smp_wmb(); /* against wdm_read() */ + WRITE_ONCE(desc->length, desc->length + length); } } skip_error: @@ -533,6 +534,7 @@ static ssize_t wdm_read return -ERESTARTSYS; cntr = READ_ONCE(desc->length); + smp_rmb(); /* against wdm_in_callback() */ if (cntr == 0) { desc->read = 0; retry: