* [PATCH] netdevice: Fix wrong string handle in kernel command line parsing
@ 2008-06-30 5:22 Wang Chen
2008-06-30 10:25 ` Ben Hutchings
0 siblings, 1 reply; 4+ messages in thread
From: Wang Chen @ 2008-06-30 5:22 UTC (permalink / raw)
To: David S. Miller; +Cc: NETDEV
1. In netdev_boot_setup_add(), a long name will leak.
ex. : dev=21,0x1234,0x1234,0x2345,eth123456789verylongname.........
2. In netdev_boot_setup_check(), mismatch will happen if s[i].name
is a substring of dev->name.
ex. : dev=...eth1 dev=...eth11
Signed-off-by: Wang Chen <wangchen@cn.fujitsu.com>
---
diff --git a/net/core/dev.c b/net/core/dev.c
index c421a1f..9ecb3db 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -454,7 +454,7 @@ static int netdev_boot_setup_add(char *name, struct ifmap *map)
for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
if (s[i].name[0] == '\0' || s[i].name[0] == ' ') {
memset(s[i].name, 0, sizeof(s[i].name));
- strcpy(s[i].name, name);
+ strncpy(s[i].name, name, IFNAMSIZ);
memcpy(&s[i].map, map, sizeof(s[i].map));
break;
}
@@ -479,7 +479,7 @@ int netdev_boot_setup_check(struct net_device *dev)
for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
if (s[i].name[0] != '\0' && s[i].name[0] != ' ' &&
- !strncmp(dev->name, s[i].name, strlen(s[i].name))) {
+ !strcmp(dev->name, s[i].name)) {
dev->irq = s[i].map.irq;
dev->base_addr = s[i].map.base_addr;
dev->mem_start = s[i].map.mem_start;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] netdevice: Fix wrong string handle in kernel command line parsing
2008-06-30 5:22 [PATCH] netdevice: Fix wrong string handle in kernel command line parsing Wang Chen
@ 2008-06-30 10:25 ` Ben Hutchings
2008-07-01 0:56 ` V2 " Wang Chen
0 siblings, 1 reply; 4+ messages in thread
From: Ben Hutchings @ 2008-06-30 10:25 UTC (permalink / raw)
To: Wang Chen; +Cc: David S. Miller, NETDEV
Wang Chen wrote:
> 1. In netdev_boot_setup_add(), a long name will leak.
> ex. : dev=21,0x1234,0x1234,0x2345,eth123456789verylongname.........
> 2. In netdev_boot_setup_check(), mismatch will happen if s[i].name
> is a substring of dev->name.
> ex. : dev=...eth1 dev=...eth11
Well spotted, but...
> Signed-off-by: Wang Chen <wangchen@cn.fujitsu.com>
> ---
> diff --git a/net/core/dev.c b/net/core/dev.c
> index c421a1f..9ecb3db 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -454,7 +454,7 @@ static int netdev_boot_setup_add(char *name, struct ifmap *map)
> for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
> if (s[i].name[0] == '\0' || s[i].name[0] == ' ') {
> memset(s[i].name, 0, sizeof(s[i].name));
> - strcpy(s[i].name, name);
> + strncpy(s[i].name, name, IFNAMSIZ);
I think that strncpy() should be strlcpy(), because strncpy() does not
ensure null-termination.
Ben.
--
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
^ permalink raw reply [flat|nested] 4+ messages in thread
* V2 [PATCH] netdevice: Fix wrong string handle in kernel command line parsing
2008-06-30 10:25 ` Ben Hutchings
@ 2008-07-01 0:56 ` Wang Chen
2008-07-02 2:57 ` David Miller
0 siblings, 1 reply; 4+ messages in thread
From: Wang Chen @ 2008-07-01 0:56 UTC (permalink / raw)
To: Ben Hutchings, David S. Miller; +Cc: NETDEV
Ben Hutchings said the following on 2008-6-30 18:25:
>> - strcpy(s[i].name, name);
>> + strncpy(s[i].name, name, IFNAMSIZ);
>
> I think that strncpy() should be strlcpy(), because strncpy() does not
> ensure null-termination.
>
Of course. Thanks, Ben.
v1->v2: Use strlcpy() to ensure s[i].name be null-termination.
1. In netdev_boot_setup_add(), a long name will leak.
ex. : dev=21,0x1234,0x1234,0x2345,eth123456789verylongname.........
2. In netdev_boot_setup_check(), mismatch will happen if s[i].name
is a substring of dev->name.
ex. : dev=...eth1 dev=...eth11
Signed-off-by: Wang Chen <wangchen@cn.fujitsu.com>
---
diff --git a/net/core/dev.c b/net/core/dev.c
index c421a1f..3360df6 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -454,7 +454,7 @@ static int netdev_boot_setup_add(char *name, struct ifmap *map)
for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
if (s[i].name[0] == '\0' || s[i].name[0] == ' ') {
memset(s[i].name, 0, sizeof(s[i].name));
- strcpy(s[i].name, name);
+ strlcpy(s[i].name, name, IFNAMSIZ);
memcpy(&s[i].map, map, sizeof(s[i].map));
break;
}
@@ -479,7 +479,7 @@ int netdev_boot_setup_check(struct net_device *dev)
for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
if (s[i].name[0] != '\0' && s[i].name[0] != ' ' &&
- !strncmp(dev->name, s[i].name, strlen(s[i].name))) {
+ !strcmp(dev->name, s[i].name)) {
dev->irq = s[i].map.irq;
dev->base_addr = s[i].map.base_addr;
dev->mem_start = s[i].map.mem_start;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: V2 [PATCH] netdevice: Fix wrong string handle in kernel command line parsing
2008-07-01 0:56 ` V2 " Wang Chen
@ 2008-07-02 2:57 ` David Miller
0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2008-07-02 2:57 UTC (permalink / raw)
To: wangchen; +Cc: bhutchings, netdev
From: Wang Chen <wangchen@cn.fujitsu.com>
Date: Tue, 01 Jul 2008 08:56:40 +0800
> Ben Hutchings said the following on 2008-6-30 18:25:
> >> - strcpy(s[i].name, name);
> >> + strncpy(s[i].name, name, IFNAMSIZ);
> >
> > I think that strncpy() should be strlcpy(), because strncpy() does not
> > ensure null-termination.
> >
>
> Of course. Thanks, Ben.
>
> v1->v2: Use strlcpy() to ensure s[i].name be null-termination.
>
> 1. In netdev_boot_setup_add(), a long name will leak.
> ex. : dev=21,0x1234,0x1234,0x2345,eth123456789verylongname.........
> 2. In netdev_boot_setup_check(), mismatch will happen if s[i].name
> is a substring of dev->name.
> ex. : dev=...eth1 dev=...eth11
>
> Signed-off-by: Wang Chen <wangchen@cn.fujitsu.com>
Looks good, applied, thanks everyone.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-07-02 2:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-30 5:22 [PATCH] netdevice: Fix wrong string handle in kernel command line parsing Wang Chen
2008-06-30 10:25 ` Ben Hutchings
2008-07-01 0:56 ` V2 " Wang Chen
2008-07-02 2:57 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).