@@ -247,6 +247,42 @@ void aa_dfa_free_kref(struct kref *kref)
247
247
dfa_free (dfa );
248
248
}
249
249
250
+
251
+
252
+ /**
253
+ * remap_data16_to_data32 - remap u16 @old table to a u32 based table
254
+ * @old: table to remap
255
+ *
256
+ * Returns: new table with u32 entries instead of u16.
257
+ *
258
+ * Note: will free @old so caller does not have to
259
+ */
260
+ static struct table_header * remap_data16_to_data32 (struct table_header * old )
261
+ {
262
+ struct table_header * new ;
263
+ size_t tsize ;
264
+ u32 i ;
265
+
266
+ tsize = table_size (old -> td_lolen , YYTD_DATA32 );
267
+ new = kvzalloc (tsize , GFP_KERNEL );
268
+ if (!new ) {
269
+ kvfree (old );
270
+ return NULL ;
271
+ }
272
+ new -> td_id = old -> td_id ;
273
+ new -> td_flags = YYTD_DATA32 ;
274
+ new -> td_lolen = old -> td_lolen ;
275
+
276
+ for (i = 0 ; i < old -> td_lolen ; i ++ )
277
+ TABLE_DATAU32 (new )[i ] = (u32 ) TABLE_DATAU16 (old )[i ];
278
+
279
+ kvfree (old );
280
+ if (is_vmalloc_addr (new ))
281
+ vm_unmap_aliases ();
282
+
283
+ return new ;
284
+ }
285
+
250
286
/**
251
287
* aa_dfa_unpack - unpack the binary tables of a serialized dfa
252
288
* @blob: aligned serialized stream of data to unpack (NOT NULL)
@@ -326,8 +362,10 @@ struct aa_dfa *aa_dfa_unpack(void *blob, size_t size, int flags)
326
362
case YYTD_ID_DEF :
327
363
case YYTD_ID_NXT :
328
364
case YYTD_ID_CHK :
329
- if (table -> td_flags != YYTD_DATA16 )
365
+ if (!(table -> td_flags == YYTD_DATA16 ||
366
+ table -> td_flags == YYTD_DATA32 )) {
330
367
goto fail ;
368
+ }
331
369
break ;
332
370
case YYTD_ID_EC :
333
371
if (table -> td_flags != YYTD_DATA8 )
@@ -342,6 +380,23 @@ struct aa_dfa *aa_dfa_unpack(void *blob, size_t size, int flags)
342
380
dfa -> tables [table -> td_id ] = table ;
343
381
data += table_size (table -> td_lolen , table -> td_flags );
344
382
size -= table_size (table -> td_lolen , table -> td_flags );
383
+
384
+ /*
385
+ * this remapping has to be done after incrementing data above
386
+ * for now straight remap, later have dfa support both
387
+ */
388
+ switch (table -> td_id ) {
389
+ case YYTD_ID_DEF :
390
+ case YYTD_ID_NXT :
391
+ case YYTD_ID_CHK :
392
+ if (table -> td_flags == YYTD_DATA16 ) {
393
+ table = remap_data16_to_data32 (table );
394
+ if (!table )
395
+ goto fail ;
396
+ }
397
+ dfa -> tables [table -> td_id ] = table ;
398
+ break ;
399
+ }
345
400
table = NULL ;
346
401
}
347
402
error = verify_table_headers (dfa -> tables , flags );
@@ -395,10 +450,10 @@ do { \
395
450
aa_state_t aa_dfa_match_len (struct aa_dfa * dfa , aa_state_t start ,
396
451
const char * str , int len )
397
452
{
398
- u16 * def = DEFAULT_TABLE (dfa );
453
+ u32 * def = DEFAULT_TABLE (dfa );
399
454
u32 * base = BASE_TABLE (dfa );
400
- u16 * next = NEXT_TABLE (dfa );
401
- u16 * check = CHECK_TABLE (dfa );
455
+ u32 * next = NEXT_TABLE (dfa );
456
+ u32 * check = CHECK_TABLE (dfa );
402
457
aa_state_t state = start ;
403
458
404
459
if (state == DFA_NOMATCH )
@@ -434,10 +489,10 @@ aa_state_t aa_dfa_match_len(struct aa_dfa *dfa, aa_state_t start,
434
489
*/
435
490
aa_state_t aa_dfa_match (struct aa_dfa * dfa , aa_state_t start , const char * str )
436
491
{
437
- u16 * def = DEFAULT_TABLE (dfa );
492
+ u32 * def = DEFAULT_TABLE (dfa );
438
493
u32 * base = BASE_TABLE (dfa );
439
- u16 * next = NEXT_TABLE (dfa );
440
- u16 * check = CHECK_TABLE (dfa );
494
+ u32 * next = NEXT_TABLE (dfa );
495
+ u32 * check = CHECK_TABLE (dfa );
441
496
aa_state_t state = start ;
442
497
443
498
if (state == DFA_NOMATCH )
@@ -472,10 +527,10 @@ aa_state_t aa_dfa_match(struct aa_dfa *dfa, aa_state_t start, const char *str)
472
527
*/
473
528
aa_state_t aa_dfa_next (struct aa_dfa * dfa , aa_state_t state , const char c )
474
529
{
475
- u16 * def = DEFAULT_TABLE (dfa );
530
+ u32 * def = DEFAULT_TABLE (dfa );
476
531
u32 * base = BASE_TABLE (dfa );
477
- u16 * next = NEXT_TABLE (dfa );
478
- u16 * check = CHECK_TABLE (dfa );
532
+ u32 * next = NEXT_TABLE (dfa );
533
+ u32 * check = CHECK_TABLE (dfa );
479
534
480
535
/* current state is <state>, matching character *str */
481
536
if (dfa -> tables [YYTD_ID_EC ]) {
@@ -490,10 +545,10 @@ aa_state_t aa_dfa_next(struct aa_dfa *dfa, aa_state_t state, const char c)
490
545
491
546
aa_state_t aa_dfa_outofband_transition (struct aa_dfa * dfa , aa_state_t state )
492
547
{
493
- u16 * def = DEFAULT_TABLE (dfa );
548
+ u32 * def = DEFAULT_TABLE (dfa );
494
549
u32 * base = BASE_TABLE (dfa );
495
- u16 * next = NEXT_TABLE (dfa );
496
- u16 * check = CHECK_TABLE (dfa );
550
+ u32 * next = NEXT_TABLE (dfa );
551
+ u32 * check = CHECK_TABLE (dfa );
497
552
u32 b = (base )[(state )];
498
553
499
554
if (!(b & MATCH_FLAG_OOB_TRANSITION ))
@@ -521,10 +576,10 @@ aa_state_t aa_dfa_outofband_transition(struct aa_dfa *dfa, aa_state_t state)
521
576
aa_state_t aa_dfa_match_until (struct aa_dfa * dfa , aa_state_t start ,
522
577
const char * str , const char * * retpos )
523
578
{
524
- u16 * def = DEFAULT_TABLE (dfa );
579
+ u32 * def = DEFAULT_TABLE (dfa );
525
580
u32 * base = BASE_TABLE (dfa );
526
- u16 * next = NEXT_TABLE (dfa );
527
- u16 * check = CHECK_TABLE (dfa );
581
+ u32 * next = NEXT_TABLE (dfa );
582
+ u32 * check = CHECK_TABLE (dfa );
528
583
u32 * accept = ACCEPT_TABLE (dfa );
529
584
aa_state_t state = start , pos ;
530
585
@@ -582,10 +637,10 @@ aa_state_t aa_dfa_match_until(struct aa_dfa *dfa, aa_state_t start,
582
637
aa_state_t aa_dfa_matchn_until (struct aa_dfa * dfa , aa_state_t start ,
583
638
const char * str , int n , const char * * retpos )
584
639
{
585
- u16 * def = DEFAULT_TABLE (dfa );
640
+ u32 * def = DEFAULT_TABLE (dfa );
586
641
u32 * base = BASE_TABLE (dfa );
587
- u16 * next = NEXT_TABLE (dfa );
588
- u16 * check = CHECK_TABLE (dfa );
642
+ u32 * next = NEXT_TABLE (dfa );
643
+ u32 * check = CHECK_TABLE (dfa );
589
644
u32 * accept = ACCEPT_TABLE (dfa );
590
645
aa_state_t state = start , pos ;
591
646
@@ -658,10 +713,10 @@ static aa_state_t leftmatch_fb(struct aa_dfa *dfa, aa_state_t start,
658
713
const char * str , struct match_workbuf * wb ,
659
714
unsigned int * count )
660
715
{
661
- u16 * def = DEFAULT_TABLE (dfa );
716
+ u32 * def = DEFAULT_TABLE (dfa );
662
717
u32 * base = BASE_TABLE (dfa );
663
- u16 * next = NEXT_TABLE (dfa );
664
- u16 * check = CHECK_TABLE (dfa );
718
+ u32 * next = NEXT_TABLE (dfa );
719
+ u32 * check = CHECK_TABLE (dfa );
665
720
aa_state_t state = start , pos ;
666
721
667
722
AA_BUG (!dfa );
0 commit comments