Skip to contentSkip to conversation

drivers/net/cxgb3/cxgb3_main.c: prevent reading uninitialized stack memory

PATCH Applied Dan Rosenberg 3 participants 3 messages Sep 15, 2010 – Sep 17, 2010

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

PATCH v2 1/1 drivers/net/cxgb3/cxgb3_main.c: prevent reading uninitialized stack memory

Fixed formatting (tabs and line breaks).

The CHELSIO_GET_QSET_NUM device ioctl allows unprivileged users to read 4 bytes of uninitialized stack memory, because the "addr" member of the ch_reg struct declared on the stack in cxgb_extension_ioctl() is not altered or zeroed before being copied back to the user. This patch takes care of it.

drivers/net/cxgb3/cxgb3_main.c +2 -0
@@ -2296,6 +2296,8 @@ static int cxgb_extension_ioctl(struct n
 	case CHELSIO_GET_QSET_NUM:{
 		struct ch_reg edata;
 
+		memset(&edata, 0, sizeof(struct ch_reg));
+
 		edata.cmd = CHELSIO_GET_QSET_NUM;
 		edata.val = pi->nqsets;
 		if (copy_to_user(useraddr, &edata, sizeof(edata)))
#1 lore raw
Quoted 13 lines · Dan Rosenberg

Fixed formatting (tabs and line breaks).

The CHELSIO_GET_QSET_NUM device ioctl allows unprivileged users to read 4 bytes of uninitialized stack memory, because the "addr" member of the ch_reg struct declared on the stack in cxgb_extension_ioctl() is not altered or zeroed before being copied back to the user. This patch takes care of it.

drivers/net/cxgb3/cxgb3_main.c static int cxgb_extension_ioctl(struct n · line 2302

Quoted 7 lines
drivers/net/cxgb3/cxgb3_main.c +2 -0
@@ -2296,6 +2296,8 @@ static int cxgb_extension_ioctl(struct n
 	case CHELSIO_GET_QSET_NUM:{
 		struct ch_reg edata;
 
+		memset(&edata, 0, sizeof(struct ch_reg));
+
 		edata.cmd = CHELSIO_GET_QSET_NUM;
 		edata.val = pi->nqsets;

This is a pretty expensive way to fix it. either...

+ edata.addr = 0;

    or:

- struct ch_reg edata;
+ struct ch_reg edata = {
+ .cmd = CHELSIO_GET_QSET_NUM,
+ .val = pi->nqsets
+ };

- edata.cmd = CHELSIO_GET_QSET_NUM;
- edata.val = pi->nqsets;

If you are worried that the struct ch_reg may grow someday.

-- Steve

Quoted 3 lines
drivers/net/cxgb3/cxgb3_main.c +0 -0
 		if (copy_to_user(useraddr, &edata, sizeof(edata)))
maintainer Applied
#2 lore raw
In reply to Dan Rosenberg

From: Dan Rosenberg <[email protected]>
Date: Wed, 15 Sep 2010 17:43:12 -0400

Quoted 9 lines

Fixed formatting (tabs and line breaks).

The CHELSIO_GET_QSET_NUM device ioctl allows unprivileged users to read 4 bytes of uninitialized stack memory, because the "addr" member of the ch_reg struct declared on the stack in cxgb_extension_ioctl() is not altered or zeroed before being copied back to the user. This patch takes care of it.

Applied.