Skip to content

Commit b2dbde3

Browse files
Michal Swiatkowskianguy11
authored andcommitted
ice: fix out-of-bounds KASAN warning in virtchnl
KASAN reported: [ 9793.708867] BUG: KASAN: global-out-of-bounds in ice_get_link_speed+0x16/0x30 [ice] [ 9793.709205] Read of size 4 at addr ffffffffc1271b1c by task kworker/6:1/402 [ 9793.709222] CPU: 6 PID: 402 Comm: kworker/6:1 Kdump: loaded Tainted: G B OE 6.1.0+ #3 [ 9793.709235] Hardware name: Intel Corporation S2600WFT/S2600WFT, BIOS SE5C620.86B.00.01.0014.070920180847 07/09/2018 [ 9793.709245] Workqueue: ice ice_service_task [ice] [ 9793.709575] Call Trace: [ 9793.709582] <TASK> [ 9793.709588] dump_stack_lvl+0x44/0x5c [ 9793.709613] print_report+0x17f/0x47b [ 9793.709632] ? __cpuidle_text_end+0x5/0x5 [ 9793.709653] ? ice_get_link_speed+0x16/0x30 [ice] [ 9793.709986] ? ice_get_link_speed+0x16/0x30 [ice] [ 9793.710317] kasan_report+0xb7/0x140 [ 9793.710335] ? ice_get_link_speed+0x16/0x30 [ice] [ 9793.710673] ice_get_link_speed+0x16/0x30 [ice] [ 9793.711006] ice_vc_notify_vf_link_state+0x14c/0x160 [ice] [ 9793.711351] ? ice_vc_repr_cfg_promiscuous_mode+0x120/0x120 [ice] [ 9793.711698] ice_vc_process_vf_msg+0x7a7/0xc00 [ice] [ 9793.712074] __ice_clean_ctrlq+0x98f/0xd20 [ice] [ 9793.712534] ? ice_bridge_setlink+0x410/0x410 [ice] [ 9793.712979] ? __request_module+0x320/0x520 [ 9793.713014] ? ice_process_vflr_event+0x27/0x130 [ice] [ 9793.713489] ice_service_task+0x11cf/0x1950 [ice] [ 9793.713948] ? io_schedule_timeout+0xb0/0xb0 [ 9793.713972] process_one_work+0x3d0/0x6a0 [ 9793.714003] worker_thread+0x8a/0x610 [ 9793.714031] ? process_one_work+0x6a0/0x6a0 [ 9793.714049] kthread+0x164/0x1a0 [ 9793.714071] ? kthread_complete_and_exit+0x20/0x20 [ 9793.714100] ret_from_fork+0x1f/0x30 [ 9793.714137] </TASK> [ 9793.714151] The buggy address belongs to the variable: [ 9793.714158] ice_aq_to_link_speed+0x3c/0xffffffffffff3520 [ice] [ 9793.714632] Memory state around the buggy address: [ 9793.714642] ffffffffc1271a00: f9 f9 f9 f9 00 00 05 f9 f9 f9 f9 f9 00 00 02 f9 [ 9793.714656] ffffffffc1271a80: f9 f9 f9 f9 00 00 04 f9 f9 f9 f9 f9 00 00 00 00 [ 9793.714670] >ffffffffc1271b00: 00 00 00 04 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9 [ 9793.714680] ^ [ 9793.714690] ffffffffc1271b80: 00 00 00 00 00 04 f9 f9 f9 f9 f9 f9 00 00 00 00 [ 9793.714704] ffffffffc1271c00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 The ICE_AQ_LINK_SPEED_UNKNOWN define is BIT(15). The value is bigger than both legacy and normal link speed tables. Add one element (0 - unknown) to both tables. There is no need to explicitly set table size, leave it empty. Fixes: 1d0e28a ("ice: Remove and replace ice speed defines with ethtool.h versions") Signed-off-by: Michal Swiatkowski <[email protected]> Reviewed-by: Alexander Lobakin <[email protected]> Tested-by: Gurucharan G <[email protected]> (A Contingent worker at Intel) Signed-off-by: Tony Nguyen <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]>
1 parent 4d159f7 commit b2dbde3

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

