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

Previous thread: [PATCH] CRED: Fix memory leak in error handling by David Howells on Monday, March 29, 2010 - 4:04 pm. (1 message)

Next thread: [RFC] alpha: hack objstrip.c to make it compile. by Matt Turner on Monday, March 29, 2010 - 6:49 pm. (4 messages)
From: wzt.wzt
Date: Tuesday, March 30, 2010 - 2:21 am

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.

Signed-off-by: Zhitong Wang <zhitong.wangzt@alibaba-inc.com>

---
 block/elevator.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/block/elevator.c b/block/elevator.c
index df75676..76e3702 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -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);
-- 
1.6.5.3

--

From: Jens Axboe
Date: Thursday, April 1, 2010 - 11:40 pm

Thanks, good catch! Applied.


-- 
Jens Axboe

--

From: Xiaotian Feng
Date: Friday, April 2, 2010 - 12:14 am

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?
--

Previous thread: [PATCH] CRED: Fix memory leak in error handling by David Howells on Monday, March 29, 2010 - 4:04 pm. (1 message)

Next thread: [RFC] alpha: hack objstrip.c to make it compile. by Matt Turner on Monday, March 29, 2010 - 6:49 pm. (4 messages)