linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Wu <lekensteyn@gmail.com>
To: Jiri Kosina <jkosina@suse.cz>
Cc: linux-input@vger.kernel.org,
	Manoj Chourasia <mchourasia@nvidia.com>,
	linux-kernel@vger.kernel.org, alnovak@suse.cz
Subject: Re: List corruption in hidraw_release in 3.11-rc4
Date: Wed, 07 Aug 2013 15:30:32 +0200	[thread overview]
Message-ID: <6207700.eHyYqS01s0@al> (raw)
In-Reply-To: <alpine.LNX.2.00.1308070258480.10817@pobox.suse.cz>

On Wednesday 07 August 2013 03:01:26 Jiri Kosina wrote:
> On Tue, 6 Aug 2013, Peter Wu wrote:
> > While debugging upowerd (with Logitech Unifying receiver via hidraw),
> > I came across this list corruption warning.
> 
> Peter,
> 
> does the patch below fix the problem you are seeing?
That one is already in 3.11-rc4 as far as I can see. Also, that code can 
probably simplified by moving the mutex_unlock after the out label, removing 
the need to duplicate the mutex_unlock.

Remember what I said about "no Oopses"? Well, it turned out that several 
memory structures were damaged which causes a general protection fault in 
sock_alloc_inode and other places.

I managed to create a program that can reproduce this bug 100% in a QEMU 
virtual machine with a Logitech USB receiver passed to it.

qemu-system-x86_64 -enable-kvm -m 1G -usb -usbdevice host:046d:c52b
(pass -kernel, -initrd, -append as needed)

Copy hidraw-test to initrd, boot QEMU and run `hidraw-test`. Result: instant
(= +/- 2 seconds) crash.

I have applied Manoj's patch[1] on top of 3.11-rc4 which seem to fix the issue. 
One observation is that the new device is named /dev/hidraw1 instead of 
/dev/hidraw0. Example:

f(){ hidraw-test /dev/hidraw$1 usb1;}
# needed for 3.11-rc4
f 1; f 1 # crash
# needed for 3.11-rc4 + patch
f 1; f 2 # ok

Regards,
Peter

 [1]: http://lkml.org/lkml/2013/7/22/248
--
/* cc hidraw-test.c -o hidraw-test
 * hidraw-test /dev/hidraw0 usb1; hidraw-test /dev/hidraw0 usb1;
 */
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>

int open_and_write(const char *path, const char *data) {
	int sfd, r;

	sfd = open(path, O_WRONLY);
	if (sfd < 0) {
		perror(path);
		return 1;
	}

	r = write(sfd, data, strlen(data));
	if (r < 0) {
		fprintf(stderr, "write(%s, %s): %s\n",
			path, data, strerror(errno));
		return 1;
	}
	close(sfd);
	return 0;
}

int dork(const char *hiddev, const char *name) {
	int fd;
	char c;

	fd = open(hiddev, O_RDWR | O_NONBLOCK);
	if (fd < 0) {
		perror("open");
		return 1;
	}

	if (open_and_write("/sys/bus/usb/drivers/usb/unbind", name))
		return 1;

	// does not make a difference
	//sleep(1);

	if (open_and_write("/sys/bus/usb/drivers/usb/bind", name))
		return 1;

	// allow devices to get discovered
	sleep(1);

	printf("read() = %zi\n", read(fd, &c, 1)); perror("read");
	close(fd);
	return 0;
}

int main(int argc, char **argv) {
	if (argc < 3) {
		fprintf(stderr, "Usage: %s /dev/hidrawN usbN\n", *argv);
		return 1;
	}

	system("modprobe -v usbhid");
	system("modprobe -v hid-logitech-dj");

	dork(argv[1], argv[2]);

	return 0;
}

  reply	other threads:[~2013-08-07 13:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-06 21:30 List corruption in hidraw_release in 3.11-rc4 Peter Wu
2013-08-07  1:01 ` Jiri Kosina
2013-08-07 13:30   ` Peter Wu [this message]
2013-08-07 13:34     ` Jiri Kosina
2013-08-07 15:06       ` Manoj Chourasia
2013-08-07 22:28       ` Peter Wu

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=6207700.eHyYqS01s0@al \
    --to=lekensteyn@gmail.com \
    --cc=alnovak@suse.cz \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mchourasia@nvidia.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).