diff mbox series

net/mlx5e: Fix slab-out-of-bounds in mlx5_query_nic_vport_mac_list()

Message ID 20231130094656.894412-1-lishifeng@sangfor.com.cn (mailing list archive)
State Awaiting Upstream
Delegated to: Netdev Maintainers
Headers show
Series net/mlx5e: Fix slab-out-of-bounds in mlx5_query_nic_vport_mac_list() | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1115 this patch: 1115
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 1142 this patch: 1142
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1142 this patch: 1142
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Shifeng Li Nov. 30, 2023, 9:46 a.m. UTC
Out_sz that the size of out buffer is calculated using query_nic_vport
_context_in structure when driver query the MAC list. However query_nic
_vport_context_in structure is smaller than query_nic_vport_context_out.
When allowed_list_size is greater than 96, calling ether_addr_copy() will
trigger an slab-out-of-bounds.

[ 1170.055866] BUG: KASAN: slab-out-of-bounds in mlx5_query_nic_vport_mac_list+0x481/0x4d0 [mlx5_core]
[ 1170.055869] Read of size 4 at addr ffff88bdbc57d912 by task kworker/u128:1/461
[ 1170.055870]
[ 1170.055932] Workqueue: mlx5_esw_wq esw_vport_change_handler [mlx5_core]
[ 1170.055936] Call Trace:
[ 1170.055949]  dump_stack+0x8b/0xbb
[ 1170.055958]  print_address_description+0x6a/0x270
[ 1170.055961]  kasan_report+0x179/0x2c0
[ 1170.056061]  mlx5_query_nic_vport_mac_list+0x481/0x4d0 [mlx5_core]
[ 1170.056162]  esw_update_vport_addr_list+0x2c5/0xcd0 [mlx5_core]
[ 1170.056257]  esw_vport_change_handle_locked+0xd08/0x1a20 [mlx5_core]
[ 1170.056377]  esw_vport_change_handler+0x6b/0x90 [mlx5_core]
[ 1170.056381]  process_one_work+0x65f/0x12d0
[ 1170.056383]  worker_thread+0x87/0xb50
[ 1170.056390]  kthread+0x2e9/0x3a0
[ 1170.056394]  ret_from_fork+0x1f/0x40

Fixes: e16aea2744ab ("net/mlx5: Introduce access functions to modify/query vport mac lists")
Cc: Ding Hui <dinghui@sangfor.com.cn>
Signed-off-by: Shifeng Li <lishifeng@sangfor.com.cn>
---
 drivers/net/ethernet/mellanox/mlx5/core/vport.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Simon Horman Dec. 3, 2023, 5:50 p.m. UTC | #1
On Thu, Nov 30, 2023 at 01:46:56AM -0800, Shifeng Li wrote:
> Out_sz that the size of out buffer is calculated using query_nic_vport
> _context_in structure when driver query the MAC list. However query_nic
> _vport_context_in structure is smaller than query_nic_vport_context_out.
> When allowed_list_size is greater than 96, calling ether_addr_copy() will
> trigger an slab-out-of-bounds.
> 
> [ 1170.055866] BUG: KASAN: slab-out-of-bounds in mlx5_query_nic_vport_mac_list+0x481/0x4d0 [mlx5_core]
> [ 1170.055869] Read of size 4 at addr ffff88bdbc57d912 by task kworker/u128:1/461
> [ 1170.055870]
> [ 1170.055932] Workqueue: mlx5_esw_wq esw_vport_change_handler [mlx5_core]
> [ 1170.055936] Call Trace:
> [ 1170.055949]  dump_stack+0x8b/0xbb
> [ 1170.055958]  print_address_description+0x6a/0x270
> [ 1170.055961]  kasan_report+0x179/0x2c0
> [ 1170.056061]  mlx5_query_nic_vport_mac_list+0x481/0x4d0 [mlx5_core]
> [ 1170.056162]  esw_update_vport_addr_list+0x2c5/0xcd0 [mlx5_core]
> [ 1170.056257]  esw_vport_change_handle_locked+0xd08/0x1a20 [mlx5_core]
> [ 1170.056377]  esw_vport_change_handler+0x6b/0x90 [mlx5_core]
> [ 1170.056381]  process_one_work+0x65f/0x12d0
> [ 1170.056383]  worker_thread+0x87/0xb50
> [ 1170.056390]  kthread+0x2e9/0x3a0
> [ 1170.056394]  ret_from_fork+0x1f/0x40
> 
> Fixes: e16aea2744ab ("net/mlx5: Introduce access functions to modify/query vport mac lists")
> Cc: Ding Hui <dinghui@sangfor.com.cn>
> Signed-off-by: Shifeng Li <lishifeng@sangfor.com.cn>

Hi,

I am unsure how you calculated the 96 figure above.
But in any case I agree that the cited patch introduced
the mismatch that you describe.

