Skip to contentSkip to conversation

autofs4 - remove string terminator check

PATCH RESEND In review Ian Kent 2 participants 5 messages Oct 28, 2008

Subsystems (2)
lore
Share & tools
lore

Ian Kent

author maintainer
#0 lore raw

PATCH RESEND 1/1 autofs4 - remove string terminator check

In a previous patch a comment was made that checking for the existence of a NULL terminator in strings copied from userspace wasn't needed as this is done in many places in the kernel without problem. This patch removes this string terminator check.

---

 fs/autofs4/dev-ioctl.c |   20 --------------------
 1 files changed, 0 insertions(+), 20 deletions(-)
fs/autofs4/dev-ioctl.c +0 -20
index 625abf5..304c1ff 100644
@@ -51,18 +51,6 @@ static int check_name(const char *name)
 }
 
 /*
- * Check a string doesn't overrun the chunk of
- * memory we copied from user land.
- */
-static int invalid_str(char *str, void *end)
-{
-	while ((void *) str <= end)
-		if (!*str++)
-			return 0;
-	return -EINVAL;
-}
-
-/*
  * Check that the user compiled against correct version of autofs
  * misc device code.
  *
@@ -143,14 +131,6 @@ static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param)
 				    cmd);
 			goto out;
 		}
-
-		err = invalid_str(param->path,
-				 (void *) ((size_t) param + param->size));
-		if (err) {
-			AUTOFS_WARN("invalid path supplied for cmd(0x%08x)",
-				    cmd);
-			goto out;
-		}
 	}
 
 	err = 0;
#1 lore raw
Quoted 5 lines · On Tue, 28 Oct 2008 10:14:30 +0900 Ian Kent <[email protected]> wrote:

In a previous patch a comment was made that checking for the existence of a NULL terminator in strings copied from userspace wasn't needed as this is done in many places in the kernel without problem. This patch removes this string terminator check.

ah, OK. Now I'm worried.

Quoted 32 lines
 fs/autofs4/dev-ioctl.c |   20 --------------------
 1 files changed, 0 insertions(+), 20 deletions(-)
fs/autofs4/dev-ioctl.c +0 -13
index 625abf5..304c1ff 100644
@@ -51,18 +51,6 @@ static int check_name(const char *name)
 }
 
 /*
- * Check a string doesn't overrun the chunk of
- * memory we copied from user land.
- */
-static int invalid_str(char *str, void *end)
-{
-	while ((void *) str <= end)
-		if (!*str++)
-			return 0;
-	return -EINVAL;
-}
-
-/*
  * Check that the user compiled against correct version of autofs
  * misc device code.
  *
@@ -143,14 +131,6 @@ static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param)
 				    cmd);
 			goto out;
 		}
-

fs/autofs4/dev-ioctl.c static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param) · line 136

Quoted 10 lines
fs/autofs4/dev-ioctl.c +0 -7
-		err = invalid_str(param->path,
-				 (void *) ((size_t) param + param->size));
-		if (err) {
-			AUTOFS_WARN("invalid path supplied for cmd(0x%08x)",
-				    cmd);
-			goto out;
-		}
 	}
 
 	err = 0;

What will now happen if userspace passes in a non-null-terminated string (if that's possible)?

Presumably that isn't possible, or it's never been tested, because before we check for null-termination we run check_name(), which _assumes_ null-termination!

The comment over validate_dev_ioctl() will need the "and is terminated" removed after this change, yes?

author maintainer
#2 lore raw
Quoted 56 lines · Andrew Morton
Quoted 5 lines · On Tue, 28 Oct 2008 10:14:30 +0900 Ian Kent <[email protected]> wrote:

In a previous patch a comment was made that checking for the existence of a NULL terminator in strings copied from userspace wasn't needed as this is done in many places in the kernel without problem. This patch removes this string terminator check.

ah, OK. Now I'm worried.

Quoted 32 lines
 fs/autofs4/dev-ioctl.c |   20 --------------------
 1 files changed, 0 insertions(+), 20 deletions(-)
fs/autofs4/dev-ioctl.c +0 -13
index 625abf5..304c1ff 100644
@@ -51,18 +51,6 @@ static int check_name(const char *name)
 }
 
 /*
- * Check a string doesn't overrun the chunk of
- * memory we copied from user land.
- */
-static int invalid_str(char *str, void *end)
-{
-	while ((void *) str <= end)
-		if (!*str++)
-			return 0;
-	return -EINVAL;
-}
-
-/*
  * Check that the user compiled against correct version of autofs
  * misc device code.
  *
@@ -143,14 +131,6 @@ static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param)
 				    cmd);
 			goto out;
 		}
-

fs/autofs4/dev-ioctl.c static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param) · line 136

Quoted 10 lines
fs/autofs4/dev-ioctl.c +0 -7
-		err = invalid_str(param->path,
-				 (void *) ((size_t) param + param->size));
-		if (err) {
-			AUTOFS_WARN("invalid path supplied for cmd(0x%08x)",
-				    cmd);
-			goto out;
-		}
 	}
 
 	err = 0;

What will now happen if userspace passes in a non-null-terminated string (if that's possible)?

Quoted 6 lines

Presumably that isn't possible, or it's never been tested, because before we check for null-termination we run check_name(), which _assumes_ null-termination!

The comment over validate_dev_ioctl() will need the "and is terminated" removed after this change, yes?

Yes, but now I think I shouldn't have removed it.
For my part I would have been happy to keep this and now I think I should so let's drop this patch.

Ian

author maintainer
#3 lore raw
Quoted 52 lines · Ian Kent
Quoted 51 lines · Andrew Morton
Quoted 5 lines · On Tue, 28 Oct 2008 10:14:30 +0900 Ian Kent <[email protected]> wrote:

In a previous patch a comment was made that checking for the existence of a NULL terminator in strings copied from userspace wasn't needed as this is done in many places in the kernel without problem. This patch removes this string terminator check.

ah, OK. Now I'm worried.

Quoted 41 lines
 fs/autofs4/dev-ioctl.c |   20 --------------------
 1 files changed, 0 insertions(+), 20 deletions(-)
fs/autofs4/dev-ioctl.c +0 -20
index 625abf5..304c1ff 100644
@@ -51,18 +51,6 @@ static int check_name(const char *name)
 }
 
 /*
- * Check a string doesn't overrun the chunk of
- * memory we copied from user land.
- */
-static int invalid_str(char *str, void *end)
-{
-	while ((void *) str <= end)
-		if (!*str++)
-			return 0;
-	return -EINVAL;
-}
-
-/*
  * Check that the user compiled against correct version of autofs
  * misc device code.
  *
@@ -143,14 +131,6 @@ static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param)
 				    cmd);
 			goto out;
 		}
-
-		err = invalid_str(param->path,
-				 (void *) ((size_t) param + param->size));
-		if (err) {
-			AUTOFS_WARN("invalid path supplied for cmd(0x%08x)",
-				    cmd);
-			goto out;
-		}
 	}
 
Quoted 8 lines
Quoted 8 lines

fs/autofs4/dev-ioctl.c static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param) · line 136

Quoted 1 line
fs/autofs4/dev-ioctl.c +0 -0
 	err = 0;

What will now happen if userspace passes in a non-null-terminated string (if that's possible)?

Presumably that isn't possible, or it's never been tested, because before we check for null-termination we run check_name(), which _assumes_ null-termination!

Oh .. hang on, point taken.

Quoted 10 lines
Quoted 3 lines

The comment over validate_dev_ioctl() will need the "and is terminated" removed after this change, yes?

Yes, but now I think I shouldn't have removed it.
For my part I would have been happy to keep this and now I think I should so let's drop this patch.

Ian

author maintainer
#4 lore raw
Quoted 58 lines · Ian Kent
Quoted 57 lines · Ian Kent
Quoted 56 lines · Andrew Morton
Quoted 5 lines · On Tue, 28 Oct 2008 10:14:30 +0900 Ian Kent <[email protected]> wrote:

In a previous patch a comment was made that checking for the existence of a NULL terminator in strings copied from userspace wasn't needed as this is done in many places in the kernel without problem. This patch removes this string terminator check.

ah, OK. Now I'm worried.

Quoted 32 lines
 fs/autofs4/dev-ioctl.c |   20 --------------------
 1 files changed, 0 insertions(+), 20 deletions(-)
fs/autofs4/dev-ioctl.c +0 -13
index 625abf5..304c1ff 100644
@@ -51,18 +51,6 @@ static int check_name(const char *name)
 }
 
 /*
- * Check a string doesn't overrun the chunk of
- * memory we copied from user land.
- */
-static int invalid_str(char *str, void *end)
-{
-	while ((void *) str <= end)
-		if (!*str++)
-			return 0;
-	return -EINVAL;
-}
-
-/*
  * Check that the user compiled against correct version of autofs
  * misc device code.
  *
@@ -143,14 +131,6 @@ static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param)
 				    cmd);
 			goto out;
 		}
-

fs/autofs4/dev-ioctl.c static int validate_dev_ioctl(int cmd, struct autofs_dev_ioctl *param) · line 136

Quoted 10 lines
fs/autofs4/dev-ioctl.c +0 -7
-		err = invalid_str(param->path,
-				 (void *) ((size_t) param + param->size));
-		if (err) {
-			AUTOFS_WARN("invalid path supplied for cmd(0x%08x)",
-				    cmd);
-			goto out;
-		}
 	}
 
 	err = 0;

What will now happen if userspace passes in a non-null-terminated string (if that's possible)?

Quoted 13 lines
Quoted 3 lines
Quoted 3 lines

Presumably that isn't possible, or it's never been tested, because before we check for null-termination we run check_name(), which _assumes_ null-termination!

Oh .. hang on, point taken.

Quoted 7 lines
Quoted 3 lines

The comment over validate_dev_ioctl() will need the "and is terminated" removed after this change, yes?

Yes, but now I think I shouldn't have removed it.
For my part I would have been happy to keep this and now I think I should so let's drop this patch.

Just to confirm.
Please drop this patch and I'll send a patch to fix the check order.

Quoted 3 lines
Quoted 3 lines

Ian