linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Changming Liu <liu.changm@northeastern.edu>
Cc: "thomas@winischhofer.net" <thomas@winischhofer.net>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"Lu, Long" <l.lu@northeastern.edu>,
	"yaohway@gmail.com" <yaohway@gmail.com>
Subject: Re: [Bug Report] drivers/usb/misc/sisusbvga: undefined result when left shift a possible negative value in sisusb_write_mem_bulk
Date: Wed, 20 May 2020 07:01:55 +0200	[thread overview]
Message-ID: <20200520050155.GB2105777@kroah.com> (raw)
In-Reply-To: <BL0PR06MB4548D5526F5BFAD528039FECE5B60@BL0PR06MB4548.namprd06.prod.outlook.com>

On Wed, May 20, 2020 at 03:51:04AM +0000, Changming Liu wrote:
> Hi Greg and Thomas,
> Greetings, I'm a first-year PhD student who is interested in the usage of UBSan for linux. And after some experiments, I've found that in drivers/usb/misc/sisusbvga/sisusb.c 
> function sisusb_write_mem_bulk, there is an undefined behavior caused by left shifting a possible negative number.
> 
> More specifically, in the switch statement for case 3, after executing copy_from_user, the the lower 3 bytes of char buf[4] are filled with data from user space.
> And these 3 bytes are left shifted accordingly to form a 32bit unsigned integer, swap32.
> 
> The potential problem is, since the buf is declared as signed char buffer so each byte might be a negative number while being left shifted. According to the C standard, when the left-hand operand of the left shift operator is a negative value, the result is undefined. So I guess change the buf declaration to unsigned will help? Given that it's only used here.

Sounds like a good idea, patches are welcome to fix this.

thanks,

greg k-h

      reply	other threads:[~2020-05-20  5:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-20  3:51 [Bug Report] drivers/usb/misc/sisusbvga: undefined result when left shift a possible negative value in sisusb_write_mem_bulk Changming Liu
2020-05-20  5:01 ` Greg KH [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200520050155.GB2105777@kroah.com \
    --to=greg@kroah.com \
    --cc=l.lu@northeastern.edu \
    --cc=linux-usb@vger.kernel.org \
    --cc=liu.changm@northeastern.edu \
    --cc=thomas@winischhofer.net \
    --cc=yaohway@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).