Skip to contentSkip to conversation

ethtool: Resolve use of uninitialized memory in rxclass_get_dev_info

PATCH In review Alexander Duyck 2 participants 4 messages Jul 13, 2012 – Jul 17, 2012

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

PATCH 1/1 ethtool: Resolve use of uninitialized memory in rxclass_get_dev_info

The ethtool function for getting the rule count was not zeroing out the data field before passing it to the kernel. As a result the value started uninitialized and was incorrectly returning a result indicating that devices supported setting new rule indexes. In order to correct this I am adding a one line fix that sets data to zero before we pass the command to the kernel.

---

I am resending this since I didn't see any notification that it had been seen. I also realized that I had not clearly identified that this is an ethtool user space patch and not an ethtool kernel space patch.

 rxclass.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
rxclass.c +1 -0
index 4d49aa6..e1633a8 100644
@@ -207,6 +207,7 @@ static int rxclass_get_dev_info(struct cmd_context *ctx, __u32 *count,
 	int err;
 
 	nfccmd.cmd = ETHTOOL_GRXCLSRLCNT;
+	nfccmd.data = 0;
 	err = send_ioctl(ctx, &nfccmd);
 	*count = nfccmd.rule_cnt;
 	if (driver_select)
#1 lore raw
Quoted 6 lines · Alexander Duyck

The ethtool function for getting the rule count was not zeroing out the data field before passing it to the kernel. As a result the value started uninitialized and was incorrectly returning a result indicating that devices supported setting new rule indexes. In order to correct this I am adding a one line fix that sets data to zero before we pass the command to the kernel.

Right. For 'get' commands with no parameters (besides the device) the data copied back to userland is normally zero-initialised and then filled out by the driver, and I seem to have worked on that assumption. But because of the odd multiplexing of RX NFC commands ETHTOOL_GRXCLSRLCNT doesn't work like that. And for 'my' driver that didn't matter. Sorry about that.

(We should really have some explicit documentation of responsibility for structure initialisation.)

Quoted 6 lines

---

I am resending this since I didn't see any notification that it had been seen. I also realized that I had not clearly identified that this is an ethtool user space patch and not an ethtool kernel space patch.

It was perfectly clear and I had queued it up to review but hadn't yet done so.

Ben.

Quoted 16 lines
 rxclass.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
rxclass.c +1 -0
index 4d49aa6..e1633a8 100644
@@ -207,6 +207,7 @@ static int rxclass_get_dev_info(struct cmd_context *ctx, __u32 *count,
 	int err;
 
 	nfccmd.cmd = ETHTOOL_GRXCLSRLCNT;
+	nfccmd.data = 0;
 	err = send_ioctl(ctx, &nfccmd);
 	*count = nfccmd.rule_cnt;
 	if (driver_select)
Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#2 lore raw
Quoted 20 lines · Ben Hutchings
Quoted 6 lines · Alexander Duyck

The ethtool function for getting the rule count was not zeroing out the data field before passing it to the kernel. As a result the value started uninitialized and was incorrectly returning a result indicating that devices supported setting new rule indexes. In order to correct this I am adding a one line fix that sets data to zero before we pass the command to the kernel.

Right. For 'get' commands with no parameters (besides the device) the data copied back to userland is normally zero-initialised and then filled out by the driver, and I seem to have worked on that assumption. But because of the odd multiplexing of RX NFC commands ETHTOOL_GRXCLSRLCNT doesn't work like that. And for 'my' driver that didn't matter. Sorry about that.

(We should really have some explicit documentation of responsibility for structure initialisation.)

Quoted 3 lines

---

Quoted 8 lines
Quoted 3 lines

I am resending this since I didn't see any notification that it had been seen. I also realized that I had not clearly identified that this is an ethtool user space patch and not an ethtool kernel space patch.

It was perfectly clear and I had queued it up to review but hadn't yet done so.

Ben.

Yeah, that was my mistake. I thought I hadn't sent it out with the ethtool prefix when I actually had.

Thanks,

Alex

#3 lore raw
Quoted 24 lines · Alexander Duyck
Quoted 23 lines · Ben Hutchings
Quoted 6 lines · Alexander Duyck

The ethtool function for getting the rule count was not zeroing out the data field before passing it to the kernel. As a result the value started uninitialized and was incorrectly returning a result indicating that devices supported setting new rule indexes. In order to correct this I am adding a one line fix that sets data to zero before we pass the command to the kernel.

Right. For 'get' commands with no parameters (besides the device) the data copied back to userland is normally zero-initialised and then filled out by the driver, and I seem to have worked on that assumption. But because of the odd multiplexing of RX NFC commands ETHTOOL_GRXCLSRLCNT doesn't work like that. And for 'my' driver that didn't matter. Sorry about that.

(We should really have some explicit documentation of responsibility for structure initialisation.)

Quoted 6 lines

---

I am resending this since I didn't see any notification that it had been seen. I also realized that I had not clearly identified that this is an ethtool user space patch and not an ethtool kernel space patch.

Quoted 7 lines
Quoted 5 lines

It was perfectly clear and I had queued it up to review but hadn't yet done so.

Ben.

Yeah, that was my mistake. I thought I hadn't sent it out with the ethtool prefix when I actually had.

So, anyway, I've applied it and just done a bug fix release (3.4.2).

Ben.

Signature · 3 lines
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.