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 E131839657B; Mon, 23 Mar 2026 15:08:20 +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=1774278501; cv=none; b=RKI7P4jU3KTQdnFjC2BeRsuf1dlD1zsk08wPIkUvMOq2zq0+5MFPpErYYHukC+mOU9HfalNaEwmvmsULjnYjgRIodfKyKegy9ro0SBox1UUMay8pRgusjUW74fg+3K0miFyFgim17A8DQrDU6thDFSjdwehSV4tPByRFEG4Wcnc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774278501; c=relaxed/simple; bh=Lfn784DPtC3qn2iT2erj82p9kqJHVTASt7bJKDZwFVA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u+y71wN9dEz/QzCRxRf0iWCIA8gGwVId17vtoBSqKrqj3+kwz2hF3+rT9Xb2pcO/rOKGhtv+LgIjEBYbEwRmL3Q+TvO/Gytvi+WVzDODeHiYjvBFoT7fbPUzTD/KhoEWtF7LOAJqtsDF4Tc76k+uoUVCjpcxHVCoiH1Hqk4sm9k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=nSVa0hgX; 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="nSVa0hgX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A237C4CEF7; Mon, 23 Mar 2026 15:08:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774278500; bh=Lfn784DPtC3qn2iT2erj82p9kqJHVTASt7bJKDZwFVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nSVa0hgXW7ut/IcgH5DhKZ4V1r26nOEO0USBGqgqhStYlAirV8gdTvOyRXwPI2BCy sgnpuURHqfb8iqwrFfPH7/KjVyu1iCZ1+DAkF+1PAZMF4zhxS5dLpqvynzwx3sbH1k YgPAX7ThymQ4VaNIZfLM+lidQXPJpkUu9sJO21po= 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.6 283/567] usb: class: cdc-wdm: fix reordering issue in read code path Date: Mon, 23 Mar 2026 14:43:23 +0100 Message-ID: <20260323134540.829521402@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260323134533.749096647@linuxfoundation.org> References: <20260323134533.749096647@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.6-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: