[dpdk-dev,11/13] KNI: guard against unterminated dev_info.name leading to BUG in alloc_netdev()

Message ID d1c6dd8ca22b51b781b2ce9f305f6a39ba9a914b.1481590851.git.mirq-linux@rere.qmqm.pl (mailing list archive)
State Accepted, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel compilation success Compilation OK

Commit Message

Michał Mirosław Dec. 13, 2016, 1:08 a.m. UTC
  Signed-off-by: Michał Mirosław <michal.miroslaw@atendesoftware.pl>
---
 lib/librte_eal/linuxapp/kni/kni_misc.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Ferruh Yigit Dec. 14, 2016, 5:33 p.m. UTC | #1
On 12/13/2016 1:08 AM, Michał Mirosław wrote:
> Signed-off-by: Michał Mirosław <michal.miroslaw@atendesoftware.pl>
> ---

Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>

I guess no harm doing extra check on user input.
  
Michał Mirosław Dec. 14, 2016, 5:37 p.m. UTC | #2
On Wed, Dec 14, 2016 at 05:33:11PM +0000, Ferruh Yigit wrote:
> On 12/13/2016 1:08 AM, Michał Mirosław wrote:
> > Signed-off-by: Michał Mirosław <michal.miroslaw@atendesoftware.pl>
> > ---
> 
> Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
> 
> I guess no harm doing extra check on user input.

This actually prevents an OOPS that happens when you try to create KNI with
too long name.

Best Regards,
Michał Mirosław
  
Ferruh Yigit Dec. 14, 2016, 5:48 p.m. UTC | #3
On 12/14/2016 5:37 PM, Michał Mirosław wrote:
> On Wed, Dec 14, 2016 at 05:33:11PM +0000, Ferruh Yigit wrote:
>> On 12/13/2016 1:08 AM, Michał Mirosław wrote:
>>> Signed-off-by: Michał Mirosław <michal.miroslaw@atendesoftware.pl>
>>> ---
>>
>> Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
>>
>> I guess no harm doing extra check on user input.
> 
> This actually prevents an OOPS that happens when you try to create KNI with
> too long name.

Thanks for fixing then.
  
Thomas Monjalon Jan. 29, 2017, 9:53 p.m. UTC | #4
2016-12-14 17:33, Ferruh Yigit:
> On 12/13/2016 1:08 AM, Michał Mirosław wrote:
> > Signed-off-by: Michał Mirosław <michal.miroslaw@atendesoftware.pl>
> > ---
> 
> Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>

Applied, thanks
  

Patch

diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c
index f0247aa..14a2e3b 100644
--- a/lib/librte_eal/linuxapp/kni/kni_misc.c
+++ b/lib/librte_eal/linuxapp/kni/kni_misc.c
@@ -344,6 +344,12 @@  kni_ioctl_create(struct net *net, uint32_t ioctl_num,
 		return -EIO;
 	}
 
+	/* Check if name is zero-ended */
+	if (strnlen(dev_info.name, sizeof(dev_info.name)) == sizeof(dev_info.name)) {
+		pr_err("kni.name not zero-terminated");
+		return -EINVAL;
+	}
+
 	/**
 	 * Check if the cpu core id is valid for binding.
 	 */