kni: fix possible buffer overflow

Message ID 20190711123508.45219-1-ferruh.yigit@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series kni: fix possible buffer overflow |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/intel-Performance-Testing success Performance Testing PASS
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/Intel-compilation fail Compilation issues

Commit Message

Ferruh Yigit July 11, 2019, 12:35 p.m. UTC
  'kni_net_rx_lo_fifo()' can get segmented buffers, using 'pkt_len' for
that case will be wrong and some values can cause buffer overflow
in destination mbuf data.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 kernel/linux/kni/kni_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Stephen Hemminger July 11, 2019, 3:33 p.m. UTC | #1
On Thu, 11 Jul 2019 13:35:07 +0100
Ferruh Yigit <ferruh.yigit@intel.com> wrote:

> 'kni_net_rx_lo_fifo()' can get segmented buffers, using 'pkt_len' for
> that case will be wrong and some values can cause buffer overflow
> in destination mbuf data.
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
>  kernel/linux/kni/kni_net.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
> index ad8365877..84341ac92 100644
> --- a/kernel/linux/kni/kni_net.c
> +++ b/kernel/linux/kni/kni_net.c
> @@ -435,7 +435,7 @@ kni_net_rx_lo_fifo(struct kni_dev *kni)
>  		/* Copy mbufs */
>  		for (i = 0; i < num; i++) {
>  			kva = pa2kva(kni->pa[i]);
> -			len = kva->pkt_len;
> +			len = kva->data_len;
>  			data_kva = kva2data_kva(kva);
>  			kni->va[i] = pa2va(kni->pa[i], kva);
>  

Acked-by: Stephen Hemminger <stephen@networkplumber.org>
  
Thomas Monjalon July 18, 2019, 9:24 p.m. UTC | #2
11/07/2019 17:33, Stephen Hemminger:
> On Thu, 11 Jul 2019 13:35:07 +0100
> Ferruh Yigit <ferruh.yigit@intel.com> wrote:
> 
> > 'kni_net_rx_lo_fifo()' can get segmented buffers, using 'pkt_len' for
> > that case will be wrong and some values can cause buffer overflow
> > in destination mbuf data.
> > 
> > Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> 
> Acked-by: Stephen Hemminger <stephen@networkplumber.org>

Applied, thanks
  
Thomas Monjalon July 18, 2019, 9:35 p.m. UTC | #3
18/07/2019 23:24, Thomas Monjalon:
> 11/07/2019 17:33, Stephen Hemminger:
> > On Thu, 11 Jul 2019 13:35:07 +0100
> > Ferruh Yigit <ferruh.yigit@intel.com> wrote:
> > 
> > > 'kni_net_rx_lo_fifo()' can get segmented buffers, using 'pkt_len' for
> > > that case will be wrong and some values can cause buffer overflow
> > > in destination mbuf data.
> > > 
> > > Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> > 
> > Acked-by: Stephen Hemminger <stephen@networkplumber.org>
> 
> Applied, thanks

I hope these lines are correct:

    Fixes: d89a58dfe90b ("kni: support chained mbufs")
    Cc: stable@dpdk.org
  
Ferruh Yigit July 19, 2019, 6:34 p.m. UTC | #4
On 7/18/2019 10:35 PM, Thomas Monjalon wrote:
> 18/07/2019 23:24, Thomas Monjalon:
>> 11/07/2019 17:33, Stephen Hemminger:
>>> On Thu, 11 Jul 2019 13:35:07 +0100
>>> Ferruh Yigit <ferruh.yigit@intel.com> wrote:
>>>
>>>> 'kni_net_rx_lo_fifo()' can get segmented buffers, using 'pkt_len' for
>>>> that case will be wrong and some values can cause buffer overflow
>>>> in destination mbuf data.
>>>>
>>>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
>>>
>>> Acked-by: Stephen Hemminger <stephen@networkplumber.org>
>>
>> Applied, thanks
> 
> I hope these lines are correct:
> 
>     Fixes: d89a58dfe90b ("kni: support chained mbufs")
>     Cc: stable@dpdk.org

Thanks for updating it, even before this commit the related code was wrong I
think, but agree that this commit should have fixed it, so agreed with the fixes
line.
  

Patch

diff --git a/kernel/linux/kni/kni_net.c b/kernel/linux/kni/kni_net.c
index ad8365877..84341ac92 100644
--- a/kernel/linux/kni/kni_net.c
+++ b/kernel/linux/kni/kni_net.c
@@ -435,7 +435,7 @@  kni_net_rx_lo_fifo(struct kni_dev *kni)
 		/* Copy mbufs */
 		for (i = 0; i < num; i++) {
 			kva = pa2kva(kni->pa[i]);
-			len = kva->pkt_len;
+			len = kva->data_len;
 			data_kva = kva2data_kva(kva);
 			kni->va[i] = pa2va(kni->pa[i], kva);