Skip to contentSkip to conversation

Block: Fix block/elevator.c elevator_get() off-by-one error

PATCH In review [email protected] 3 participants 3 messages Mar 30, 2010 – Apr 2, 2010 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Block: Fix block/elevator.c elevator_get() off-by-one error

elevator_get() not check the name length, if the name length > sizeof(elv), elv will miss the '\0'. And elv buffer will be replace "-iosched" as something like aaaaaaaaa, then call request_module() can load an not trust module.

---
 block/elevator.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
block/elevator.c +1 -1
index df75676..76e3702 100644
@@ -154,7 +154,7 @@ static struct elevator_type *elevator_get(const char *name)
 
 		spin_unlock(&elv_list_lock);
 
-		sprintf(elv, "%s-iosched", name);
+		snprintf(elv, sizeof(elv), "%s-iosched", name);
 
 		request_module("%s", elv);
 		spin_lock(&elv_list_lock);
Signature · 1 line
1.6.5.3
#1 lore raw
Quoted 3 lines · On Tue, Mar 30 2010, [email protected] wrote:

elevator_get() not check the name length, if the name length > sizeof(elv), elv will miss the '\0'. And elv buffer will be replace "-iosched" as something like aaaaaaaaa, then call request_module() can load an not trust module.

Thanks, good catch! Applied.

Signature · 1 line
Jens Axboe
#2 lore raw
In reply to [email protected]
Quoted 15 lines · On Tue, Mar 30, 2010 at 5:21 PM, <[email protected]> wrote:

elevator_get() not check the name length, if the name length > sizeof(elv), elv will miss the '\0'. And elv buffer will be replace "-iosched" as something like aaaaaaaaa, then call request_module() can load an not trust module.

---
 block/elevator.c |    2 +-

 1 files changed, 1 insertions(+), 1 deletions(-)
block/elevator.c +0 -0
index df75676..76e3702 100644

block/elevator.c static struct elevator_type *elevator_get(const char *name) · line 158

Quoted 6 lines
block/elevator.c +1 -1
@@ -154,7 +154,7 @@ static struct elevator_type *elevator_get(const char *name)
 
                spin_unlock(&elv_list_lock);
 
-               sprintf(elv, "%s-iosched", name);
+               snprintf(elv, sizeof(elv), "%s-iosched", name);
 

elv is defined as char elv[ELV_NAME_MAX + strlen("-iosched")]; so if name length > sizeof(elv), the name length must already bigger than ELV_NAME_MAX

elevator_get is used in elevator_init, so if elevator_init is passing a super long name, why not just return -EINVAL?
In this patch, if we pass a super long name, we're still trying to cut it and request_module an invalid name, right?
Although '\0' is kept, but name is still invalid, right?

Quoted 11 lines
block/elevator.c +0 -1
                request_module("%s", elv);
                spin_lock(&elv_list_lock);
--

1.6.5.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/