Skip to contentSkip to conversation

usb: usbtmc: initialize memory written to device

PATCH In review Pimyn Girgis [email protected] 4 participants 6 messages Oct 4, 2024 USB

lore
Share & tools
lore

Pimyn Girgis [email protected]

author
#0 lore raw

PATCH 1/1 usb: usbtmc: initialize memory written to device

Avoid kernel-usb-infoleak by initializing all memory written to device. The buffer length uses 32bit alignment which might cause some buffer data to be read without any initialization.

---
 drivers/usb/class/usbtmc.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/class/usbtmc.c +3 -0
index ffc9c6fdd7e1..d79a08dfb54d 100644
@@ -21,6 +21,7 @@
 #include <linux/usb.h>
 #include <linux/compat.h>
 #include <linux/usb/tmc.h>
+#include <linux/string.h>
 
 /* Increment API VERSION when changing tmc.h with new flags or ioctls
  * or when changing a significant behavior of the driver.
@@ -1169,6 +1170,8 @@ static ssize_t usbtmc_generic_write(struct usbtmc_file_data *file_data,
 		 * (size + 3 & ~3) rounds up and simplifies user code
 		 */
 		aligned = (this_part + 3) & ~3;
+		/* Initialize the remaining part of the buffer */
+		memzero_explicit(buffer + this_part, aligned - this_part);
 		dev_dbg(dev, "write(size:%u align:%u done:%u)\n",
 			(unsigned int)this_part,
 			(unsigned int)aligned,
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
maintainer
#1 lore raw
Quoted 10 lines · On Fri, Oct 04, 2024 at 12:33:13PM +0000, [email protected] wrote:

Avoid kernel-usb-infoleak by initializing all memory written to device. The buffer length uses 32bit alignment which might cause some buffer data to be read without any initialization.

---
 drivers/usb/class/usbtmc.c | 3 +++
 1 file changed, 3 insertions(+)

The "From:" line of this commit is obviously not correct and does not match this signed-off-by line.

Also, as you are from google, just use your google.com email address please.

thanks,

greg k-h

#2 lore raw
Quoted 2 lines · Greg KH

On Fri, Oct 04, 2024 at 12:33:13PM +0000, [email protected] wrote:

Just curious, what's up with this @web.codeaurora.org address? It wasn't in the original patch, where did it come from? :)

Quoted 11 lines
Quoted 10 lines

Avoid kernel-usb-infoleak by initializing all memory written to device. The buffer length uses 32bit alignment which might cause some buffer data to be read without any initialization.

---
 drivers/usb/class/usbtmc.c | 3 +++
 1 file changed, 3 insertions(+)
Quoted 2 lines

The "From:" line of this commit is obviously not correct and does not match this signed-off-by line.

Sorry, does it mean the "(Google)" part should be present in the From:
line as well?

Quoted 2 lines

Also, as you are from google, just use your google.com email address please.

Unfortunately Pimyn cannot send emails outside the @google.com domain.

maintainer
#3 lore raw
Quoted 6 lines · Alexander Potapenko
Quoted 2 lines · Greg KH

On Fri, Oct 04, 2024 at 12:33:13PM +0000, [email protected] wrote:

Just curious, what's up with this @web.codeaurora.org address? It wasn't in the original patch, where did it come from? :)

You tell me, look at the original patch, it's in the email...

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

Avoid kernel-usb-infoleak by initializing all memory written to device. The buffer length uses 32bit alignment which might cause some buffer data to be read without any initialization.

---
 drivers/usb/class/usbtmc.c | 3 +++
 1 file changed, 3 insertions(+)
Quoted 5 lines
Quoted 2 lines

The "From:" line of this commit is obviously not correct and does not match this signed-off-by line.

Sorry, does it mean the "(Google)" part should be present in the From:
line as well?

A valid email address should be in the "From:" line.

Quoted 4 lines
Quoted 2 lines

Also, as you are from google, just use your google.com email address please.

Unfortunately Pimyn cannot send emails outside the @google.com domain.

Google has well-known facilities and abilities to handle this, please use them and do not hide behind gmail accounts.

thanks,

greg k-h

maintainer
#4 lore raw
In reply to Pimyn Girgis [email protected]
Quoted 24 lines · On Fri, Oct 04, 2024 at 12:33:13PM +0000, [email protected] wrote:

Avoid kernel-usb-infoleak by initializing all memory written to device. The buffer length uses 32bit alignment which might cause some buffer data to be read without any initialization.

---
 drivers/usb/class/usbtmc.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/class/usbtmc.c +1 -0
index ffc9c6fdd7e1..d79a08dfb54d 100644
@@ -21,6 +21,7 @@
 #include <linux/usb.h>
 #include <linux/compat.h>
 #include <linux/usb/tmc.h>
+#include <linux/string.h>
 
 /* Increment API VERSION when changing tmc.h with new flags or ioctls
  * or when changing a significant behavior of the driver.

drivers/usb/class/usbtmc.c static ssize_t usbtmc_generic_write(struct usbtmc_file_data *file_data, · line 1174

Quoted 5 lines
drivers/usb/class/usbtmc.c +2 -0
@@ -1169,6 +1170,8 @@ static ssize_t usbtmc_generic_write(struct usbtmc_file_data *file_data,
 		 * (size + 3 & ~3) rounds up and simplifies user code
 		 */
 		aligned = (this_part + 3) & ~3;
+		/* Initialize the remaining part of the buffer */
+		memzero_explicit(buffer + this_part, aligned - this_part);

Why "explicit"?

Also, what about commit 625fa77151f0 ("USB: usbtmc: prevent kernel-usb-infoleak"), doesn't that solve the issue here?

thanks,

greg k-h

#5 lore raw
Quoted 1 line · Greg KH

Why "explicit"?

Thank you. I think we could use memzero here instead.

Quoted 2 lines

Also, what about commit 625fa77151f0 ("USB: usbtmc: prevent kernel-usb-infoleak"), doesn't that solve the issue here?

You're right. This commit is not in 6.11, so I missed it.