Subject: Re: [net-next 05/13] i40e: add range check to i40e_aq_rc_to_posix

From: Sergei Shtylyov <[email-masked]>
Date: Tue, 09 Dec 2014 17:23:56 +0300

Hello.

On 12/9/2014 2:22 PM, Jeff Kirsher wrote:

> From: Shannon Nelson <[email-masked]>

> Just to be sure, add a range check to avoid any possible
> array index-out-of-bound issues.

> Change-ID: I9323bee6732c2a47599816e1d6c6b3a1f8dcbf54
> Signed-off-by: Shannon Nelson <[email-masked]>
> Acked-by: Michal Kosiarz <[email-masked]>
> Tested-by: Jim Young <[email-masked]>
> Signed-off-by: Jeff Kirsher <[email-masked]>
> ---
>   drivers/net/ethernet/intel/i40e/i40e_adminq.h   | 2 ++
>   drivers/net/ethernet/intel/i40evf/i40e_adminq.h | 2 ++
>   2 files changed, 4 insertions(+)

> diff --git a/drivers/net/ethernet/intel/i40e/i40e_adminq.h b/drivers/net/ethernet/intel/i40e/i40e_adminq.h
> index 618fe96..4064b1e 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_adminq.h
> +++ b/drivers/net/ethernet/intel/i40e/i40e_adminq.h
> @@ -136,6 +136,8 @@ static inline int i40e_aq_rc_to_posix(u16 aq_rc)
>   		-EFBIG,      /* I40E_AQ_RC_EFBIG */
>   	};
>
> +	if (aq_rc >= (sizeof(aq_to_posix) / sizeof((aq_to_posix)[0])))

    There's ARRAY_SIZE() macro exactly for such computations. And parens 
around the last 'aq_to_posix' are not needed.

> +		return -ERANGE;
>   	return aq_to_posix[aq_rc];
>   }
>
> diff --git a/drivers/net/ethernet/intel/i40evf/i40e_adminq.h b/drivers/net/ethernet/intel/i40evf/i40e_adminq.h
> index d5d3c93..4d63514 100644
> --- a/drivers/net/ethernet/intel/i40evf/i40e_adminq.h
> +++ b/drivers/net/ethernet/intel/i40evf/i40e_adminq.h
> @@ -136,6 +136,8 @@ static inline int i40e_aq_rc_to_posix(u16 aq_rc)
>   		-EFBIG,      /* I40E_AQ_RC_EFBIG */
>   	};
>
> +	if (aq_rc >= (sizeof(aq_to_posix) / sizeof((aq_to_posix)[0])))

    Likewise.

[...]

WBR, Sergei