* [PATCH] netns: more input validation
@ 2017-07-25 13:30 Matteo Croce
2017-07-25 13:47 ` David Laight
2017-07-27 18:26 ` Stephen Hemminger
0 siblings, 2 replies; 4+ messages in thread
From: Matteo Croce @ 2017-07-25 13:30 UTC (permalink / raw)
To: netdev; +Cc: Stephen Hemminger
ip netns accepts invalid input as namespace name like an empty string or a
string longer than the maximum file name length.
Check that the netns name is not empty and less than or equal to NAME_MAX.
Signed-off-by: Matteo Croce <mcroce@redhat.com>
---
ip/ipnetns.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index 42549944..198e9de8 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -768,7 +768,8 @@ static int netns_monitor(int argc, char **argv)
static int invalid_name(const char *name)
{
- return strchr(name, '/') || !strcmp(name, ".") || !strcmp(name, "..");
+ return !*name || strlen(name) > NAME_MAX ||
+ strchr(name, '/') || !strcmp(name, ".") || !strcmp(name, "..");
}
int do_netns(int argc, char **argv)
--
2.11.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH] netns: more input validation
2017-07-25 13:30 [PATCH] netns: more input validation Matteo Croce
@ 2017-07-25 13:47 ` David Laight
2017-07-25 14:08 ` Matteo Croce
2017-07-27 18:26 ` Stephen Hemminger
1 sibling, 1 reply; 4+ messages in thread
From: David Laight @ 2017-07-25 13:47 UTC (permalink / raw)
To: 'Matteo Croce', netdev@vger.kernel.org; +Cc: Stephen Hemminger
From: Matteo Croce
> Sent: 25 July 2017 14:31
> ip netns accepts invalid input as namespace name like an empty string or a
> string longer than the maximum file name length.
> Check that the netns name is not empty and less than or equal to NAME_MAX.
>
> Signed-off-by: Matteo Croce <mcroce@redhat.com>
> ---
> ip/ipnetns.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/ip/ipnetns.c b/ip/ipnetns.c
> index 42549944..198e9de8 100644
> --- a/ip/ipnetns.c
> +++ b/ip/ipnetns.c
> @@ -768,7 +768,8 @@ static int netns_monitor(int argc, char **argv)
>
> static int invalid_name(const char *name)
> {
> - return strchr(name, '/') || !strcmp(name, ".") || !strcmp(name, "..");
> + return !*name || strlen(name) > NAME_MAX ||
> + strchr(name, '/') || !strcmp(name, ".") || !strcmp(name, "..");
Think I'd check:
!name[0] || !memchr(name, 0, NAME_MAX) || strchr(name, '/') ||
(name[0] == '.' && (!name[1] || (name[1] == '.' && !name[2])))
David
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] netns: more input validation
2017-07-25 13:47 ` David Laight
@ 2017-07-25 14:08 ` Matteo Croce
0 siblings, 0 replies; 4+ messages in thread
From: Matteo Croce @ 2017-07-25 14:08 UTC (permalink / raw)
To: David Laight, netdev@vger.kernel.org; +Cc: Stephen Hemminger
Il giorno mar, 25/07/2017 alle 13.47 +0000, David Laight ha scritto:
> Think I'd check:
> !name[0] || !memchr(name, 0, NAME_MAX) || strchr(name, '/') ||
> (name[0] == '.' && (!name[1] || (name[1] == '.' &&
> !name[2])))
>
> David
Nice optimization, but as strchr() and strcmp() are builtin functions,
at least in GCC, I don't know if there is any real advantage.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] netns: more input validation
2017-07-25 13:30 [PATCH] netns: more input validation Matteo Croce
2017-07-25 13:47 ` David Laight
@ 2017-07-27 18:26 ` Stephen Hemminger
1 sibling, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2017-07-27 18:26 UTC (permalink / raw)
To: Matteo Croce; +Cc: netdev
On Tue, 25 Jul 2017 15:30:31 +0200
Matteo Croce <mcroce@redhat.com> wrote:
> ip netns accepts invalid input as namespace name like an empty string or a
> string longer than the maximum file name length.
> Check that the netns name is not empty and less than or equal to NAME_MAX.
>
> Signed-off-by: Matteo Croce <mcroce@redhat.com>
Sure, applied.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-07-27 18:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-25 13:30 [PATCH] netns: more input validation Matteo Croce
2017-07-25 13:47 ` David Laight
2017-07-25 14:08 ` Matteo Croce
2017-07-27 18:26 ` Stephen Hemminger
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).