@@ -139,75 +139,75 @@ pub fn execute_program(
139
139
// BPF_LDX class
140
140
ebpf:: LD_B_REG => reg[ _dst] = unsafe {
141
141
#[ allow( clippy:: cast_ptr_alignment) ]
142
- let x = ( reg[ _src] as * const u8 ) . offset ( insn. off as isize ) as * const u8 ;
142
+ let x = ( reg[ _src] as * const u8 ) . wrapping_offset ( insn. off as isize ) as * const u8 ;
143
143
check_mem_load ( x as u64 , 1 , insn_ptr) ?;
144
144
x. read_unaligned ( ) as u64
145
145
} ,
146
146
ebpf:: LD_H_REG => reg[ _dst] = unsafe {
147
147
#[ allow( clippy:: cast_ptr_alignment) ]
148
- let x = ( reg[ _src] as * const u8 ) . offset ( insn. off as isize ) as * const u16 ;
148
+ let x = ( reg[ _src] as * const u8 ) . wrapping_offset ( insn. off as isize ) as * const u16 ;
149
149
check_mem_load ( x as u64 , 2 , insn_ptr) ?;
150
150
x. read_unaligned ( ) as u64
151
151
} ,
152
152
ebpf:: LD_W_REG => reg[ _dst] = unsafe {
153
153
#[ allow( clippy:: cast_ptr_alignment) ]
154
- let x = ( reg[ _src] as * const u8 ) . offset ( insn. off as isize ) as * const u32 ;
154
+ let x = ( reg[ _src] as * const u8 ) . wrapping_offset ( insn. off as isize ) as * const u32 ;
155
155
check_mem_load ( x as u64 , 4 , insn_ptr) ?;
156
156
x. read_unaligned ( ) as u64
157
157
} ,
158
158
ebpf:: LD_DW_REG => reg[ _dst] = unsafe {
159
159
#[ allow( clippy:: cast_ptr_alignment) ]
160
- let x = ( reg[ _src] as * const u8 ) . offset ( insn. off as isize ) as * const u64 ;
160
+ let x = ( reg[ _src] as * const u8 ) . wrapping_offset ( insn. off as isize ) as * const u64 ;
161
161
check_mem_load ( x as u64 , 8 , insn_ptr) ?;
162
162
x. read_unaligned ( )
163
163
} ,
164
164
165
165
// BPF_ST class
166
166
ebpf:: ST_B_IMM => unsafe {
167
- let x = ( reg[ _dst] as * const u8 ) . offset ( insn. off as isize ) as * mut u8 ;
167
+ let x = ( reg[ _dst] as * const u8 ) . wrapping_offset ( insn. off as isize ) as * mut u8 ;
168
168
check_mem_store ( x as u64 , 1 , insn_ptr) ?;
169
169
x. write_unaligned ( insn. imm as u8 ) ;
170
170
} ,
171
171
ebpf:: ST_H_IMM => unsafe {
172
172
#[ allow( clippy:: cast_ptr_alignment) ]
173
- let x = ( reg[ _dst] as * const u8 ) . offset ( insn. off as isize ) as * mut u16 ;
173
+ let x = ( reg[ _dst] as * const u8 ) . wrapping_offset ( insn. off as isize ) as * mut u16 ;
174
174
check_mem_store ( x as u64 , 2 , insn_ptr) ?;
175
175
x. write_unaligned ( insn. imm as u16 ) ;
176
176
} ,
177
177
ebpf:: ST_W_IMM => unsafe {
178
178
#[ allow( clippy:: cast_ptr_alignment) ]
179
- let x = ( reg[ _dst] as * const u8 ) . offset ( insn. off as isize ) as * mut u32 ;
179
+ let x = ( reg[ _dst] as * const u8 ) . wrapping_offset ( insn. off as isize ) as * mut u32 ;
180
180
check_mem_store ( x as u64 , 4 , insn_ptr) ?;
181
181
x. write_unaligned ( insn. imm as u32 ) ;
182
182
} ,
183
183
ebpf:: ST_DW_IMM => unsafe {
184
184
#[ allow( clippy:: cast_ptr_alignment) ]
185
- let x = ( reg[ _dst] as * const u8 ) . offset ( insn. off as isize ) as * mut u64 ;
185
+ let x = ( reg[ _dst] as * const u8 ) . wrapping_offset ( insn. off as isize ) as * mut u64 ;
186
186
check_mem_store ( x as u64 , 8 , insn_ptr) ?;
187
187
x. write_unaligned ( insn. imm as u64 ) ;
188
188
} ,
189
189
190
190
// BPF_STX class
191
191
ebpf:: ST_B_REG => unsafe {
192
- let x = ( reg[ _dst] as * const u8 ) . offset ( insn. off as isize ) as * mut u8 ;
192
+ let x = ( reg[ _dst] as * const u8 ) . wrapping_offset ( insn. off as isize ) as * mut u8 ;
193
193
check_mem_store ( x as u64 , 1 , insn_ptr) ?;
194
194
x. write_unaligned ( reg[ _src] as u8 ) ;
195
195
} ,
196
196
ebpf:: ST_H_REG => unsafe {
197
197
#[ allow( clippy:: cast_ptr_alignment) ]
198
- let x = ( reg[ _dst] as * const u8 ) . offset ( insn. off as isize ) as * mut u16 ;
198
+ let x = ( reg[ _dst] as * const u8 ) . wrapping_offset ( insn. off as isize ) as * mut u16 ;
199
199
check_mem_store ( x as u64 , 2 , insn_ptr) ?;
200
200
x. write_unaligned ( reg[ _src] as u16 ) ;
201
201
} ,
202
202
ebpf:: ST_W_REG => unsafe {
203
203
#[ allow( clippy:: cast_ptr_alignment) ]
204
- let x = ( reg[ _dst] as * const u8 ) . offset ( insn. off as isize ) as * mut u32 ;
204
+ let x = ( reg[ _dst] as * const u8 ) . wrapping_offset ( insn. off as isize ) as * mut u32 ;
205
205
check_mem_store ( x as u64 , 4 , insn_ptr) ?;
206
206
x. write_unaligned ( reg[ _src] as u32 ) ;
207
207
} ,
208
208
ebpf:: ST_DW_REG => unsafe {
209
209
#[ allow( clippy:: cast_ptr_alignment) ]
210
- let x = ( reg[ _dst] as * const u8 ) . offset ( insn. off as isize ) as * mut u64 ;
210
+ let x = ( reg[ _dst] as * const u8 ) . wrapping_offset ( insn. off as isize ) as * mut u64 ;
211
211
check_mem_store ( x as u64 , 8 , insn_ptr) ?;
212
212
x. write_unaligned ( reg[ _src] ) ;
213
213
} ,
0 commit comments