Commit 819da758 authored by Johannes Berg's avatar Johannes Berg Committed by Luis Henriques

rfkill: copy the name into the rfkill struct

commit b7bb1100 upstream.

Some users of rfkill, like NFC and cfg80211, use a dynamic name when
allocating rfkill, in those cases dev_name(). Therefore, the pointer
passed to rfkill_alloc() might not be valid forever, I specifically
found the case that the rfkill name was quite obviously an invalid
pointer (or at least garbage) when the wiphy had been renamed.

Fix this by making a copy of the rfkill name in rfkill_alloc().
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 2b4c87db
...@@ -49,7 +49,6 @@ ...@@ -49,7 +49,6 @@
struct rfkill { struct rfkill {
spinlock_t lock; spinlock_t lock;
const char *name;
enum rfkill_type type; enum rfkill_type type;
unsigned long state; unsigned long state;
...@@ -73,6 +72,7 @@ struct rfkill { ...@@ -73,6 +72,7 @@ struct rfkill {
struct delayed_work poll_work; struct delayed_work poll_work;
struct work_struct uevent_work; struct work_struct uevent_work;
struct work_struct sync_work; struct work_struct sync_work;
char name[];
}; };
#define to_rfkill(d) container_of(d, struct rfkill, dev) #define to_rfkill(d) container_of(d, struct rfkill, dev)
...@@ -862,14 +862,14 @@ struct rfkill * __must_check rfkill_alloc(const char *name, ...@@ -862,14 +862,14 @@ struct rfkill * __must_check rfkill_alloc(const char *name,
if (WARN_ON(type == RFKILL_TYPE_ALL || type >= NUM_RFKILL_TYPES)) if (WARN_ON(type == RFKILL_TYPE_ALL || type >= NUM_RFKILL_TYPES))
return NULL; return NULL;
rfkill = kzalloc(sizeof(*rfkill), GFP_KERNEL); rfkill = kzalloc(sizeof(*rfkill) + strlen(name) + 1, GFP_KERNEL);
if (!rfkill) if (!rfkill)
return NULL; return NULL;
spin_lock_init(&rfkill->lock); spin_lock_init(&rfkill->lock);
INIT_LIST_HEAD(&rfkill->node); INIT_LIST_HEAD(&rfkill->node);
rfkill->type = type; rfkill->type = type;
rfkill->name = name; strcpy(rfkill->name, name);
rfkill->ops = ops; rfkill->ops = ops;
rfkill->data = ops_data; rfkill->data = ops_data;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment