Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1499659

[PATCH 3.4 075/125] rfkill: copy the name into the rfkill struct

From lizf@kernel.org
Newsgroups linux.kernel
Subject [PATCH 3.4 075/125] rfkill: copy the name into the rfkill struct
Date 2016-10-12 15:10 +0200
Message-ID <srrsf-4OM-93@gated-at.bofh.it> (permalink)
References <srqZb-4nM-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Johannes Berg <johannes.berg@intel.com>

3.4.113-rc1 review patch.  If anyone has any objections, please let me know.

------------------


commit b7bb110008607a915298bf0f47d25886ecb94477 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: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Zefan Li <lizefan@huawei.com>
---
 net/rfkill/core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/rfkill/core.c b/net/rfkill/core.c
index f974961..feef1a45 100644
--- a/net/rfkill/core.c
+++ b/net/rfkill/core.c
@@ -51,7 +51,6 @@
 struct rfkill {
 	spinlock_t		lock;
 
-	const char		*name;
 	enum rfkill_type	type;
 
 	unsigned long		state;
@@ -75,6 +74,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)
 
@@ -849,14 +849,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;
 
-- 
1.9.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 3.4 000/125] 3.4.113-rc1 review lizf@kernel.org - 2016-10-12 15:10 +0200
  [PATCH 3.4 116/125] sctp: Prevent soft lockup when sctp_accept() is called during a timeout event lizf@kernel.org - 2016-10-12 15:10 +0200
  [PATCH 3.4 105/125] parisc: Fix syscall restarts lizf@kernel.org - 2016-10-12 15:10 +0200
  [PATCH 3.4 075/125] rfkill: copy the name into the rfkill struct lizf@kernel.org - 2016-10-12 15:10 +0200
  Re: [PATCH 3.4 000/125] 3.4.113-rc1 review Guenter Roeck <linux@roeck-us.net> - 2016-10-12 19:00 +0200
    Re: [PATCH 3.4 000/125] 3.4.113-rc1 review Zefan Li <lizefan@huawei.com> - 2016-10-13 03:10 +0200

csiph-web