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 AEA2D2459DC; Tue, 17 Mar 2026 17:17:16 +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=1773767836; cv=none; b=WSEFZqB8FzC9Zu4agr+oxGQAGT+pT9RDNjxoqywpyjtZ/4qbMGPWbx7ckwVV8B314s6FxhcAl1Qi4zAtW3YZz1TVVC7MzLZwKkdv5JD44pWxvEvnxL8cYgbhodHDal4491EcdzsWDvwll1DXWl6E5Pp7EsHoblInbf+1k9ZIWUo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773767836; c=relaxed/simple; bh=/QdK10yHQAtvRHWXp8d8vi1vxAarop0UwwmBYqrnZYk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XHO5QtDrJwCgUtBfcKEaSUcelceBfZR37xa3YlZzxnTGIx7Am/RFjEji/252nZkWqZvdv80SFDvg3jhtgafdV7L8I8wJTUt+jER7sFXtPsnGCKiT6idt7owEXjn/4UVJVBLaZdaxAaeoux0BZ56yl56N0DmdrZEpc6oYeJDny5A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=BkIZllyd; 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="BkIZllyd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C0AFC4CEF7; Tue, 17 Mar 2026 17:17:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1773767836; bh=/QdK10yHQAtvRHWXp8d8vi1vxAarop0UwwmBYqrnZYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BkIZllydhdtzZvVsoMzz7uO6vJhb0WRbiz8+orLHumid3qaO6YBjUuTiVDTd6Jb0w c8xgId4OASk/W76PESwAPRtCIf6f3wzynByWOX9bj6lkHkHBTpOi+VcMUlApcmcjST A7PzMD9+hSGOrZ7g07nQNr8cajglpCNY9SQVuqm8= 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.18 141/333] usb: class: cdc-wdm: fix reordering issue in read code path Date: Tue, 17 Mar 2026 17:32:50 +0100 Message-ID: <20260317163004.590041118@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260317162959.345812316@linuxfoundation.org> References: <20260317162959.345812316@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.18-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: