|
| 1 | +bnxt_re: avoid shift undefined behavior in bnxt_qplib_alloc_init_hwq |
| 2 | + |
| 3 | +jira LE-3201 |
| 4 | +cve CVE-2024-38540 |
| 5 | +Rebuild_History Non-Buildable kernel-rt-4.18.0-553.27.1.rt7.368.el8_10 |
| 6 | +commit-author Michal Schmidt < [email protected]> |
| 7 | +commit 78cfd17142ef70599d6409cbd709d94b3da58659 |
| 8 | +Empty-Commit: Cherry-Pick Conflicts during history rebuild. |
| 9 | +Will be included in final tarball splat. Ref for failed cherry-pick at: |
| 10 | +ciq/ciq_backports/kernel-rt-4.18.0-553.27.1.rt7.368.el8_10/78cfd171.failed |
| 11 | + |
| 12 | +Undefined behavior is triggered when bnxt_qplib_alloc_init_hwq is called |
| 13 | +with hwq_attr->aux_depth != 0 and hwq_attr->aux_stride == 0. |
| 14 | +In that case, "roundup_pow_of_two(hwq_attr->aux_stride)" gets called. |
| 15 | +roundup_pow_of_two is documented as undefined for 0. |
| 16 | + |
| 17 | +Fix it in the one caller that had this combination. |
| 18 | + |
| 19 | +The undefined behavior was detected by UBSAN: |
| 20 | + UBSAN: shift-out-of-bounds in ./include/linux/log2.h:57:13 |
| 21 | + shift exponent 64 is too large for 64-bit type 'long unsigned int' |
| 22 | + CPU: 24 PID: 1075 Comm: (udev-worker) Not tainted 6.9.0-rc6+ #4 |
| 23 | + Hardware name: Abacus electric, s.r.o. - [email protected] Super Server/H12SSW-iN, BIOS 2.7 10/25/2023 |
| 24 | + Call Trace: |
| 25 | + <TASK> |
| 26 | + dump_stack_lvl+0x5d/0x80 |
| 27 | + ubsan_epilogue+0x5/0x30 |
| 28 | + __ubsan_handle_shift_out_of_bounds.cold+0x61/0xec |
| 29 | + __roundup_pow_of_two+0x25/0x35 [bnxt_re] |
| 30 | + bnxt_qplib_alloc_init_hwq+0xa1/0x470 [bnxt_re] |
| 31 | + bnxt_qplib_create_qp+0x19e/0x840 [bnxt_re] |
| 32 | + bnxt_re_create_qp+0x9b1/0xcd0 [bnxt_re] |
| 33 | + ? srso_alias_return_thunk+0x5/0xfbef5 |
| 34 | + ? srso_alias_return_thunk+0x5/0xfbef5 |
| 35 | + ? __kmalloc+0x1b6/0x4f0 |
| 36 | + ? create_qp.part.0+0x128/0x1c0 [ib_core] |
| 37 | + ? __pfx_bnxt_re_create_qp+0x10/0x10 [bnxt_re] |
| 38 | + create_qp.part.0+0x128/0x1c0 [ib_core] |
| 39 | + ib_create_qp_kernel+0x50/0xd0 [ib_core] |
| 40 | + create_mad_qp+0x8e/0xe0 [ib_core] |
| 41 | + ? __pfx_qp_event_handler+0x10/0x10 [ib_core] |
| 42 | + ib_mad_init_device+0x2be/0x680 [ib_core] |
| 43 | + add_client_context+0x10d/0x1a0 [ib_core] |
| 44 | + enable_device_and_get+0xe0/0x1d0 [ib_core] |
| 45 | + ib_register_device+0x53c/0x630 [ib_core] |
| 46 | + ? srso_alias_return_thunk+0x5/0xfbef5 |
| 47 | + bnxt_re_probe+0xbd8/0xe50 [bnxt_re] |
| 48 | + ? __pfx_bnxt_re_probe+0x10/0x10 [bnxt_re] |
| 49 | + auxiliary_bus_probe+0x49/0x80 |
| 50 | + ? driver_sysfs_add+0x57/0xc0 |
| 51 | + really_probe+0xde/0x340 |
| 52 | + ? pm_runtime_barrier+0x54/0x90 |
| 53 | + ? __pfx___driver_attach+0x10/0x10 |
| 54 | + __driver_probe_device+0x78/0x110 |
| 55 | + driver_probe_device+0x1f/0xa0 |
| 56 | + __driver_attach+0xba/0x1c0 |
| 57 | + bus_for_each_dev+0x8f/0xe0 |
| 58 | + bus_add_driver+0x146/0x220 |
| 59 | + driver_register+0x72/0xd0 |
| 60 | + __auxiliary_driver_register+0x6e/0xd0 |
| 61 | + ? __pfx_bnxt_re_mod_init+0x10/0x10 [bnxt_re] |
| 62 | + bnxt_re_mod_init+0x3e/0xff0 [bnxt_re] |
| 63 | + ? __pfx_bnxt_re_mod_init+0x10/0x10 [bnxt_re] |
| 64 | + do_one_initcall+0x5b/0x310 |
| 65 | + do_init_module+0x90/0x250 |
| 66 | + init_module_from_file+0x86/0xc0 |
| 67 | + idempotent_init_module+0x121/0x2b0 |
| 68 | + __x64_sys_finit_module+0x5e/0xb0 |
| 69 | + do_syscall_64+0x82/0x160 |
| 70 | + ? srso_alias_return_thunk+0x5/0xfbef5 |
| 71 | + ? syscall_exit_to_user_mode_prepare+0x149/0x170 |
| 72 | + ? srso_alias_return_thunk+0x5/0xfbef5 |
| 73 | + ? syscall_exit_to_user_mode+0x75/0x230 |
| 74 | + ? srso_alias_return_thunk+0x5/0xfbef5 |
| 75 | + ? do_syscall_64+0x8e/0x160 |
| 76 | + ? srso_alias_return_thunk+0x5/0xfbef5 |
| 77 | + ? __count_memcg_events+0x69/0x100 |
| 78 | + ? srso_alias_return_thunk+0x5/0xfbef5 |
| 79 | + ? count_memcg_events.constprop.0+0x1a/0x30 |
| 80 | + ? srso_alias_return_thunk+0x5/0xfbef5 |
| 81 | + ? handle_mm_fault+0x1f0/0x300 |
| 82 | + ? srso_alias_return_thunk+0x5/0xfbef5 |
| 83 | + ? do_user_addr_fault+0x34e/0x640 |
| 84 | + ? srso_alias_return_thunk+0x5/0xfbef5 |
| 85 | + ? srso_alias_return_thunk+0x5/0xfbef5 |
| 86 | + entry_SYSCALL_64_after_hwframe+0x76/0x7e |
| 87 | + RIP: 0033:0x7f4e5132821d |
| 88 | + Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d e3 db 0c 00 f7 d8 64 89 01 48 |
| 89 | + RSP: 002b:00007ffca9c906a8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 |
| 90 | + RAX: ffffffffffffffda RBX: 0000563ec8a8f130 RCX: 00007f4e5132821d |
| 91 | + RDX: 0000000000000000 RSI: 00007f4e518fa07d RDI: 000000000000003b |
| 92 | + RBP: 00007ffca9c90760 R08: 00007f4e513f6b20 R09: 00007ffca9c906f0 |
| 93 | + R10: 0000563ec8a8faa0 R11: 0000000000000246 R12: 00007f4e518fa07d |
| 94 | + R13: 0000000000020000 R14: 0000563ec8409e90 R15: 0000563ec8a8fa60 |
| 95 | + </TASK> |
| 96 | + ---[ end trace ]--- |
| 97 | + |
| 98 | +Fixes: 0c4dcd602817 ("RDMA/bnxt_re: Refactor hardware queue memory allocation") |
| 99 | + Signed-off-by: Michal Schmidt < [email protected]> |
| 100 | +Link: https://lore.kernel.org/r/ [email protected] |
| 101 | + Acked-by: Selvin Xavier < [email protected]> |
| 102 | + Signed-off-by: Leon Romanovsky < [email protected]> |
| 103 | +(cherry picked from commit 78cfd17142ef70599d6409cbd709d94b3da58659) |
| 104 | + Signed-off-by: Jonathan Maple < [email protected]> |
| 105 | + |
| 106 | +# Conflicts: |
| 107 | +# drivers/infiniband/hw/bnxt_re/qplib_fp.c |
| 108 | +diff --cc drivers/infiniband/hw/bnxt_re/qplib_fp.c |
| 109 | +index f9d327f5b0be,04258676d072..000000000000 |
| 110 | +--- a/drivers/infiniband/hw/bnxt_re/qplib_fp.c |
| 111 | ++++ b/drivers/infiniband/hw/bnxt_re/qplib_fp.c |
| 112 | +@@@ -985,7 -1013,15 +985,19 @@@ int bnxt_qplib_create_qp(struct bnxt_qp |
| 113 | + hwq_attr.stride = sizeof(struct sq_sge); |
| 114 | + hwq_attr.depth = bnxt_qplib_get_depth(sq); |
| 115 | + hwq_attr.aux_stride = psn_sz; |
| 116 | +++<<<<<<< HEAD |
| 117 | + + hwq_attr.aux_depth = bnxt_qplib_set_sq_size(sq, qp->wqe_mode); |
| 118 | +++======= |
| 119 | ++ hwq_attr.aux_depth = psn_sz ? bnxt_qplib_set_sq_size(sq, qp->wqe_mode) |
| 120 | ++ : 0; |
| 121 | ++ /* Update msn tbl size */ |
| 122 | ++ if (BNXT_RE_HW_RETX(qp->dev_cap_flags) && psn_sz) { |
| 123 | ++ hwq_attr.aux_depth = roundup_pow_of_two(bnxt_qplib_set_sq_size(sq, qp->wqe_mode)); |
| 124 | ++ qp->msn_tbl_sz = hwq_attr.aux_depth; |
| 125 | ++ qp->msn = 0; |
| 126 | ++ } |
| 127 | ++ |
| 128 | +++>>>>>>> 78cfd17142ef (bnxt_re: avoid shift undefined behavior in bnxt_qplib_alloc_init_hwq) |
| 129 | + hwq_attr.type = HWQ_TYPE_QUEUE; |
| 130 | + rc = bnxt_qplib_alloc_init_hwq(&sq->hwq, &hwq_attr); |
| 131 | + if (rc) |
| 132 | +* Unmerged path drivers/infiniband/hw/bnxt_re/qplib_fp.c |
0 commit comments