Skip to contentSkip to conversation

blktrace: pass the right pointer to kfree()

PATCH In review Li Zefan 2 participants 3 messages Apr 9, 2009

Subsystems (2)
lore
Share & tools
lore

Li Zefan

author
#0 lore raw

PATCH 1/1 blktrace: pass the right pointer to kfree()

If passing a string with leading white spaces to strstrip(), the returned ptr != the original ptr.

This bug was introduced by me.

---
 kernel/trace/blktrace.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
kernel/trace/blktrace.c +5 -5
index b32ff44..921ef5d 100644
@@ -1377,12 +1377,12 @@ static int blk_trace_str2mask(const char *str)
 {
 	int i;
 	int mask = 0;
-	char *s, *token;
+	char *buf, *s, *token;
 
-	s = kstrdup(str, GFP_KERNEL);
-	if (s == NULL)
+	buf = kstrdup(str, GFP_KERNEL);
+	if (buf == NULL)
 		return -ENOMEM;
-	s = strstrip(s);
+	s = strstrip(buf);
 
 	while (1) {
 		token = strsep(&s, ",");
@@ -1403,7 +1403,7 @@ static int blk_trace_str2mask(const char *str)
 			break;
 		}
 	}
-	kfree(s);
+	kfree(buf);
 
 	return mask;
 }
Signature · 1 line
1.5.4.rc3
author
#1 lore raw
Commit-ID:  9eb85125ce218a8b8d9a7c982510388e227adbec
Gitweb:     http://git.kernel.org/tip/9eb85125ce218a8b8d9a7c982510388e227adbec
Author:     Li Zefan <[email protected]>
AuthorDate: Thu, 9 Apr 2009 11:19:40 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Thu, 9 Apr 2009 05:52:40 +0200

blktrace: pass the right pointer to kfree()

Impact: fix kfree crash with non-standard act_mask string

If passing a string with leading white spaces to strstrip(), the returned ptr != the original ptr.

This bug was introduced by me.

Cc Jens Axboe <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

LKML-Reference: <[email protected]>

---
 kernel/trace/blktrace.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
kernel/trace/blktrace.c +5 -5
index b32ff44..921ef5d 100644
@@ -1377,12 +1377,12 @@ static int blk_trace_str2mask(const char *str)
 {
 	int i;
 	int mask = 0;
-	char *s, *token;
+	char *buf, *s, *token;
 
-	s = kstrdup(str, GFP_KERNEL);
-	if (s == NULL)
+	buf = kstrdup(str, GFP_KERNEL);
+	if (buf == NULL)
 		return -ENOMEM;
-	s = strstrip(s);
+	s = strstrip(buf);
 
 	while (1) {
 		token = strsep(&s, ",");
@@ -1403,7 +1403,7 @@ static int blk_trace_str2mask(const char *str)
 			break;
 		}
 	}
-	kfree(s);
+	kfree(buf);
 
 	return mask;
 }
Acked-by on v1 1/1
#2 lore raw
In reply to Li Zefan

Em Thu, Apr 09, 2009 at 11:19:40AM +0800, Li Zefan escreveu:

Quoted 6 lines

If passing a string with leading white spaces to strstrip(), the returned ptr != the original ptr.

This bug was introduced by me.

I hadn't noticed that strstrip was added, oops.

Quoted 36 lines
---
 kernel/trace/blktrace.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
kernel/trace/blktrace.c +5 -5
index b32ff44..921ef5d 100644
@@ -1377,12 +1377,12 @@ static int blk_trace_str2mask(const char *str)
 {
 	int i;
 	int mask = 0;
-	char *s, *token;
+	char *buf, *s, *token;
 
-	s = kstrdup(str, GFP_KERNEL);
-	if (s == NULL)
+	buf = kstrdup(str, GFP_KERNEL);
+	if (buf == NULL)
 		return -ENOMEM;
-	s = strstrip(s);
+	s = strstrip(buf);
 
 	while (1) {
 		token = strsep(&s, ",");
@@ -1403,7 +1403,7 @@ static int blk_trace_str2mask(const char *str)
 			break;
 		}
 	}
-	kfree(s);
+	kfree(buf);
 
 	return mask;
 }
Signature · 1 line
1.5.4.rc3