On Tue, May 28, 2024 at 07:28:34AM +0000, Soumyadeep Hore wrote:
> When the message for getting timestamp latches is sent by the driver,
> number of latches is equal to 0. Current implementation of message
> validation function incorrectly notifies this kind of message length as
> invalid.
> 

This description doesn't seem to match what the code is doing here.
The code change below is changing the check on the message length from
checking for >88 bytes rather than >= 88 bytes. This doesn't seem to have
anything to do with not returning error when latches == 0. That check is a
few lines further in the code block and is unmodified by this patch:

1872 >       case VIRTCHNL2_OP_GET_PTP_CAPS:
1873 >       >       valid_len = sizeof(struct virtchnl2_get_ptp_caps);
1874 
1875 >       >       if (msglen >= valid_len) {
1876 >       >       >       struct virtchnl2_get_ptp_caps *ptp_caps =
1877 >       >       >       (struct virtchnl2_get_ptp_caps *)msg;
1878
1879 >       >       >       if (ptp_caps->tx_tstamp.num_latches == 0) {

This is the check for 0         ^^^^

1880 >       >       >       >       err_msg_format = true;
1881 >       >       >       >       break;
1882 >       >       >       }
1883 
1884 >       >       >       valid_len += ((ptp_caps->tx_tstamp.num_latches - 
1) *
1885 >       >       >       >             sizeof(struct 
virtchnl2_ptp_tx_tstamp_entry));

But alowing num_latches == 0 would make this calculation overflow ^^^^

1886 >       >       }
1887 >       >       break;

> Signed-off-by: Soumyadeep Hore <soumyadeep.h...@intel.com>
> ---
>  drivers/common/idpf/base/virtchnl2.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/common/idpf/base/virtchnl2.h 
> b/drivers/common/idpf/base/virtchnl2.h
> index f44c0965b4..9a1310ca24 100644
> --- a/drivers/common/idpf/base/virtchnl2.h
> +++ b/drivers/common/idpf/base/virtchnl2.h
> @@ -1873,7 +1873,7 @@ virtchnl2_vc_validate_vf_msg(__rte_unused struct 
> virtchnl2_version_info *ver, u3
>       case VIRTCHNL2_OP_GET_PTP_CAPS:
>               valid_len = sizeof(struct virtchnl2_get_ptp_caps);
>  
> -             if (msglen >= valid_len) {
> +             if (msglen > valid_len) {
>                       struct virtchnl2_get_ptp_caps *ptp_caps =
>                       (struct virtchnl2_get_ptp_caps *)msg;
>  
> @@ -1889,7 +1889,7 @@ virtchnl2_vc_validate_vf_msg(__rte_unused struct 
> virtchnl2_version_info *ver, u3
>       case VIRTCHNL2_OP_GET_PTP_TX_TSTAMP_LATCHES:
>               valid_len = sizeof(struct virtchnl2_ptp_tx_tstamp_latches);
>  
> -             if (msglen >= valid_len) {
> +             if (msglen > valid_len) {
>                       struct virtchnl2_ptp_tx_tstamp_latches 
> *tx_tstamp_latches =
>                       (struct virtchnl2_ptp_tx_tstamp_latches *)msg;
>  
> -- 
> 2.43.0
> 

Reply via email to