drivers/net/ethernet/intel/ice/ice_common.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5524,7 +5524,7 @@ bool ice_fw_supports_report_dflt_cfg(struct ice_hw *hw)
55245524
* returned by the firmware is a 16 bit * value, but is indexed
55255525
* by [fls(speed) - 1]
55265526
*/
5527-
static const u32 ice_aq_to_link_speed[15] = {
5527+
static const u32 ice_aq_to_link_speed[] = {
55285528
SPEED_10, /* BIT(0) */
55295529
SPEED_100,
55305530
SPEED_1000,
@@ -5536,10 +5536,6 @@ static const u32 ice_aq_to_link_speed[15] = {
55365536
SPEED_40000,
55375537
SPEED_50000,
55385538
SPEED_100000, /* BIT(10) */
5539-
0,
5540-
0,
5541-
0,
5542-
0 /* BIT(14) */
55435539
};
55445540

55455541
/**
@@ -5550,5 +5546,8 @@ static const u32 ice_aq_to_link_speed[15] = {
55505546
*/
55515547
u32 ice_get_link_speed(u16 index)
55525548
{
5549+
if (index >= ARRAY_SIZE(ice_aq_to_link_speed))
5550+
return 0;
5551+
55535552
return ice_aq_to_link_speed[index];
55545553
}

drivers/net/ethernet/intel/ice/ice_vf_mbx.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ ice_aq_send_msg_to_vf(struct ice_hw *hw, u16 vfid, u32 v_opcode, u32 v_retval,
3939
return ice_sq_send_cmd(hw, &hw->mailboxq, &desc, msg, msglen, cd);
4040
}
4141

42-
static const u32 ice_legacy_aq_to_vc_speed[15] = {
42+
static const u32 ice_legacy_aq_to_vc_speed[] = {
4343
VIRTCHNL_LINK_SPEED_100MB, /* BIT(0) */
4444
VIRTCHNL_LINK_SPEED_100MB,
4545
VIRTCHNL_LINK_SPEED_1GB,
@@ -51,10 +51,6 @@ static const u32 ice_legacy_aq_to_vc_speed[15] = {
5151
VIRTCHNL_LINK_SPEED_40GB,
5252
VIRTCHNL_LINK_SPEED_40GB,
5353
VIRTCHNL_LINK_SPEED_40GB,
54-
VIRTCHNL_LINK_SPEED_UNKNOWN,
55-
VIRTCHNL_LINK_SPEED_UNKNOWN,
56-
VIRTCHNL_LINK_SPEED_UNKNOWN,
57-
VIRTCHNL_LINK_SPEED_UNKNOWN /* BIT(14) */
5854
};
5955

6056
/**
@@ -71,21 +67,20 @@ static const u32 ice_legacy_aq_to_vc_speed[15] = {
7167
*/
7268
u32 ice_conv_link_speed_to_virtchnl(bool adv_link_support, u16 link_speed)
7369
{
74-
u32 speed;
70+
/* convert a BIT() value into an array index */
71+
u32 index = fls(link_speed) - 1;
7572

76-
if (adv_link_support) {
77-
/* convert a BIT() value into an array index */
78-
speed = ice_get_link_speed(fls(link_speed) - 1);
79-
} else {
73+
if (adv_link_support)
74+
return ice_get_link_speed(index);
75+
else if (index < ARRAY_SIZE(ice_legacy_aq_to_vc_speed))
8076
/* Virtchnl speeds are not defined for every speed supported in
8177
* the hardware. To maintain compatibility with older AVF
8278
* drivers, while reporting the speed the new speed values are
8379
* resolved to the closest known virtchnl speeds
8480
*/
85-
speed = ice_legacy_aq_to_vc_speed[fls(link_speed) - 1];
86-
}
81+
return ice_legacy_aq_to_vc_speed[index];
8782

88-
return speed;
83+
return VIRTCHNL_LINK_SPEED_UNKNOWN;
8984
}
9085

9186
/* The mailbox overflow detection algorithm helps to check if there

0 commit comments

Comments
 (0)