Skip to content

Commit

Permalink
rfkill: copy the name into the rfkill struct
Browse files Browse the repository at this point in the history
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().

Cc: stable@vger.kernel.org
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
  • Loading branch information
Johannes Berg committed Dec 10, 2015
1 parent c1df932 commit b7bb110
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions net/rfkill/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
struct rfkill {
spinlock_t lock;

const char *name;
enum rfkill_type type;

unsigned long state;
Expand All @@ -73,6 +72,7 @@ struct rfkill {
struct delayed_work poll_work;
struct work_struct uevent_work;
struct work_struct sync_work;
char name[];
};
#define to_rfkill(d) container_of(d, struct rfkill, dev)

Expand Down Expand Up @@ -876,14 +876,14 @@ struct rfkill * __must_check rfkill_alloc(const char *name,
if (WARN_ON(type == RFKILL_TYPE_ALL || type >= NUM_RFKILL_TYPES))
return NULL;

rfkill = kzalloc(sizeof(*rfkill), GFP_KERNEL);
rfkill = kzalloc(sizeof(*rfkill) + strlen(name) + 1, GFP_KERNEL);
if (!rfkill)
return NULL;

spin_lock_init(&rfkill->lock);
INIT_LIST_HEAD(&rfkill->node);
rfkill->type = type;
rfkill->name = name;
strcpy(rfkill->name, name);
rfkill->ops = ops;
rfkill->data = ops_data;

Expand Down

0 comments on commit b7bb110

Please sign in to comment.