Skip to contentSkip to conversation

bluetooth: debugfs changes use too much stack

PATCH In review Dan Carpenter 4 participants 4 messages Mar 6, 2010 1 message not in the archive

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bluetooth: debugfs changes use too much stack

The original code would break with a 4K stack.

---
This was compile tested only. Sorry about that.

net/bluetooth/hci_sysfs.c +7 -2
index 1a79a6c..835758f 100644
@@ -417,9 +417,11 @@ static ssize_t inquiry_cache_read(struct file *file, char __user *userbuf,
 	struct hci_dev *hdev = file->private_data;
 	struct inquiry_cache *cache = &hdev->inq_cache;
 	struct inquiry_entry *e;
-	char buf[4096];
+	char *buf;
 	int n = 0;
+	ssize_t ret;
 
+	buf = kmalloc(4096, GFP_KERNEL);
 	hci_dev_lock_bh(hdev);
 
 	for (e = cache->list; e; e = e->next) {
@@ -437,7 +439,10 @@ static ssize_t inquiry_cache_read(struct file *file, char __user *userbuf,
 
 	hci_dev_unlock_bh(hdev);
 
-	return simple_read_from_buffer(userbuf, count, ppos, buf, n);
+	ret = simple_read_from_buffer(userbuf, count, ppos, buf, n);
+	kfree(buf);
+
+	return ret;
 }
 
 static const struct file_operations inquiry_cache_fops = {
#1 lore raw

Dan Carpenter wrote:

Error handling?

Quoted 11 lines

The original code would break with a 4K stack.

---
This was compile tested only. Sorry about that.

net/bluetooth/hci_sysfs.c +0 -0
index 1a79a6c..835758f 100644

net/bluetooth/hci_sysfs.c static ssize_t inquiry_cache_read(struct file *file, char __user *userbuf, · line 424

Quoted 9 lines
net/bluetooth/hci_sysfs.c +3 -1
@@ -417,9 +417,11 @@ static ssize_t inquiry_cache_read(struct file *file, char __user *userbuf,
 	struct hci_dev *hdev = file->private_data;
 	struct inquiry_cache *cache = &hdev->inq_cache;
 	struct inquiry_entry *e;
-	char buf[4096];
+	char *buf;
 	int n = 0;
+	ssize_t ret;
 
+	buf = kmalloc(4096, GFP_KERNEL);

Could this kmalloc not fail?

#3 lore raw
In reply to a message not in the archive
Quoted 23 lines · Jan Ceuleers

Dan Carpenter wrote:

Error handling?

Quoted 19 lines

The original code would break with a 4K stack.

---
This was compile tested only. Sorry about that.

net/bluetooth/hci_sysfs.c +2 -1
index 1a79a6c..835758f 100644
@@ -417,9 +417,11 @@ static ssize_t inquiry_cache_read(struct file *file, char __user *userbuf,
 	struct hci_dev *hdev = file->private_data;
 	struct inquiry_cache *cache = &hdev->inq_cache;
 	struct inquiry_entry *e;
-	char buf[4096];
+	char *buf;
 	int n = 0;
+	ssize_t ret;
 
Quoted 3 lines

net/bluetooth/hci_sysfs.c static ssize_t inquiry_cache_read(struct file *file, char __user *userbuf, · line 424

Quoted 1 line
net/bluetooth/hci_sysfs.c +1 -0
+	buf = kmalloc(4096, GFP_KERNEL);

Could this kmalloc not fail?

Grr... I'm really sorry about that.

I will send an updated patch tomorrow.

regards,
dan carpenter

maintainer
#4 lore raw

Hi Dan,

Quoted 21 lines
Quoted 21 lines

Error handling?

Quoted 19 lines

The original code would break with a 4K stack.

---
This was compile tested only. Sorry about that.

net/bluetooth/hci_sysfs.c +2 -1
index 1a79a6c..835758f 100644
@@ -417,9 +417,11 @@ static ssize_t inquiry_cache_read(struct file *file, char __user *userbuf,
 	struct hci_dev *hdev = file->private_data;
 	struct inquiry_cache *cache = &hdev->inq_cache;
 	struct inquiry_entry *e;
-	char buf[4096];
+	char *buf;
 	int n = 0;
+	ssize_t ret;
 
Quoted 7 lines
Quoted 3 lines

net/bluetooth/hci_sysfs.c static ssize_t inquiry_cache_read(struct file *file, char __user *userbuf, · line 424

Quoted 1 line
net/bluetooth/hci_sysfs.c +1 -0
+	buf = kmalloc(4096, GFP_KERNEL);

Could this kmalloc not fail?

Grr... I'm really sorry about that.

I will send an updated patch tomorrow.

please don't since we fixed this already in the net-2.6 tree.

Regards

Marcel