UBUNTU-CVE-2024-40918
In the Linux kernel, the following vulnerability has been resolved: parisc: Try to fix random segmentation faults in package builds PA-RISC systems with PA8800 and PA8900 processors have had problems with random segmentation faults for many years. Systems with earlier processors are much more stable. Systems with PA8800 and PA8900 processors have a large L2 cache which needs per page flushing for decent performance when a large range is flushed. The combined cache in these systems is also more sensitive to non-equivalent aliases than the caches in earlier systems. The majority of random segmentation faults that I have looked at appear to be memory corruption in memory allocated using mmap and malloc. My first attempt at fixing the random faults didn't work. On reviewing the cache code, I realized that there were two issues which the existing code didn't handle correctly. Both relate to cache move-in. Another issue is that the present bit in PTEs is racy. 1) PA-RISC caches have a mind of their own and they can speculatively load data and instructions for a page as long as there is a entry in the TLB for the page which allows move-in. TLBs are local to each CPU. Thus, the TLB entry for a page must be purged before flushing the page. This is particularly important on SMP systems. In some of the flush routines, the flush routine would be called and then the TLB entry would be purged. This was because the flush routine needed the TLB entry to do the flush. 2) My initial approach to trying the fix the random faults was to try and use flush_cache_page_if_present for all flush operations. This actually made things worse and led to a couple of hardware lockups. It finally dawned on me that some lines weren't being flushed because the pte check code was racy. This resulted in random inequivalent mappings to physical pages. The __flush_cache_page tmpalias flush sets up its own TLB entry and it doesn't need the existing TLB entry. As long as we can find the pte pointer for the vm page, we can get the pfn and physical address of the page. We can also purge the TLB entry for the page before doing the flush. Further, __flush_cache_page uses a special TLB entry that inhibits cache move-in. When switching page mappings, we need to ensure that lines are removed from the cache. It is not sufficient to just flush the lines to memory as they may come back. This made it clear that we needed to implement all the required flush operations using tmpalias routines. This includes flushes for user and kernel pages. After modifying the code to use tmpalias flushes, it became clear that the random segmentation faults were not fully resolved. The frequency of faults was worse on systems with a 64 MB L2 (PA8900) and systems with more CPUs (rp4440). The warning that I added to flush_cache_page_if_present to detect pages that couldn't be flushed triggered frequently on some systems. Helge and I looked at the pages that couldn't be flushed and found that the PTE was either cleared or for a swap page. Ignoring pages that were swapped out seemed okay but pages with cleared PTEs seemed problematic. I looked at routines related to pte_clear and noticed ptep_clear_flush. The default implementation just flushes the TLB entry. However, it was obvious that on parisc we need to flush the cache page as well. If we don't flush the cache page, stale lines will be left in the cache and cause random corruption. Once a PTE is cleared, there is no way to find the physical address associated with the PTE and flush the associated page at a later time. I implemented an updated change with a parisc specific version of ptep_clear_flush. It fixed the random data corruption on Helge's rp4440 and rp3440, as well as on my c8000. At this point, I realized that I could restore the code where we only flush in flush_cache_page_if_present if the page has been accessed. However, for this, we also need to flush the cache when the accessed bit is cleared in ---truncated---
02 / AFFECTED SOFTWARE
Affected packages
11 explicit affected versions
53 explicit affected versions
116 explicit affected versions
89 explicit affected versions
50 explicit affected versions
6 explicit affected versions
12 explicit affected versions
19 explicit affected versions
6 explicit affected versions
100 explicit affected versions
61 explicit affected versions
10 explicit affected versions
85 explicit affected versions
84 explicit affected versions
91 explicit affected versions
86 explicit affected versions
76 explicit affected versions
10 explicit affected versions
3 explicit affected versions
9 explicit affected versions
90 explicit affected versions
191 explicit affected versions
7 explicit affected versions
84 explicit affected versions
4 explicit affected versions
13 explicit affected versions
85 explicit affected versions
6 explicit affected versions
35 explicit affected versions
51 explicit affected versions
50 explicit affected versions
18 explicit affected versions
42 explicit affected versions
118 explicit affected versions
64 explicit affected versions
9 explicit affected versions
120 explicit affected versions
13 explicit affected versions
4 explicit affected versions
121 explicit affected versions
23 explicit affected versions
13 explicit affected versions
124 explicit affected versions
1 explicit affected versions
21 explicit affected versions
16 explicit affected versions
10 explicit affected versions
76 explicit affected versions
11 explicit affected versions
7 explicit affected versions
12 explicit affected versions
111 explicit affected versions
12 explicit affected versions
14 explicit affected versions
1 explicit affected versions
7 explicit affected versions
104 explicit affected versions
12 explicit affected versions
105 explicit affected versions
12 explicit affected versions
4 explicit affected versions
120 explicit affected versions
45 explicit affected versions
5 explicit affected versions
10 explicit affected versions
37 explicit affected versions
13 explicit affected versions
2 explicit affected versions
10 explicit affected versions
68 explicit affected versions
1 explicit affected versions
26 explicit affected versions
13 explicit affected versions
144 explicit affected versions
37 explicit affected versions
1 explicit affected versions
29 explicit affected versions
111 explicit affected versions
13 explicit affected versions
96 explicit affected versions
3 explicit affected versions
4 explicit affected versions
1 explicit affected versions
100 explicit affected versions
92 explicit affected versions
55 explicit affected versions
33 explicit affected versions
23 explicit affected versions
60 explicit affected versions
10 explicit affected versions
1 explicit affected versions
188 explicit affected versions
11 explicit affected versions
12 explicit affected versions
7 explicit affected versions
12 explicit affected versions
138 explicit affected versions
2 explicit affected versions
77 explicit affected versions
132 explicit affected versions
93 explicit affected versions
165 explicit affected versions
154 explicit affected versions
10 explicit affected versions
26 explicit affected versions
11 explicit affected versions
1 explicit affected versions
69 explicit affected versions
3 explicit affected versions
12 explicit affected versions
13 explicit affected versions
11 explicit affected versions
139 explicit affected versions
78 explicit affected versions
16 explicit affected versions
91 explicit affected versions
12 explicit affected versions
116 explicit affected versions
3 explicit affected versions
132 explicit affected versions
93 explicit affected versions
1 explicit affected versions
2 explicit affected versions
51 explicit affected versions
92 explicit affected versions
9 explicit affected versions
12 explicit affected versions
71 explicit affected versions
80 explicit affected versions
27 explicit affected versions
66 explicit affected versions
121 explicit affected versions
1 explicit affected versions
1 explicit affected versions
98 explicit affected versions
5 explicit affected versions
8 explicit affected versions
55 explicit affected versions
5 explicit affected versions
8 explicit affected versions
1 explicit affected versions
10 explicit affected versions
8 explicit affected versions
13 explicit affected versions
110 explicit affected versions
13 explicit affected versions
72 explicit affected versions
7 explicit affected versions
140 explicit affected versions
94 explicit affected versions
10 explicit affected versions
12 explicit affected versions
39 explicit affected versions
108 explicit affected versions
80 explicit affected versions
56 explicit affected versions
44 explicit affected versions
16 explicit affected versions
3 explicit affected versions
13 explicit affected versions
26 explicit affected versions
45 explicit affected versions
37 explicit affected versions
12 explicit affected versions
14 explicit affected versions
38 explicit affected versions
167 explicit affected versions
9 explicit affected versions
11 explicit affected versions
4 explicit affected versions
92 explicit affected versions
7 explicit affected versions
97 explicit affected versions
121 explicit affected versions
4 explicit affected versions
81 explicit affected versions
1 explicit affected versions
1 explicit affected versions
91 explicit affected versions
80 explicit affected versions
79 explicit affected versions
13 explicit affected versions
43 explicit affected versions
77 explicit affected versions
119 explicit affected versions
10 explicit affected versions
8 explicit affected versions
7 explicit affected versions
88 explicit affected versions
14 explicit affected versions
4 explicit affected versions
78 explicit affected versions
11 explicit affected versions
1 explicit affected versions
69 explicit affected versions
123 explicit affected versions
5 explicit affected versions
80 explicit affected versions
03 / CONNECTIONS
Connected vulnerabilities
04 / EVIDENCE
Source records
In the Linux kernel, the following vulnerability has been resolved: parisc: Try to fix random segmentation faults in package builds PA-RISC systems with PA8800 and PA8900 processors have had problems with random segmentation faults for many years. Systems with earlier processors are much more stable. Systems with PA8800 and PA8900 processors have a large L2 cache which needs per page flushing for decent performance when a large range is flushed. The combined cache in these systems is also more sensitive to non-equivalent aliases than the caches in earlier systems. The majority of random segmentation faults that I have looked at appear to be memory corruption in memory allocated using mmap and malloc. My first attempt at fixing the random faults didn't work. On reviewing the cache code, I realized that there were two issues which the existing code didn't handle correctly. Both relate to cache move-in. Another issue is that the present bit in PTEs is racy. 1) PA-RISC caches have a mind of their own and they can speculatively load data and instructions for a page as long as there is a entry in the TLB for the page which allows move-in. TLBs are local to each CPU. Thus, the TLB entry for a page must be purged before flushing the page. This is particularly important on SMP systems. In some of the flush routines, the flush routine would be called and then the TLB entry would be purged. This was because the flush routine needed the TLB entry to do the flush. 2) My initial approach to trying the fix the random faults was to try and use flush_cache_page_if_present for all flush operations. This actually made things worse and led to a couple of hardware lockups. It finally dawned on me that some lines weren't being flushed because the pte check code was racy. This resulted in random inequivalent mappings to physical pages. The __flush_cache_page tmpalias flush sets up its own TLB entry and it doesn't need the existing TLB entry. As long as we can find the pte pointer for the vm page, we can get the pfn and physical address of the page. We can also purge the TLB entry for the page before doing the flush. Further, __flush_cache_page uses a special TLB entry that inhibits cache move-in. When switching page mappings, we need to ensure that lines are removed from the cache. It is not sufficient to just flush the lines to memory as they may come back. This made it clear that we needed to implement all the required flush operations using tmpalias routines. This includes flushes for user and kernel pages. After modifying the code to use tmpalias flushes, it became clear that the random segmentation faults were not fully resolved. The frequency of faults was worse on systems with a 64 MB L2 (PA8900) and systems with more CPUs (rp4440). The warning that I added to flush_cache_page_if_present to detect pages that couldn't be flushed triggered frequently on some systems. Helge and I looked at the pages that couldn't be flushed and found that the PTE was either cleared or for a swap page. Ignoring pages that were swapped out seemed okay but pages with cleared PTEs seemed problematic. I looked at routines related to pte_clear and noticed ptep_clear_flush. The default implementation just flushes the TLB entry. However, it was obvious that on parisc we need to flush the cache page as well. If we don't flush the cache page, stale lines will be left in the cache and cause random corruption. Once a PTE is cleared, there is no way to find the physical address associated with the PTE and flush the associated page at a later time. I implemented an updated change with a parisc specific version of ptep_clear_flush. It fixed the random data corruption on Helge's rp4440 and rp3440, as well as on my c8000. At this point, I realized that I could restore the code where we only flush in flush_cache_page_if_present if the page has been accessed. However, for this, we also need to flush the cache when the accessed bit is cleared in ---truncated---
05 / REFERENCES
Further evidence
- https://git.kernel.org/linus/72d95924ee35c8cd16ef52f912483ee938a34d49
- https://git.kernel.org/stable/c/5bf196f1936bf93df31112fbdfb78c03537c07b0
- https://git.kernel.org/stable/c/72d95924ee35c8cd16ef52f912483ee938a34d49
- https://git.kernel.org/stable/c/d66f2607d89f760cdffed88b22f309c895a2af20
- https://ubuntu.com/security/CVE-2024-40918
- https://ubuntu.com/security/notices/USN-6999-1
- https://ubuntu.com/security/notices/USN-6999-2
- https://ubuntu.com/security/notices/USN-7004-1
- https://ubuntu.com/security/notices/USN-7005-1
- https://ubuntu.com/security/notices/USN-7005-2
- https://ubuntu.com/security/notices/USN-7008-1
- https://ubuntu.com/security/notices/USN-7029-1
- https://www.cve.org/CVERecord?id=CVE-2024-40918