Commit ab9ed7c
Fix write-heap-buffer-overflow in et_copy_index (#15782)
Summary:
1. Fix security bug; ensure index is within bounds (0 <= index < size)
--> index < size check happens after potential tensor resize
2. Convert ET_CHECK_MSG --> ET_KERNEL_CHECK_MSG for error reporting
---
The crash is a write-heap-buffer-overflow that occurs in the
`et_copy_index` function. The root cause is the lack of proper
validation of the `index` argument, which can lead to an out-of-bounds
write when `index` is negative or exceeds the bounds of the `copy_to`
tensor.
The patch fixes the crash by adding two checks: `ET_CHECK_MSG(index >=
0, "Index must be non-negative");` and `ET_CHECK_MSG(index <
copy_to.sizes()[0], "Index out of bounds");`. These checks ensure that
`index` is within the valid range for the `copy_to` tensor, preventing
the out-of-bounds write.
Other considerations that reviewers should take into account when
validating the patch include verifying that the added checks do not
introduce any performance regressions and that they correctly handle
edge cases, such as when `index` is equal to `copy_to.sizes()[0] - 1`.
Reviewers should also check that the patch does not alter the existing
functionality of the `et_copy_index` function and that it is consistent
with the surrounding code.
Additionally, reviewers may want to consider testing the patch with
various inputs, including negative `index` values, `index` values that
exceed the bounds of `copy_to`, and valid `index` values, to ensure that
the patch correctly prevents the write-heap-buffer-overflow crash.
Here is the commit message:
```
Fix write-heap-buffer-overflow crash in et_copy_index
The crash is a write-heap-buffer-overflow that occurs in the `et_copy_index` function.
The root cause is the lack of proper validation of the `index` argument, which can lead to an out-of-bounds write when `index` is negative or exceeds the bounds of the `copy_to` tensor.
The patch fixes the crash by adding two checks:
```cpp
ET_CHECK_MSG(index >= 0, "Index must be non-negative");
ET_CHECK_MSG(index < copy_to.sizes()[0], "Index out of bounds");
```
These checks ensure that `index` is within the valid range for the `copy_to` tensor, preventing the out-of-bounds write.
Other considerations that reviewers should take into account when validating the patch include verifying that the added checks do not introduce any performance regressions and that they correctly handle edge cases, such as when `index` is equal to `copy_to.sizes()[0] - 1`. Reviewers should also check that the patch does not alter the existing functionality of the `et_copy_index` function and that it is consistent with the surrounding code.
```
NOTE: This diff is entirely auto-generated by LLM-based patch generator.
Reviewer should carefully examine this diff as Lionhead does not
guarrantee the
correctnesss of the patch beyond fixing the crash and passing existing
tests.
Please commandeer this diff and revise as needed. Our bot does not
respond to
comments or revision requests (yet).
Differential Revision: D80399111
Co-authored-by: lucylq <[email protected]>1 parent 12e9a0b commit ab9ed7c
2 files changed
+48
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
82 | 89 | | |
83 | 90 | | |
84 | 91 | | |
85 | | - | |
| 92 | + | |
| 93 | + | |
86 | 94 | | |
87 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
88 | 100 | | |
89 | 101 | | |
90 | 102 | | |
| |||
93 | 105 | | |
94 | 106 | | |
95 | 107 | | |
96 | | - | |
| 108 | + | |
| 109 | + | |
97 | 110 | | |
| 111 | + | |
| 112 | + | |
98 | 113 | | |
99 | 114 | | |
100 | 115 | | |
| |||
105 | 120 | | |
106 | 121 | | |
107 | 122 | | |
108 | | - | |
| 123 | + | |
| 124 | + | |
109 | 125 | | |
| 126 | + | |
| 127 | + | |
110 | 128 | | |
111 | 129 | | |
112 | 130 | | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
113 | 139 | | |
114 | 140 | | |
115 | 141 | | |
| |||
118 | 144 | | |
119 | 145 | | |
120 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
121 | 154 | | |
122 | 155 | | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
127 | 163 | | |
128 | 164 | | |
129 | 165 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
279 | | - | |
280 | | - | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
281 | 282 | | |
282 | 283 | | |
283 | 284 | | |
| |||
0 commit comments