Reviewed-by: Simon Horman <horms@kernel.org>
Shifeng Li Dec. 4, 2023, 2:30 a.m. UTC | #2
On 2023/12/4 1:50, Simon Horman wrote:
> On Thu, Nov 30, 2023 at 01:46:56AM -0800, Shifeng Li wrote:
>> Out_sz that the size of out buffer is calculated using query_nic_vport
>> _context_in structure when driver query the MAC list. However query_nic
>> _vport_context_in structure is smaller than query_nic_vport_context_out.
>> When allowed_list_size is greater than 96, calling ether_addr_copy() will
>> trigger an slab-out-of-bounds.
>>
>> [ 1170.055866] BUG: KASAN: slab-out-of-bounds in mlx5_query_nic_vport_mac_list+0x481/0x4d0 [mlx5_core]
>> [ 1170.055869] Read of size 4 at addr ffff88bdbc57d912 by task kworker/u128:1/461
>> [ 1170.055870]
>> [ 1170.055932] Workqueue: mlx5_esw_wq esw_vport_change_handler [mlx5_core]
>> [ 1170.055936] Call Trace:
>> [ 1170.055949]  dump_stack+0x8b/0xbb
>> [ 1170.055958]  print_address_description+0x6a/0x270
>> [ 1170.055961]  kasan_report+0x179/0x2c0
>> [ 1170.056061]  mlx5_query_nic_vport_mac_list+0x481/0x4d0 [mlx5_core]
>> [ 1170.056162]  esw_update_vport_addr_list+0x2c5/0xcd0 [mlx5_core]
>> [ 1170.056257]  esw_vport_change_handle_locked+0xd08/0x1a20 [mlx5_core]
>> [ 1170.056377]  esw_vport_change_handler+0x6b/0x90 [mlx5_core]
>> [ 1170.056381]  process_one_work+0x65f/0x12d0
>> [ 1170.056383]  worker_thread+0x87/0xb50
>> [ 1170.056390]  kthread+0x2e9/0x3a0
>> [ 1170.056394]  ret_from_fork+0x1f/0x40
>>
>> Fixes: e16aea2744ab ("net/mlx5: Introduce access functions to modify/query vport mac lists")
>> Cc: Ding Hui <dinghui@sangfor.com.cn>
>> Signed-off-by: Shifeng Li <lishifeng@sangfor.com.cn>
> 
> Hi,
> 
> I am unsure how you calculated the 96 figure above.
> But in any case I agree that the cited patch introduced
> the mismatch that you describe.
> 
out_sz = MLX5_ST_SZ_BYTES(query_nic_vport_context_in) + req_list_size * MLX5_ST_SZ_BYTES(mac_address_layout)
        = 0x80/8 + 128 * 0x40/8 = 0x410 (bytes)

nic_vport_ctx = MLX5_ADDR_OF(query_nic_vport_context_out, out, nic_vport_context)
               = 0x880/8 = 0x110 (bytes)
mac_addr = MLX5_ADDR_OF(nic_vport_context, nic_vport_ctx, current_uc_mac_address[96]) + 2
          = 0x110 + 96 * 8 + 2
          = 0x412 (bytes)

When i is 96,  the mac_addr offset is 0x412 but the out_sz is 0x410.
And that will trigger an slab-out-of-bounds.

Thanks.

