lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_F437644B027489769D66E43D51361E965A09@qq.com>
Date: Sat,  7 Sep 2024 10:08:57 +0800
From: Edward Adam Davis <eadavis@...com>
To: stern@...land.harvard.edu
Cc: eadavis@...com,
	gregkh@...uxfoundation.org,
	linux-kernel@...r.kernel.org,
	linux-usb@...r.kernel.org,
	syzbot+9d34f80f841e948c3fdb@...kaller.appspotmail.com,
	syzkaller-bugs@...glegroups.com
Subject: Re: [PATCH V2] USB: usbtmc: prevent kernel-usb-infoleak

On Fri, 6 Sep 2024 10:28:11 -0400, Alan Stern wrote:
> On Fri, Sep 06, 2024 at 10:11:03PM +0800, Edward Adam Davis wrote:
> > The syzbot reported a kernel-usb-infoleak in usbtmc_write.
> > 
> > The expression "aligned = (transfersize + (USBTMC_HEADER_SIZE + 3)) & ~3;"
> > in usbtmcw_write() follows the following pattern:
> > 
> > aligned = (1 + 12 + 3) & ~3 = 16   // 3 bytes have not been initialized
> > aligned = (2 + 12 + 3) & ~3 = 16   // 2 bytes have not been initialized
> > aligned = (3 + 12 + 3) & ~3 = 16   // 1 byte has not been initialized
> > aligned = (4 + 12 + 3) & ~3 = 16   // All bytes have been initialized
> > aligned = (5 + 12 + 3) & ~3 = 20   // 3 bytes have not been initialized
> > aligned = (6 + 12 + 3) & ~3 = 20   // 2 bytes have not been initialized
> > aligned = (7 + 12 + 3) & ~3 = 20   // 1 byte has not been initialized
> > aligned = (8 + 12 + 3) & ~3 = 20   // All bytes have been initialized
> > aligned = (9 + 12 + 3) & ~3 = 24
> > ...
> 
> What is the purpose of aligned?  Why doesn't the driver simply use
> USBTMC_HEADER_SIZE + transfersize instead of rounding it up to a 
> multiple of 4?
I just found out that the logic of aligned calculation is like this. 
As for why it is calculated like this, perhaps Guido Kiener can provide
a clearer explanation.
It was introduced by commit 4d5e18d9ed93 ("usb: usbtmc: Optimize usbtmc_write").
> 
> > Note: #define USBTMC_HEADER_SIZE      12
> > 
> > This results in the buffer[USBTMC_SEAD_SIZE+transfersize] and its
> > subsequent memory not being initialized.
> > 
> > The condition aligned < buflen is used to avoid out of bounds access to
> > the buffer[USBTMC_HEADER_SIZE + transfersize] when "transfersize = 
> > buflen - USBTMC_HEADER_SIZE".
> > 
> > Fixes: 4ddc645f40e9 ("usb: usbtmc: Add ioctl for vendor specific write")
> > Reported-and-tested-by: syzbot+9d34f80f841e948c3fdb@...kaller.appspotmail.com
> > Closes: https://syzkaller.appspot.com/bug?extid=9d34f80f841e948c3fdb
> > Signed-off-by: Edward Adam Davis <eadavis@...com>
> > ---
> >  drivers/usb/class/usbtmc.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
> > index 6bd9fe565385..faf8c5508997 100644
> > --- a/drivers/usb/class/usbtmc.c
> > +++ b/drivers/usb/class/usbtmc.c
> > @@ -1591,6 +1591,10 @@ static ssize_t usbtmc_write(struct file *filp, const char __user *buf,
> >  		goto exit;
> >  	}
> >  
> > +	if (aligned < buflen && (transfersize % 4))
> 
> Shouldn't this be
> 
> 	if (USBTMC_HEADER_SIZE + transfersize < aligned)
Logically, it seems possible to write it this way.
> 
> ?
> 
> Alan Stern
> 
> > +		memset(&buffer[USBTMC_HEADER_SIZE + transfersize], 0,
> > +			aligned - USBTMC_HEADER_SIZE - transfersize);
> > +
> >  	dev_dbg(&data->intf->dev, "%s(size:%u align:%u)\n", __func__,
> >  		(unsigned int)transfersize, (unsigned int)aligned);

BR,
Edward


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