Commit 86348d2
net: prestera: Add flex arrays to some structs
The "struct prestera_msg_vtcam_rule_add_req" uses a dynamically sized
set of trailing elements. Specifically, it uses an array of structures
of type "prestera_msg_acl_action actions_msg".
The "struct prestera_msg_flood_domain_ports_set_req" also uses a
dynamically sized set of trailing elements. Specifically, it uses an
array of structures of type "prestera_msg_acl_action actions_msg".
So, use the preferred way in the kernel declaring flexible arrays [1].
At the same time, prepare for the coming implementation by GCC and Clang
of the __counted_by attribute. Flexible array members annotated with
__counted_by can have their accesses bounds-checked at run-time via
CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for
strcpy/memcpy-family functions). In this case, it is important to note
that the attribute used is specifically __counted_by_le since the
counters are of type __le32.
The logic does not need to change since the counters for the flexible
arrays are asigned before any access to the arrays.
The order in which the structure prestera_msg_vtcam_rule_add_req and the
structure prestera_msg_flood_domain_ports_set_req are defined must be
changed to avoid incomplete type errors.
Also, avoid the open-coded arithmetic in memory allocator functions [2]
using the "struct_size" macro.
Moreover, the new structure members also allow us to avoid the open-
coded arithmetic on pointers. So, take advantage of this refactoring
accordingly.
This code was detected with the help of Coccinelle, and audited and
modified manually.
Link: https://www.kernel.org/doc/html/next/process/deprecated.html#zero-length-and-one-element-arrays [1]
Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [2]
Signed-off-by: Erick Archer <[email protected]>
Reviewed-by: Simon Horman <[email protected]>
Reviewed-by: Kees Cook <[email protected]>
Link: https://lore.kernel.org/r/AS8PR02MB7237E8469568A59795F1F0408BE12@AS8PR02MB7237.eurprd02.prod.outlook.com
Signed-off-by: Jakub Kicinski <[email protected]>1 parent a6fb986 commit 86348d2
1 file changed
+37
-46
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
419 | 419 | | |
420 | 420 | | |
421 | 421 | | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | 422 | | |
432 | 423 | | |
433 | 424 | | |
| |||
471 | 462 | | |
472 | 463 | | |
473 | 464 | | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
474 | 475 | | |
475 | 476 | | |
476 | 477 | | |
| |||
702 | 703 | | |
703 | 704 | | |
704 | 705 | | |
705 | | - | |
706 | | - | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | 706 | | |
712 | 707 | | |
713 | 708 | | |
| |||
725 | 720 | | |
726 | 721 | | |
727 | 722 | | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
728 | 730 | | |
729 | 731 | | |
730 | 732 | | |
| |||
1371 | 1373 | | |
1372 | 1374 | | |
1373 | 1375 | | |
1374 | | - | |
1375 | 1376 | | |
1376 | 1377 | | |
1377 | | - | |
1378 | | - | |
| 1378 | + | |
1379 | 1379 | | |
1380 | 1380 | | |
1381 | 1381 | | |
1382 | | - | |
1383 | | - | |
1384 | | - | |
1385 | | - | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
1386 | 1385 | | |
1387 | 1386 | | |
1388 | | - | |
1389 | 1387 | | |
1390 | | - | |
1391 | 1388 | | |
1392 | 1389 | | |
1393 | 1390 | | |
1394 | 1391 | | |
1395 | 1392 | | |
1396 | 1393 | | |
1397 | 1394 | | |
1398 | | - | |
| 1395 | + | |
1399 | 1396 | | |
1400 | 1397 | | |
1401 | 1398 | | |
| |||
1411 | 1408 | | |
1412 | 1409 | | |
1413 | 1410 | | |
1414 | | - | |
| 1411 | + | |
1415 | 1412 | | |
1416 | 1413 | | |
1417 | 1414 | | |
| |||
2461 | 2458 | | |
2462 | 2459 | | |
2463 | 2460 | | |
2464 | | - | |
2465 | 2461 | | |
2466 | 2462 | | |
2467 | 2463 | | |
2468 | | - | |
2469 | | - | |
| 2464 | + | |
2470 | 2465 | | |
2471 | 2466 | | |
| 2467 | + | |
2472 | 2468 | | |
2473 | 2469 | | |
2474 | 2470 | | |
| |||
2477 | 2473 | | |
2478 | 2474 | | |
2479 | 2475 | | |
2480 | | - | |
2481 | | - | |
2482 | | - | |
2483 | | - | |
| 2476 | + | |
| 2477 | + | |
| 2478 | + | |
2484 | 2479 | | |
2485 | 2480 | | |
2486 | | - | |
2487 | | - | |
2488 | | - | |
2489 | 2481 | | |
2490 | 2482 | | |
2491 | 2483 | | |
| |||
2494 | 2486 | | |
2495 | 2487 | | |
2496 | 2488 | | |
2497 | | - | |
| 2489 | + | |
2498 | 2490 | | |
2499 | 2491 | | |
2500 | 2492 | | |
2501 | | - | |
| 2493 | + | |
2502 | 2494 | | |
2503 | | - | |
| 2495 | + | |
2504 | 2496 | | |
2505 | 2497 | | |
2506 | 2498 | | |
2507 | | - | |
| 2499 | + | |
2508 | 2500 | | |
2509 | | - | |
2510 | | - | |
| 2501 | + | |
| 2502 | + | |
2511 | 2503 | | |
2512 | 2504 | | |
2513 | | - | |
2514 | | - | |
2515 | | - | |
| 2505 | + | |
| 2506 | + | |
2516 | 2507 | | |
2517 | 2508 | | |
2518 | 2509 | | |
2519 | 2510 | | |
2520 | 2511 | | |
2521 | | - | |
| 2512 | + | |
2522 | 2513 | | |
2523 | 2514 | | |
2524 | 2515 | | |
| |||
0 commit comments