netns: more input validation
Subsystems (2)
PATCH 1/1 netns: more input validation
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.
--- ip/ipnetns.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
ip/ipnetns.c +2 -1
@@ -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)
Signature · 1 line
2.11.0
From: Matteo Croce
Quoted 15 lines
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 toNAME_MAX.Signed-off-by Matteo Croce <[email protected]>--- ip/ipnetns.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)ip/ipnetns.c +0
-0
ip/ipnetns.c static int netns_monitor(int argc, char **argv) · line 772
Quoted 6 lines
ip/ipnetns.c +2
-1@@ -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
Il giorno mar, 25/07/2017 alle 13.47 +0000, David Laight ha scritto:
Quoted 6 lines
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.
Quoted 5 lines · On Tue, 25 Jul 2017 15:30:31 +0200 Matteo Croce <[email protected]> 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 toNAME_MAX.Signed-off-by Matteo Croce <[email protected]>
Sure, applied.