LWN: Comments on "A security fix briefly breaks DMA" https://lwn.net/Articles/889593/ This is a special feed containing comments posted to the individual LWN article titled "A security fix briefly breaks DMA". en-us Fri, 29 Aug 2025 10:14:00 +0000 Fri, 29 Aug 2025 10:14:00 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net A security fix briefly breaks DMA https://lwn.net/Articles/890632/ https://lwn.net/Articles/890632/ kpfleming <div class="FormattedComment"> I&#x27;m not sure that&#x27;s fair.<br> <p> You tell a NIC it can receive a packet directly into a buffer. It does so. You don&#x27;t know how large the packet was until you look into the buffer to find out.<br> <p> The NIC could conceivably communicate the &#x27;bytes written&#x27; amount in some other location outside the buffer, but that significantly complicates the data handling.<br> </div> Thu, 07 Apr 2022 15:16:32 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/890204/ https://lwn.net/Articles/890204/ johill <div class="FormattedComment"> Well in this case we&#x27;re talking about swiotlb, so imagine driver 1 maps a buffer A and gets buffer A&#x27; in swiotlb, fills some data into it (perhaps it&#x27;s a crypto driver and there&#x27;s some key data). Then it unmaps because it&#x27;s no longer in use. Some time later driver 2 maps a buffer B and also gets A&#x27; in the swiotlb shadow data, so now all of the stale data from driver 1 is exposed to driver 2&#x27;s device for DMA.<br> </div> Mon, 04 Apr 2022 15:33:57 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/890202/ https://lwn.net/Articles/890202/ imMute <div class="FormattedComment"> <font class="QuotedText">&gt;I suspect that is potentially the device or its driver that is re-using the buffer for further purposes?</font><br> <p> This. It&#x27;s fairly common for drivers to setup a ring of buffers that get reused. As for how the data can be &quot;unrelated&quot; imagine a NIC driver pulling packets off the device - each packet may very well be destined for entirely different processes, but they all use the same set of buffers over and over again.<br> </div> Mon, 04 Apr 2022 14:51:38 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/890144/ https://lwn.net/Articles/890144/ taladar <div class="FormattedComment"> That doesn&#x27;t really matter, if you are the kernel and essentially want a design that works with all hardware you have to expect some terribly designed hardware too.<br> </div> Mon, 04 Apr 2022 08:17:14 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/890102/ https://lwn.net/Articles/890102/ iabervon <div class="FormattedComment"> That&#x27;s what I thought, but how does the CPU know that none of the sync happened before the status word was written, with the copy of the status word happening after it was written? You&#x27;d need to make sure that the first thing that gets copied during the sync is the status word, and I&#x27;m not finding any documentation that the sync happens in any particular order.<br> <p> I expect that the copy actually happens from low to high, and the status word is at the beginning, so it always works, but relies on a property of the core API that was never promised.<br> </div> Sun, 03 Apr 2022 17:40:40 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/890082/ https://lwn.net/Articles/890082/ Flow <div class="FormattedComment"> Great summary, as always. However<br> <p> <font class="QuotedText">&gt; It makes sense to zero the bounce buffer before setting it up, but DMA buffers are often used many times, and it is not normal to zero them between operations. So even a bounce buffer that was zeroed at the beginning may accumulate unrelated data and expose it to user space.</font><br> <p> I would be thankful if someone could elaborate on the process that is causing unrelated data to accumulate. This is not immediately obvious to me. I suspect that is potentially the device or its driver that is re-using the buffer for further purposes?<br> </div> Sun, 03 Apr 2022 09:38:32 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/890080/ https://lwn.net/Articles/890080/ dvrabel <div class="FormattedComment"> The device writes the status word (with its RxDone bit) _after_ writing the packet and other metadata. Thus, if the CPU sees RxDone it knows all the other data has been written.<br> </div> Sun, 03 Apr 2022 08:54:03 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/890077/ https://lwn.net/Articles/890077/ farnz <p>In the bounce buffer case, it can't. But on a lot of systems, especially those in WiFi APs, the DMA is happening into the CPU buffer directly (no bounce buffer), and there it's an optimization to say "hey, packet copied in, resync and continue". Sun, 03 Apr 2022 08:36:43 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/890062/ https://lwn.net/Articles/890062/ iabervon <div class="FormattedComment"> I don&#x27;t see how the bounce buffer copy and the ongoing DMA avoid interacting in such a way that a_packet_is_ready() can return true when not all of the packet was in the bounce buffer in time to get copied out. It seems like you&#x27;d need a sync operation that let you specify the order that the bounce buffer is read in a way that wouldn&#x27;t be optimal for a sync operation that was only reliable if the device was no longer writing when you called it.<br> </div> Sat, 02 Apr 2022 19:55:23 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/890059/ https://lwn.net/Articles/890059/ khim <p>Because it wouldn't solve anything: DMA mechanism itself has no way to check how many bytes were actually written, only the driver can know that.</p> <p>And using value passed along from the driver to make information unavailable to said driver… what would that achieve? The driver already can ignore the part that it doesn't need.</p> Sat, 02 Apr 2022 16:46:47 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/890054/ https://lwn.net/Articles/890054/ johill Oh, it probably *shouldn't* be used in this case, practically speaking. But (and credit goes to Halil for quoting this to me in https://lore.kernel.org/r/20220327051502.63fde20a.pasic@linux.ibm.com) the <a href="https://www.kernel.org/doc/html/latest/core-api/dma-api.html">documentation</a> states: <pre> void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size, enum dma_data_direction direction) void dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle, size_t size, enum dma_data_direction direction) void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nents, enum dma_data_direction direction) void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, int nents, enum dma_data_direction direction) Synchronise a single contiguous or scatter/gather mapping for the CPU and device. With the sync_sg API, all the parameters must be the same as those passed into the single mapping API. With the sync_single API, you can use dma_handle and size parameters that aren't identical to those passed into the single mapping API to do a partial sync. </pre> Which, at least in our reading, seems to imply that for SG all must be the same, for single all but handle/size must be the same. Practically, that doesn't seem to be desired, and it's not even entirely clear what these should mean for DMA_BIDIRECTIONAL. Sat, 02 Apr 2022 12:49:58 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/890045/ https://lwn.net/Articles/890045/ NYKevin <div class="FormattedComment"> I would tend to expect that the vast majority of hardware falls into one of two cases:<br> <p> * It&#x27;s something like a NIC, and the data is eventually going to end up in some sort of userspace buffer (e.g. via read() or recv()). This implies that some part of the kernel is going to have to figure out the size at some point, because you can&#x27;t leak extraneous data to userspace, so you might as well do it in the driver.<br> * It&#x27;s something like a keyboard or capture card, and the data has a fixed or configurable size and/or format, which the driver should already know because it presumably configured the size/format in the first place.<br> <p> Is there really a lot of variable-sized input hardware where the input *doesn&#x27;t* eventually end up in userspace?<br> </div> Sat, 02 Apr 2022 06:24:03 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/890042/ https://lwn.net/Articles/890042/ developer122 <div class="FormattedComment"> This sounds a lot like terrible hardware design.<br> </div> Sat, 02 Apr 2022 03:20:55 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/890013/ https://lwn.net/Articles/890013/ mb <div class="FormattedComment"> Thanks for the additional insight.<br> <p> But could you please elaborate, why DMA_BIDIRECTIONAL should be used? I don&#x27;t quite get why.<br> </div> Fri, 01 Apr 2022 18:32:26 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/890011/ https://lwn.net/Articles/890011/ mb <div class="FormattedComment"> In most cases it&#x27;s probably unknown how much the device actually wrote, unless the driver actually looks at the data written.<br> </div> Fri, 01 Apr 2022 18:30:16 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/890009/ https://lwn.net/Articles/890009/ mario-campos <div class="FormattedComment"> That actually made a lot of sense! THIS is why I read LWN :)<br> <p> On the matter at hand, though... Why not just create an additional `size_t` parameter in the DMA API and only bounce/copy the necessary data (instead of the full buffer)?<br> </div> Fri, 01 Apr 2022 17:43:15 +0000 Typo reports https://lwn.net/Articles/890005/ https://lwn.net/Articles/890005/ corbet Fixed. For future reference, please send typo reports to lwn@lwn.net so as to not clutter the comment stream. Fri, 01 Apr 2022 16:59:41 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/890004/ https://lwn.net/Articles/890004/ larkey <div class="FormattedComment"> There&#x27;s a small typo in the index link of the article: &quot;DIrect memory access&quot; (note the capital &quot;I&quot;).<br> <p> Really great writeup!<br> </div> Fri, 01 Apr 2022 16:56:28 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/889997/ https://lwn.net/Articles/889997/ johill Couple of notes, having participated in the thread: <ul> <li>According to the documentation, the call(s) shouldn't even specify DMA_FROM_DEVICE, it/they should specify DMA_BIDIRECTIONAL as the buffer is documented that way. That would probably break ath9k too, haven't checked the exact code though. <li>According to Linus's thinking on it, however, the DMA_FROM_DEVICE actually makes sense ... <li>The ownership model doesn't work as documented, at least not for devices such as ath9k, since here the device is writing while the driver is reading (which you touch upon), but that implies sort of "dual ownership" or weaking the ownership to "write ownership" perhaps? <li>There was a whole sub-discussion about cache invalidate etc., e.g. with a reference to the ARC (I think?) documentation, which was also quite worthwhile IMHO. </ul> In any case, for me one of the take-aways from the thread was that the documented DMA model is actually not applicable in practice (i.e. it's wrong), which might've been worth going into even if nobody has stepped up yet to try to fix it. Fri, 01 Apr 2022 15:15:19 +0000 A security fix briefly breaks DMA https://lwn.net/Articles/889995/ https://lwn.net/Articles/889995/ post-factum <div class="FormattedComment"> I sincerely hoped LWN would make a nice summary of that LKML thread, and here we are :). Thank you a lot!<br> </div> Fri, 01 Apr 2022 14:46:34 +0000