> Reviewed-by: Simon Horman <horms@kernel.org>
Simon Horman Dec. 6, 2023, 9:30 p.m. UTC | #3
On Mon, Dec 04, 2023 at 10:30:14AM +0800, Shifeng Li wrote:
> On 2023/12/4 1:50, Simon Horman wrote:
> > On Thu, Nov 30, 2023 at 01:46:56AM -0800, Shifeng Li wrote:
> > > Out_sz that the size of out buffer is calculated using query_nic_vport
> > > _context_in structure when driver query the MAC list. However query_nic
> > > _vport_context_in structure is smaller than query_nic_vport_context_out.
> > > When allowed_list_size is greater than 96, calling ether_addr_copy() will
> > > trigger an slab-out-of-bounds.
> > > 
> > > [ 1170.055866] BUG: KASAN: slab-out-of-bounds in mlx5_query_nic_vport_mac_list+0x481/0x4d0 [mlx5_core]
> > > [ 1170.055869] Read of size 4 at addr ffff88bdbc57d912 by task kworker/u128:1/461
> > > [ 1170.055870]
> > > [ 1170.055932] Workqueue: mlx5_esw_wq esw_vport_change_handler [mlx5_core]
> > > [ 1170.055936] Call Trace:
> > > [ 1170.055949]  dump_stack+0x8b/0xbb
> > > [ 1170.055958]  print_address_description+0x6a/0x270
> > > [ 1170.055961]  kasan_report+0x179/0x2c0
> > > [ 1170.056061]  mlx5_query_nic_vport_mac_list+0x481/0x4d0 [mlx5_core]
> > > [ 1170.056162]  esw_update_vport_addr_list+0x2c5/0xcd0 [mlx5_core]
> > > [ 1170.056257]  esw_vport_change_handle_locked+0xd08/0x1a20 [mlx5_core]
> > > [ 1170.056377]  esw_vport_change_handler+0x6b/0x90 [mlx5_core]
> > > [ 1170.056381]  process_one_work+0x65f/0x12d0
> > > [ 1170.056383]  worker_thread+0x87/0xb50
> > > [ 1170.056390]  kthread+0x2e9/0x3a0
> > > [ 1170.056394]  ret_from_fork+0x1f/0x40
> > > 
> > > Fixes: e16aea2744ab ("net/mlx5: Introduce access functions to modify/query vport mac lists")
> > > Cc: Ding Hui <dinghui@sangfor.com.cn>
> > > Signed-off-by: Shifeng Li <lishifeng@sangfor.com.cn>
> > 
> > Hi,
> > 
> > I am unsure how you calculated the 96 figure above.
> > But in any case I agree that the cited patch introduced
> > the mismatch that you describe.
> > 
> out_sz = MLX5_ST_SZ_BYTES(query_nic_vport_context_in) + req_list_size * MLX5_ST_SZ_BYTES(mac_address_layout)
>        = 0x80/8 + 128 * 0x40/8 = 0x410 (bytes)
> 
> nic_vport_ctx = MLX5_ADDR_OF(query_nic_vport_context_out, out, nic_vport_context)
>               = 0x880/8 = 0x110 (bytes)
> mac_addr = MLX5_ADDR_OF(nic_vport_context, nic_vport_ctx, current_uc_mac_address[96]) + 2
>          = 0x110 + 96 * 8 + 2
>          = 0x412 (bytes)
> 
> When i is 96,  the mac_addr offset is 0x412 but the out_sz is 0x410.
> And that will trigger an slab-out-of-bounds.

Thanks for the clarification, this looks good to me.

> > Reviewed-by: Simon Horman <horms@kernel.org>
Saeed Mahameed Dec. 6, 2023, 9:43 p.m. UTC | #4
On 30 Nov 01:46, Shifeng Li wrote:
>Out_sz that the size of out buffer is calculated using query_nic_vport
>_context_in structure when driver query the MAC list. However query_nic
>_vport_context_in structure is smaller than query_nic_vport_context_out.
>When allowed_list_size is greater than 96, calling ether_addr_copy() will
>trigger an slab-out-of-bounds.
>
>[ 1170.055866] BUG: KASAN: slab-out-of-bounds in mlx5_query_nic_vport_mac_list+0x481/0x4d0 [mlx5_core]
>[ 1170.055869] Read of size 4 at addr ffff88bdbc57d912 by task kworker/u128:1/461
>[ 1170.055870]
>[ 1170.055932] Workqueue: mlx5_esw_wq esw_vport_change_handler [mlx5_core]
>[ 1170.055936] Call Trace:
>[ 1170.055949]  dump_stack+0x8b/0xbb
>[ 1170.055958]  print_address_description+0x6a/0x270
>[ 1170.055961]  kasan_report+0x179/0x2c0
>[ 1170.056061]  mlx5_query_nic_vport_mac_list+0x481/0x4d0 [mlx5_core]
>[ 1170.056162]  esw_update_vport_addr_list+0x2c5/0xcd0 [mlx5_core]
>[ 1170.056257]  esw_vport_change_handle_locked+0xd08/0x1a20 [mlx5_core]
>[ 1170.056377]  esw_vport_change_handler+0x6b/0x90 [mlx5_core]
>[ 1170.056381]  process_one_work+0x65f/0x12d0
>[ 1170.056383]  worker_thread+0x87/0xb50
>[ 1170.056390]  kthread+0x2e9/0x3a0
>[ 1170.056394]  ret_from_fork+0x1f/0x40
>
>Fixes: e16aea2744ab ("net/mlx5: Introduce access functions to modify/query vport mac lists")
>Cc: Ding Hui <dinghui@sangfor.com.cn>
>Signed-off-by: Shifeng Li <lishifeng@sangfor.com.cn>

Applied to net-mlx5. 

Thanks,
Saeed.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/vport.c b/drivers/net/ethernet/mellanox/mlx5/core/vport.c
index 5a31fb47ffa5..21753f327868 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/vport.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/vport.c
@@ -277,7 +277,7 @@  int mlx5_query_nic_vport_mac_list(struct mlx5_core_dev *dev,
 		req_list_size = max_list_size;
 	}
 
-	out_sz = MLX5_ST_SZ_BYTES(query_nic_vport_context_in) +
+	out_sz = MLX5_ST_SZ_BYTES(query_nic_vport_context_out) +
 			req_list_size * MLX5_ST_SZ_BYTES(mac_address_layout);
 
 	out = kvzalloc(out_sz, GFP_KERNEL);