Skip to contentSkip to conversation

net: irda: using kzalloc() instead of kmalloc() to avoid strncpy() issue.

PATCH Applied Chen Gang 2 participants 3 messages May 17, 2013 – May 20, 2013

Subsystems (2)
lore
Share & tools
lore

Chen Gang

author
#0 lore raw

PATCH 1/1 net: irda: using kzalloc() instead of kmalloc() to avoid strncpy() issue.

'discovery->data.info' length is 22, NICKNAME_MAX_LEN is 21, so the strncpy() will always left the last byte of 'discovery->data.info' uninitialized.

When 'text' length is longer than 21 (NICKNAME_MAX_LEN), if still left the last byte of 'discovery->data.info' uninitialized, the next strlen() will cause issue.

Also 'discovery->data' is 'struct irda_device_info' which defined in "include/uapi/...", it may copy to user mode, so need whole initialized.

All together, need use kzalloc() instead of kmalloc() to initialize all members firstly.

---
 net/irda/irlap_frame.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
net/irda/irlap_frame.c +1 -1
index 8c00416..9ea0c93 100644
@@ -544,7 +544,7 @@ static void irlap_recv_discovery_xid_cmd(struct irlap_cb *self,
 		/*
 		 *  We now have some discovery info to deliver!
 		 */
-		discovery = kmalloc(sizeof(discovery_t), GFP_ATOMIC);
+		discovery = kzalloc(sizeof(discovery_t), GFP_ATOMIC);
 		if (!discovery) {
 			IRDA_WARNING("%s: unable to malloc!\n", __func__);
 			return;
Signature · 1 line
1.7.7.6
maintainer Applied
#1 lore raw

From: Chen Gang <[email protected]>
Date: Fri, 17 May 2013 17:13:04 +0800

Quoted 9 lines

'discovery->data.info' length is 22, NICKNAME_MAX_LEN is 21, so the strncpy() will always left the last byte of 'discovery->data.info' uninitialized.

When 'text' length is longer than 21 (NICKNAME_MAX_LEN), if still left the last byte of 'discovery->data.info' uninitialized, the next strlen() will cause issue.

Quoted 7 lines

Also 'discovery->data' is 'struct irda_device_info' which defined in "include/uapi/...", it may copy to user mode, so need whole initialized.

All together, need use kzalloc() instead of kmalloc() to initialize all members firstly.

Applied, thanks.

author
#2 lore raw
Quoted 12 lines · David Miller

From: Chen Gang <[email protected]>
Date: Fri, 17 May 2013 17:13:04 +0800

Quoted 9 lines
Quoted 9 lines

'discovery->data.info' length is 22, NICKNAME_MAX_LEN is 21, so the strncpy() will always left the last byte of 'discovery->data.info' uninitialized.

When 'text' length is longer than 21 (NICKNAME_MAX_LEN), if still left the last byte of 'discovery->data.info' uninitialized, the next strlen() will cause issue.

Quoted 10 lines
Quoted 7 lines
Quoted 7 lines

Also 'discovery->data' is 'struct irda_device_info' which defined in "include/uapi/...", it may copy to user mode, so need whole initialized.

All together, need use kzalloc() instead of kmalloc() to initialize all members firstly.

Applied, thanks.

Thank you, too.

Thanks.

Signature · 3 lines
Chen Gang

Asianux Corporation